From 5db697abb1880c53c7835a5d0b85148e451786b8 Mon Sep 17 00:00:00 2001 From: Ellpeck Date: Sun, 19 Dec 2021 16:51:20 +0100 Subject: [PATCH] register features more --- .../blocks/BlockProjectileGenerator.java | 2 +- .../tiles/BlockEntityFurnaceHeater.java | 2 +- .../naturesaura/events/CommonEvents.java | 17 ++++------- .../ellpeck/naturesaura/gen/ModFeatures.java | 12 +++++++- .../ellpeck/naturesaura/reg/ModRegistry.java | 30 ++++++++++++++----- 5 files changed, 42 insertions(+), 21 deletions(-) diff --git a/src/main/java/de/ellpeck/naturesaura/blocks/BlockProjectileGenerator.java b/src/main/java/de/ellpeck/naturesaura/blocks/BlockProjectileGenerator.java index 41a8dabc..c0c1d794 100644 --- a/src/main/java/de/ellpeck/naturesaura/blocks/BlockProjectileGenerator.java +++ b/src/main/java/de/ellpeck/naturesaura/blocks/BlockProjectileGenerator.java @@ -51,7 +51,7 @@ public class BlockProjectileGenerator extends BlockContainerImpl implements ITES protected Projectile getProjectile(Level levelIn, Position position, ItemStack stackIn) { var ret = new ThrownTrident(EntityType.TRIDENT, levelIn); ret.setPos(position.x(), position.y(), position.z()); - ObfuscationReflectionHelper.setPrivateValue(ThrownTrident.class, ret, stackIn.copy(), "tridentItem"); + ObfuscationReflectionHelper.setPrivateValue(ThrownTrident.class, ret, stackIn.copy(), "f_37555_"); ret.pickup = AbstractArrow.Pickup.ALLOWED; return ret; } diff --git a/src/main/java/de/ellpeck/naturesaura/blocks/tiles/BlockEntityFurnaceHeater.java b/src/main/java/de/ellpeck/naturesaura/blocks/tiles/BlockEntityFurnaceHeater.java index 8e4838f8..8c861c1a 100644 --- a/src/main/java/de/ellpeck/naturesaura/blocks/tiles/BlockEntityFurnaceHeater.java +++ b/src/main/java/de/ellpeck/naturesaura/blocks/tiles/BlockEntityFurnaceHeater.java @@ -24,7 +24,7 @@ import java.lang.reflect.Field; public class BlockEntityFurnaceHeater extends BlockEntityImpl implements ITickableBlockEntity { - private static final Field FURNACE_DATA_FIELD = ObfuscationReflectionHelper.findField(AbstractFurnaceBlockEntity.class, "dataAccess"); + private static final Field FURNACE_DATA_FIELD = ObfuscationReflectionHelper.findField(AbstractFurnaceBlockEntity.class, "f_58311_"); public boolean isActive; public BlockEntityFurnaceHeater(BlockPos pos, BlockState state) { diff --git a/src/main/java/de/ellpeck/naturesaura/events/CommonEvents.java b/src/main/java/de/ellpeck/naturesaura/events/CommonEvents.java index c8f56018..22394012 100644 --- a/src/main/java/de/ellpeck/naturesaura/events/CommonEvents.java +++ b/src/main/java/de/ellpeck/naturesaura/events/CommonEvents.java @@ -19,11 +19,8 @@ import net.minecraft.server.level.ChunkHolder; import net.minecraft.server.level.ChunkMap; import net.minecraft.server.level.ServerChunkCache; import net.minecraft.world.entity.player.Player; -import net.minecraft.world.item.ItemStack; import net.minecraft.world.level.ChunkPos; import net.minecraft.world.level.Level; -import net.minecraft.world.level.block.state.BlockState; -import net.minecraft.world.level.chunk.ChunkAccess; import net.minecraft.world.level.chunk.LevelChunk; import net.minecraftforge.event.AttachCapabilitiesEvent; import net.minecraftforge.event.TickEvent; @@ -37,28 +34,26 @@ import net.minecraftforge.fml.util.ObfuscationReflectionHelper; import java.lang.reflect.InvocationTargetException; import java.lang.reflect.Method; -import java.util.List; import java.util.UUID; import static net.minecraft.world.level.levelgen.GenerationStep.Decoration; public class CommonEvents { - private static final Method GET_LOADED_CHUNKS_METHOD = ObfuscationReflectionHelper.findMethod(ChunkMap.class, "getChunks"); + private static final Method GET_LOADED_CHUNKS_METHOD = ObfuscationReflectionHelper.findMethod(ChunkMap.class, "m_140416_"); private static final ListMultimap PENDING_AURA_CHUNKS = ArrayListMultimap.create(); @SubscribeEvent public void onBiomeLoad(BiomeLoadingEvent event) { if (ModConfig.instance.auraBlooms.get()) { - // TODO features might have to be registered *AGAIN* now because .placed() is another thing again oh my God - event.getGeneration().addFeature(Decoration.VEGETAL_DECORATION, ModFeatures.Configured.AURA_BLOOM.placed()); + event.getGeneration().addFeature(Decoration.VEGETAL_DECORATION, ModFeatures.Placed.AURA_BLOOM); switch (event.getCategory()) { - case DESERT -> event.getGeneration().addFeature(Decoration.VEGETAL_DECORATION, ModFeatures.Configured.AURA_CACTUS.placed()); + case DESERT -> event.getGeneration().addFeature(Decoration.VEGETAL_DECORATION, ModFeatures.Placed.AURA_CACTUS); case NETHER -> { - event.getGeneration().addFeature(Decoration.VEGETAL_DECORATION, ModFeatures.Configured.CRIMSON_AURA_MUSHROOM.placed()); - event.getGeneration().addFeature(Decoration.VEGETAL_DECORATION, ModFeatures.Configured.WARPED_AURA_MUSHROOM.placed()); + event.getGeneration().addFeature(Decoration.VEGETAL_DECORATION, ModFeatures.Placed.CRIMSON_AURA_MUSHROOM); + event.getGeneration().addFeature(Decoration.VEGETAL_DECORATION, ModFeatures.Placed.WARPED_AURA_MUSHROOM); } - case MUSHROOM -> event.getGeneration().addFeature(Decoration.VEGETAL_DECORATION, ModFeatures.Configured.AURA_MUSHROOM.placed()); + case MUSHROOM -> event.getGeneration().addFeature(Decoration.VEGETAL_DECORATION, ModFeatures.Placed.AURA_MUSHROOM); } } } diff --git a/src/main/java/de/ellpeck/naturesaura/gen/ModFeatures.java b/src/main/java/de/ellpeck/naturesaura/gen/ModFeatures.java index 7470460b..d3ae0f39 100644 --- a/src/main/java/de/ellpeck/naturesaura/gen/ModFeatures.java +++ b/src/main/java/de/ellpeck/naturesaura/gen/ModFeatures.java @@ -5,6 +5,7 @@ import net.minecraft.world.level.levelgen.feature.Feature; import net.minecraft.world.level.levelgen.feature.configurations.FeatureConfiguration; import net.minecraft.world.level.levelgen.feature.configurations.NoneFeatureConfiguration; import net.minecraft.world.level.levelgen.feature.configurations.TreeConfiguration; +import net.minecraft.world.level.levelgen.placement.PlacedFeature; @SuppressWarnings("FieldNamingConvention") public final class ModFeatures { @@ -20,7 +21,6 @@ public final class ModFeatures { public static final class Configured { public static final ConfiguredFeature ANCIENT_TREE = ModFeatures.ANCIENT_TREE.configured(new TreeConfiguration.TreeConfigurationBuilder(null, null, null, null, null).build()); - public static final ConfiguredFeature NETHER_WART_MUSHROOM = ModFeatures.NETHER_WART_MUSHROOM.configured(FeatureConfiguration.NONE); public static final ConfiguredFeature AURA_BLOOM = ModFeatures.AURA_BLOOM.configured(FeatureConfiguration.NONE); public static final ConfiguredFeature AURA_CACTUS = ModFeatures.AURA_CACTUS.configured(FeatureConfiguration.NONE); public static final ConfiguredFeature WARPED_AURA_MUSHROOM = ModFeatures.WARPED_AURA_MUSHROOM.configured(FeatureConfiguration.NONE); @@ -28,4 +28,14 @@ public final class ModFeatures { public static final ConfiguredFeature AURA_MUSHROOM = ModFeatures.AURA_MUSHROOM.configured(FeatureConfiguration.NONE); } + + public static final class Placed { + + public static final PlacedFeature AURA_BLOOM = ModFeatures.Configured.AURA_BLOOM.placed(); + public static final PlacedFeature AURA_CACTUS = ModFeatures.Configured.AURA_CACTUS.placed(); + public static final PlacedFeature WARPED_AURA_MUSHROOM = ModFeatures.Configured.WARPED_AURA_MUSHROOM.placed(); + public static final PlacedFeature CRIMSON_AURA_MUSHROOM = ModFeatures.Configured.CRIMSON_AURA_MUSHROOM.placed(); + public static final PlacedFeature AURA_MUSHROOM = ModFeatures.Configured.AURA_MUSHROOM.placed(); + + } } diff --git a/src/main/java/de/ellpeck/naturesaura/reg/ModRegistry.java b/src/main/java/de/ellpeck/naturesaura/reg/ModRegistry.java index 9e27e8aa..8363b991 100644 --- a/src/main/java/de/ellpeck/naturesaura/reg/ModRegistry.java +++ b/src/main/java/de/ellpeck/naturesaura/reg/ModRegistry.java @@ -30,7 +30,6 @@ import net.minecraft.client.renderer.entity.EntityRendererProvider; import net.minecraft.client.renderer.entity.ThrownItemRenderer; import net.minecraft.core.Registry; import net.minecraft.data.BuiltinRegistries; -import net.minecraft.resources.ResourceLocation; import net.minecraft.world.effect.MobEffect; import net.minecraft.world.entity.EntityType; import net.minecraft.world.entity.EquipmentSlot; @@ -46,18 +45,22 @@ import net.minecraft.world.level.block.Blocks; import net.minecraft.world.level.block.FlowerPotBlock; import net.minecraft.world.level.block.SoundType; import net.minecraft.world.level.block.entity.BlockEntityType; +import net.minecraft.world.level.levelgen.feature.ConfiguredFeature; import net.minecraft.world.level.levelgen.feature.Feature; import net.minecraft.world.level.levelgen.feature.StructureFeature; +import net.minecraft.world.level.levelgen.placement.PlacedFeature; import net.minecraft.world.level.material.Material; import net.minecraftforge.common.crafting.CraftingHelper; import net.minecraftforge.common.extensions.IForgeMenuType; import net.minecraftforge.event.RegistryEvent; import net.minecraftforge.eventbus.api.SubscribeEvent; import net.minecraftforge.fml.common.Mod; +import net.minecraftforge.fml.util.ObfuscationReflectionHelper; import net.minecraftforge.items.IItemHandler; import java.util.HashSet; import java.util.Set; +import java.util.function.Supplier; @Mod.EventBusSubscriber(bus = Mod.EventBusSubscriber.Bus.MOD) public final class ModRegistry { @@ -337,12 +340,25 @@ public final class ModRegistry { provider.registerTESR(); } - // register features again for some reason - Registry.register(BuiltinRegistries.CONFIGURED_FEATURE, new ResourceLocation(NaturesAura.MOD_ID, "aura_bloom"), ModFeatures.Configured.AURA_BLOOM); - Registry.register(BuiltinRegistries.CONFIGURED_FEATURE, new ResourceLocation(NaturesAura.MOD_ID, "aura_cactus"), ModFeatures.Configured.AURA_CACTUS); - Registry.register(BuiltinRegistries.CONFIGURED_FEATURE, new ResourceLocation(NaturesAura.MOD_ID, "crimson_aura_mushroom"), ModFeatures.Configured.CRIMSON_AURA_MUSHROOM); - Registry.register(BuiltinRegistries.CONFIGURED_FEATURE, new ResourceLocation(NaturesAura.MOD_ID, "warped_aura_mushroom"), ModFeatures.Configured.WARPED_AURA_MUSHROOM); - Registry.register(BuiltinRegistries.CONFIGURED_FEATURE, new ResourceLocation(NaturesAura.MOD_ID, "aura_mushroom"), ModFeatures.Configured.AURA_MUSHROOM); + // register features 27 more times for some reason + for (var entry : ModFeatures.Configured.class.getFields()) { + try { + var feature = (ConfiguredFeature) entry.get(null); + Registry.register(BuiltinRegistries.CONFIGURED_FEATURE, feature.feature.getRegistryName(), feature); + } catch (IllegalAccessException e) { + NaturesAura.LOGGER.error(e); + } + } + for (var entry : ModFeatures.Placed.class.getFields()) { + try { + var placed = (PlacedFeature) entry.get(null); + // why are you making this so difficult for me + Supplier> feature = ObfuscationReflectionHelper.getPrivateValue(PlacedFeature.class, placed, "f_191775_"); + Registry.register(BuiltinRegistries.PLACED_FEATURE, feature.get().feature.getRegistryName(), placed); + } catch (IllegalAccessException e) { + NaturesAura.LOGGER.error(e); + } + } } public static Block createFlowerPot(Block block) {