fixed effect powder being unable to save correctly

closes #267
This commit is contained in:
Ell 2022-09-15 15:59:32 +02:00
parent a24d73dc77
commit fbbf793e36
2 changed files with 22 additions and 17 deletions

View file

@ -2,8 +2,9 @@ package de.ellpeck.naturesaura.items;
import de.ellpeck.naturesaura.entities.EntityStructureFinder; import de.ellpeck.naturesaura.entities.EntityStructureFinder;
import de.ellpeck.naturesaura.entities.ModEntities; import de.ellpeck.naturesaura.entities.ModEntities;
import net.minecraft.core.Holder;
import net.minecraft.core.HolderSet; import net.minecraft.core.HolderSet;
import net.minecraft.core.Registry;
import net.minecraft.resources.ResourceKey;
import net.minecraft.server.level.ServerLevel; import net.minecraft.server.level.ServerLevel;
import net.minecraft.world.InteractionHand; import net.minecraft.world.InteractionHand;
import net.minecraft.world.InteractionResult; import net.minecraft.world.InteractionResult;
@ -15,13 +16,13 @@ import net.minecraft.world.level.levelgen.feature.ConfiguredStructureFeature;
public class ItemStructureFinder extends ItemImpl { public class ItemStructureFinder extends ItemImpl {
private final Holder<ConfiguredStructureFeature<?, ?>> structureName; private final ResourceKey<ConfiguredStructureFeature<?, ?>> structure;
private final int color; private final int color;
private final int radius; private final int radius;
public ItemStructureFinder(String baseName, Holder<ConfiguredStructureFeature<?, ?>> structureName, int color, int radius) { public ItemStructureFinder(String baseName, ResourceKey<ConfiguredStructureFeature<?, ?>> structure, int color, int radius) {
super(baseName); super(baseName);
this.structureName = structureName; this.structure = structure;
this.color = color; this.color = color;
this.radius = radius; this.radius = radius;
} }
@ -30,17 +31,20 @@ public class ItemStructureFinder extends ItemImpl {
public InteractionResultHolder<ItemStack> use(Level levelIn, Player playerIn, InteractionHand handIn) { public InteractionResultHolder<ItemStack> use(Level levelIn, Player playerIn, InteractionHand handIn) {
var stack = playerIn.getItemInHand(handIn); var stack = playerIn.getItemInHand(handIn);
if (!levelIn.isClientSide && ((ServerLevel) levelIn).structureFeatureManager().shouldGenerateFeatures()) { if (!levelIn.isClientSide && ((ServerLevel) levelIn).structureFeatureManager().shouldGenerateFeatures()) {
var holderSet = HolderSet.direct(this.structureName); var registry = levelIn.registryAccess().registryOrThrow(Registry.CONFIGURED_STRUCTURE_FEATURE_REGISTRY);
var pos = ((ServerLevel) levelIn).getChunkSource().getGenerator().findNearestMapFeature((ServerLevel) levelIn, holderSet, playerIn.blockPosition(), this.radius, false); var holderSet = registry.getHolder(this.structure).map(HolderSet::direct).orElse(null);
if (pos != null) { if (holderSet != null) {
var entity = new EntityStructureFinder(ModEntities.STRUCTURE_FINDER, levelIn); var pos = ((ServerLevel) levelIn).getChunkSource().getGenerator().findNearestMapFeature((ServerLevel) levelIn, holderSet, playerIn.blockPosition(), this.radius, false);
entity.setPos(playerIn.getX(), playerIn.getY(0.5D), playerIn.getZ()); if (pos != null) {
entity.setItem(stack); var entity = new EntityStructureFinder(ModEntities.STRUCTURE_FINDER, levelIn);
entity.getEntityData().set(EntityStructureFinder.COLOR, this.color); entity.setPos(playerIn.getX(), playerIn.getY(0.5D), playerIn.getZ());
entity.signalTo(pos.getFirst().above(64)); entity.setItem(stack);
levelIn.addFreshEntity(entity); 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); return new InteractionResultHolder<>(InteractionResult.SUCCESS, stack);

View file

@ -48,6 +48,7 @@ import net.minecraft.world.level.levelgen.feature.StructureFeature;
import net.minecraft.world.level.levelgen.feature.configurations.NoneFeatureConfiguration; import net.minecraft.world.level.levelgen.feature.configurations.NoneFeatureConfiguration;
import net.minecraft.world.level.levelgen.feature.configurations.TreeConfiguration; import net.minecraft.world.level.levelgen.feature.configurations.TreeConfiguration;
import net.minecraft.world.level.levelgen.placement.PlacedFeature; import net.minecraft.world.level.levelgen.placement.PlacedFeature;
import net.minecraft.world.level.levelgen.structure.BuiltinStructures;
import net.minecraft.world.level.material.Material; import net.minecraft.world.level.material.Material;
import net.minecraftforge.common.crafting.CraftingHelper; import net.minecraftforge.common.crafting.CraftingHelper;
import net.minecraftforge.common.extensions.IForgeMenuType; import net.minecraftforge.common.extensions.IForgeMenuType;
@ -219,9 +220,9 @@ public final class ModRegistry {
new ItemArmor("sky_chest", ModArmorMaterial.SKY, EquipmentSlot.CHEST), new ItemArmor("sky_chest", ModArmorMaterial.SKY, EquipmentSlot.CHEST),
new ItemArmor("sky_pants", ModArmorMaterial.SKY, EquipmentSlot.LEGS), new ItemArmor("sky_pants", ModArmorMaterial.SKY, EquipmentSlot.LEGS),
new ItemArmor("sky_shoes", ModArmorMaterial.SKY, EquipmentSlot.FEET), new ItemArmor("sky_shoes", ModArmorMaterial.SKY, EquipmentSlot.FEET),
new ItemStructureFinder("fortress_finder", StructureFeatures.FORTRESS, 0xba2800, 1024), new ItemStructureFinder("fortress_finder", BuiltinStructures.FORTRESS, 0xba2800, 1024),
new ItemStructureFinder("end_city_finder", StructureFeatures.END_CITY, 0xca5cd6, 1024), new ItemStructureFinder("end_city_finder", BuiltinStructures.END_CITY, 0xca5cd6, 1024),
new ItemStructureFinder("outpost_finder", StructureFeatures.PILLAGER_OUTPOST, 0xab9f98, 2048), new ItemStructureFinder("outpost_finder", BuiltinStructures.PILLAGER_OUTPOST, 0xab9f98, 2048),
new ItemBreakPrevention(), new ItemBreakPrevention(),
new ItemPetReviver(), new ItemPetReviver(),
new ItemNetheriteFinder() new ItemNetheriteFinder()