mirror of
https://github.com/Ellpeck/NaturesAura.git
synced 2024-11-25 20:58:34 +01:00
parent
a24d73dc77
commit
fbbf793e36
2 changed files with 22 additions and 17 deletions
|
@ -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,13 +16,13 @@ import net.minecraft.world.level.levelgen.feature.ConfiguredStructureFeature;
|
|||
|
||||
public class ItemStructureFinder extends ItemImpl {
|
||||
|
||||
private final Holder<ConfiguredStructureFeature<?, ?>> structureName;
|
||||
private final ResourceKey<ConfiguredStructureFeature<?, ?>> structure;
|
||||
private final int color;
|
||||
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);
|
||||
this.structureName = structureName;
|
||||
this.structure = structure;
|
||||
this.color = color;
|
||||
this.radius = radius;
|
||||
}
|
||||
|
@ -30,17 +31,20 @@ 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).structureFeatureManager().shouldGenerateFeatures()) {
|
||||
var holderSet = HolderSet.direct(this.structureName);
|
||||
var pos = ((ServerLevel) levelIn).getChunkSource().getGenerator().findNearestMapFeature((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.CONFIGURED_STRUCTURE_FEATURE_REGISTRY);
|
||||
var holderSet = registry.getHolder(this.structure).map(HolderSet::direct).orElse(null);
|
||||
if (holderSet != null) {
|
||||
var pos = ((ServerLevel) levelIn).getChunkSource().getGenerator().findNearestMapFeature((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);
|
||||
|
|
|
@ -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.TreeConfiguration;
|
||||
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.minecraftforge.common.crafting.CraftingHelper;
|
||||
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_pants", ModArmorMaterial.SKY, EquipmentSlot.LEGS),
|
||||
new ItemArmor("sky_shoes", ModArmorMaterial.SKY, EquipmentSlot.FEET),
|
||||
new ItemStructureFinder("fortress_finder", StructureFeatures.FORTRESS, 0xba2800, 1024),
|
||||
new ItemStructureFinder("end_city_finder", StructureFeatures.END_CITY, 0xca5cd6, 1024),
|
||||
new ItemStructureFinder("outpost_finder", StructureFeatures.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()
|
||||
|
|
Loading…
Reference in a new issue