From b2343b16b03f5a04316da5357df8cc4963a91775 Mon Sep 17 00:00:00 2001 From: Ellpeck Date: Thu, 15 Sep 2022 15:59:32 +0200 Subject: [PATCH] fixed structure finders not working Closes #269 --- .../items/ItemStructureFinder.java | 30 +++++++++++-------- .../ellpeck/naturesaura/reg/ModRegistry.java | 7 +++-- 2 files changed, 21 insertions(+), 16 deletions(-) diff --git a/src/main/java/de/ellpeck/naturesaura/items/ItemStructureFinder.java b/src/main/java/de/ellpeck/naturesaura/items/ItemStructureFinder.java index aad98dc4..68f9be0c 100644 --- a/src/main/java/de/ellpeck/naturesaura/items/ItemStructureFinder.java +++ b/src/main/java/de/ellpeck/naturesaura/items/ItemStructureFinder.java @@ -2,8 +2,9 @@ package de.ellpeck.naturesaura.items; import de.ellpeck.naturesaura.entities.EntityStructureFinder; import de.ellpeck.naturesaura.entities.ModEntities; -import net.minecraft.core.Holder; import net.minecraft.core.HolderSet; +import net.minecraft.core.Registry; +import net.minecraft.resources.ResourceKey; import net.minecraft.server.level.ServerLevel; import net.minecraft.world.InteractionHand; import net.minecraft.world.InteractionResult; @@ -15,11 +16,11 @@ import net.minecraft.world.level.levelgen.structure.Structure; public class ItemStructureFinder extends ItemImpl { - private final Holder structure; + private final ResourceKey structure; private final int color; private final int radius; - public ItemStructureFinder(String baseName, Holder structure, int color, int radius) { + public ItemStructureFinder(String baseName, ResourceKey structure, int color, int radius) { super(baseName); this.structure = structure; this.color = color; @@ -30,17 +31,20 @@ public class ItemStructureFinder extends ItemImpl { public InteractionResultHolder use(Level levelIn, Player playerIn, InteractionHand handIn) { var stack = playerIn.getItemInHand(handIn); if (!levelIn.isClientSide && ((ServerLevel) levelIn).structureManager().shouldGenerateStructures()) { - var holderSet = HolderSet.direct(this.structure); - var pos = ((ServerLevel) levelIn).getChunkSource().getGenerator().findNearestMapStructure((ServerLevel) levelIn, holderSet, playerIn.blockPosition(), this.radius, false); - if (pos != null) { - var entity = new EntityStructureFinder(ModEntities.STRUCTURE_FINDER, levelIn); - entity.setPos(playerIn.getX(), playerIn.getY(0.5D), playerIn.getZ()); - entity.setItem(stack); - entity.getEntityData().set(EntityStructureFinder.COLOR, this.color); - entity.signalTo(pos.getFirst().above(64)); - levelIn.addFreshEntity(entity); + var registry = levelIn.registryAccess().registryOrThrow(Registry.STRUCTURE_REGISTRY); + var holderSet = registry.getHolder(this.structure).map(HolderSet::direct).orElse(null); + if (holderSet != null) { + var pos = ((ServerLevel) levelIn).getChunkSource().getGenerator().findNearestMapStructure((ServerLevel) levelIn, holderSet, playerIn.blockPosition(), this.radius, false); + if (pos != null) { + var entity = new EntityStructureFinder(ModEntities.STRUCTURE_FINDER, levelIn); + entity.setPos(playerIn.getX(), playerIn.getY(0.5D), playerIn.getZ()); + entity.setItem(stack); + entity.getEntityData().set(EntityStructureFinder.COLOR, this.color); + entity.signalTo(pos.getFirst().above(64)); + levelIn.addFreshEntity(entity); - stack.shrink(1); + stack.shrink(1); + } } } return new InteractionResultHolder<>(InteractionResult.SUCCESS, stack); diff --git a/src/main/java/de/ellpeck/naturesaura/reg/ModRegistry.java b/src/main/java/de/ellpeck/naturesaura/reg/ModRegistry.java index 3dc77385..9fcea6fc 100644 --- a/src/main/java/de/ellpeck/naturesaura/reg/ModRegistry.java +++ b/src/main/java/de/ellpeck/naturesaura/reg/ModRegistry.java @@ -38,6 +38,7 @@ import net.minecraft.world.level.block.FlowerPotBlock; import net.minecraft.world.level.block.SoundType; import net.minecraft.world.level.levelgen.feature.configurations.NoneFeatureConfiguration; import net.minecraft.world.level.levelgen.feature.configurations.TreeConfiguration; +import net.minecraft.world.level.levelgen.structure.BuiltinStructures; import net.minecraft.world.level.material.Material; import net.minecraftforge.common.crafting.CraftingHelper; import net.minecraftforge.common.extensions.IForgeMenuType; @@ -201,9 +202,9 @@ public final class ModRegistry { new ItemArmor("sky_chest", ModArmorMaterial.SKY, EquipmentSlot.CHEST), new ItemArmor("sky_pants", ModArmorMaterial.SKY, EquipmentSlot.LEGS), new ItemArmor("sky_shoes", ModArmorMaterial.SKY, EquipmentSlot.FEET), - new ItemStructureFinder("fortress_finder", Structures.FORTRESS, 0xba2800, 1024), - new ItemStructureFinder("end_city_finder", Structures.END_CITY, 0xca5cd6, 1024), - new ItemStructureFinder("outpost_finder", Structures.PILLAGER_OUTPOST, 0xab9f98, 2048), + new ItemStructureFinder("fortress_finder", BuiltinStructures.FORTRESS, 0xba2800, 1024), + new ItemStructureFinder("end_city_finder", BuiltinStructures.END_CITY, 0xca5cd6, 1024), + new ItemStructureFinder("outpost_finder", BuiltinStructures.PILLAGER_OUTPOST, 0xab9f98, 2048), new ItemBreakPrevention(), new ItemPetReviver(), new ItemNetheriteFinder()