Skip to content

Commit

Permalink
More code improvements
Browse files Browse the repository at this point in the history
  • Loading branch information
AlexProgrammerDE committed Dec 31, 2023
1 parent 93455ab commit ec6e395
Show file tree
Hide file tree
Showing 88 changed files with 288 additions and 350 deletions.
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package dev.u9g.minecraftdatagenerator.ClientSideAnnoyances;
package dev.u9g.minecraftdatagenerator.clientsideannoyances;

import dev.u9g.minecraftdatagenerator.util.EmptyBlockView;
import net.minecraft.util.math.BlockPos;
Expand All @@ -7,8 +7,8 @@
import java.util.Iterator;

public class BiomeColors {
private static final ColorProvider GRASS_COLOR = (biome, pos) -> biome.getGrassColor(pos);
private static final ColorProvider FOLIAGE_COLOR = (biome, pos) -> biome.getFoliageColor(pos);
private static final ColorProvider GRASS_COLOR = Biome::getGrassColor;
private static final ColorProvider FOLIAGE_COLOR = Biome::getFoliageColor;
private static final ColorProvider WATER_COLOR = (biome, pos) -> biome.getWaterColor();

private static int getColor(EmptyBlockView view, BlockPos pos, ColorProvider provider) {
Expand All @@ -17,7 +17,7 @@ private static int getColor(EmptyBlockView view, BlockPos pos, ColorProvider pro
int k = 0;

int l;
for (Iterator iterator = BlockPos.mutableIterate(pos.add(-1, 0, -1), pos.add(1, 0, 1)).iterator(); iterator.hasNext(); k += l & 255) {
for (Iterator<BlockPos.Mutable> iterator = BlockPos.mutableIterate(pos.add(-1, 0, -1), pos.add(1, 0, 1)).iterator(); iterator.hasNext(); k += l & 255) {
BlockPos.Mutable mutable = (BlockPos.Mutable) iterator.next();
l = provider.getColorAtPos(view.getBiome(mutable), mutable);
i += (l & 16711680) >> 16;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package dev.u9g.minecraftdatagenerator.ClientSideAnnoyances;
package dev.u9g.minecraftdatagenerator.clientsideannoyances;

import dev.u9g.minecraftdatagenerator.util.EmptyBlockView;
import net.minecraft.block.BlockState;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package dev.u9g.minecraftdatagenerator.ClientSideAnnoyances;
package dev.u9g.minecraftdatagenerator.clientsideannoyances;

import dev.u9g.minecraftdatagenerator.util.EmptyBlockView;
import net.minecraft.block.*;
Expand All @@ -19,7 +19,7 @@ public BlockColors() {
public static BlockColors create() {
final BlockColors blockColors = new BlockColors();
blockColors.method_12158((blockState, blockView, blockPos, i) -> {
DoublePlantBlock.DoublePlantType doublePlantType = (DoublePlantBlock.DoublePlantType) blockState.get(DoublePlantBlock.VARIANT);
DoublePlantBlock.DoublePlantType doublePlantType = blockState.get(DoublePlantBlock.VARIANT);
return blockView == null || blockPos == null || doublePlantType != DoublePlantBlock.DoublePlantType.GRASS && doublePlantType != DoublePlantBlock.DoublePlantType.FERN ? -1 : BiomeColors.getGrassColor(blockView, blockPos);
}, Blocks.DOUBLE_PLANT);
blockColors.method_12158((blockState, blockView, blockPos, i) -> {
Expand All @@ -38,7 +38,7 @@ public static BlockColors create() {
}, Blocks.FLOWER_POT);
blockColors.method_12158((blockState, blockView, blockPos, i) -> blockView != null && blockPos != null ? BiomeColors.getGrassColor(blockView, blockPos) : GrassColors.getColor(0.5D, 1.0D), Blocks.GRASS);
blockColors.method_12158((blockState, blockView, blockPos, i) -> {
PlanksBlock.WoodType woodType = (PlanksBlock.WoodType) blockState.get(Leaves1Block.VARIANT);
PlanksBlock.WoodType woodType = blockState.get(Leaves1Block.VARIANT);
if (woodType == PlanksBlock.WoodType.SPRUCE) {
return FoliageColors.getSpruceColor();
} else if (woodType == PlanksBlock.WoodType.BIRCH) {
Expand All @@ -49,10 +49,10 @@ public static BlockColors create() {
}, Blocks.LEAVES);
blockColors.method_12158((blockState, blockView, blockPos, i) -> blockView != null && blockPos != null ? BiomeColors.getFoliageColor(blockView, blockPos) : FoliageColors.getDefaultColor(), Blocks.LEAVES2);
blockColors.method_12158((blockState, blockView, blockPos, i) -> blockView != null && blockPos != null ? BiomeColors.getWaterColor(blockView, blockPos) : -1, Blocks.WATER, Blocks.FLOWING_WATER);
blockColors.method_12158((blockState, blockView, blockPos, i) -> RedstoneWireBlock.method_8877((Integer) blockState.get(RedstoneWireBlock.POWER)), Blocks.REDSTONE_WIRE);
blockColors.method_12158((blockState, blockView, blockPos, i) -> RedstoneWireBlock.method_8877(blockState.get(RedstoneWireBlock.POWER)), Blocks.REDSTONE_WIRE);
blockColors.method_12158((blockState, blockView, blockPos, i) -> blockView != null && blockPos != null ? BiomeColors.getGrassColor(blockView, blockPos) : -1, Blocks.SUGARCANE);
blockColors.method_12158((blockState, blockView, blockPos, i) -> {
int j = (Integer) blockState.get(AttachedStemBlock.AGE);
int j = blockState.get(AttachedStemBlock.AGE);
int k = j * 32;
int l = 255 - j * 8;
int m = j * 4;
Expand All @@ -71,25 +71,24 @@ public static BlockColors create() {
}

public int method_13410(BlockState blockState) {
BlockColorable blockColorable = (BlockColorable) this.BlockColor2Id.fromId(Block.getIdByBlock(blockState.getBlock()));
BlockColorable blockColorable = this.BlockColor2Id.fromId(Block.getIdByBlock(blockState.getBlock()));
if (blockColorable != null) {
return blockColorable.method_12155(blockState, (EmptyBlockView) null, (BlockPos) null, 0);
return blockColorable.method_12155(blockState, null, null, 0);
} else {
MaterialColor materialColor = blockState.getMaterialColor();
return materialColor != null ? materialColor.color : -1;
}
}

public int method_12157(BlockState blockState, @Nullable EmptyBlockView blockView, @Nullable BlockPos blockPos, int i) {
BlockColorable blockColorable = (BlockColorable) this.BlockColor2Id.fromId(Block.getIdByBlock(blockState.getBlock()));
BlockColorable blockColorable = this.BlockColor2Id.fromId(Block.getIdByBlock(blockState.getBlock()));
return blockColorable == null ? -1 : blockColorable.method_12155(blockState, blockView, blockPos, i);
}

public void method_12158(BlockColorable blockColorable, Block... blocks) {
int i = blocks.length;

for (int j = 0; j < i; ++j) {
Block block = blocks[j];
for (Block block : blocks) {
this.BlockColor2Id.set(blockColorable, Block.getIdByBlock(block));
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package dev.u9g.minecraftdatagenerator.ClientSideAnnoyances;
package dev.u9g.minecraftdatagenerator.clientsideannoyances;

import net.minecraft.util.math.MathHelper;
import net.minecraft.world.biome.Biome;
Expand Down Expand Up @@ -30,8 +30,8 @@ public static int getDefaultColor() {
}

public static int getFoliageColor(Biome biome) {
double d = (double) MathHelper.clamp(biome.getTemperature(), 0.0F, 1.0F);
double e = (double) MathHelper.clamp(biome.getRainfall(), 0.0F, 1.0F);
double d = MathHelper.clamp(biome.getTemperature(), 0.0F, 1.0F);
double e = MathHelper.clamp(biome.getRainfall(), 0.0F, 1.0F);
return FoliageColors.getColor(d, e);
}
}
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package dev.u9g.minecraftdatagenerator.ClientSideAnnoyances;
package dev.u9g.minecraftdatagenerator.clientsideannoyances;

import net.minecraft.util.math.MathHelper;
import net.minecraft.world.biome.Biome;
Expand All @@ -19,8 +19,8 @@ public static int getColor(double temperature, double humidity) {
}

public static int getGrassColor(Biome biome) {
double d = (double) MathHelper.clamp(biome.getTemperature(), 0.0F, 1.0F);
double e = (double) MathHelper.clamp(biome.getRainfall(), 0.0F, 1.0F);
double d = MathHelper.clamp(biome.getTemperature(), 0.0F, 1.0F);
double e = MathHelper.clamp(biome.getRainfall(), 0.0F, 1.0F);
return GrassColors.getColor(d, e);
}
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package dev.u9g.minecraftdatagenerator.ClientSideAnnoyances;
package dev.u9g.minecraftdatagenerator.clientsideannoyances;

import net.minecraft.util.math.MathHelper;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -96,31 +96,22 @@ public JsonObject toJSON() {
return shapes;
}

private static class Shapes {
final List<Box> boxes;

public Shapes(List<Box> boxes) {
this.boxes = boxes;
}
private record Shapes(List<Box> boxes) {

public JsonArray toJSON() {
JsonArray arr = new JsonArray();
boxes.forEach(box -> arr.add(jsonOf(box)));
return arr;
}
JsonArray arr = new JsonArray();
boxes.forEach(box -> arr.add(jsonOf(box)));
return arr;
}

@Override
public boolean equals(Object o) {
if (this == o) return true;
if (o == null || getClass() != o.getClass()) return false;
Shapes shapes = (Shapes) o;
return Objects.equals(boxes, shapes.boxes);
}
@Override
public boolean equals(Object o) {
if (this == o) return true;
if (o == null || getClass() != o.getClass()) return false;
Shapes shapes = (Shapes) o;
return Objects.equals(boxes, shapes.boxes);
}

@Override
public int hashCode() {
return boxes != null ? boxes.hashCode() : 0;
}
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ private static Entity makeEntity(Class<? extends Entity> type) {
private static String getCategoryFrom(@NotNull Class<?> entityClass) {
if (entityClass == PlayerEntity.class) return "other"; // fail early for player entities
String packageName = entityClass.getPackage().getName();
String category = switch (packageName) {
return switch (packageName) {
case "net.minecraft.entity.decoration", "net.minecraft.entity.decoration.painting" -> "Immobile";
case "net.minecraft.entity.boss", "net.minecraft.entity.mob", "net.minecraft.entity.boss.dragon" ->
"Hostile mobs";
Expand All @@ -65,7 +65,6 @@ private static String getCategoryFrom(@NotNull Class<?> entityClass) {
case "net.minecraft.entity" -> "other";
default -> throw new Error("Unexpected entity type: " + packageName);
};
return category;
}

//Honestly, both "type" and "category" fields in the schema and examples do not contain any useful information
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,10 @@
import com.google.gson.JsonArray;
import com.google.gson.JsonObject;
import com.google.gson.JsonPrimitive;
import dev.u9g.minecraftdatagenerator.ClientSideAnnoyances.BlockColors;
import dev.u9g.minecraftdatagenerator.ClientSideAnnoyances.FoliageColors;
import dev.u9g.minecraftdatagenerator.ClientSideAnnoyances.GrassColors;
import dev.u9g.minecraftdatagenerator.ClientSideAnnoyances.ServerSideRedstoneWireBlock;
import dev.u9g.minecraftdatagenerator.clientsideannoyances.BlockColors;
import dev.u9g.minecraftdatagenerator.clientsideannoyances.FoliageColors;
import dev.u9g.minecraftdatagenerator.clientsideannoyances.GrassColors;
import dev.u9g.minecraftdatagenerator.clientsideannoyances.ServerSideRedstoneWireBlock;
import dev.u9g.minecraftdatagenerator.mixin.BiomeAccessor;
import dev.u9g.minecraftdatagenerator.util.EmptyBlockView;
import dev.u9g.minecraftdatagenerator.util.Registries;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package dev.u9g.minecraftdatagenerator.ClientSideAnnoyances;
package dev.u9g.minecraftdatagenerator.clientsideannoyances;

import dev.u9g.minecraftdatagenerator.util.EmptyBlockView;
import net.minecraft.util.math.BlockPos;
Expand All @@ -9,13 +9,13 @@

public class BiomeColors {
private static final ColorProvider GRASS_COLOR = (biome, pos) -> {
double d = (double) MathHelper.clamp(biome.getTemperature(pos), 0.0F, 1.0F);
double e = (double) MathHelper.clamp(biome.getRainfall(), 0.0F, 1.0F);
double d = MathHelper.clamp(biome.getTemperature(pos), 0.0F, 1.0F);
double e = MathHelper.clamp(biome.getRainfall(), 0.0F, 1.0F);
return GrassColors.getColor(d, e);
};
private static final ColorProvider FOLIAGE_COLOR = (biome, pos) -> {
double d = (double) MathHelper.clamp(biome.getTemperature(pos), 0.0F, 1.0F);
double e = (double) MathHelper.clamp(biome.getRainfall(), 0.0F, 1.0F);
double d = MathHelper.clamp(biome.getTemperature(pos), 0.0F, 1.0F);
double e = MathHelper.clamp(biome.getRainfall(), 0.0F, 1.0F);
return FoliageColors.getColor(d, e);
};
private static final ColorProvider WATER_COLOR = (biome, pos) -> biome.getWaterColor();
Expand All @@ -26,7 +26,7 @@ private static int getColor(EmptyBlockView view, BlockPos pos, ColorProvider pro
int k = 0;

int l;
for (Iterator var6 = BlockPos.mutableIterate(pos.add(-1, 0, -1), pos.add(1, 0, 1)).iterator(); var6.hasNext(); k += l & 255) {
for (Iterator<BlockPos.Mutable> var6 = BlockPos.mutableIterate(pos.add(-1, 0, -1), pos.add(1, 0, 1)).iterator(); var6.hasNext(); k += l & 255) {
BlockPos.Mutable mutable = (BlockPos.Mutable) var6.next();
l = provider.getColorAtPos(view.getBiome(mutable), mutable);
i += (l & 16711680) >> 16;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package dev.u9g.minecraftdatagenerator.ClientSideAnnoyances;
package dev.u9g.minecraftdatagenerator.clientsideannoyances;

import dev.u9g.minecraftdatagenerator.util.EmptyBlockView;
import net.minecraft.block.BlockState;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package dev.u9g.minecraftdatagenerator.ClientSideAnnoyances;
package dev.u9g.minecraftdatagenerator.clientsideannoyances;

import dev.u9g.minecraftdatagenerator.util.EmptyBlockView;
import net.minecraft.block.*;
Expand All @@ -18,7 +18,7 @@ public BlockColors() {
public static BlockColors create() {
final BlockColors blockColors = new BlockColors();
blockColors.method_12158((blockState, blockView, blockPos, i) -> {
DoublePlantBlock.DoublePlantType doublePlantType = (DoublePlantBlock.DoublePlantType) blockState.get(DoublePlantBlock.VARIANT);
DoublePlantBlock.DoublePlantType doublePlantType = blockState.get(DoublePlantBlock.VARIANT);
return blockView != null && blockPos != null && (doublePlantType == DoublePlantBlock.DoublePlantType.GRASS || doublePlantType == DoublePlantBlock.DoublePlantType.FERN) ? BiomeColors.getGrassColor(blockView, blockState.get(DoublePlantBlock.HALF) == DoublePlantBlock.HalfType.UPPER ? blockPos.down() : blockPos) : -1;
}, Blocks.DOUBLE_PLANT);
blockColors.method_12158((blockState, blockView, blockPos, i) -> {
Expand All @@ -37,7 +37,7 @@ public static BlockColors create() {
}, Blocks.FLOWER_POT);
blockColors.method_12158((blockState, blockView, blockPos, i) -> blockView != null && blockPos != null ? BiomeColors.getGrassColor(blockView, blockPos) : GrassColors.getColor(0.5D, 1.0D), Blocks.GRASS);
blockColors.method_12158((blockState, blockView, blockPos, i) -> {
PlanksBlock.WoodType woodType = (PlanksBlock.WoodType) blockState.get(Leaves1Block.VARIANT);
PlanksBlock.WoodType woodType = blockState.get(Leaves1Block.VARIANT);
if (woodType == PlanksBlock.WoodType.SPRUCE) {
return net.minecraft.client.color.world.FoliageColors.getSpruceColor();
} else if (woodType == PlanksBlock.WoodType.BIRCH) {
Expand All @@ -48,10 +48,10 @@ public static BlockColors create() {
}, Blocks.LEAVES);
blockColors.method_12158((blockState, blockView, blockPos, i) -> blockView != null && blockPos != null ? BiomeColors.getFoliageColor(blockView, blockPos) : FoliageColors.getDefaultColor(), Blocks.LEAVES2);
blockColors.method_12158((blockState, blockView, blockPos, i) -> blockView != null && blockPos != null ? BiomeColors.getWaterColor(blockView, blockPos) : -1, Blocks.WATER, Blocks.FLOWING_WATER);
blockColors.method_12158((blockState, blockView, blockPos, i) -> RedstoneWireBlock.method_8877((Integer) blockState.get(RedstoneWireBlock.POWER)), Blocks.REDSTONE_WIRE);
blockColors.method_12158((blockState, blockView, blockPos, i) -> RedstoneWireBlock.method_8877(blockState.get(RedstoneWireBlock.POWER)), Blocks.REDSTONE_WIRE);
blockColors.method_12158((blockState, blockView, blockPos, i) -> blockView != null && blockPos != null ? BiomeColors.getGrassColor(blockView, blockPos) : -1, Blocks.SUGARCANE);
blockColors.method_12158((blockState, blockView, blockPos, i) -> {
int j = (Integer) blockState.get(AttachedStemBlock.AGE);
int j = blockState.get(AttachedStemBlock.AGE);
int k = j * 32;
int l = 255 - j * 8;
int m = j * 4;
Expand All @@ -70,25 +70,24 @@ public static BlockColors create() {
}

public int method_13410(BlockState blockState) {
BlockColorable blockColorable = (BlockColorable) this.BlockColor2Id.fromId(Block.getIdByBlock(blockState.getBlock()));
BlockColorable blockColorable = this.BlockColor2Id.fromId(Block.getIdByBlock(blockState.getBlock()));
if (blockColorable != null) {
return blockColorable.method_12155(blockState, null, (BlockPos) null, 0);
return blockColorable.method_12155(blockState, null, null, 0);
} else {
MaterialColor materialColor = blockState.getMaterialColor();
return materialColor != null ? materialColor.color : -1;
}
}

public int method_12157(BlockState blockState, @Nullable EmptyBlockView blockView, @Nullable BlockPos blockPos, int i) {
BlockColorable blockColorable = (BlockColorable) this.BlockColor2Id.fromId(Block.getIdByBlock(blockState.getBlock()));
BlockColorable blockColorable = this.BlockColor2Id.fromId(Block.getIdByBlock(blockState.getBlock()));
return blockColorable == null ? -1 : blockColorable.method_12155(blockState, blockView, blockPos, i);
}

public void method_12158(BlockColorable blockColorable, Block... blocks) {
int var4 = blocks.length;

for (int var5 = 0; var5 < var4; ++var5) {
Block block = blocks[var5];
for (Block block : blocks) {
this.BlockColor2Id.set(blockColorable, Block.getIdByBlock(block));
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package dev.u9g.minecraftdatagenerator.ClientSideAnnoyances;
package dev.u9g.minecraftdatagenerator.clientsideannoyances;

public class FoliageColors {
private static int[] colorMap = new int[65536];
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package dev.u9g.minecraftdatagenerator.ClientSideAnnoyances;
package dev.u9g.minecraftdatagenerator.clientsideannoyances;

public class GrassColors {
private static int[] colorMap = new int[65536];
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package dev.u9g.minecraftdatagenerator.ClientSideAnnoyances;
package dev.u9g.minecraftdatagenerator.clientsideannoyances;

import net.minecraft.util.math.MathHelper;

Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package dev.u9g.minecraftdatagenerator.ClientSideAnnoyances;
package dev.u9g.minecraftdatagenerator.clientsideannoyances;

import net.minecraft.util.math.MathHelper;
import net.minecraft.world.biome.Biome;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

import com.google.gson.JsonArray;
import com.google.gson.JsonObject;
import dev.u9g.minecraftdatagenerator.ClientSideAnnoyances.SkyColor;
import dev.u9g.minecraftdatagenerator.clientsideannoyances.SkyColor;
import dev.u9g.minecraftdatagenerator.mixin.BiomeAccessor;
import net.minecraft.util.Identifier;
import net.minecraft.util.registry.SimpleRegistry;
Expand Down
Loading

0 comments on commit ec6e395

Please sign in to comment.