fixed structure finders not working

Closes #269
This commit is contained in:
Ell 2022-09-15 15:59:32 +02:00
parent 5dd9f2d510
commit b2343b16b0
2 changed files with 21 additions and 16 deletions

View file

@ -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> structure;
private final ResourceKey<Structure> structure;
private final int color;
private final int radius;
public ItemStructureFinder(String baseName, Holder<Structure> structure, int color, int radius) {
public ItemStructureFinder(String baseName, ResourceKey<Structure> structure, int color, int radius) {
super(baseName);
this.structure = structure;
this.color = color;
@ -30,7 +31,9 @@ public class ItemStructureFinder extends ItemImpl {
public InteractionResultHolder<ItemStack> 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 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);
@ -43,6 +46,7 @@ public class ItemStructureFinder extends ItemImpl {
stack.shrink(1);
}
}
}
return new InteractionResultHolder<>(InteractionResult.SUCCESS, stack);
}
}

View file

@ -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()