a start on 1.19

This commit is contained in:
u9g
2022-06-07 16:49:17 -04:00
parent 7cccf2e6e5
commit b655a809ff
11 changed files with 196 additions and 103 deletions
+11
View File
@@ -79,3 +79,14 @@ publishing {
// retrieving dependencies. // retrieving dependencies.
} }
} }
loom {
splitEnvironmentSourceSets()
mods {
modid {
sourceSet sourceSets.main
// sourceSet sourceSets.client
}
}
}
+3 -3
View File
@@ -2,9 +2,9 @@
org.gradle.jvmargs=-Xmx1G org.gradle.jvmargs=-Xmx1G
# Fabric Properties # Fabric Properties
# check these on https://modmuss50.me/fabric.html # check these on https://modmuss50.me/fabric.html
minecraft_version=1.18 minecraft_version=1.19
yarn_mappings=1.18+build.1 yarn_mappings=1.19+build.1
loader_version=0.14.4 loader_version=0.14.6
# Mod Properties # Mod Properties
mod_version=1.0-SNAPSHOT mod_version=1.0-SNAPSHOT
maven_group=dev.u9g maven_group=dev.u9g
@@ -3,17 +3,20 @@ package dev.u9g.minecraftdatagenerator.generators;
import com.google.gson.JsonArray; import com.google.gson.JsonArray;
import com.google.gson.JsonObject; import com.google.gson.JsonObject;
import dev.u9g.minecraftdatagenerator.util.DGU; import dev.u9g.minecraftdatagenerator.util.DGU;
import net.fabricmc.fabric.api.biome.v1.NetherBiomes;
import net.fabricmc.fabric.api.biome.v1.TheEndBiomes;
import net.minecraft.util.Identifier; import net.minecraft.util.Identifier;
import net.minecraft.util.registry.DynamicRegistryManager; import net.minecraft.util.registry.DynamicRegistryManager;
import net.minecraft.util.registry.Registry; import net.minecraft.util.registry.Registry;
import net.minecraft.world.biome.Biome; import net.minecraft.world.biome.Biome;
import net.minecraft.world.biome.BuiltinBiomes;
public class BiomesDataGenerator implements IDataGenerator { public class BiomesDataGenerator implements IDataGenerator {
private static String guessBiomeDimensionFromCategory(Biome biome) { private static String guessBiomeDimensionFromCategory(Biome biome) {
return switch (biome.getCategory()) { return switch (biome.getCategory()) {
case NETHER -> "nether"; case NETHER -> "nether";
case THEEND -> "end"; case END -> "end";
default -> "overworld"; default -> "overworld";
}; };
} }
@@ -15,7 +15,7 @@ import net.minecraft.item.Items;
import net.minecraft.item.MiningToolItem; import net.minecraft.item.MiningToolItem;
import net.minecraft.item.SwordItem; import net.minecraft.item.SwordItem;
import net.minecraft.tag.BlockTags; import net.minecraft.tag.BlockTags;
import net.minecraft.tag.Tag; import net.minecraft.tag.TagKey;
import net.minecraft.util.registry.Registry; import net.minecraft.util.registry.Registry;
import java.util.*; import java.util.*;
@@ -40,9 +40,8 @@ public class MaterialsDataGenerator implements IDataGenerator {
return "materials"; return "materials";
} }
private static String makeMaterialNameForTag(Tag<Block> tag) { private static String makeMaterialNameForTag(TagKey<Block> tag) {
Tag.Identified<Block> identifiedTag = (Tag.Identified<Block>) tag; return tag.id().getPath();
return identifiedTag.getId().getPath();
} }
public static class MaterialInfo { public static class MaterialInfo {
@@ -2,14 +2,13 @@ package dev.u9g.minecraftdatagenerator.generators;
import com.google.gson.JsonArray; import com.google.gson.JsonArray;
import com.google.gson.JsonObject; import com.google.gson.JsonObject;
import dev.u9g.minecraftdatagenerator.mojangannoyances.BlockColors;
import dev.u9g.minecraftdatagenerator.util.EmptyRenderBlockView; import dev.u9g.minecraftdatagenerator.util.EmptyRenderBlockView;
import net.fabricmc.api.EnvType; import net.fabricmc.api.EnvType;
import net.fabricmc.api.Environment; import net.fabricmc.api.Environment;
import net.fabricmc.loader.api.FabricLoader;
import net.minecraft.block.Block; import net.minecraft.block.Block;
import net.minecraft.block.Blocks; import net.minecraft.block.Blocks;
import net.minecraft.block.RedstoneWireBlock; import net.minecraft.block.RedstoneWireBlock;
import net.minecraft.client.color.block.BlockColors;
import net.minecraft.client.color.world.FoliageColors; import net.minecraft.client.color.world.FoliageColors;
import net.minecraft.util.Identifier; import net.minecraft.util.Identifier;
import net.minecraft.util.math.BlockPos; import net.minecraft.util.math.BlockPos;
@@ -141,18 +140,13 @@ public class TintsDataGenerator implements IDataGenerator {
@Override @Override
public JsonObject generateDataJson() { public JsonObject generateDataJson() {
DynamicRegistryManager registryManager = DynamicRegistryManager.create(); DynamicRegistryManager registryManager = DynamicRegistryManager.BUILTIN.get();
Registry<Biome> biomeRegistry = registryManager.get(Registry.BIOME_KEY); Registry<Biome> biomeRegistry = registryManager.get(Registry.BIOME_KEY);
Registry<Block> blockRegistry = registryManager.get(Registry.BLOCK_KEY); Registry<Block> blockRegistry = registryManager.get(Registry.BLOCK_KEY);
BiomeTintColors biomeTintColors = generateBiomeTintColors(biomeRegistry); BiomeTintColors biomeTintColors = generateBiomeTintColors(biomeRegistry);
Map<Integer, Integer> redstoneColors = generateRedstoneTintColors(); Map<Integer, Integer> redstoneColors = generateRedstoneTintColors();
Map<Block, Integer> constantTintColors = Collections.emptyMap(); Map<Block, Integer> constantTintColors = generateConstantTintColors();
EnvType currentEnvironment = FabricLoader.getInstance().getEnvironmentType();
if (currentEnvironment == EnvType.CLIENT) {
constantTintColors = generateConstantTintColors();
}
JsonObject resultObject = new JsonObject(); JsonObject resultObject = new JsonObject();
@@ -1,57 +0,0 @@
package dev.u9g.minecraftdatagenerator.mixin;
import com.google.common.base.Preconditions;
import net.minecraft.block.BlockState;
import net.minecraft.client.MinecraftClient;
import net.minecraft.client.network.ClientPlayerInteractionManager;
import net.minecraft.util.math.BlockPos;
import net.minecraft.util.math.Direction;
import net.minecraft.world.World;
import org.objectweb.asm.Opcodes;
import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.Unique;
import org.spongepowered.asm.mixin.injection.At;
import org.spongepowered.asm.mixin.injection.Inject;
import org.spongepowered.asm.mixin.injection.callback.CallbackInfo;
import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable;
@Mixin(ClientPlayerInteractionManager.class)
public abstract class ClientPlayerInteractionManagerMixin {
@Unique
private long blockBreakingStartTicks;
@Unique
private BlockState stateBeingBroken;
@Inject(method = "attackBlock", at = @At(value = "FIELD", target = "Lnet/minecraft/client/network/ClientPlayerInteractionManager;currentBreakingProgress:F", opcode = Opcodes.PUTFIELD))
private void onBlockAttacked(BlockPos pos, Direction direction, CallbackInfoReturnable<Boolean> callbackInfo) {
World world = Preconditions.checkNotNull(MinecraftClient.getInstance().world);
this.blockBreakingStartTicks = world.getTime();
}
@Inject(method = "cancelBlockBreaking", at = @At("HEAD"))
private void onBlockBreakingCanceled(CallbackInfo callbackInfo) {
this.blockBreakingStartTicks = -1L;
}
@Inject(method = "breakBlock", at = @At("HEAD"))
private void onBreakBlockHead(BlockPos pos, CallbackInfoReturnable<Boolean> callbackInfo) {
World world = Preconditions.checkNotNull(MinecraftClient.getInstance().world);
this.stateBeingBroken = world.getBlockState(pos);
}
@Inject(method = "breakBlock", at = @At("RETURN"))
private void onBreakBlockReturn(BlockPos pos, CallbackInfoReturnable<Boolean> callbackInfo) {
World world = Preconditions.checkNotNull(MinecraftClient.getInstance().world);
if (callbackInfo.getReturnValue()) {
Preconditions.checkNotNull(stateBeingBroken);
if (blockBreakingStartTicks != -1L) {
long totalTicksElapsed = world.getTime() - this.blockBreakingStartTicks;
long totalTimeElapsed = totalTicksElapsed * 50L;
System.out.printf("Breaking block %s took %dms%n", stateBeingBroken.getBlock(), totalTimeElapsed);
} else {
System.out.printf("Breaking block %s took 0ms [INSTANT BREAK]%n", stateBeingBroken.getBlock());
}
}
this.blockBreakingStartTicks = -1L;
}
}
@@ -2,7 +2,7 @@ package dev.u9g.minecraftdatagenerator.mixin;
import net.minecraft.block.Block; import net.minecraft.block.Block;
import net.minecraft.item.MiningToolItem; import net.minecraft.item.MiningToolItem;
import net.minecraft.tag.Tag; import net.minecraft.tag.TagKey;
import org.spongepowered.asm.mixin.Mixin; import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.gen.Accessor; import org.spongepowered.asm.mixin.gen.Accessor;
@@ -10,7 +10,7 @@ import org.spongepowered.asm.mixin.gen.Accessor;
public interface MiningToolItemAccessor { public interface MiningToolItemAccessor {
@Accessor @Accessor
Tag<Block> getEffectiveBlocks(); TagKey<Block> getEffectiveBlocks();
@Accessor @Accessor
float getMiningSpeed(); float getMiningSpeed();
@@ -0,0 +1,39 @@
package dev.u9g.minecraftdatagenerator.mojangannoyances;
import net.fabricmc.api.EnvType;
import net.fabricmc.api.Environment;
import net.minecraft.util.math.BlockPos;
import net.minecraft.world.BlockRenderView;
import net.minecraft.world.biome.Biome;
import net.minecraft.world.level.ColorResolver;
@Environment(EnvType.CLIENT)
public class BiomeColors {
public static final ColorResolver GRASS_COLOR = Biome::getGrassColorAt;
public static final ColorResolver FOLIAGE_COLOR = (biome, x, z) -> {
return biome.getFoliageColor();
};
public static final ColorResolver WATER_COLOR = (biome, x, z) -> {
return biome.getWaterColor();
};
public BiomeColors() {
}
private static int getColor(BlockRenderView world, BlockPos pos, ColorResolver resolver) {
return world.getColor(pos, resolver);
}
public static int getGrassColor(BlockRenderView world, BlockPos pos) {
return getColor(world, pos, GRASS_COLOR);
}
public static int getFoliageColor(BlockRenderView world, BlockPos pos) {
return getColor(world, pos, FOLIAGE_COLOR);
}
public static int getWaterColor(BlockRenderView world, BlockPos pos) {
return getColor(world, pos, WATER_COLOR);
}
}
@@ -0,0 +1,11 @@
package dev.u9g.minecraftdatagenerator.mojangannoyances;
import net.minecraft.block.BlockState;
import net.minecraft.util.math.BlockPos;
import net.minecraft.world.BlockRenderView;
import org.jetbrains.annotations.Nullable;
public interface BlockColorProvider {
int getColor(BlockState state, @Nullable BlockRenderView world, @Nullable BlockPos pos, int tintIndex);
}
@@ -0,0 +1,117 @@
package dev.u9g.minecraftdatagenerator.mojangannoyances;
import com.google.common.collect.ImmutableSet;
import com.google.common.collect.Maps;
import net.minecraft.block.*;
import net.minecraft.block.enums.DoubleBlockHalf;
import net.minecraft.client.color.world.FoliageColors;
import net.minecraft.client.color.world.GrassColors;
import net.minecraft.state.property.Property;
import net.minecraft.util.collection.IdList;
import net.minecraft.util.math.BlockPos;
import net.minecraft.util.registry.Registry;
import net.minecraft.world.BlockRenderView;
import net.minecraft.world.World;
import org.jetbrains.annotations.Nullable;
import java.util.Map;
import java.util.Set;
public class BlockColors {
private static final int NO_COLOR = -1;
private final IdList<BlockColorProvider> providers = new IdList(32);
private final Map<Block, Set<Property<?>>> properties = Maps.newHashMap();
public BlockColors() {
}
public static BlockColors create() {
BlockColors blockColors = new BlockColors();
blockColors.registerColorProvider((state, world, pos, tintIndex) -> {
return world != null && pos != null ? BiomeColors.getGrassColor(world, state.get(TallPlantBlock.HALF) == DoubleBlockHalf.UPPER ? pos.down() : pos) : -1;
}, Blocks.LARGE_FERN, Blocks.TALL_GRASS);
blockColors.registerColorProperty(TallPlantBlock.HALF, Blocks.LARGE_FERN, Blocks.TALL_GRASS);
blockColors.registerColorProvider((state, world, pos, tintIndex) -> {
return world != null && pos != null ? BiomeColors.getGrassColor(world, pos) : GrassColors.getColor(0.5, 1.0);
}, Blocks.GRASS_BLOCK, Blocks.FERN, Blocks.GRASS, Blocks.POTTED_FERN);
blockColors.registerColorProvider((state, world, pos, tintIndex) -> {
return FoliageColors.getSpruceColor();
}, Blocks.SPRUCE_LEAVES);
blockColors.registerColorProvider((state, world, pos, tintIndex) -> {
return FoliageColors.getBirchColor();
}, Blocks.BIRCH_LEAVES);
blockColors.registerColorProvider((state, world, pos, tintIndex) -> {
return world != null && pos != null ? BiomeColors.getFoliageColor(world, pos) : FoliageColors.getDefaultColor();
}, Blocks.OAK_LEAVES, Blocks.JUNGLE_LEAVES, Blocks.ACACIA_LEAVES, Blocks.DARK_OAK_LEAVES, Blocks.VINE, Blocks.MANGROVE_LEAVES);
blockColors.registerColorProvider((state, world, pos, tintIndex) -> {
return world != null && pos != null ? BiomeColors.getWaterColor(world, pos) : -1;
}, Blocks.WATER, Blocks.BUBBLE_COLUMN, Blocks.WATER_CAULDRON);
blockColors.registerColorProvider((state, world, pos, tintIndex) -> {
return RedstoneWireBlock.getWireColor((Integer)state.get(RedstoneWireBlock.POWER));
}, Blocks.REDSTONE_WIRE);
blockColors.registerColorProperty(RedstoneWireBlock.POWER, Blocks.REDSTONE_WIRE);
blockColors.registerColorProvider((state, world, pos, tintIndex) -> {
return world != null && pos != null ? BiomeColors.getGrassColor(world, pos) : -1;
}, Blocks.SUGAR_CANE);
blockColors.registerColorProvider((state, world, pos, tintIndex) -> {
return 14731036;
}, Blocks.ATTACHED_MELON_STEM, Blocks.ATTACHED_PUMPKIN_STEM);
blockColors.registerColorProvider((state, world, pos, tintIndex) -> {
int i = (Integer)state.get(StemBlock.AGE);
int j = i * 32;
int k = 255 - i * 8;
int l = i * 4;
return j << 16 | k << 8 | l;
}, Blocks.MELON_STEM, Blocks.PUMPKIN_STEM);
blockColors.registerColorProperty(StemBlock.AGE, Blocks.MELON_STEM, Blocks.PUMPKIN_STEM);
blockColors.registerColorProvider((state, world, pos, tintIndex) -> {
return world != null && pos != null ? 2129968 : 7455580;
}, Blocks.LILY_PAD);
return blockColors;
}
public int getParticleColor(BlockState state, World world, BlockPos pos) {
BlockColorProvider blockColorProvider = (BlockColorProvider)this.providers.get(Registry.BLOCK.getRawId(state.getBlock()));
if (blockColorProvider != null) {
return blockColorProvider.getColor(state, (BlockRenderView)null, (BlockPos)null, 0);
} else {
MapColor mapColor = state.getMapColor(world, pos);
return mapColor != null ? mapColor.color : -1;
}
}
public int getColor(BlockState state, @Nullable BlockRenderView world, @Nullable BlockPos pos, int tintIndex) {
BlockColorProvider blockColorProvider = (BlockColorProvider)this.providers.get(Registry.BLOCK.getRawId(state.getBlock()));
return blockColorProvider == null ? -1 : blockColorProvider.getColor(state, world, pos, tintIndex);
}
public void registerColorProvider(BlockColorProvider provider, Block... blocks) {
Block[] var3 = blocks;
int var4 = blocks.length;
for(int var5 = 0; var5 < var4; ++var5) {
Block block = var3[var5];
this.providers.set(provider, Registry.BLOCK.getRawId(block));
}
}
private void registerColorProperties(Set<Property<?>> properties, Block... blocks) {
Block[] var3 = blocks;
int var4 = blocks.length;
for(int var5 = 0; var5 < var4; ++var5) {
Block block = var3[var5];
this.properties.put(block, properties);
}
}
private void registerColorProperty(Property<?> property, Block... blocks) {
this.registerColorProperties(ImmutableSet.of(property), blocks);
}
public Set<Property<?>> getProperties(Block block) {
return (Set)this.properties.getOrDefault(block, ImmutableSet.of());
}
}
@@ -3,52 +3,28 @@ package dev.u9g.minecraftdatagenerator.util;
import net.fabricmc.api.EnvType; import net.fabricmc.api.EnvType;
import net.fabricmc.api.Environment; import net.fabricmc.api.Environment;
import net.fabricmc.loader.api.FabricLoader; import net.fabricmc.loader.api.FabricLoader;
import net.minecraft.client.MinecraftClient;
import net.minecraft.client.resource.language.I18n;
import net.minecraft.server.MinecraftServer; import net.minecraft.server.MinecraftServer;
import net.minecraft.util.Language; import net.minecraft.util.Language;
import net.minecraft.world.World; import net.minecraft.world.World;
public class DGU { public class DGU {
@Environment(EnvType.CLIENT)
private static MinecraftServer getCurrentlyRunningServerClient() {
return MinecraftClient.getInstance().getServer();
}
@SuppressWarnings("deprecation") @SuppressWarnings("deprecation")
private static MinecraftServer getCurrentlyRunningServerDedicated() { private static MinecraftServer getCurrentlyRunningServerDedicated() {
return (MinecraftServer) FabricLoader.getInstance().getGameInstance(); return (MinecraftServer) FabricLoader.getInstance().getGameInstance();
} }
public static MinecraftServer getCurrentlyRunningServer() { public static MinecraftServer getCurrentlyRunningServer() {
EnvType environmentType = FabricLoader.getInstance().getEnvironmentType(); return getCurrentlyRunningServerDedicated();
if (environmentType == EnvType.CLIENT) {
return getCurrentlyRunningServerClient();
} else if (environmentType == EnvType.SERVER) {
return getCurrentlyRunningServerDedicated();
}
throw new UnsupportedOperationException();
} }
@Environment(EnvType.CLIENT) private static final Language language = Language.getInstance();
private static String translateTextClient(String translationKey) {
return I18n.translate(translationKey);
}
private static Language language = Language.getInstance();
private static String translateTextFallback(String translationKey) { private static String translateTextFallback(String translationKey) {
try { return language.get(translationKey);
return language.get(translationKey);
} catch (Exception ignored) {}
throw new RuntimeException("Failed to translate: '" + translationKey + "'");
} }
public static String translateText(String translationKey) { public static String translateText(String translationKey) {
EnvType environmentType = FabricLoader.getInstance().getEnvironmentType();
if (environmentType == EnvType.CLIENT) {
return translateTextClient(translationKey);
}
return translateTextFallback(translationKey); return translateTextFallback(translationKey);
} }