mirror of
https://github.com/Ellpeck/NaturesAura.git
synced 2024-11-22 11:53:29 +01:00
parent
5dd9f2d510
commit
b2343b16b0
2 changed files with 21 additions and 16 deletions
|
@ -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,11 +16,11 @@ import net.minecraft.world.level.levelgen.structure.Structure;
|
||||||
|
|
||||||
public class ItemStructureFinder extends ItemImpl {
|
public class ItemStructureFinder extends ItemImpl {
|
||||||
|
|
||||||
private final Holder<Structure> structure;
|
private final ResourceKey<Structure> structure;
|
||||||
private final int color;
|
private final int color;
|
||||||
private final int radius;
|
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);
|
super(baseName);
|
||||||
this.structure = structure;
|
this.structure = structure;
|
||||||
this.color = color;
|
this.color = color;
|
||||||
|
@ -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).structureManager().shouldGenerateStructures()) {
|
if (!levelIn.isClientSide && ((ServerLevel) levelIn).structureManager().shouldGenerateStructures()) {
|
||||||
var holderSet = HolderSet.direct(this.structure);
|
var registry = levelIn.registryAccess().registryOrThrow(Registry.STRUCTURE_REGISTRY);
|
||||||
var pos = ((ServerLevel) levelIn).getChunkSource().getGenerator().findNearestMapStructure((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().findNearestMapStructure((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);
|
||||||
|
|
|
@ -38,6 +38,7 @@ import net.minecraft.world.level.block.FlowerPotBlock;
|
||||||
import net.minecraft.world.level.block.SoundType;
|
import net.minecraft.world.level.block.SoundType;
|
||||||
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.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;
|
||||||
|
@ -201,9 +202,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", Structures.FORTRESS, 0xba2800, 1024),
|
new ItemStructureFinder("fortress_finder", BuiltinStructures.FORTRESS, 0xba2800, 1024),
|
||||||
new ItemStructureFinder("end_city_finder", Structures.END_CITY, 0xca5cd6, 1024),
|
new ItemStructureFinder("end_city_finder", BuiltinStructures.END_CITY, 0xca5cd6, 1024),
|
||||||
new ItemStructureFinder("outpost_finder", Structures.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()
|
||||||
|
|
Loading…
Reference in a new issue