a lot more 1.20.4 port work

This commit is contained in:
Ell 2024-03-10 15:54:58 +01:00
parent 5a4a191973
commit f2547e6555
64 changed files with 348 additions and 398 deletions

View file

@ -5,6 +5,7 @@ import de.ellpeck.naturesaura.api.aura.chunk.IAuraChunk;
import de.ellpeck.naturesaura.api.misc.ILevelData; import de.ellpeck.naturesaura.api.misc.ILevelData;
import de.ellpeck.naturesaura.api.multiblock.IMultiblock; import de.ellpeck.naturesaura.api.multiblock.IMultiblock;
import de.ellpeck.naturesaura.blocks.multi.Multiblock; import de.ellpeck.naturesaura.blocks.multi.Multiblock;
import de.ellpeck.naturesaura.chunk.AuraChunk;
import de.ellpeck.naturesaura.misc.LevelData; import de.ellpeck.naturesaura.misc.LevelData;
import net.minecraft.core.BlockPos; import net.minecraft.core.BlockPos;
import net.minecraft.resources.ResourceLocation; import net.minecraft.resources.ResourceLocation;
@ -38,9 +39,9 @@ public class InternalHooks implements NaturesAuraAPI.IInternalHooks {
private boolean auraPlayerInteraction(Player player, int amount, boolean extract, boolean simulate) { private boolean auraPlayerInteraction(Player player, int amount, boolean extract, boolean simulate) {
if (extract && player.isCreative()) if (extract && player.isCreative())
return true; return true;
var stack = Helper.getEquippedItem(s -> s.getCapability(NaturesAuraAPI.AURA_CONTAINER_CAPABILITY) != null, player, false); var stack = Helper.getEquippedItem(s -> s.getCapability(NaturesAuraAPI.AURA_CONTAINER_ITEM_CAPABILITY) != null, player, false);
if (!stack.isEmpty()) { if (!stack.isEmpty()) {
var container = stack.getCapability(NaturesAuraAPI.AURA_CONTAINER_CAPABILITY); var container = stack.getCapability(NaturesAuraAPI.AURA_CONTAINER_ITEM_CAPABILITY);
if (extract) { if (extract) {
return container.drainAura(amount, simulate) > 0; return container.drainAura(amount, simulate) > 0;
} else { } else {
@ -199,4 +200,9 @@ public class InternalHooks implements NaturesAuraAPI.IInternalHooks {
} }
} }
@Override
public IAuraChunk createAuraChunk() {
return new AuraChunk();
}
} }

View file

@ -2,6 +2,7 @@ package de.ellpeck.naturesaura.api;
import com.google.common.collect.BiMap; import com.google.common.collect.BiMap;
import com.google.common.collect.HashBiMap; import com.google.common.collect.HashBiMap;
import de.ellpeck.naturesaura.api.aura.chunk.AuraChunkProvider;
import de.ellpeck.naturesaura.api.aura.chunk.IAuraChunk; import de.ellpeck.naturesaura.api.aura.chunk.IAuraChunk;
import de.ellpeck.naturesaura.api.aura.chunk.IDrainSpotEffect; import de.ellpeck.naturesaura.api.aura.chunk.IDrainSpotEffect;
import de.ellpeck.naturesaura.api.aura.container.IAuraContainer; import de.ellpeck.naturesaura.api.aura.container.IAuraContainer;
@ -14,6 +15,7 @@ import de.ellpeck.naturesaura.api.misc.WeightedOre;
import de.ellpeck.naturesaura.api.multiblock.IMultiblock; import de.ellpeck.naturesaura.api.multiblock.IMultiblock;
import de.ellpeck.naturesaura.api.multiblock.Matcher; import de.ellpeck.naturesaura.api.multiblock.Matcher;
import net.minecraft.core.BlockPos; import net.minecraft.core.BlockPos;
import net.minecraft.core.Direction;
import net.minecraft.resources.ResourceLocation; import net.minecraft.resources.ResourceLocation;
import net.minecraft.util.Tuple; import net.minecraft.util.Tuple;
import net.minecraft.world.entity.EntityType; import net.minecraft.world.entity.EntityType;
@ -24,6 +26,7 @@ import net.minecraft.world.level.block.state.BlockState;
import net.minecraft.world.phys.AABB; import net.minecraft.world.phys.AABB;
import net.minecraft.world.phys.Vec3; import net.minecraft.world.phys.Vec3;
import net.neoforged.neoforge.attachment.AttachmentType; import net.neoforged.neoforge.attachment.AttachmentType;
import net.neoforged.neoforge.capabilities.BlockCapability;
import net.neoforged.neoforge.capabilities.ItemCapability; import net.neoforged.neoforge.capabilities.ItemCapability;
import org.apache.commons.lang3.tuple.Pair; import org.apache.commons.lang3.tuple.Pair;
@ -82,9 +85,13 @@ public final class NaturesAuraAPI {
*/ */
public static final Map<ItemStack, WeatherType> WEATHER_CHANGER_CONVERSIONS = new HashMap<>(); public static final Map<ItemStack, WeatherType> WEATHER_CHANGER_CONVERSIONS = new HashMap<>();
/** /**
* The capability for any item or block that stores Aura in the form of an {@link IAuraContainer} * The capability for any item that stores Aura in the form of an {@link IAuraContainer}
*/ */
public static final ItemCapability<IAuraContainer, Void> AURA_CONTAINER_CAPABILITY = ItemCapability.createVoid(new ResourceLocation(NaturesAuraAPI.MOD_ID, "aura_container"), IAuraContainer.class); public static final ItemCapability<IAuraContainer, Void> AURA_CONTAINER_ITEM_CAPABILITY = ItemCapability.createVoid(new ResourceLocation(NaturesAuraAPI.MOD_ID, "aura_container_item"), IAuraContainer.class);
/**
* The capability for any block that stores Aura in the form of an {@link IAuraContainer}
*/
public static final BlockCapability<IAuraContainer, Direction> AURA_CONTAINER_BLOCK_CAPABILITY = BlockCapability.create(new ResourceLocation(NaturesAuraAPI.MOD_ID, "aura_container_block"), IAuraContainer.class, Direction.class);
/** /**
* The capability for any item that can be recharged from an Aura storage container like the Aura Cache in the form of {@link IAuraRecharge} by a player holding it in their hand * The capability for any item that can be recharged from an Aura storage container like the Aura Cache in the form of {@link IAuraRecharge} by a player holding it in their hand
*/ */
@ -92,7 +99,7 @@ public final class NaturesAuraAPI {
/** /**
* The capability that any chunk in a level has to store Aura in it. As this is only applicable to chunks and all chunks in the level automatically get assigned this capability, using it directly is not necessary for addon developers. To retrieve this capability from any chunk, use the helper method {@link IAuraChunk#getAuraChunk(net.minecraft.world.level.Level, BlockPos)}. * The capability that any chunk in a level has to store Aura in it. As this is only applicable to chunks and all chunks in the level automatically get assigned this capability, using it directly is not necessary for addon developers. To retrieve this capability from any chunk, use the helper method {@link IAuraChunk#getAuraChunk(net.minecraft.world.level.Level, BlockPos)}.
*/ */
public static final AttachmentType<IAuraChunk> AURA_CHUNK_ATTACHMENT = AttachmentType.serializable(() -> (IAuraChunk) null).build(); public static final AttachmentType<AuraChunkProvider> AURA_CHUNK_ATTACHMENT = AttachmentType.serializable(AuraChunkProvider::new).build();
private static final IInternalHooks INSTANCE; private static final IInternalHooks INSTANCE;
static { static {
@ -253,6 +260,8 @@ public final class NaturesAuraAPI {
ILevelData getLevelData(Level level); ILevelData getLevelData(Level level);
IAuraChunk createAuraChunk();
} }
} }

View file

@ -0,0 +1,29 @@
package de.ellpeck.naturesaura.api.aura.chunk;
import de.ellpeck.naturesaura.api.NaturesAuraAPI;
import net.minecraft.nbt.CompoundTag;
import net.minecraft.world.level.chunk.LevelChunk;
import net.neoforged.neoforge.common.util.INBTSerializable;
public class AuraChunkProvider implements INBTSerializable<CompoundTag> {
private IAuraChunk auraChunk;
public IAuraChunk get(LevelChunk chunk) {
if (this.auraChunk == null)
this.auraChunk = NaturesAuraAPI.instance().createAuraChunk();
this.auraChunk.ensureInitialized(chunk);
return this.auraChunk;
}
@Override
public CompoundTag serializeNBT() {
return this.get(null).serializeNBT();
}
@Override
public void deserializeNBT(CompoundTag nbt) {
this.get(null).deserializeNBT(nbt);
}
}

View file

@ -33,7 +33,7 @@ public interface IAuraChunk extends INBTSerializable<CompoundTag> {
*/ */
static IAuraChunk getAuraChunk(Level level, BlockPos pos) { static IAuraChunk getAuraChunk(Level level, BlockPos pos) {
var chunk = (LevelChunk) level.getChunk(pos); var chunk = (LevelChunk) level.getChunk(pos);
return chunk.getData(NaturesAuraAPI.AURA_CHUNK_ATTACHMENT); return chunk.getData(NaturesAuraAPI.AURA_CHUNK_ATTACHMENT).get(chunk);
} }
/** /**
@ -160,4 +160,6 @@ public interface IAuraChunk extends INBTSerializable<CompoundTag> {
void markDirty(); void markDirty();
void ensureInitialized(LevelChunk chunk);
} }

View file

@ -53,7 +53,8 @@ public class BlockAncientLeaves extends LeavesBlock implements IModItem, IColorP
if (rand.nextFloat() >= 0.95F && !levelIn.getBlockState(pos.below()).isCollisionShapeFullBlock(levelIn, pos)) { if (rand.nextFloat() >= 0.95F && !levelIn.getBlockState(pos.below()).isCollisionShapeFullBlock(levelIn, pos)) {
var tile = levelIn.getBlockEntity(pos); var tile = levelIn.getBlockEntity(pos);
if (tile instanceof BlockEntityAncientLeaves) { if (tile instanceof BlockEntityAncientLeaves) {
if (((BlockEntityAncientLeaves) tile).getAuraContainer().getStoredAura() > 0) { var container = levelIn.getCapability(NaturesAuraAPI.AURA_CONTAINER_BLOCK_CAPABILITY, tile.getBlockPos(), tile.getBlockState(), tile, null);
if (container.getStoredAura() > 0) {
NaturesAuraAPI.instance().spawnMagicParticle( NaturesAuraAPI.instance().spawnMagicParticle(
pos.getX() + rand.nextDouble(), pos.getY(), pos.getZ() + rand.nextDouble(), pos.getX() + rand.nextDouble(), pos.getY(), pos.getZ() + rand.nextDouble(),
0F, 0F, 0F, 0xCC4780, 0F, 0F, 0F, 0xCC4780,
@ -72,7 +73,8 @@ public class BlockAncientLeaves extends LeavesBlock implements IModItem, IColorP
if (!levelIn.isClientSide) { if (!levelIn.isClientSide) {
var tile = levelIn.getBlockEntity(pos); var tile = levelIn.getBlockEntity(pos);
if (tile instanceof BlockEntityAncientLeaves) { if (tile instanceof BlockEntityAncientLeaves) {
if (((BlockEntityAncientLeaves) tile).getAuraContainer().getStoredAura() <= 0) { var container = levelIn.getCapability(NaturesAuraAPI.AURA_CONTAINER_BLOCK_CAPABILITY, tile.getBlockPos(), tile.getBlockState(), tile, null);
if (container.getStoredAura() <= 0) {
levelIn.setBlockAndUpdate(pos, ModBlocks.DECAYED_LEAVES.defaultBlockState()); levelIn.setBlockAndUpdate(pos, ModBlocks.DECAYED_LEAVES.defaultBlockState());
} }
} }
@ -94,4 +96,5 @@ public class BlockAncientLeaves extends LeavesBlock implements IModItem, IColorP
public BlockEntity newBlockEntity(BlockPos pos, BlockState state) { public BlockEntity newBlockEntity(BlockPos pos, BlockState state) {
return new BlockEntityAncientLeaves(pos, state); return new BlockEntityAncientLeaves(pos, state);
} }
} }

View file

@ -1,5 +1,6 @@
package de.ellpeck.naturesaura.blocks; package de.ellpeck.naturesaura.blocks;
import com.mojang.serialization.MapCodec;
import de.ellpeck.naturesaura.data.BlockStateGenerator; import de.ellpeck.naturesaura.data.BlockStateGenerator;
import de.ellpeck.naturesaura.data.ItemModelGenerator; import de.ellpeck.naturesaura.data.ItemModelGenerator;
import de.ellpeck.naturesaura.gen.ModFeatures; import de.ellpeck.naturesaura.gen.ModFeatures;
@ -61,7 +62,7 @@ public class BlockAncientSapling extends BushBlock implements BonemealableBlock,
} }
@Override @Override
public boolean isValidBonemealTarget(LevelReader p_256559_, BlockPos p_50898_, BlockState p_50899_, boolean p_50900_) { public boolean isValidBonemealTarget(LevelReader pLevel, BlockPos pPos, BlockState pState) {
return true; return true;
} }
@ -89,4 +90,10 @@ public class BlockAncientSapling extends BushBlock implements BonemealableBlock,
public void generateCustomItemModel(ItemModelGenerator generator) { public void generateCustomItemModel(ItemModelGenerator generator) {
generator.withExistingParent(this.getBaseName(), "item/generated").texture("layer0", "block/" + this.getBaseName()); generator.withExistingParent(this.getBaseName(), "item/generated").texture("layer0", "block/" + this.getBaseName());
} }
@Override
protected MapCodec<? extends BushBlock> codec() {
return null;
}
} }

View file

@ -21,7 +21,7 @@ public class BlockAnimalContainer extends BlockContainerImpl implements IVisuali
private static final VoxelShape SHAPE = Block.box(5, 0, 5, 11, 13, 11); private static final VoxelShape SHAPE = Block.box(5, 0, 5, 11, 13, 11);
public BlockAnimalContainer() { public BlockAnimalContainer() {
super("animal_container", BlockEntityAnimalContainer.class, Properties.copy(Blocks.STONE)); super("animal_container", BlockEntityAnimalContainer.class, Properties.ofFullCopy(Blocks.STONE));
} }
@Override @Override
@ -57,4 +57,5 @@ public class BlockAnimalContainer extends BlockContainerImpl implements IVisuali
public void generateCustomBlockState(BlockStateGenerator generator) { public void generateCustomBlockState(BlockStateGenerator generator) {
generator.simpleBlock(this, generator.models().getExistingFile(generator.modLoc(this.getBaseName()))); generator.simpleBlock(this, generator.models().getExistingFile(generator.modLoc(this.getBaseName())));
} }
} }

View file

@ -1,5 +1,6 @@
package de.ellpeck.naturesaura.blocks; package de.ellpeck.naturesaura.blocks;
import com.mojang.serialization.MapCodec;
import de.ellpeck.naturesaura.blocks.tiles.BlockEntityAuraBloom; import de.ellpeck.naturesaura.blocks.tiles.BlockEntityAuraBloom;
import de.ellpeck.naturesaura.blocks.tiles.ITickableBlockEntity; import de.ellpeck.naturesaura.blocks.tiles.ITickableBlockEntity;
import de.ellpeck.naturesaura.blocks.tiles.ModBlockEntities; import de.ellpeck.naturesaura.blocks.tiles.ModBlockEntities;
@ -47,6 +48,11 @@ public class BlockAuraBloom extends BushBlock implements IModItem, ICustomBlockS
return this.mayPlaceOn(levelIn.getBlockState(down), levelIn, down); return this.mayPlaceOn(levelIn.getBlockState(down), levelIn, down);
} }
@Override
protected MapCodec<? extends BushBlock> codec() {
return null;
}
@Override @Override
protected boolean mayPlaceOn(BlockState state, BlockGetter levelIn, BlockPos pos) { protected boolean mayPlaceOn(BlockState state, BlockGetter levelIn, BlockPos pos) {
return Arrays.stream(this.allowedGround).anyMatch(state::is); return Arrays.stream(this.allowedGround).anyMatch(state::is);
@ -92,4 +98,5 @@ public class BlockAuraBloom extends BushBlock implements IModItem, ICustomBlockS
public <T extends BlockEntity> BlockEntityTicker<T> getTicker(Level level, BlockState state, BlockEntityType<T> type) { public <T extends BlockEntity> BlockEntityTicker<T> getTicker(Level level, BlockState state, BlockEntityType<T> type) {
return ITickableBlockEntity.createTickerHelper(type, ModBlockEntities.AURA_BLOOM); return ITickableBlockEntity.createTickerHelper(type, ModBlockEntities.AURA_BLOOM);
} }
} }

View file

@ -31,7 +31,7 @@ public class BlockAuraTimer extends BlockContainerImpl implements ICustomBlockSt
private static final VoxelShape SHAPE = Block.box(1, 0, 1, 15, 15, 15); private static final VoxelShape SHAPE = Block.box(1, 0, 1, 15, 15, 15);
public BlockAuraTimer() { public BlockAuraTimer() {
super("aura_timer", BlockEntityAuraTimer.class, Properties.copy(Blocks.SMOOTH_STONE)); super("aura_timer", BlockEntityAuraTimer.class, Properties.ofFullCopy(Blocks.SMOOTH_STONE));
this.registerDefaultState(this.defaultBlockState().setValue(BlockStateProperties.POWERED, false)); this.registerDefaultState(this.defaultBlockState().setValue(BlockStateProperties.POWERED, false));
} }

View file

@ -22,7 +22,7 @@ public class BlockBlastFurnaceBooster extends BlockContainerImpl implements ICus
private static final VoxelShape SHAPE = Shapes.create(1 / 16F, 0, 1 / 16F, 15 / 16F, 1, 15 / 16F); private static final VoxelShape SHAPE = Shapes.create(1 / 16F, 0, 1 / 16F, 15 / 16F, 1, 15 / 16F);
public BlockBlastFurnaceBooster() { public BlockBlastFurnaceBooster() {
super("blast_furnace_booster", BlockEntityBlastFurnaceBooster.class, Block.Properties.copy(Blocks.BLAST_FURNACE).lightLevel(s -> 0)); super("blast_furnace_booster", BlockEntityBlastFurnaceBooster.class, Block.Properties.ofFullCopy(Blocks.BLAST_FURNACE).lightLevel(s -> 0));
} }
@Override @Override

View file

@ -8,7 +8,7 @@ import net.minecraft.world.level.block.Blocks;
public class BlockChorusGenerator extends BlockContainerImpl implements ICustomBlockState { public class BlockChorusGenerator extends BlockContainerImpl implements ICustomBlockState {
public BlockChorusGenerator() { public BlockChorusGenerator() {
super("chorus_generator", BlockEntityChorusGenerator.class, Properties.copy(Blocks.END_STONE)); super("chorus_generator", BlockEntityChorusGenerator.class, Properties.ofFullCopy(Blocks.END_STONE));
} }
@Override @Override

View file

@ -1,5 +1,6 @@
package de.ellpeck.naturesaura.blocks; package de.ellpeck.naturesaura.blocks;
import com.mojang.serialization.MapCodec;
import de.ellpeck.naturesaura.blocks.tiles.BlockEntityImpl; import de.ellpeck.naturesaura.blocks.tiles.BlockEntityImpl;
import de.ellpeck.naturesaura.blocks.tiles.ITickableBlockEntity; import de.ellpeck.naturesaura.blocks.tiles.ITickableBlockEntity;
import de.ellpeck.naturesaura.reg.IModItem; import de.ellpeck.naturesaura.reg.IModItem;
@ -106,6 +107,11 @@ public class BlockContainerImpl extends BaseEntityBlock implements IModItem {
return this.baseName; return this.baseName;
} }
@Override
protected MapCodec<? extends BaseEntityBlock> codec() {
return null;
}
@Override @Override
public RenderShape getRenderShape(BlockState state) { public RenderShape getRenderShape(BlockState state) {
return RenderShape.MODEL; return RenderShape.MODEL;

View file

@ -1,5 +1,6 @@
package de.ellpeck.naturesaura.blocks; package de.ellpeck.naturesaura.blocks;
import com.mojang.serialization.MapCodec;
import de.ellpeck.naturesaura.api.aura.chunk.IAuraChunk; import de.ellpeck.naturesaura.api.aura.chunk.IAuraChunk;
import de.ellpeck.naturesaura.data.BlockStateGenerator; import de.ellpeck.naturesaura.data.BlockStateGenerator;
import de.ellpeck.naturesaura.data.ItemModelGenerator; import de.ellpeck.naturesaura.data.ItemModelGenerator;
@ -49,7 +50,7 @@ public class BlockDimensionRail extends BaseRailBlock implements IModItem, ICust
@SafeVarargs @SafeVarargs
public BlockDimensionRail(String name, ResourceKey<Level> goalDim, ResourceKey<Level>... canUseDims) { public BlockDimensionRail(String name, ResourceKey<Level> goalDim, ResourceKey<Level>... canUseDims) {
super(false, Properties.copy(Blocks.RAIL)); super(false, Properties.ofFullCopy(Blocks.RAIL));
this.name = name; this.name = name;
this.goalDim = goalDim; this.goalDim = goalDim;
this.canUseDims = canUseDims; this.canUseDims = canUseDims;
@ -136,6 +137,11 @@ public class BlockDimensionRail extends BaseRailBlock implements IModItem, ICust
} }
} }
@Override
protected MapCodec<? extends BaseRailBlock> codec() {
return null;
}
@Override @Override
@SuppressWarnings({"deprecation", "RedundantSuppression"}) @SuppressWarnings({"deprecation", "RedundantSuppression"})
public Property<RailShape> getShapeProperty() { public Property<RailShape> getShapeProperty() {

View file

@ -1,5 +1,6 @@
package de.ellpeck.naturesaura.blocks; package de.ellpeck.naturesaura.blocks;
import com.mojang.serialization.MapCodec;
import de.ellpeck.naturesaura.blocks.tiles.BlockEntityEndFlower; import de.ellpeck.naturesaura.blocks.tiles.BlockEntityEndFlower;
import de.ellpeck.naturesaura.blocks.tiles.ITickableBlockEntity; import de.ellpeck.naturesaura.blocks.tiles.ITickableBlockEntity;
import de.ellpeck.naturesaura.blocks.tiles.ModBlockEntities; import de.ellpeck.naturesaura.blocks.tiles.ModBlockEntities;
@ -70,6 +71,11 @@ public class BlockEndFlower extends BushBlock implements IModItem, ICustomBlockS
} }
} }
@Override
protected MapCodec<? extends BushBlock> codec() {
return null;
}
@Override @Override
public boolean canSurvive(BlockState state, LevelReader levelIn, BlockPos pos) { public boolean canSurvive(BlockState state, LevelReader levelIn, BlockPos pos) {
return levelIn.getBlockState(pos.below()).getBlock() == Blocks.END_STONE; return levelIn.getBlockState(pos.below()).getBlock() == Blocks.END_STONE;

View file

@ -34,7 +34,7 @@ public class BlockGoldPowder extends BlockImpl implements IColorProvidingBlock,
protected static final VoxelShape[] SHAPES = {Block.box(3.0D, 0.0D, 3.0D, 13.0D, 1.0D, 13.0D), Block.box(3.0D, 0.0D, 3.0D, 13.0D, 1.0D, 16.0D), Block.box(0.0D, 0.0D, 3.0D, 13.0D, 1.0D, 13.0D), Block.box(0.0D, 0.0D, 3.0D, 13.0D, 1.0D, 16.0D), Block.box(3.0D, 0.0D, 0.0D, 13.0D, 1.0D, 13.0D), Block.box(3.0D, 0.0D, 0.0D, 13.0D, 1.0D, 16.0D), Block.box(0.0D, 0.0D, 0.0D, 13.0D, 1.0D, 13.0D), Block.box(0.0D, 0.0D, 0.0D, 13.0D, 1.0D, 16.0D), Block.box(3.0D, 0.0D, 3.0D, 16.0D, 1.0D, 13.0D), Block.box(3.0D, 0.0D, 3.0D, 16.0D, 1.0D, 16.0D), Block.box(0.0D, 0.0D, 3.0D, 16.0D, 1.0D, 13.0D), Block.box(0.0D, 0.0D, 3.0D, 16.0D, 1.0D, 16.0D), Block.box(3.0D, 0.0D, 0.0D, 16.0D, 1.0D, 13.0D), Block.box(3.0D, 0.0D, 0.0D, 16.0D, 1.0D, 16.0D), Block.box(0.0D, 0.0D, 0.0D, 16.0D, 1.0D, 13.0D), Block.box(0.0D, 0.0D, 0.0D, 16.0D, 1.0D, 16.0D)}; protected static final VoxelShape[] SHAPES = {Block.box(3.0D, 0.0D, 3.0D, 13.0D, 1.0D, 13.0D), Block.box(3.0D, 0.0D, 3.0D, 13.0D, 1.0D, 16.0D), Block.box(0.0D, 0.0D, 3.0D, 13.0D, 1.0D, 13.0D), Block.box(0.0D, 0.0D, 3.0D, 13.0D, 1.0D, 16.0D), Block.box(3.0D, 0.0D, 0.0D, 13.0D, 1.0D, 13.0D), Block.box(3.0D, 0.0D, 0.0D, 13.0D, 1.0D, 16.0D), Block.box(0.0D, 0.0D, 0.0D, 13.0D, 1.0D, 13.0D), Block.box(0.0D, 0.0D, 0.0D, 13.0D, 1.0D, 16.0D), Block.box(3.0D, 0.0D, 3.0D, 16.0D, 1.0D, 13.0D), Block.box(3.0D, 0.0D, 3.0D, 16.0D, 1.0D, 16.0D), Block.box(0.0D, 0.0D, 3.0D, 16.0D, 1.0D, 13.0D), Block.box(0.0D, 0.0D, 3.0D, 16.0D, 1.0D, 16.0D), Block.box(3.0D, 0.0D, 0.0D, 16.0D, 1.0D, 13.0D), Block.box(3.0D, 0.0D, 0.0D, 16.0D, 1.0D, 16.0D), Block.box(0.0D, 0.0D, 0.0D, 16.0D, 1.0D, 13.0D), Block.box(0.0D, 0.0D, 0.0D, 16.0D, 1.0D, 16.0D)};
public BlockGoldPowder() { public BlockGoldPowder() {
super("gold_powder", Properties.copy(Blocks.REDSTONE_WIRE)); super("gold_powder", Properties.ofFullCopy(Blocks.REDSTONE_WIRE));
this.registerDefaultState(this.defaultBlockState().setValue(BlockGoldPowder.NORTH, RedstoneSide.NONE).setValue(BlockGoldPowder.EAST, RedstoneSide.NONE).setValue(BlockGoldPowder.SOUTH, RedstoneSide.NONE).setValue(BlockGoldPowder.WEST, RedstoneSide.NONE)); this.registerDefaultState(this.defaultBlockState().setValue(BlockGoldPowder.NORTH, RedstoneSide.NONE).setValue(BlockGoldPowder.EAST, RedstoneSide.NONE).setValue(BlockGoldPowder.SOUTH, RedstoneSide.NONE).setValue(BlockGoldPowder.WEST, RedstoneSide.NONE));
} }

View file

@ -27,6 +27,7 @@ import net.minecraft.world.phys.shapes.BooleanOp;
import net.minecraft.world.phys.shapes.CollisionContext; import net.minecraft.world.phys.shapes.CollisionContext;
import net.minecraft.world.phys.shapes.Shapes; import net.minecraft.world.phys.shapes.Shapes;
import net.minecraft.world.phys.shapes.VoxelShape; import net.minecraft.world.phys.shapes.VoxelShape;
import net.neoforged.neoforge.capabilities.Capabilities;
import net.neoforged.neoforge.items.IItemHandler; import net.neoforged.neoforge.items.IItemHandler;
import javax.annotation.Nullable; import javax.annotation.Nullable;
@ -122,7 +123,7 @@ public class BlockGratedChute extends BlockContainerImpl implements ICustomBlock
public int getAnalogOutputSignal(BlockState blockState, Level levelIn, BlockPos pos) { public int getAnalogOutputSignal(BlockState blockState, Level levelIn, BlockPos pos) {
var tile = levelIn.getBlockEntity(pos); var tile = levelIn.getBlockEntity(pos);
if (tile instanceof BlockEntityGratedChute) { if (tile instanceof BlockEntityGratedChute) {
IItemHandler handler = ((BlockEntityGratedChute) tile).getItemHandler(); var handler = levelIn.getCapability(Capabilities.ItemHandler.BLOCK, tile.getBlockPos(), tile.getBlockState(), tile, null);
var stack = handler.getStackInSlot(0); var stack = handler.getStackInSlot(0);
if (stack.isEmpty()) if (stack.isEmpty())
return 0; return 0;
@ -146,4 +147,5 @@ public class BlockGratedChute extends BlockContainerImpl implements ICustomBlock
public void generateCustomItemModel(ItemModelGenerator generator) { public void generateCustomItemModel(ItemModelGenerator generator) {
generator.withExistingParent(this.getBaseName(), generator.modLoc("block/" + this.getBaseName() + "_down")); generator.withExistingParent(this.getBaseName(), generator.modLoc("block/" + this.getBaseName() + "_down"));
} }
} }

View file

@ -15,7 +15,7 @@ import net.minecraft.world.phys.BlockHitResult;
public class BlockItemDistributor extends BlockContainerImpl implements ICustomBlockState { public class BlockItemDistributor extends BlockContainerImpl implements ICustomBlockState {
public BlockItemDistributor() { public BlockItemDistributor() {
super("item_distributor", BlockEntityItemDistributor.class, Properties.copy(Blocks.STONE_BRICKS)); super("item_distributor", BlockEntityItemDistributor.class, Properties.ofFullCopy(Blocks.STONE_BRICKS));
} }
@Override @Override

View file

@ -15,7 +15,7 @@ import net.minecraft.world.level.block.state.BlockState;
public class BlockNetherGrass extends BlockImpl implements ICustomBlockState, BonemealableBlock { public class BlockNetherGrass extends BlockImpl implements ICustomBlockState, BonemealableBlock {
public BlockNetherGrass() { public BlockNetherGrass() {
super("nether_grass", Properties.copy(Blocks.NETHERRACK).randomTicks()); super("nether_grass", Properties.ofFullCopy(Blocks.NETHERRACK).randomTicks());
} }
@Override @Override
@ -36,7 +36,7 @@ public class BlockNetherGrass extends BlockImpl implements ICustomBlockState, Bo
} }
@Override @Override
public boolean isValidBonemealTarget(LevelReader levelIn, BlockPos pos, BlockState state, boolean isClient) { public boolean isValidBonemealTarget(LevelReader levelIn, BlockPos pos, BlockState state) {
return levelIn.getBlockState(pos.above()).isAir(); return levelIn.getBlockState(pos.above()).isAir();
} }
@ -48,7 +48,7 @@ public class BlockNetherGrass extends BlockImpl implements ICustomBlockState, Bo
@Override @Override
public void performBonemeal(ServerLevel level, RandomSource rand, BlockPos pos, BlockState state) { public void performBonemeal(ServerLevel level, RandomSource rand, BlockPos pos, BlockState state) {
var blockpos = pos.above(); var blockpos = pos.above();
var blockstate = Blocks.GRASS.defaultBlockState(); var blockstate = Blocks.GRASS_BLOCK.defaultBlockState();
for (var i = 0; i < 128; ++i) { for (var i = 0; i < 128; ++i) {
var blockpos1 = blockpos; var blockpos1 = blockpos;
@ -81,4 +81,5 @@ public class BlockNetherGrass extends BlockImpl implements ICustomBlockState, Bo
} }
} }
} }

View file

@ -19,7 +19,7 @@ import net.neoforged.bus.api.SubscribeEvent;
public class BlockSlimeSplitGenerator extends BlockContainerImpl implements IVisualizable, ICustomBlockState { public class BlockSlimeSplitGenerator extends BlockContainerImpl implements IVisualizable, ICustomBlockState {
public BlockSlimeSplitGenerator() { public BlockSlimeSplitGenerator() {
super("slime_split_generator", BlockEntitySlimeSplitGenerator.class, Properties.copy(Blocks.SLIME_BLOCK).strength(2)); super("slime_split_generator", BlockEntitySlimeSplitGenerator.class, Properties.ofFullCopy(Blocks.SLIME_BLOCK).strength(2));
NeoForge.EVENT_BUS.register(new Events()); NeoForge.EVENT_BUS.register(new Events());
} }

View file

@ -14,7 +14,7 @@ import net.neoforged.api.distmarker.OnlyIn;
public class BlockSnowCreator extends BlockContainerImpl implements IVisualizable, ICustomBlockState { public class BlockSnowCreator extends BlockContainerImpl implements IVisualizable, ICustomBlockState {
public BlockSnowCreator() { public BlockSnowCreator() {
super("snow_creator", BlockEntitySnowCreator.class, Properties.copy(Blocks.STONE_BRICKS)); super("snow_creator", BlockEntitySnowCreator.class, Properties.ofFullCopy(Blocks.STONE_BRICKS));
} }
@Override @Override

View file

@ -21,13 +21,14 @@ import net.minecraft.world.level.block.state.BlockState;
import net.minecraft.world.level.material.Fluids; import net.minecraft.world.level.material.Fluids;
import net.neoforged.api.distmarker.Dist; import net.neoforged.api.distmarker.Dist;
import net.neoforged.api.distmarker.OnlyIn; import net.neoforged.api.distmarker.OnlyIn;
import org.jetbrains.annotations.Nullable;
import java.util.Optional; import java.util.Optional;
public class BlockSpring extends BlockContainerImpl implements ICustomBlockState, IColorProvidingBlock, IColorProvidingItem, BucketPickup { public class BlockSpring extends BlockContainerImpl implements ICustomBlockState, IColorProvidingBlock, IColorProvidingItem, BucketPickup {
public BlockSpring() { public BlockSpring() {
super("spring", BlockEntitySpring.class, Properties.copy(Blocks.STONE_BRICKS)); super("spring", BlockEntitySpring.class, Properties.ofFullCopy(Blocks.STONE_BRICKS));
} }
@Override @Override
@ -57,8 +58,8 @@ public class BlockSpring extends BlockContainerImpl implements ICustomBlockState
} }
@Override @Override
public ItemStack pickupBlock(LevelAccessor levelIn, BlockPos pos, BlockState state) { public ItemStack pickupBlock(@Nullable Player pPlayer, LevelAccessor pLevel, BlockPos pPos, BlockState pState) {
if (levelIn.getBlockEntity(pos) instanceof BlockEntitySpring spring && spring.tryConsumeAura(2500)) if (pLevel.getBlockEntity(pPos) instanceof BlockEntitySpring spring && spring.tryConsumeAura(2500))
return new ItemStack(Items.WATER_BUCKET); return new ItemStack(Items.WATER_BUCKET);
return ItemStack.EMPTY; return ItemStack.EMPTY;
} }
@ -68,4 +69,5 @@ public class BlockSpring extends BlockContainerImpl implements ICustomBlockState
public Optional<SoundEvent> getPickupSound() { public Optional<SoundEvent> getPickupSound() {
return Fluids.WATER.getPickupSound(); return Fluids.WATER.getPickupSound();
} }
} }

View file

@ -8,7 +8,7 @@ import net.minecraft.world.level.block.Blocks;
public class BlockWeatherChanger extends BlockContainerImpl implements ICustomBlockState { public class BlockWeatherChanger extends BlockContainerImpl implements ICustomBlockState {
public BlockWeatherChanger() { public BlockWeatherChanger() {
super("weather_changer", BlockEntityWeatherChanger.class, Properties.copy(Blocks.STONE_BRICKS)); super("weather_changer", BlockEntityWeatherChanger.class, Properties.ofFullCopy(Blocks.STONE_BRICKS));
} }
@Override @Override

View file

@ -62,8 +62,8 @@ public class BlockWoodStand extends BlockContainerImpl implements ITESRProvider<
var saplingStack = new ItemStack(level.getBlockState(pos).getBlock()); var saplingStack = new ItemStack(level.getBlockState(pos).getBlock());
if (!saplingStack.isEmpty()) { if (!saplingStack.isEmpty()) {
for (var recipe : ((Level) level).getRecipeManager().getRecipesFor(ModRecipes.TREE_RITUAL_TYPE, null, (Level) level)) { for (var recipe : ((Level) level).getRecipeManager().getRecipesFor(ModRecipes.TREE_RITUAL_TYPE, null, (Level) level)) {
if (recipe.saplingType.test(saplingStack)) { if (recipe.value().saplingType.test(saplingStack)) {
List<Ingredient> required = new ArrayList<>(Arrays.asList(recipe.ingredients)); List<Ingredient> required = new ArrayList<>(recipe.value().ingredients);
var toPick = new MutableObject<BlockEntityWoodStand>(); var toPick = new MutableObject<BlockEntityWoodStand>();
var fine = Multiblocks.TREE_RITUAL.forEach(pos, 'W', (tilePos, matcher) -> { var fine = Multiblocks.TREE_RITUAL.forEach(pos, 'W', (tilePos, matcher) -> {
@ -89,7 +89,7 @@ public class BlockWoodStand extends BlockContainerImpl implements ITESRProvider<
}); });
if (fine && required.isEmpty()) { if (fine && required.isEmpty()) {
toPick.getValue().setRitual(pos, recipe); toPick.getValue().setRitual(pos, recipe.value());
break; break;
} }
} }

View file

@ -1,7 +1,6 @@
package de.ellpeck.naturesaura.blocks.tiles; package de.ellpeck.naturesaura.blocks.tiles;
import de.ellpeck.naturesaura.api.NaturesAuraAPI; import de.ellpeck.naturesaura.api.NaturesAuraAPI;
import de.ellpeck.naturesaura.api.aura.container.IAuraContainer;
import de.ellpeck.naturesaura.api.aura.container.NaturalAuraContainer; import de.ellpeck.naturesaura.api.aura.container.NaturalAuraContainer;
import net.minecraft.core.BlockPos; import net.minecraft.core.BlockPos;
import net.minecraft.nbt.CompoundTag; import net.minecraft.nbt.CompoundTag;
@ -9,7 +8,7 @@ import net.minecraft.world.level.block.state.BlockState;
public class BlockEntityAncientLeaves extends BlockEntityImpl { public class BlockEntityAncientLeaves extends BlockEntityImpl {
private final NaturalAuraContainer container = new NaturalAuraContainer(NaturesAuraAPI.TYPE_OVERWORLD, 2000, 500) { public final NaturalAuraContainer container = new NaturalAuraContainer(NaturesAuraAPI.TYPE_OVERWORLD, 2000, 500) {
@Override @Override
public int getAuraColor() { public int getAuraColor() {
return 0xCE5489; return 0xCE5489;
@ -29,11 +28,6 @@ public class BlockEntityAncientLeaves extends BlockEntityImpl {
super(ModBlockEntities.ANCIENT_LEAVES, pos, state); super(ModBlockEntities.ANCIENT_LEAVES, pos, state);
} }
@Override
public IAuraContainer getAuraContainer() {
return this.container;
}
@Override @Override
public void writeNBT(CompoundTag compound, SaveType type) { public void writeNBT(CompoundTag compound, SaveType type) {
super.writeNBT(compound, type); super.writeNBT(compound, type);

View file

@ -16,6 +16,7 @@ import net.minecraft.util.Mth;
import net.minecraft.world.entity.Entity; import net.minecraft.world.entity.Entity;
import net.minecraft.world.entity.item.ItemEntity; import net.minecraft.world.entity.item.ItemEntity;
import net.minecraft.world.item.crafting.Ingredient; import net.minecraft.world.item.crafting.Ingredient;
import net.minecraft.world.item.crafting.RecipeHolder;
import net.minecraft.world.level.block.state.BlockState; import net.minecraft.world.level.block.state.BlockState;
import net.minecraft.world.phys.AABB; import net.minecraft.world.phys.AABB;
@ -25,7 +26,7 @@ import java.util.List;
public class BlockEntityAnimalSpawner extends BlockEntityImpl implements ITickableBlockEntity { public class BlockEntityAnimalSpawner extends BlockEntityImpl implements ITickableBlockEntity {
private AnimalSpawnerRecipe currentRecipe; private RecipeHolder<AnimalSpawnerRecipe> currentRecipe;
private double spawnX; private double spawnX;
private double spawnZ; private double spawnZ;
private int time; private int time;
@ -50,7 +51,7 @@ public class BlockEntityAnimalSpawner extends BlockEntityImpl implements ITickab
} }
if (this.currentRecipe != null) { if (this.currentRecipe != null) {
var drain = Mth.ceil(this.currentRecipe.aura / (float) this.currentRecipe.time * 10F); var drain = Mth.ceil(this.currentRecipe.value().aura / (float) this.currentRecipe.value().time * 10F);
if (!this.canUseRightNow(drain)) if (!this.canUseRightNow(drain))
return; return;
@ -58,8 +59,8 @@ public class BlockEntityAnimalSpawner extends BlockEntityImpl implements ITickab
IAuraChunk.getAuraChunk(this.level, spot).drainAura(spot, drain); IAuraChunk.getAuraChunk(this.level, spot).drainAura(spot, drain);
this.time += 10; this.time += 10;
if (this.time >= this.currentRecipe.time) { if (this.time >= this.currentRecipe.value().time) {
var entity = this.currentRecipe.makeEntity(this.level, BlockPos.containing(this.spawnX, this.worldPosition.getY() + 1, this.spawnZ)); var entity = this.currentRecipe.value().makeEntity(this.level, BlockPos.containing(this.spawnX, this.worldPosition.getY() + 1, this.spawnZ));
this.level.addFreshEntity(entity); this.level.addFreshEntity(entity);
this.currentRecipe = null; this.currentRecipe = null;
@ -71,9 +72,9 @@ public class BlockEntityAnimalSpawner extends BlockEntityImpl implements ITickab
new AABB(this.worldPosition).inflate(2)); new AABB(this.worldPosition).inflate(2));
for (var recipe : this.level.getRecipeManager().getRecipesFor(ModRecipes.ANIMAL_SPAWNER_TYPE, null, this.level)) { for (var recipe : this.level.getRecipeManager().getRecipesFor(ModRecipes.ANIMAL_SPAWNER_TYPE, null, this.level)) {
if (recipe.ingredients.length != items.size()) if (recipe.value().ingredients.size() != items.size())
continue; continue;
List<Ingredient> required = new ArrayList<>(Arrays.asList(recipe.ingredients)); List<Ingredient> required = new ArrayList<>(recipe.value().ingredients);
for (var item : items) { for (var item : items) {
if (!item.isAlive() || item.hasPickUpDelay()) if (!item.isAlive() || item.hasPickUpDelay())
break; break;
@ -123,7 +124,7 @@ public class BlockEntityAnimalSpawner extends BlockEntityImpl implements ITickab
this.level.random.nextFloat() + 0.5F); this.level.random.nextFloat() + 0.5F);
if (this.entityClient == null) { if (this.entityClient == null) {
this.entityClient = this.currentRecipe.makeEntity(this.level, BlockPos.ZERO); this.entityClient = this.currentRecipe.value().makeEntity(this.level, BlockPos.ZERO);
this.entityClient.setPos(this.spawnX, this.worldPosition.getY() + 1, this.spawnZ); this.entityClient.setPos(this.spawnX, this.worldPosition.getY() + 1, this.spawnZ);
} }
var bounds = this.entityClient.getBoundingBox(); var bounds = this.entityClient.getBoundingBox();
@ -141,7 +142,7 @@ public class BlockEntityAnimalSpawner extends BlockEntityImpl implements ITickab
super.writeNBT(compound, type); super.writeNBT(compound, type);
if (type != SaveType.BLOCK) { if (type != SaveType.BLOCK) {
if (this.currentRecipe != null) { if (this.currentRecipe != null) {
compound.putString("recipe", this.currentRecipe.name.toString()); compound.putString("recipe", this.currentRecipe.id().toString());
compound.putDouble("spawn_x", this.spawnX); compound.putDouble("spawn_x", this.spawnX);
compound.putDouble("spawn_z", this.spawnZ); compound.putDouble("spawn_z", this.spawnZ);
compound.putInt("time", this.time); compound.putInt("time", this.time);
@ -149,6 +150,7 @@ public class BlockEntityAnimalSpawner extends BlockEntityImpl implements ITickab
} }
} }
@SuppressWarnings("unchecked")
@Override @Override
public void readNBT(CompoundTag compound, SaveType type) { public void readNBT(CompoundTag compound, SaveType type) {
super.readNBT(compound, type); super.readNBT(compound, type);
@ -156,7 +158,7 @@ public class BlockEntityAnimalSpawner extends BlockEntityImpl implements ITickab
if (compound.contains("recipe")) { if (compound.contains("recipe")) {
if (this.hasLevel()) { if (this.hasLevel()) {
var name = new ResourceLocation(compound.getString("recipe")); var name = new ResourceLocation(compound.getString("recipe"));
this.currentRecipe = (AnimalSpawnerRecipe) this.level.getRecipeManager().byKey(name).orElse(null); this.currentRecipe = (RecipeHolder<AnimalSpawnerRecipe>) this.level.getRecipeManager().byKey(name).orElse(null);
} }
this.spawnX = compound.getDouble("spawn_x"); this.spawnX = compound.getDouble("spawn_x");
this.spawnZ = compound.getDouble("spawn_z"); this.spawnZ = compound.getDouble("spawn_z");
@ -172,4 +174,5 @@ public class BlockEntityAnimalSpawner extends BlockEntityImpl implements ITickab
public boolean allowsLowerLimiter() { public boolean allowsLowerLimiter() {
return true; return true;
} }
} }

View file

@ -12,7 +12,6 @@ import net.minecraft.nbt.CompoundTag;
import net.minecraft.world.item.ItemStack; import net.minecraft.world.item.ItemStack;
import net.minecraft.world.level.block.state.BlockState; import net.minecraft.world.level.block.state.BlockState;
import net.minecraft.world.level.block.state.properties.BlockStateProperties; import net.minecraft.world.level.block.state.properties.BlockStateProperties;
import net.neoforged.neoforge.items.IItemHandlerModifiable;
import java.util.Map; import java.util.Map;
@ -22,7 +21,7 @@ public class BlockEntityAuraTimer extends BlockEntityImpl implements ITickableBl
.put(NaturesAuraAPI.TYPE_OVERWORLD, 20) .put(NaturesAuraAPI.TYPE_OVERWORLD, 20)
.put(NaturesAuraAPI.TYPE_NETHER, 20 * 60) .put(NaturesAuraAPI.TYPE_NETHER, 20 * 60)
.put(NaturesAuraAPI.TYPE_END, 20 * 60 * 60).build(); .put(NaturesAuraAPI.TYPE_END, 20 * 60 * 60).build();
private final ItemStackHandlerNA itemHandler = new ItemStackHandlerNA(1, this, true) { public final ItemStackHandlerNA itemHandler = new ItemStackHandlerNA(1, this, true) {
@Override @Override
protected boolean canInsert(ItemStack stack, int slot) { protected boolean canInsert(ItemStack stack, int slot) {
return stack.getItem() == ModItems.AURA_BOTTLE; return stack.getItem() == ModItems.AURA_BOTTLE;
@ -98,11 +97,6 @@ public class BlockEntityAuraTimer extends BlockEntityImpl implements ITickableBl
return this.timer / (float) this.getTotalTime(); return this.timer / (float) this.getTotalTime();
} }
@Override
public IItemHandlerModifiable getItemHandler() {
return this.itemHandler;
}
@Override @Override
public void writeNBT(CompoundTag compound, SaveType type) { public void writeNBT(CompoundTag compound, SaveType type) {
super.writeNBT(compound, type); super.writeNBT(compound, type);

View file

@ -82,7 +82,7 @@ public class BlockEntityAutoCrafter extends BlockEntityImpl implements ITickable
if (recipe == null) if (recipe == null)
return; return;
var result = recipe.assemble(this.crafting, this.level.registryAccess()); var result = recipe.value().assemble(this.crafting, this.level.registryAccess());
if (result.isEmpty()) if (result.isEmpty())
return; return;
var resultItem = new ItemEntity(this.level, var resultItem = new ItemEntity(this.level,
@ -90,7 +90,7 @@ public class BlockEntityAutoCrafter extends BlockEntityImpl implements ITickable
resultItem.setDeltaMovement(0, 0, 0); resultItem.setDeltaMovement(0, 0, 0);
this.level.addFreshEntity(resultItem); this.level.addFreshEntity(resultItem);
var remainingItems = recipe.getRemainingItems(this.crafting); var remainingItems = recipe.value().getRemainingItems(this.crafting);
for (var i = 0; i < items.length; i++) { for (var i = 0; i < items.length; i++) {
var item = items[i]; var item = items[i];
if (item == null) if (item == null)

View file

@ -2,7 +2,6 @@ package de.ellpeck.naturesaura.blocks.tiles;
import de.ellpeck.naturesaura.api.NaturesAuraAPI; import de.ellpeck.naturesaura.api.NaturesAuraAPI;
import de.ellpeck.naturesaura.api.aura.container.BasicAuraContainer; import de.ellpeck.naturesaura.api.aura.container.BasicAuraContainer;
import de.ellpeck.naturesaura.api.aura.container.IAuraContainer;
import de.ellpeck.naturesaura.packet.PacketHandler; import de.ellpeck.naturesaura.packet.PacketHandler;
import de.ellpeck.naturesaura.packet.PacketParticles; import de.ellpeck.naturesaura.packet.PacketParticles;
import net.minecraft.core.BlockPos; import net.minecraft.core.BlockPos;
@ -16,7 +15,7 @@ import net.minecraft.world.phys.AABB;
public class BlockEntityEndFlower extends BlockEntityImpl implements ITickableBlockEntity { public class BlockEntityEndFlower extends BlockEntityImpl implements ITickableBlockEntity {
private final BasicAuraContainer container = new BasicAuraContainer(null, 500000) { public final BasicAuraContainer container = new BasicAuraContainer(null, 500000) {
{ {
this.aura = this.maxAura; this.aura = this.maxAura;
} }
@ -94,11 +93,6 @@ public class BlockEntityEndFlower extends BlockEntityImpl implements ITickableBl
} }
} }
@Override
public IAuraContainer getAuraContainer() {
return this.container;
}
@Override @Override
public void writeNBT(CompoundTag compound, SaveType type) { public void writeNBT(CompoundTag compound, SaveType type) {
super.writeNBT(compound, type); super.writeNBT(compound, type);
@ -116,4 +110,5 @@ public class BlockEntityEndFlower extends BlockEntityImpl implements ITickableBl
this.isDrainMode = compound.getBoolean("drain_mode"); this.isDrainMode = compound.getBoolean("drain_mode");
} }
} }
} }

View file

@ -24,7 +24,7 @@ import javax.annotation.Nullable;
public class BlockEntityEnderCrate extends BlockEntityImpl implements MenuProvider { public class BlockEntityEnderCrate extends BlockEntityImpl implements MenuProvider {
public String name; public String name;
private final IItemHandlerModifiable wrappedEnderStorage = new IItemHandlerModifiable() { public final IItemHandlerModifiable wrappedEnderStorage = new IItemHandlerModifiable() {
@Override @Override
public void setStackInSlot(int slot, @Nonnull ItemStack stack) { public void setStackInSlot(int slot, @Nonnull ItemStack stack) {
this.getStorage().setStackInSlot(slot, stack); this.getStorage().setStackInSlot(slot, stack);
@ -82,13 +82,6 @@ public class BlockEntityEnderCrate extends BlockEntityImpl implements MenuProvid
super(ModBlockEntities.ENDER_CRATE, pos, state); super(ModBlockEntities.ENDER_CRATE, pos, state);
} }
@Override
public IItemHandlerModifiable getItemHandler() {
if (this.canOpen())
return this.wrappedEnderStorage;
return null;
}
public boolean canOpen() { public boolean canOpen() {
return this.name != null; return this.name != null;
} }
@ -149,11 +142,12 @@ public class BlockEntityEnderCrate extends BlockEntityImpl implements MenuProvid
@Nullable @Nullable
@Override @Override
public AbstractContainerMenu createMenu(int window, Inventory inv, Player player) { public AbstractContainerMenu createMenu(int window, Inventory inv, Player player) {
return new ContainerEnderCrate(ModContainers.ENDER_CRATE, window, player, this.getItemHandler()); return new ContainerEnderCrate(ModContainers.ENDER_CRATE, window, player, this.wrappedEnderStorage);
} }
@Override @Override
public boolean allowsLowerLimiter() { public boolean allowsLowerLimiter() {
return true; return true;
} }
} }

View file

@ -108,7 +108,7 @@ public class BlockEntityFieldCreator extends BlockEntityImpl implements ITickabl
var state = this.level.getBlockState(pos); var state = this.level.getBlockState(pos);
if (!state.isAir() && state.getDestroySpeed(this.level, pos) >= 0F) { if (!state.isAir() && state.getDestroySpeed(this.level, pos) >= 0F) {
var fake = FakePlayerFactory.getMinecraft((ServerLevel) this.level); var fake = FakePlayerFactory.getMinecraft((ServerLevel) this.level);
if (!NeoForge.EVENT_BUS.post(new BlockEvent.BreakEvent(this.level, pos, state, fake))) { if (!NeoForge.EVENT_BUS.post(new BlockEvent.BreakEvent(this.level, pos, state, fake)).isCanceled()) {
var drops = state.getDrops(new LootParams.Builder((ServerLevel) this.level) var drops = state.getDrops(new LootParams.Builder((ServerLevel) this.level)
.withParameter(LootContextParams.THIS_ENTITY, fake) .withParameter(LootContextParams.THIS_ENTITY, fake)
.withParameter(LootContextParams.ORIGIN, Vec3.atCenterOf(pos)) .withParameter(LootContextParams.ORIGIN, Vec3.atCenterOf(pos))
@ -208,4 +208,5 @@ public class BlockEntityFieldCreator extends BlockEntityImpl implements ITickabl
public boolean allowsLowerLimiter() { public boolean allowsLowerLimiter() {
return true; return true;
} }
} }

View file

@ -105,7 +105,7 @@ public class BlockEntityFurnaceHeater extends BlockEntityImpl implements ITickab
var recipe = this.level.getRecipeManager().getRecipeFor(BlockEntityFurnaceHeater.getRecipeType(furnace), furnace, this.level).orElse(null); var recipe = this.level.getRecipeManager().getRecipeFor(BlockEntityFurnaceHeater.getRecipeType(furnace), furnace, this.level).orElse(null);
if (recipe == null) if (recipe == null)
return false; return false;
var output = recipe.getResultItem(this.level.registryAccess()); var output = recipe.value().getResultItem(this.level.registryAccess());
var currOutput = furnace.getItem(2); var currOutput = furnace.getItem(2);
return currOutput.isEmpty() || Helper.areItemsEqual(currOutput, output, true) && currOutput.getCount() + output.getCount() <= output.getMaxStackSize(); return currOutput.isEmpty() || Helper.areItemsEqual(currOutput, output, true) && currOutput.getCount() + output.getCount() <= output.getMaxStackSize();
} else } else

View file

@ -2,9 +2,6 @@ package de.ellpeck.naturesaura.blocks.tiles;
import net.minecraft.core.BlockPos; import net.minecraft.core.BlockPos;
import net.minecraft.world.level.block.state.BlockState; import net.minecraft.world.level.block.state.BlockState;
import net.minecraft.world.phys.AABB;
import net.neoforged.api.distmarker.Dist;
import net.neoforged.api.distmarker.OnlyIn;
public class BlockEntityGeneratorLimitRemover extends BlockEntityImpl { public class BlockEntityGeneratorLimitRemover extends BlockEntityImpl {
@ -12,9 +9,4 @@ public class BlockEntityGeneratorLimitRemover extends BlockEntityImpl {
super(ModBlockEntities.GENERATOR_LIMIT_REMOVER, pos, state); super(ModBlockEntities.GENERATOR_LIMIT_REMOVER, pos, state);
} }
@Override
@OnlyIn(Dist.CLIENT)
public AABB getRenderBoundingBox() {
return new AABB(this.worldPosition, this.worldPosition.offset(1, 2, 1));
}
} }

View file

@ -10,12 +10,11 @@ import net.minecraft.world.item.ItemStack;
import net.minecraft.world.level.block.state.BlockState; import net.minecraft.world.level.block.state.BlockState;
import net.minecraft.world.phys.AABB; import net.minecraft.world.phys.AABB;
import net.neoforged.neoforge.capabilities.Capabilities; import net.neoforged.neoforge.capabilities.Capabilities;
import net.neoforged.neoforge.items.IItemHandlerModifiable;
public class BlockEntityGratedChute extends BlockEntityImpl implements ITickableBlockEntity { public class BlockEntityGratedChute extends BlockEntityImpl implements ITickableBlockEntity {
public boolean isBlacklist; public boolean isBlacklist;
private final ItemStackHandlerNA items = new ItemStackHandlerNA(1, this, true) { public final ItemStackHandlerNA items = new ItemStackHandlerNA(1, this, true) {
@Override @Override
protected boolean canExtract(ItemStack stack, int slot, int amount) { protected boolean canExtract(ItemStack stack, int slot, int amount) {
return BlockEntityGratedChute.this.redstonePower <= 0; return BlockEntityGratedChute.this.redstonePower <= 0;
@ -139,9 +138,5 @@ public class BlockEntityGratedChute extends BlockEntityImpl implements ITickable
} }
} }
@Override
public IItemHandlerModifiable getItemHandler() {
return this.items;
}
} }

View file

@ -2,9 +2,6 @@ package de.ellpeck.naturesaura.blocks.tiles;
import net.minecraft.core.BlockPos; import net.minecraft.core.BlockPos;
import net.minecraft.world.level.block.state.BlockState; import net.minecraft.world.level.block.state.BlockState;
import net.minecraft.world.phys.AABB;
import net.neoforged.api.distmarker.Dist;
import net.neoforged.api.distmarker.OnlyIn;
public class BlockEntityLowerLimiter extends BlockEntityImpl { public class BlockEntityLowerLimiter extends BlockEntityImpl {
@ -12,9 +9,4 @@ public class BlockEntityLowerLimiter extends BlockEntityImpl {
super(ModBlockEntities.LOWER_LIMITER, pos, state); super(ModBlockEntities.LOWER_LIMITER, pos, state);
} }
@Override
@OnlyIn(Dist.CLIENT)
public AABB getRenderBoundingBox() {
return new AABB(this.worldPosition, this.worldPosition.offset(1, 2, 1));
}
} }

View file

@ -12,6 +12,7 @@ import de.ellpeck.naturesaura.packet.PacketParticles;
import de.ellpeck.naturesaura.recipes.AltarRecipe; import de.ellpeck.naturesaura.recipes.AltarRecipe;
import de.ellpeck.naturesaura.recipes.ModRecipes; import de.ellpeck.naturesaura.recipes.ModRecipes;
import net.minecraft.core.BlockPos; import net.minecraft.core.BlockPos;
import net.minecraft.core.Holder;
import net.minecraft.nbt.CompoundTag; import net.minecraft.nbt.CompoundTag;
import net.minecraft.resources.ResourceLocation; import net.minecraft.resources.ResourceLocation;
import net.minecraft.sounds.SoundEvents; import net.minecraft.sounds.SoundEvents;
@ -19,6 +20,7 @@ import net.minecraft.sounds.SoundSource;
import net.minecraft.util.Mth; import net.minecraft.util.Mth;
import net.minecraft.world.item.ItemStack; import net.minecraft.world.item.ItemStack;
import net.minecraft.world.item.crafting.Ingredient; import net.minecraft.world.item.crafting.Ingredient;
import net.minecraft.world.item.crafting.RecipeHolder;
import net.minecraft.world.level.block.state.BlockState; import net.minecraft.world.level.block.state.BlockState;
import net.neoforged.api.distmarker.Dist; import net.neoforged.api.distmarker.Dist;
import net.neoforged.api.distmarker.OnlyIn; import net.neoforged.api.distmarker.OnlyIn;
@ -27,7 +29,7 @@ import net.neoforged.neoforge.items.ItemStackHandler;
public class BlockEntityNatureAltar extends BlockEntityImpl implements ITickableBlockEntity { public class BlockEntityNatureAltar extends BlockEntityImpl implements ITickableBlockEntity {
private final BasicAuraContainer container = new BasicAuraContainer(null, 500000) { public final BasicAuraContainer container = new BasicAuraContainer(null, 500000) {
@Override @Override
public int getAuraColor() { public int getAuraColor() {
return IAuraType.forLevel(BlockEntityNatureAltar.this.level).getColor(); return IAuraType.forLevel(BlockEntityNatureAltar.this.level).getColor();
@ -42,12 +44,12 @@ public class BlockEntityNatureAltar extends BlockEntityImpl implements ITickable
@Override @Override
protected boolean canInsert(ItemStack stack, int slot) { protected boolean canInsert(ItemStack stack, int slot) {
return BlockEntityNatureAltar.this.getRecipeForInput(stack) != null || stack.getCapability(NaturesAuraAPI.CAP_AURA_CONTAINER, null).isPresent(); return BlockEntityNatureAltar.this.getRecipeForInput(stack) != null || stack.getCapability(NaturesAuraAPI.AURA_CONTAINER_ITEM_CAPABILITY, null) != null;
} }
@Override @Override
protected boolean canExtract(ItemStack stack, int slot, int amount) { protected boolean canExtract(ItemStack stack, int slot, int amount) {
var cap = stack.getCapability(NaturesAuraAPI.CAP_AURA_CONTAINER, null).orElse(null); var cap = stack.getCapability(NaturesAuraAPI.AURA_CONTAINER_ITEM_CAPABILITY);
if (cap != null) { if (cap != null) {
return cap.storeAura(1, true) <= 0; return cap.storeAura(1, true) <= 0;
} else { } else {
@ -59,7 +61,7 @@ public class BlockEntityNatureAltar extends BlockEntityImpl implements ITickable
public int bobTimer; public int bobTimer;
public boolean isComplete; public boolean isComplete;
private AltarRecipe currentRecipe; private RecipeHolder<AltarRecipe> currentRecipe;
private int timer; private int timer;
private int lastAura; private int lastAura;
private boolean firstTick = true; private boolean firstTick = true;
@ -118,7 +120,7 @@ public class BlockEntityNatureAltar extends BlockEntityImpl implements ITickable
} }
var stack = this.items.getStackInSlot(0); var stack = this.items.getStackInSlot(0);
var container = stack.getCapability(NaturesAuraAPI.CAP_AURA_CONTAINER, null).orElse(null); var container = stack.getCapability(NaturesAuraAPI.AURA_CONTAINER_ITEM_CAPABILITY);
if (!stack.isEmpty() && container != null) { if (!stack.isEmpty() && container != null) {
var theoreticalDrain = this.container.drainAura(1000, true); var theoreticalDrain = this.container.drainAura(1000, true);
if (theoreticalDrain > 0) { if (theoreticalDrain > 0) {
@ -136,11 +138,11 @@ public class BlockEntityNatureAltar extends BlockEntityImpl implements ITickable
this.currentRecipe = this.getRecipeForInput(stack); this.currentRecipe = this.getRecipeForInput(stack);
} }
} else { } else {
if (stack.isEmpty() || !this.currentRecipe.input.test(stack)) { if (stack.isEmpty() || !this.currentRecipe.value().input.test(stack)) {
this.currentRecipe = null; this.currentRecipe = null;
this.timer = 0; this.timer = 0;
} else { } else {
var req = Mth.ceil(this.currentRecipe.aura / (double) this.currentRecipe.time); var req = Mth.ceil(this.currentRecipe.value().aura / (double) this.currentRecipe.value().time);
if (this.container.getStoredAura() >= req) { if (this.container.getStoredAura() >= req) {
this.container.drainAura(req, false); this.container.drainAura(req, false);
@ -148,8 +150,8 @@ public class BlockEntityNatureAltar extends BlockEntityImpl implements ITickable
PacketHandler.sendToAllAround(this.level, this.worldPosition, 32, new PacketParticles(this.worldPosition.getX(), this.worldPosition.getY(), this.worldPosition.getZ(), PacketParticles.Type.ALTAR_CONVERSION, this.container.getAuraColor())); PacketHandler.sendToAllAround(this.level, this.worldPosition, 32, new PacketParticles(this.worldPosition.getX(), this.worldPosition.getY(), this.worldPosition.getZ(), PacketParticles.Type.ALTAR_CONVERSION, this.container.getAuraColor()));
this.timer++; this.timer++;
if (this.timer >= this.currentRecipe.time) { if (this.timer >= this.currentRecipe.value().time) {
this.items.setStackInSlot(0, this.currentRecipe.output.copy()); this.items.setStackInSlot(0, this.currentRecipe.value().output.copy());
this.currentRecipe = null; this.currentRecipe = null;
this.timer = 0; this.timer = 0;
@ -197,14 +199,15 @@ public class BlockEntityNatureAltar extends BlockEntityImpl implements ITickable
} }
} }
private AltarRecipe getRecipeForInput(ItemStack input) { private RecipeHolder<AltarRecipe> getRecipeForInput(ItemStack input) {
for (var recipe : this.level.getRecipeManager().getRecipesFor(ModRecipes.ALTAR_TYPE, null, this.level)) { for (var holder : this.level.getRecipeManager().getRecipesFor(ModRecipes.ALTAR_TYPE, null, this.level)) {
var recipe = holder.value();
if (recipe.input.test(input)) { if (recipe.input.test(input)) {
if (recipe.catalyst == Ingredient.EMPTY) if (recipe.catalyst == Ingredient.EMPTY)
return recipe; return holder;
for (var stack : this.catalysts) { for (var stack : this.catalysts) {
if (recipe.catalyst.test(stack)) if (recipe.catalyst.test(stack))
return recipe; return holder;
} }
} }
} }
@ -221,12 +224,13 @@ public class BlockEntityNatureAltar extends BlockEntityImpl implements ITickable
} }
if (type == SaveType.TILE) { if (type == SaveType.TILE) {
if (this.currentRecipe != null) { if (this.currentRecipe != null) {
compound.putString("recipe", this.currentRecipe.name.toString()); compound.putString("recipe", this.currentRecipe.id().toString());
compound.putInt("timer", this.timer); compound.putInt("timer", this.timer);
} }
} }
} }
@SuppressWarnings("unchecked")
@Override @Override
public void readNBT(CompoundTag compound, SaveType type) { public void readNBT(CompoundTag compound, SaveType type) {
super.readNBT(compound, type); super.readNBT(compound, type);
@ -238,19 +242,10 @@ public class BlockEntityNatureAltar extends BlockEntityImpl implements ITickable
if (type == SaveType.TILE) { if (type == SaveType.TILE) {
if (compound.contains("recipe")) { if (compound.contains("recipe")) {
if (this.hasLevel()) if (this.hasLevel())
this.currentRecipe = (AltarRecipe) this.level.getRecipeManager().byKey(new ResourceLocation(compound.getString("recipe"))).orElse(null); this.currentRecipe = (RecipeHolder<AltarRecipe>) this.level.getRecipeManager().byKey(new ResourceLocation(compound.getString("recipe"))).orElse(null);
this.timer = compound.getInt("timer"); this.timer = compound.getInt("timer");
} }
} }
} }
@Override
public IAuraContainer getAuraContainer() {
return this.container;
}
@Override
public IItemHandlerModifiable getItemHandler() {
return this.items;
}
} }

View file

@ -17,7 +17,6 @@ import net.minecraft.world.level.block.Blocks;
import net.minecraft.world.level.block.state.BlockState; import net.minecraft.world.level.block.state.BlockState;
import net.minecraft.world.phys.AABB; import net.minecraft.world.phys.AABB;
import net.minecraft.world.phys.Vec3; import net.minecraft.world.phys.Vec3;
import net.neoforged.neoforge.items.IItemHandlerModifiable;
import net.neoforged.neoforge.items.ItemStackHandler; import net.neoforged.neoforge.items.ItemStackHandler;
import java.util.ArrayDeque; import java.util.ArrayDeque;
@ -39,8 +38,8 @@ public class BlockEntityOfferingTable extends BlockEntityImpl implements ITickab
private OfferingRecipe getRecipe(ItemStack input) { private OfferingRecipe getRecipe(ItemStack input) {
for (var recipe : this.level.getRecipeManager().getRecipesFor(ModRecipes.OFFERING_TYPE, null, this.level)) for (var recipe : this.level.getRecipeManager().getRecipesFor(ModRecipes.OFFERING_TYPE, null, this.level))
if (recipe.input.test(input)) if (recipe.value().input.test(input))
return recipe; return recipe.value();
return null; return null;
} }
@ -114,7 +113,7 @@ public class BlockEntityOfferingTable extends BlockEntityImpl implements ITickab
if (type != SaveType.SYNC) { if (type != SaveType.SYNC) {
var list = new ListTag(); var list = new ListTag();
for (var stack : this.itemsToSpawn) for (var stack : this.itemsToSpawn)
list.add(stack.serializeNBT()); list.add(stack.save(new CompoundTag()));
compound.put("items_to_spawn", list); compound.put("items_to_spawn", list);
} }
} }
@ -135,9 +134,4 @@ public class BlockEntityOfferingTable extends BlockEntityImpl implements ITickab
} }
} }
@Override
public IItemHandlerModifiable getItemHandler() {
return this.items;
}
} }

View file

@ -15,14 +15,13 @@ import net.minecraft.tags.BlockTags;
import net.minecraft.world.entity.item.ItemEntity; import net.minecraft.world.entity.item.ItemEntity;
import net.minecraft.world.item.ItemStack; import net.minecraft.world.item.ItemStack;
import net.minecraft.world.item.crafting.Ingredient; import net.minecraft.world.item.crafting.Ingredient;
import net.minecraft.world.item.crafting.RecipeHolder;
import net.minecraft.world.level.block.Blocks; import net.minecraft.world.level.block.Blocks;
import net.minecraft.world.level.block.LeavesBlock; import net.minecraft.world.level.block.LeavesBlock;
import net.minecraft.world.level.block.state.BlockState; import net.minecraft.world.level.block.state.BlockState;
import net.neoforged.neoforge.items.IItemHandlerModifiable;
import net.neoforged.neoforge.items.ItemStackHandler; import net.neoforged.neoforge.items.ItemStackHandler;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Arrays;
import java.util.List; import java.util.List;
public class BlockEntityWoodStand extends BlockEntityImpl implements ITickableBlockEntity { public class BlockEntityWoodStand extends BlockEntityImpl implements ITickableBlockEntity {
@ -34,7 +33,7 @@ public class BlockEntityWoodStand extends BlockEntityImpl implements ITickableBl
} }
}; };
private TreeRitualRecipe recipe; private RecipeHolder<TreeRitualRecipe> recipe;
private BlockPos ritualPos; private BlockPos ritualPos;
private int timer; private int timer;
@ -42,7 +41,7 @@ public class BlockEntityWoodStand extends BlockEntityImpl implements ITickableBl
super(ModBlockEntities.WOOD_STAND, pos, state); super(ModBlockEntities.WOOD_STAND, pos, state);
} }
public void setRitual(BlockPos pos, TreeRitualRecipe recipe) { public void setRitual(BlockPos pos, RecipeHolder<TreeRitualRecipe> recipe) {
this.ritualPos = pos; this.ritualPos = pos;
this.recipe = recipe; this.recipe = recipe;
} }
@ -53,9 +52,9 @@ public class BlockEntityWoodStand extends BlockEntityImpl implements ITickableBl
if (this.ritualPos != null && this.recipe != null) { if (this.ritualPos != null && this.recipe != null) {
if (this.level.getGameTime() % 5 == 0) { if (this.level.getGameTime() % 5 == 0) {
if (this.isRitualOkay()) { if (this.isRitualOkay()) {
var wasOverHalf = this.timer >= this.recipe.time / 2; var wasOverHalf = this.timer >= this.recipe.value().time / 2;
this.timer += 5; this.timer += 5;
var isOverHalf = this.timer >= this.recipe.time / 2; var isOverHalf = this.timer >= this.recipe.value().time / 2;
if (!isOverHalf) if (!isOverHalf)
Multiblocks.TREE_RITUAL.forEach(this.ritualPos, 'W', (pos, matcher) -> { Multiblocks.TREE_RITUAL.forEach(this.ritualPos, 'W', (pos, matcher) -> {
@ -75,7 +74,7 @@ public class BlockEntityWoodStand extends BlockEntityImpl implements ITickableBl
PacketHandler.sendToAllAround(this.level, this.ritualPos, 32, PacketHandler.sendToAllAround(this.level, this.ritualPos, 32,
new PacketParticles(this.ritualPos.getX(), this.ritualPos.getY(), this.ritualPos.getZ(), PacketParticles.Type.TR_GOLD_POWDER)); new PacketParticles(this.ritualPos.getX(), this.ritualPos.getY(), this.ritualPos.getZ(), PacketParticles.Type.TR_GOLD_POWDER));
if (this.timer >= this.recipe.time) { if (this.timer >= this.recipe.value().time) {
Multiblocks.TREE_RITUAL.forEach(this.ritualPos, 'G', (pos, matcher) -> { Multiblocks.TREE_RITUAL.forEach(this.ritualPos, 'G', (pos, matcher) -> {
this.level.setBlockAndUpdate(pos, Blocks.AIR.defaultBlockState()); this.level.setBlockAndUpdate(pos, Blocks.AIR.defaultBlockState());
return true; return true;
@ -84,7 +83,7 @@ public class BlockEntityWoodStand extends BlockEntityImpl implements ITickableBl
var item = new ItemEntity(this.level, var item = new ItemEntity(this.level,
this.ritualPos.getX() + 0.5, this.ritualPos.getY() + 4.5, this.ritualPos.getZ() + 0.5, this.ritualPos.getX() + 0.5, this.ritualPos.getY() + 4.5, this.ritualPos.getZ() + 0.5,
this.recipe.result.copy()); this.recipe.value().result.copy());
this.level.addFreshEntity(item); this.level.addFreshEntity(item);
PacketHandler.sendToAllAround(this.level, this.worldPosition, 32, PacketHandler.sendToAllAround(this.level, this.worldPosition, 32,
@ -130,8 +129,8 @@ public class BlockEntityWoodStand extends BlockEntityImpl implements ITickableBl
if (!state.is(BlockTags.LOGS)) if (!state.is(BlockTags.LOGS))
return false; return false;
} }
if (this.timer < this.recipe.time / 2) { if (this.timer < this.recipe.value().time / 2) {
List<Ingredient> required = new ArrayList<>(Arrays.asList(this.recipe.ingredients)); List<Ingredient> required = new ArrayList<>(this.recipe.value().ingredients);
var fine = Multiblocks.TREE_RITUAL.forEach(this.ritualPos, 'W', (pos, matcher) -> { var fine = Multiblocks.TREE_RITUAL.forEach(this.ritualPos, 'W', (pos, matcher) -> {
var tile = this.level.getBlockEntity(pos); var tile = this.level.getBlockEntity(pos);
if (tile instanceof BlockEntityWoodStand) { if (tile instanceof BlockEntityWoodStand) {
@ -164,11 +163,12 @@ public class BlockEntityWoodStand extends BlockEntityImpl implements ITickableBl
if (this.ritualPos != null && this.recipe != null) { if (this.ritualPos != null && this.recipe != null) {
compound.putLong("ritual_pos", this.ritualPos.asLong()); compound.putLong("ritual_pos", this.ritualPos.asLong());
compound.putInt("timer", this.timer); compound.putInt("timer", this.timer);
compound.putString("recipe", this.recipe.name.toString()); compound.putString("recipe", this.recipe.toString());
} }
} }
} }
@SuppressWarnings("unchecked")
@Override @Override
public void readNBT(CompoundTag compound, SaveType type) { public void readNBT(CompoundTag compound, SaveType type) {
super.readNBT(compound, type); super.readNBT(compound, type);
@ -180,14 +180,9 @@ public class BlockEntityWoodStand extends BlockEntityImpl implements ITickableBl
this.ritualPos = BlockPos.of(compound.getLong("ritual_pos")); this.ritualPos = BlockPos.of(compound.getLong("ritual_pos"));
this.timer = compound.getInt("timer"); this.timer = compound.getInt("timer");
if (this.hasLevel()) if (this.hasLevel())
this.recipe = (TreeRitualRecipe) this.level.getRecipeManager().byKey(new ResourceLocation(compound.getString("recipe"))).orElse(null); this.recipe = (RecipeHolder<TreeRitualRecipe>) this.level.getRecipeManager().byKey(new ResourceLocation(compound.getString("recipe"))).orElse(null);
} }
} }
} }
@Override
public IItemHandlerModifiable getItemHandler() {
return this.items;
}
} }

View file

@ -33,17 +33,23 @@ import java.util.function.BiConsumer;
public class AuraChunk implements IAuraChunk { public class AuraChunk implements IAuraChunk {
private final LevelChunk chunk;
private final IAuraType type;
private final Map<BlockPos, DrainSpot> drainSpots = new ConcurrentHashMap<>(); private final Map<BlockPos, DrainSpot> drainSpots = new ConcurrentHashMap<>();
private final Table<BlockPos, Integer, Pair<Integer, Integer>> auraAndSpotAmountCache = HashBasedTable.create(); private final Table<BlockPos, Integer, Pair<Integer, Integer>> auraAndSpotAmountCache = HashBasedTable.create();
private final Table<BlockPos, Integer, Pair<BlockPos, Integer>[]> limitSpotCache = HashBasedTable.create(); private final Table<BlockPos, Integer, Pair<BlockPos, Integer>[]> limitSpotCache = HashBasedTable.create();
private final List<IDrainSpotEffect> effects = new ArrayList<>(); private final List<IDrainSpotEffect> effects = new ArrayList<>();
private LevelChunk chunk;
private IAuraType type;
private boolean needsSync; private boolean needsSync;
public AuraChunk(LevelChunk chunk, IAuraType type) { @Override
public void ensureInitialized(LevelChunk chunk) {
// are we already initialized?
if (this.chunk != null)
return;
this.chunk = chunk; this.chunk = chunk;
this.type = type; this.type = IAuraType.forLevel(chunk.getLevel());
for (var supplier : NaturesAuraAPI.DRAIN_SPOT_EFFECTS.values()) { for (var supplier : NaturesAuraAPI.DRAIN_SPOT_EFFECTS.values()) {
var effect = supplier.get(); var effect = supplier.get();
@ -269,7 +275,7 @@ public class AuraChunk implements IAuraChunk {
private void addOrRemoveAsActive() { private void addOrRemoveAsActive() {
var chunkPos = this.chunk.getPos().toLong(); var chunkPos = this.chunk.getPos().toLong();
var data = (LevelData) ILevelData.getLevelData(this.chunk.getLevel()); var data = (LevelData) ILevelData.getLevelData(this.chunk.getLevel());
if (this.drainSpots.size() > 0) { if (!this.drainSpots.isEmpty()) {
data.auraChunksWithSpots.put(chunkPos, this); data.auraChunksWithSpots.put(chunkPos, this);
} else { } else {
data.auraChunksWithSpots.remove(chunkPos); data.auraChunksWithSpots.remove(chunkPos);
@ -300,5 +306,7 @@ public class AuraChunk implements IAuraChunk {
ret.putLong("original_spread_pos", this.originalSpreadPos.asLong()); ret.putLong("original_spread_pos", this.originalSpreadPos.asLong());
return ret; return ret;
} }
} }
} }

View file

@ -1,47 +0,0 @@
package de.ellpeck.naturesaura.chunk;
import de.ellpeck.naturesaura.api.NaturesAuraAPI;
import de.ellpeck.naturesaura.api.aura.chunk.IAuraChunk;
import de.ellpeck.naturesaura.api.aura.type.IAuraType;
import net.minecraft.core.Direction;
import net.minecraft.nbt.CompoundTag;
import net.minecraft.world.level.chunk.LevelChunk;
import net.neoforged.neoforge.common.capabilities.Capability;
import net.neoforged.neoforge.common.capabilities.ICapabilityProvider;
import net.neoforged.neoforge.common.util.INBTSerializable;
import net.neoforged.neoforge.common.util.LazyOptional;
import javax.annotation.Nonnull;
import javax.annotation.Nullable;
public class AuraChunkProvider implements INBTSerializable<CompoundTag> {
private final LevelChunk chunk;
private IAuraChunk auraChunk;
public AuraChunkProvider(LevelChunk chunk) {
this.chunk = chunk;
}
private IAuraChunk getAuraChunk() {
if (this.auraChunk == null)
this.auraChunk = new AuraChunk(this.chunk, IAuraType.forLevel(this.chunk.getLevel()));
return this.auraChunk;
}
@Nullable
@Override
public <T> LazyOptional<T> getCapability(@Nonnull Capability<T> capability, @Nullable Direction facing) {
return capability == NaturesAuraAPI.CAP_AURA_CHUNK ? this.lazyChunk.cast() : LazyOptional.empty();
}
@Override
public CompoundTag serializeNBT() {
return this.getAuraChunk().serializeNBT();
}
@Override
public void deserializeNBT(CompoundTag nbt) {
this.getAuraChunk().deserializeNBT(nbt);
}
}

View file

@ -79,7 +79,7 @@ public class PlantBoostEffect implements IDrainSpotEffect {
var state = level.getBlockState(plantPos); var state = level.getBlockState(plantPos);
var block = state.getBlock(); var block = state.getBlock();
if (block instanceof BonemealableBlock growable && !PlantBoostEffect.EXCEPTIONS.contains(block) && !(block instanceof DoublePlantBlock) && !(block instanceof TallGrassBlock)) { if (block instanceof BonemealableBlock growable && !PlantBoostEffect.EXCEPTIONS.contains(block) && !(block instanceof DoublePlantBlock) && !(block instanceof TallGrassBlock)) {
if (growable.isValidBonemealTarget(level, plantPos, state, false)) { if (growable.isValidBonemealTarget(level, plantPos, state)) {
try { try {
growable.performBonemeal((ServerLevel) level, level.random, plantPos, state); growable.performBonemeal((ServerLevel) level, level.random, plantPos, state);
} catch (Exception e) { } catch (Exception e) {

View file

@ -25,7 +25,7 @@ public class ReplenishingEffect implements IDrainSpotEffect {
if (spot < 0) { if (spot < 0) {
List<ISpotDrainable> tiles = new ArrayList<>(); List<ISpotDrainable> tiles = new ArrayList<>();
Helper.getBlockEntitiesInArea(level, pos, 25, tile -> { Helper.getBlockEntitiesInArea(level, pos, 25, tile -> {
var container = tile.getCapability(NaturesAuraAPI.CAP_AURA_CONTAINER, null).orElse(null); var container = level.getCapability(NaturesAuraAPI.AURA_CONTAINER_BLOCK_CAPABILITY, tile.getBlockPos(), tile.getBlockState(), tile, null);
if (container instanceof ISpotDrainable) if (container instanceof ISpotDrainable)
tiles.add((ISpotDrainable) container); tiles.add((ISpotDrainable) container);
return false; return false;
@ -58,4 +58,5 @@ public class ReplenishingEffect implements IDrainSpotEffect {
public ResourceLocation getName() { public ResourceLocation getName() {
return ReplenishingEffect.NAME; return ReplenishingEffect.NAME;
} }
} }

View file

@ -23,6 +23,7 @@ import net.minecraft.world.entity.Entity;
import net.minecraft.world.entity.EntityType; import net.minecraft.world.entity.EntityType;
import net.minecraft.world.entity.LivingEntity; import net.minecraft.world.entity.LivingEntity;
import net.minecraft.world.item.ItemStack; import net.minecraft.world.item.ItemStack;
import net.minecraft.world.item.SpawnEggItem;
import net.neoforged.neoforge.common.DeferredSpawnEggItem; import net.neoforged.neoforge.common.DeferredSpawnEggItem;
import java.util.Arrays; import java.util.Arrays;
@ -103,9 +104,9 @@ public class AnimalSpawnerCategory implements IRecipeCategory<AnimalSpawnerRecip
@Override @Override
public void setRecipe(IRecipeLayoutBuilder builder, AnimalSpawnerRecipe recipe, IFocusGroup focuses) { public void setRecipe(IRecipeLayoutBuilder builder, AnimalSpawnerRecipe recipe, IFocusGroup focuses) {
for (var i = 0; i < recipe.ingredients.length; i++) for (var i = 0; i < recipe.ingredients.size(); i++)
builder.addSlot(RecipeIngredientRole.INPUT, i * 18 + 1, 69).addItemStacks(Arrays.asList(recipe.ingredients[i].getItems())); builder.addSlot(RecipeIngredientRole.INPUT, i * 18 + 1, 69).addItemStacks(Arrays.asList(recipe.ingredients.get(i).getItems()));
builder.addInvisibleIngredients(RecipeIngredientRole.OUTPUT).addItemStack(new ItemStack(DeferredSpawnEggItem.fromEntityType(recipe.entity))); builder.addInvisibleIngredients(RecipeIngredientRole.OUTPUT).addItemStack(new ItemStack(SpawnEggItem.byId(recipe.entity)));
} }
@Override @Override

View file

@ -19,6 +19,7 @@ import mezz.jei.api.registration.ISubtypeRegistration;
import net.minecraft.client.Minecraft; import net.minecraft.client.Minecraft;
import net.minecraft.resources.ResourceLocation; import net.minecraft.resources.ResourceLocation;
import net.minecraft.world.item.ItemStack; import net.minecraft.world.item.ItemStack;
import net.minecraft.world.item.crafting.RecipeHolder;
@JeiPlugin @JeiPlugin
public class JEINaturesAuraPlugin implements IModPlugin { public class JEINaturesAuraPlugin implements IModPlugin {
@ -50,7 +51,7 @@ public class JEINaturesAuraPlugin implements IModPlugin {
registration.registerSubtypeInterpreter(VanillaTypes.ITEM_STACK, ModItems.AURA_BOTTLE, (stack, context) -> ItemAuraBottle.getType(stack).getName().toString()); registration.registerSubtypeInterpreter(VanillaTypes.ITEM_STACK, ModItems.AURA_BOTTLE, (stack, context) -> ItemAuraBottle.getType(stack).getName().toString());
var auraInterpreter = (IIngredientSubtypeInterpreter<ItemStack>) (stack, context) -> { var auraInterpreter = (IIngredientSubtypeInterpreter<ItemStack>) (stack, context) -> {
var container = stack.getCapability(NaturesAuraAPI.CAP_AURA_CONTAINER).orElse(null); var container = stack.getCapability(NaturesAuraAPI.AURA_CONTAINER_ITEM_CAPABILITY);
if (container != null) if (container != null)
return String.valueOf(container.getStoredAura()); return String.valueOf(container.getStoredAura());
return IIngredientSubtypeInterpreter.NONE; return IIngredientSubtypeInterpreter.NONE;
@ -71,9 +72,10 @@ public class JEINaturesAuraPlugin implements IModPlugin {
@Override @Override
public void registerRecipes(IRecipeRegistration registration) { public void registerRecipes(IRecipeRegistration registration) {
var manager = Minecraft.getInstance().level.getRecipeManager(); var manager = Minecraft.getInstance().level.getRecipeManager();
registration.addRecipes(JEINaturesAuraPlugin.TREE_RITUAL, manager.getAllRecipesFor(ModRecipes.TREE_RITUAL_TYPE)); registration.addRecipes(JEINaturesAuraPlugin.TREE_RITUAL, manager.getAllRecipesFor(ModRecipes.TREE_RITUAL_TYPE).stream().map(RecipeHolder::value).toList());
registration.addRecipes(JEINaturesAuraPlugin.ALTAR, manager.getAllRecipesFor(ModRecipes.ALTAR_TYPE)); registration.addRecipes(JEINaturesAuraPlugin.ALTAR, manager.getAllRecipesFor(ModRecipes.ALTAR_TYPE).stream().map(RecipeHolder::value).toList());
registration.addRecipes(JEINaturesAuraPlugin.OFFERING, manager.getAllRecipesFor(ModRecipes.OFFERING_TYPE)); registration.addRecipes(JEINaturesAuraPlugin.OFFERING, manager.getAllRecipesFor(ModRecipes.OFFERING_TYPE).stream().map(RecipeHolder::value).toList());
registration.addRecipes(JEINaturesAuraPlugin.SPAWNER, manager.getAllRecipesFor(ModRecipes.ANIMAL_SPAWNER_TYPE)); registration.addRecipes(JEINaturesAuraPlugin.SPAWNER, manager.getAllRecipesFor(ModRecipes.ANIMAL_SPAWNER_TYPE).stream().map(RecipeHolder::value).toList());
} }
} }

View file

@ -48,8 +48,8 @@ public class TreeRitualCategory implements IRecipeCategory<TreeRitualRecipe> {
builder.addSlot(RecipeIngredientRole.OUTPUT, 125, 35).addItemStack(recipe.result); builder.addSlot(RecipeIngredientRole.OUTPUT, 125, 35).addItemStack(recipe.result);
var positions = new int[][]{{35, 1}, {35, 69}, {1, 35}, {69, 35}, {12, 12}, {58, 58}, {58, 12}, {12, 58}}; var positions = new int[][]{{35, 1}, {35, 69}, {1, 35}, {69, 35}, {12, 12}, {58, 58}, {58, 12}, {12, 58}};
for (var i = 0; i < recipe.ingredients.length; i++) for (var i = 0; i < recipe.ingredients.size(); i++)
builder.addSlot(RecipeIngredientRole.INPUT, positions[i][0], positions[i][1]).addItemStacks(Arrays.asList(recipe.ingredients[i].getItems())); builder.addSlot(RecipeIngredientRole.INPUT, positions[i][0], positions[i][1]).addItemStacks(Arrays.asList(recipe.ingredients.get(i).getItems()));
} }
} }

View file

@ -54,7 +54,7 @@ public class PatchouliCompat implements ICompat {
var manager = Minecraft.getInstance().level.getRecipeManager(); var manager = Minecraft.getInstance().level.getRecipeManager();
var res = new ResourceLocation(name); var res = new ResourceLocation(name);
var pre = new ResourceLocation(res.getNamespace(), type + "/" + res.getPath()); var pre = new ResourceLocation(res.getNamespace(), type + "/" + res.getPath());
return (T) manager.byKey(pre).orElse(null); return (T) manager.byKey(pre).orElse(null).value();
} }
public static IVariable ingredientVariable(Ingredient ingredient) { public static IVariable ingredientVariable(Ingredient ingredient) {

View file

@ -1,10 +1,10 @@
package de.ellpeck.naturesaura.compat.patchouli; package de.ellpeck.naturesaura.compat.patchouli;
import de.ellpeck.naturesaura.recipes.AnimalSpawnerRecipe; import de.ellpeck.naturesaura.recipes.AnimalSpawnerRecipe;
import net.minecraft.core.registries.BuiltInRegistries;
import net.minecraft.world.item.ItemStack; import net.minecraft.world.item.ItemStack;
import net.minecraft.world.item.SpawnEggItem;
import net.minecraft.world.level.Level; import net.minecraft.world.level.Level;
import net.neoforged.neoforge.common.DeferredSpawnEggItem;
import net.neoforged.neoforge.registries.ForgeRegistries;
import vazkii.patchouli.api.IComponentProcessor; import vazkii.patchouli.api.IComponentProcessor;
import vazkii.patchouli.api.IVariable; import vazkii.patchouli.api.IVariable;
import vazkii.patchouli.api.IVariableProvider; import vazkii.patchouli.api.IVariableProvider;
@ -24,12 +24,12 @@ public class ProcessorAnimalSpawner implements IComponentProcessor {
return null; return null;
if (key.startsWith("input")) { if (key.startsWith("input")) {
var id = Integer.parseInt(key.substring(5)) - 1; var id = Integer.parseInt(key.substring(5)) - 1;
return this.recipe.ingredients.length > id ? PatchouliCompat.ingredientVariable(this.recipe.ingredients[id]) : null; return this.recipe.ingredients.size() > id ? PatchouliCompat.ingredientVariable(this.recipe.ingredients.get(id)) : null;
} else { } else {
return switch (key) { return switch (key) {
case "name" -> IVariable.wrap(this.recipe.entity.getDescription().getString()); case "name" -> IVariable.wrap(this.recipe.entity.getDescription().getString());
case "entity" -> IVariable.wrap(ForgeRegistries.ENTITY_TYPES.getKey(this.recipe.entity).toString()); case "entity" -> IVariable.wrap(BuiltInRegistries.ENTITY_TYPE.getKey(this.recipe.entity).toString());
case "egg" -> IVariable.from(new ItemStack(DeferredSpawnEggItem.fromEntityType(this.recipe.entity))); case "egg" -> IVariable.from(new ItemStack(SpawnEggItem.byId(this.recipe.entity)));
default -> null; default -> null;
}; };
} }
@ -39,4 +39,5 @@ public class ProcessorAnimalSpawner implements IComponentProcessor {
public boolean allowRender(String group) { public boolean allowRender(String group) {
return !"seekrit".equals(group); return !"seekrit".equals(group);
} }
} }

View file

@ -21,7 +21,7 @@ public class ProcessorTreeRitual implements IComponentProcessor {
return null; return null;
if (key.startsWith("input")) { if (key.startsWith("input")) {
var id = Integer.parseInt(key.substring(5)) - 1; var id = Integer.parseInt(key.substring(5)) - 1;
return this.recipe.ingredients.length > id ? PatchouliCompat.ingredientVariable(this.recipe.ingredients[id]) : null; return this.recipe.ingredients.size() > id ? PatchouliCompat.ingredientVariable(this.recipe.ingredients.get(id)) : null;
} else { } else {
return switch (key) { return switch (key) {
case "output" -> IVariable.from(this.recipe.result); case "output" -> IVariable.from(this.recipe.result);

View file

@ -2,19 +2,17 @@ package de.ellpeck.naturesaura.data;
import de.ellpeck.naturesaura.NaturesAura; import de.ellpeck.naturesaura.NaturesAura;
import de.ellpeck.naturesaura.gen.ModFeatures; import de.ellpeck.naturesaura.gen.ModFeatures;
import net.minecraft.core.HolderGetter;
import net.minecraft.core.HolderSet; import net.minecraft.core.HolderSet;
import net.minecraft.core.registries.Registries; import net.minecraft.core.registries.Registries;
import net.minecraft.data.worldgen.BootstapContext; import net.minecraft.data.worldgen.BootstapContext;
import net.minecraft.resources.ResourceKey; import net.minecraft.resources.ResourceKey;
import net.minecraft.resources.ResourceLocation; import net.minecraft.resources.ResourceLocation;
import net.minecraft.tags.BiomeTags; import net.minecraft.tags.BiomeTags;
import net.minecraft.world.level.biome.Biome;
import net.minecraft.world.level.levelgen.GenerationStep; import net.minecraft.world.level.levelgen.GenerationStep;
import net.minecraft.world.level.levelgen.placement.PlacedFeature;
import net.neoforged.neoforge.common.Tags; import net.neoforged.neoforge.common.Tags;
import net.neoforged.neoforge.common.world.BiomeModifier; import net.neoforged.neoforge.common.world.BiomeModifier;
import net.neoforged.neoforge.common.world.BiomeModifiers.AddFeaturesBiomeModifier; import net.neoforged.neoforge.common.world.BiomeModifiers.AddFeaturesBiomeModifier;
import net.neoforged.neoforge.registries.NeoForgeRegistries;
public class BiomeModifiers { public class BiomeModifiers {
@ -25,7 +23,7 @@ public class BiomeModifiers {
public static final ResourceKey<BiomeModifier> AURA_MUSHROOM = BiomeModifiers.createKey("aura_mushroom"); public static final ResourceKey<BiomeModifier> AURA_MUSHROOM = BiomeModifiers.createKey("aura_mushroom");
private static ResourceKey<BiomeModifier> createKey(String id) { private static ResourceKey<BiomeModifier> createKey(String id) {
return ResourceKey.create(ForgeRegistries.Keys.BIOME_MODIFIERS, new ResourceLocation(NaturesAura.MOD_ID, id)); return ResourceKey.create(NeoForgeRegistries.Keys.BIOME_MODIFIERS, new ResourceLocation(NaturesAura.MOD_ID, id));
} }
public static void bootstrap(BootstapContext<BiomeModifier> context) { public static void bootstrap(BootstapContext<BiomeModifier> context) {

View file

@ -14,7 +14,7 @@ import net.neoforged.neoforge.common.data.DatapackBuiltinEntriesProvider;
import net.neoforged.neoforge.data.event.GatherDataEvent; import net.neoforged.neoforge.data.event.GatherDataEvent;
import net.neoforged.bus.api.SubscribeEvent; import net.neoforged.bus.api.SubscribeEvent;
import net.neoforged.fml.common.Mod; import net.neoforged.fml.common.Mod;
import net.neoforged.neoforge.registries.ForgeRegistries; import net.neoforged.neoforge.registries.NeoForgeRegistries;
import java.util.List; import java.util.List;
import java.util.Set; import java.util.Set;
@ -43,11 +43,12 @@ public final class ModData {
final RegistrySetBuilder registryBuilder = new RegistrySetBuilder(); final RegistrySetBuilder registryBuilder = new RegistrySetBuilder();
registryBuilder.add(Registries.CONFIGURED_FEATURE, ModFeatures.Configured::bootstrap); registryBuilder.add(Registries.CONFIGURED_FEATURE, ModFeatures.Configured::bootstrap);
registryBuilder.add(Registries.PLACED_FEATURE, ModFeatures.Placed::bootstrap); registryBuilder.add(Registries.PLACED_FEATURE, ModFeatures.Placed::bootstrap);
registryBuilder.add(ForgeRegistries.Keys.BIOME_MODIFIERS, BiomeModifiers::bootstrap); registryBuilder.add(NeoForgeRegistries.Keys.BIOME_MODIFIERS, BiomeModifiers::bootstrap);
// We need the BIOME registry to be present, so we can use a biome tag, doesn't matter that it's empty // We need the BIOME registry to be present, so we can use a biome tag, doesn't matter that it's empty
registryBuilder.add(Registries.BIOME, context -> { registryBuilder.add(Registries.BIOME, context -> {
}); });
RegistryAccess.Frozen regAccess = RegistryAccess.fromRegistryOfRegistries(BuiltInRegistries.REGISTRY); var regAccess = RegistryAccess.fromRegistryOfRegistries(BuiltInRegistries.REGISTRY);
return registryBuilder.buildPatch(regAccess, VanillaRegistries.createLookup()); return registryBuilder.buildPatch(regAccess, VanillaRegistries.createLookup());
} }
} }

View file

@ -20,16 +20,11 @@ public class AuraMendingEnchantment extends ModEnchantment {
@Override @Override
public boolean canEnchant(ItemStack stack) { public boolean canEnchant(ItemStack stack) {
return super.canEnchant(stack) && !stack.getCapability(NaturesAuraAPI.CAP_AURA_RECHARGE).isPresent(); return super.canEnchant(stack) && stack.getCapability(NaturesAuraAPI.AURA_RECHARGE_CAPABILITY) == null;
} }
@Override @Override
public boolean canApplyAtEnchantingTable(ItemStack stack) { public boolean canApplyAtEnchantingTable(ItemStack stack) {
return super.canApplyAtEnchantingTable(stack) && !stack.getCapability(NaturesAuraAPI.CAP_AURA_RECHARGE).isPresent(); return super.canApplyAtEnchantingTable(stack) && stack.getCapability(NaturesAuraAPI.AURA_RECHARGE_CAPABILITY) == null;
}
@Override
public int getMaxLevel() {
return 1;
} }
} }

View file

@ -8,17 +8,16 @@ import de.ellpeck.naturesaura.api.NaturesAuraAPI;
import de.ellpeck.naturesaura.api.aura.chunk.IAuraChunk; import de.ellpeck.naturesaura.api.aura.chunk.IAuraChunk;
import de.ellpeck.naturesaura.api.misc.ILevelData; import de.ellpeck.naturesaura.api.misc.ILevelData;
import de.ellpeck.naturesaura.chunk.AuraChunk; import de.ellpeck.naturesaura.chunk.AuraChunk;
import de.ellpeck.naturesaura.chunk.AuraChunkProvider;
import de.ellpeck.naturesaura.commands.CommandAura; import de.ellpeck.naturesaura.commands.CommandAura;
import de.ellpeck.naturesaura.misc.LevelData; import de.ellpeck.naturesaura.misc.LevelData;
import de.ellpeck.naturesaura.packet.PacketHandler; import de.ellpeck.naturesaura.packet.PacketHandler;
import net.minecraft.core.registries.BuiltInRegistries;
import net.minecraft.resources.ResourceLocation; import net.minecraft.resources.ResourceLocation;
import net.minecraft.server.level.ChunkHolder; import net.minecraft.server.level.ChunkHolder;
import net.minecraft.server.level.ChunkMap; import net.minecraft.server.level.ChunkMap;
import net.minecraft.server.level.ServerChunkCache; import net.minecraft.server.level.ServerChunkCache;
import net.minecraft.world.entity.player.Player; import net.minecraft.world.entity.player.Player;
import net.minecraft.world.level.ChunkPos; import net.minecraft.world.level.ChunkPos;
import net.minecraft.world.level.Level;
import net.minecraft.world.level.chunk.LevelChunk; import net.minecraft.world.level.chunk.LevelChunk;
import net.neoforged.neoforge.event.TickEvent; import net.neoforged.neoforge.event.TickEvent;
import net.neoforged.neoforge.event.entity.player.PlayerInteractEvent; import net.neoforged.neoforge.event.entity.player.PlayerInteractEvent;
@ -26,8 +25,6 @@ import net.neoforged.neoforge.event.level.ChunkEvent;
import net.neoforged.neoforge.event.level.ChunkWatchEvent; import net.neoforged.neoforge.event.level.ChunkWatchEvent;
import net.neoforged.bus.api.SubscribeEvent; import net.neoforged.bus.api.SubscribeEvent;
import net.neoforged.fml.util.ObfuscationReflectionHelper; import net.neoforged.fml.util.ObfuscationReflectionHelper;
import net.neoforged.neoforge.registries.ForgeRegistries;
import net.neoforged.neoforge.event.AttachCapabilitiesEvent;
import net.neoforged.neoforge.event.RegisterCommandsEvent; import net.neoforged.neoforge.event.RegisterCommandsEvent;
import java.lang.reflect.InvocationTargetException; import java.lang.reflect.InvocationTargetException;
@ -39,22 +36,11 @@ public class CommonEvents {
private static final Method GET_LOADED_CHUNKS_METHOD = ObfuscationReflectionHelper.findMethod(ChunkMap.class, "m_140416_"); private static final Method GET_LOADED_CHUNKS_METHOD = ObfuscationReflectionHelper.findMethod(ChunkMap.class, "m_140416_");
private static final ListMultimap<UUID, ChunkPos> PENDING_AURA_CHUNKS = ArrayListMultimap.create(); private static final ListMultimap<UUID, ChunkPos> PENDING_AURA_CHUNKS = ArrayListMultimap.create();
@SubscribeEvent
public void onChunkCapsAttach(AttachCapabilitiesEvent<LevelChunk> event) {
var chunk = event.getObject();
event.addCapability(new ResourceLocation(NaturesAura.MOD_ID, "aura"), new AuraChunkProvider(chunk));
}
@SubscribeEvent
public void onLevelCapsAttach(AttachCapabilitiesEvent<Level> event) {
event.addCapability(new ResourceLocation(NaturesAura.MOD_ID, "data"), new LevelData());
}
@SubscribeEvent @SubscribeEvent
public void onChunkUnload(ChunkEvent.Unload event) { public void onChunkUnload(ChunkEvent.Unload event) {
var iChunk = event.getChunk(); var iChunk = event.getChunk();
if (iChunk instanceof LevelChunk chunk) { if (iChunk instanceof LevelChunk chunk) {
var auraChunk = chunk.getCapability(NaturesAuraAPI.CAP_AURA_CHUNK).orElse(null); var auraChunk = chunk.getData(NaturesAuraAPI.AURA_CHUNK_ATTACHMENT).get(chunk);
if (auraChunk instanceof AuraChunk) { if (auraChunk instanceof AuraChunk) {
var data = (LevelData) ILevelData.getLevelData(chunk.getLevel()); var data = (LevelData) ILevelData.getLevelData(chunk.getLevel());
data.auraChunksWithSpots.remove(chunk.getPos().toLong()); data.auraChunksWithSpots.remove(chunk.getPos().toLong());
@ -68,7 +54,7 @@ public class CommonEvents {
if (player.level().isClientSide) if (player.level().isClientSide)
return; return;
var held = event.getItemStack(); var held = event.getItemStack();
if (!held.isEmpty() && ForgeRegistries.ITEMS.getKey(held.getItem()).getPath().contains("chisel")) { if (!held.isEmpty() && BuiltInRegistries.ITEM.getKey(held.getItem()).getPath().contains("chisel")) {
var state = player.level().getBlockState(event.getPos()); var state = player.level().getBlockState(event.getPos());
if (NaturesAuraAPI.BOTANIST_PICKAXE_CONVERSIONS.containsKey(state)) { if (NaturesAuraAPI.BOTANIST_PICKAXE_CONVERSIONS.containsKey(state)) {
var data = (LevelData) ILevelData.getLevelData(player.level()); var data = (LevelData) ILevelData.getLevelData(player.level());
@ -90,7 +76,7 @@ public class CommonEvents {
var chunk = holder.getTickingChunk(); var chunk = holder.getTickingChunk();
if (chunk == null) if (chunk == null)
continue; continue;
var auraChunk = (AuraChunk) chunk.getCapability(NaturesAuraAPI.CAP_AURA_CHUNK, null).orElse(null); var auraChunk = (AuraChunk) chunk.getData(NaturesAuraAPI.AURA_CHUNK_ATTACHMENT).get(chunk);
if (auraChunk != null) if (auraChunk != null)
auraChunk.update(); auraChunk.update();
} }
@ -130,7 +116,7 @@ public class CommonEvents {
var chunk = Helper.getLoadedChunk(player.level(), pos.x, pos.z); var chunk = Helper.getLoadedChunk(player.level(), pos.x, pos.z);
if (!(chunk instanceof LevelChunk levelChunk)) if (!(chunk instanceof LevelChunk levelChunk))
return false; return false;
var auraChunk = (AuraChunk) levelChunk.getCapability(NaturesAuraAPI.CAP_AURA_CHUNK, null).orElse(null); var auraChunk = (AuraChunk) levelChunk.getData(NaturesAuraAPI.AURA_CHUNK_ATTACHMENT).get(levelChunk);
if (auraChunk == null) if (auraChunk == null)
return false; return false;
PacketHandler.sendTo(player, auraChunk.makePacket()); PacketHandler.sendTo(player, auraChunk.makePacket());
@ -141,4 +127,5 @@ public class CommonEvents {
public void onCommands(RegisterCommandsEvent event) { public void onCommands(RegisterCommandsEvent event) {
CommandAura.register(event.getDispatcher()); CommandAura.register(event.getDispatcher());
} }
} }

View file

@ -107,7 +107,7 @@ public class LevelGenAncientTree extends Feature<NoneFeatureConfiguration> {
var goal = pos.offset(x, y, z); var goal = pos.offset(x, y, z);
if (pos.distSqr(goal) <= radius * radius + rand.nextInt(3) - 1) { if (pos.distSqr(goal) <= radius * radius + rand.nextInt(3) - 1) {
if (!level.isStateAtPosition(goal, s -> s.is(BlockTags.LEAVES))) { if (!level.isStateAtPosition(goal, s -> s.is(BlockTags.LEAVES))) {
if (level.isStateAtPosition(goal, st -> !st.is(BlockTags.LOGS) && st.getBlock() != Blocks.DIRT && st.getBlock() != Blocks.GRASS)) if (level.isStateAtPosition(goal, st -> !st.is(BlockTags.LOGS) && st.getBlock() != Blocks.DIRT && st.getBlock() != Blocks.GRASS_BLOCK))
this.setBlock(level, goal, state); this.setBlock(level, goal, state);
} }
} }

View file

@ -20,7 +20,6 @@ public class GuiEnderCrate extends AbstractContainerScreen<ContainerEnderCrate>
@Override @Override
public void render(GuiGraphics graphics, int mouseX, int mouseY, float partialTicks) { public void render(GuiGraphics graphics, int mouseX, int mouseY, float partialTicks) {
this.renderBackground(graphics);
super.render(graphics, mouseX, mouseY, partialTicks); super.render(graphics, mouseX, mouseY, partialTicks);
this.renderTooltip(graphics, mouseX, mouseY); this.renderTooltip(graphics, mouseX, mouseY);
} }
@ -38,4 +37,5 @@ public class GuiEnderCrate extends AbstractContainerScreen<ContainerEnderCrate>
graphics.blit(GuiEnderCrate.CHEST_GUI_TEXTURE, i, j, 0, 0, this.imageWidth, 3 * 18 + 17); graphics.blit(GuiEnderCrate.CHEST_GUI_TEXTURE, i, j, 0, 0, this.imageWidth, 3 * 18 + 17);
graphics.blit(GuiEnderCrate.CHEST_GUI_TEXTURE, i, j + 3 * 18 + 17, 0, 126, this.imageWidth, 96); graphics.blit(GuiEnderCrate.CHEST_GUI_TEXTURE, i, j + 3 * 18 + 17, 0, 126, this.imageWidth, 96);
} }
} }

View file

@ -36,10 +36,10 @@ public class ItemAuraBottle extends ItemImpl implements IColorProvidingItem, ICu
NeoForge.EVENT_BUS.register(new EventHandler()); NeoForge.EVENT_BUS.register(new EventHandler());
DispenserBlock.registerBehavior(emptyBottle, (source, stack) -> { DispenserBlock.registerBehavior(emptyBottle, (source, stack) -> {
Level level = source.getLevel(); Level level = source.level();
var state = source.getBlockState(); var state = source.state();
var facing = state.getValue(DispenserBlock.FACING); var facing = state.getValue(DispenserBlock.FACING);
var offset = source.getPos().relative(facing); var offset = source.pos().relative(facing);
var offsetState = level.getBlockState(offset); var offsetState = level.getBlockState(offset);
var dispense = stack.split(1); var dispense = stack.split(1);

View file

@ -2,6 +2,7 @@ package de.ellpeck.naturesaura.items;
import de.ellpeck.naturesaura.api.NaturesAuraAPI; import de.ellpeck.naturesaura.api.NaturesAuraAPI;
import net.minecraft.core.BlockPos; import net.minecraft.core.BlockPos;
import net.minecraft.core.registries.BuiltInRegistries;
import net.minecraft.world.InteractionHand; import net.minecraft.world.InteractionHand;
import net.minecraft.world.InteractionResult; import net.minecraft.world.InteractionResult;
import net.minecraft.world.InteractionResultHolder; import net.minecraft.world.InteractionResultHolder;
@ -9,7 +10,6 @@ import net.minecraft.world.entity.player.Player;
import net.minecraft.world.item.ItemStack; import net.minecraft.world.item.ItemStack;
import net.minecraft.world.level.Level; import net.minecraft.world.level.Level;
import net.minecraft.world.level.block.Blocks; import net.minecraft.world.level.block.Blocks;
import net.neoforged.neoforge.registries.ForgeRegistries;
public class ItemNetheriteFinder extends ItemImpl { public class ItemNetheriteFinder extends ItemImpl {
@ -35,7 +35,7 @@ public class ItemNetheriteFinder extends ItemImpl {
for (var z = -range; z <= range; z++) { for (var z = -range; z <= range; z++) {
var offset = new BlockPos(pos.getX() + x, y, pos.getZ() + z); var offset = new BlockPos(pos.getX() + x, y, pos.getZ() + z);
var state = levelIn.getBlockState(offset); var state = levelIn.getBlockState(offset);
if (state.getBlock() == Blocks.ANCIENT_DEBRIS || ForgeRegistries.BLOCKS.getKey(state.getBlock()).toString().contains("netherite")) { if (state.getBlock() == Blocks.ANCIENT_DEBRIS || BuiltInRegistries.BLOCK.getKey(state.getBlock()).toString().contains("netherite")) {
inst.spawnMagicParticle( inst.spawnMagicParticle(
offset.getX() + 0.5F, offset.getY() + 0.5F, offset.getZ() + 0.5F, offset.getX() + 0.5F, offset.getY() + 0.5F, offset.getZ() + 0.5F,
0F, 0F, 0F, 0xab4d38, 6F, 20 * 60, 0F, false, true); 0F, 0F, 0F, 0xab4d38, 6F, 20 * 60, 0F, false, true);
@ -52,4 +52,5 @@ public class ItemNetheriteFinder extends ItemImpl {
playerIn.getCooldowns().addCooldown(this, 20 * 60); playerIn.getCooldowns().addCooldown(this, 20 * 60);
return new InteractionResultHolder<>(InteractionResult.SUCCESS, stack); return new InteractionResultHolder<>(InteractionResult.SUCCESS, stack);
} }
} }

View file

@ -16,12 +16,10 @@ import net.minecraft.world.entity.player.Player;
import net.minecraft.world.item.*; import net.minecraft.world.item.*;
import net.minecraft.world.phys.AABB; import net.minecraft.world.phys.AABB;
import net.neoforged.neoforge.common.NeoForgeMod; import net.neoforged.neoforge.common.NeoForgeMod;
import net.neoforged.neoforge.common.capabilities.ICapabilityProvider;
import net.neoforged.neoforge.event.TickEvent; import net.neoforged.neoforge.event.TickEvent;
import net.neoforged.neoforge.event.entity.living.LivingAttackEvent; import net.neoforged.neoforge.event.entity.living.LivingAttackEvent;
import net.neoforged.bus.api.SubscribeEvent; import net.neoforged.bus.api.SubscribeEvent;
import net.neoforged.fml.common.Mod; import net.neoforged.fml.common.Mod;
import net.neoforged.neoforge.registries.ForgeRegistries;
import javax.annotation.Nullable; import javax.annotation.Nullable;
import java.util.Comparator; import java.util.Comparator;

View file

@ -61,7 +61,7 @@ public class PacketAuraChunk implements CustomPacketPayload {
var chunk = level.getChunk(this.chunkX, this.chunkZ); var chunk = level.getChunk(this.chunkX, this.chunkZ);
if (chunk.isEmpty()) if (chunk.isEmpty())
return false; return false;
var auraChunk = (AuraChunk) chunk.getData(NaturesAuraAPI.AURA_CHUNK_ATTACHMENT); var auraChunk = (AuraChunk) chunk.getData(NaturesAuraAPI.AURA_CHUNK_ATTACHMENT).get(chunk);
if (auraChunk == null) if (auraChunk == null)
return false; return false;
auraChunk.setSpots(this.drainSpots); auraChunk.setSpots(this.drainSpots);

View file

@ -1,14 +1,13 @@
package de.ellpeck.naturesaura.recipes; package de.ellpeck.naturesaura.recipes;
import com.google.gson.JsonObject; import com.mojang.serialization.Codec;
import com.mojang.serialization.codecs.RecordCodecBuilder;
import net.minecraft.core.RegistryAccess; import net.minecraft.core.RegistryAccess;
import net.minecraft.network.FriendlyByteBuf; import net.minecraft.network.FriendlyByteBuf;
import net.minecraft.resources.ResourceLocation;
import net.minecraft.world.item.ItemStack; import net.minecraft.world.item.ItemStack;
import net.minecraft.world.item.crafting.Ingredient; import net.minecraft.world.item.crafting.Ingredient;
import net.minecraft.world.item.crafting.RecipeSerializer; import net.minecraft.world.item.crafting.RecipeSerializer;
import net.minecraft.world.item.crafting.RecipeType; import net.minecraft.world.item.crafting.RecipeType;
import net.neoforged.neoforge.common.crafting.CraftingHelper;
import javax.annotation.Nullable; import javax.annotation.Nullable;
@ -20,8 +19,7 @@ public class AltarRecipe extends ModRecipe {
public final int aura; public final int aura;
public final int time; public final int time;
public AltarRecipe(ResourceLocation name, Ingredient input, ItemStack output, Ingredient catalyst, int aura, int time) { public AltarRecipe(Ingredient input, ItemStack output, Ingredient catalyst, int aura, int time) {
super(name);
this.input = input; this.input = input;
this.output = output; this.output = output;
this.catalyst = catalyst; this.catalyst = catalyst;
@ -46,27 +44,23 @@ public class AltarRecipe extends ModRecipe {
public static class Serializer implements RecipeSerializer<AltarRecipe> { public static class Serializer implements RecipeSerializer<AltarRecipe> {
private static final Codec<AltarRecipe> CODEC = RecordCodecBuilder.create(i -> i.group(
Ingredient.CODEC.fieldOf("input").forGetter(r -> r.input),
ItemStack.CODEC.fieldOf("output").forGetter(r -> r.output),
Ingredient.CODEC.fieldOf("catalyst").forGetter(r -> r.catalyst),
Codec.INT.fieldOf("aura").forGetter(r -> r.aura),
Codec.INT.fieldOf("time").forGetter(r -> r.time)
).apply(i, AltarRecipe::new));
@Override @Override
public AltarRecipe fromJson(ResourceLocation recipeId, JsonObject json) { public Codec<AltarRecipe> codec() {
return new AltarRecipe( return Serializer.CODEC;
recipeId,
Ingredient.fromJson(json.getAsJsonObject("input")),
CraftingHelper.getItemStack(json.getAsJsonObject("output"), true),
json.has("catalyst") ? Ingredient.fromJson(json.getAsJsonObject("catalyst")) : Ingredient.EMPTY,
json.get("aura").getAsInt(),
json.get("time").getAsInt());
} }
@Nullable @Nullable
@Override @Override
public AltarRecipe fromNetwork(ResourceLocation recipeId, FriendlyByteBuf buffer) { public AltarRecipe fromNetwork(FriendlyByteBuf buffer) {
return new AltarRecipe( return new AltarRecipe(Ingredient.fromNetwork(buffer), buffer.readItem(), Ingredient.fromNetwork(buffer), buffer.readInt(), buffer.readInt());
recipeId,
Ingredient.fromNetwork(buffer),
buffer.readItem(),
Ingredient.fromNetwork(buffer),
buffer.readInt(),
buffer.readInt());
} }
@Override @Override
@ -77,5 +71,7 @@ public class AltarRecipe extends ModRecipe {
buffer.writeInt(recipe.aura); buffer.writeInt(recipe.aura);
buffer.writeInt(recipe.time); buffer.writeInt(recipe.time);
} }
} }
} }

View file

@ -1,8 +1,10 @@
package de.ellpeck.naturesaura.recipes; package de.ellpeck.naturesaura.recipes;
import com.google.gson.JsonObject; import com.mojang.serialization.Codec;
import com.mojang.serialization.codecs.RecordCodecBuilder;
import net.minecraft.core.BlockPos; import net.minecraft.core.BlockPos;
import net.minecraft.core.RegistryAccess; import net.minecraft.core.RegistryAccess;
import net.minecraft.core.registries.BuiltInRegistries;
import net.minecraft.network.FriendlyByteBuf; import net.minecraft.network.FriendlyByteBuf;
import net.minecraft.resources.ResourceLocation; import net.minecraft.resources.ResourceLocation;
import net.minecraft.server.level.ServerLevel; import net.minecraft.server.level.ServerLevel;
@ -14,23 +16,20 @@ import net.minecraft.world.item.crafting.Ingredient;
import net.minecraft.world.item.crafting.RecipeSerializer; import net.minecraft.world.item.crafting.RecipeSerializer;
import net.minecraft.world.item.crafting.RecipeType; import net.minecraft.world.item.crafting.RecipeType;
import net.minecraft.world.level.Level; import net.minecraft.world.level.Level;
import net.neoforged.neoforge.registries.ForgeRegistries;
import javax.annotation.Nullable;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.List; import java.util.List;
public class AnimalSpawnerRecipe extends ModRecipe { public class AnimalSpawnerRecipe extends ModRecipe {
public final Ingredient[] ingredients; public final List<Ingredient> ingredients;
public final EntityType<?> entity; public final EntityType<?> entity;
public final int aura; public final int aura;
public final int time; public final int time;
public AnimalSpawnerRecipe(ResourceLocation name, EntityType<?> entity, int aura, int time, Ingredient... ingredients) { public AnimalSpawnerRecipe(ResourceLocation entityType, int aura, int time, List<Ingredient> ingredients) {
super(name);
this.ingredients = ingredients; this.ingredients = ingredients;
this.entity = entity; this.entity = BuiltInRegistries.ENTITY_TYPE.get(entityType);
this.aura = aura; this.aura = aura;
this.time = time; this.time = time;
} }
@ -59,40 +58,36 @@ public class AnimalSpawnerRecipe extends ModRecipe {
public static class Serializer implements RecipeSerializer<AnimalSpawnerRecipe> { public static class Serializer implements RecipeSerializer<AnimalSpawnerRecipe> {
private static final Codec<AnimalSpawnerRecipe> CODEC = RecordCodecBuilder.create(i -> i.group(
ResourceLocation.CODEC.fieldOf("entity").forGetter(r -> BuiltInRegistries.ENTITY_TYPE.getKey(r.entity)),
Codec.INT.fieldOf("aura").forGetter(r -> r.aura),
Codec.INT.fieldOf("time").forGetter(r -> r.time),
Ingredient.CODEC.listOf().fieldOf("ingredients").forGetter(r -> r.ingredients)
).apply(i, AnimalSpawnerRecipe::new));
@Override @Override
public AnimalSpawnerRecipe fromJson(ResourceLocation recipeId, JsonObject json) { public Codec<AnimalSpawnerRecipe> codec() {
List<Ingredient> ingredients = new ArrayList<>(); return Serializer.CODEC;
for (var e : json.getAsJsonArray("ingredients"))
ingredients.add(Ingredient.fromJson(e));
return new AnimalSpawnerRecipe(recipeId,
ForgeRegistries.ENTITY_TYPES.getValue(new ResourceLocation(json.get("entity").getAsString())),
json.get("aura").getAsInt(),
json.get("time").getAsInt(),
ingredients.toArray(new Ingredient[0]));
} }
@Nullable
@Override @Override
public AnimalSpawnerRecipe fromNetwork(ResourceLocation recipeId, FriendlyByteBuf buffer) { public AnimalSpawnerRecipe fromNetwork(FriendlyByteBuf buffer) {
var ings = new Ingredient[buffer.readInt()]; var ingredients = new ArrayList<Ingredient>();
for (var i = 0; i < ings.length; i++) for (var i = buffer.readInt(); i > 0; i--)
ings[i] = Ingredient.fromNetwork(buffer); ingredients.add(Ingredient.fromNetwork(buffer));
return new AnimalSpawnerRecipe( return new AnimalSpawnerRecipe(buffer.readResourceLocation(), buffer.readInt(), buffer.readInt(), ingredients);
recipeId,
ForgeRegistries.ENTITY_TYPES.getValue(buffer.readResourceLocation()),
buffer.readInt(),
buffer.readInt(),
ings);
} }
@Override @Override
public void toNetwork(FriendlyByteBuf buffer, AnimalSpawnerRecipe recipe) { public void toNetwork(FriendlyByteBuf buffer, AnimalSpawnerRecipe recipe) {
buffer.writeInt(recipe.ingredients.length); buffer.writeInt(recipe.ingredients.size());
for (var ing : recipe.ingredients) for (var ing : recipe.ingredients)
ing.toNetwork(buffer); ing.toNetwork(buffer);
buffer.writeResourceLocation(ForgeRegistries.ENTITY_TYPES.getKey(recipe.entity)); buffer.writeResourceLocation(BuiltInRegistries.ENTITY_TYPE.getKey(recipe.entity));
buffer.writeInt(recipe.aura); buffer.writeInt(recipe.aura);
buffer.writeInt(recipe.time); buffer.writeInt(recipe.time);
} }
} }
} }

View file

@ -1,17 +1,18 @@
package de.ellpeck.naturesaura.recipes; package de.ellpeck.naturesaura.recipes;
import com.google.gson.JsonObject; import com.mojang.serialization.Codec;
import com.mojang.serialization.codecs.RecordCodecBuilder;
import de.ellpeck.naturesaura.ModConfig; import de.ellpeck.naturesaura.ModConfig;
import de.ellpeck.naturesaura.NaturesAura; import de.ellpeck.naturesaura.NaturesAura;
import net.minecraft.resources.ResourceLocation;
import net.minecraft.util.GsonHelper;
import net.neoforged.neoforge.common.ModConfigSpec; import net.neoforged.neoforge.common.ModConfigSpec;
import net.neoforged.neoforge.common.crafting.conditions.ICondition; import net.neoforged.neoforge.common.conditions.ICondition;
import net.neoforged.neoforge.common.crafting.conditions.IConditionSerializer;
public class EnabledCondition implements ICondition { public class EnabledCondition implements ICondition {
private static final ResourceLocation NAME = new ResourceLocation(NaturesAura.MOD_ID, "enabled"); private static final Codec<EnabledCondition> CODEC = RecordCodecBuilder.create(i ->
i.group(Codec.STRING.fieldOf("name").forGetter(c -> c.name)).apply(i, EnabledCondition::new)
);
private ModConfigSpec.ConfigValue<Boolean> config; private ModConfigSpec.ConfigValue<Boolean> config;
private final String name; private final String name;
@ -25,31 +26,14 @@ public class EnabledCondition implements ICondition {
} }
} }
@Override
public ResourceLocation getID() {
return EnabledCondition.NAME;
}
@Override @Override
public boolean test(IContext context) { public boolean test(IContext context) {
return this.config != null && this.config.get(); return this.config != null && this.config.get();
} }
public static class Serializer implements IConditionSerializer<EnabledCondition> {
@Override @Override
public void write(JsonObject json, EnabledCondition value) { public Codec<? extends ICondition> codec() {
json.addProperty("config", value.name); return EnabledCondition.CODEC;
} }
@Override
public EnabledCondition read(JsonObject json) {
return new EnabledCondition(GsonHelper.getAsString(json, "config"));
}
@Override
public ResourceLocation getID() {
return EnabledCondition.NAME;
}
}
} }

View file

@ -1,7 +1,6 @@
package de.ellpeck.naturesaura.recipes; package de.ellpeck.naturesaura.recipes;
import net.minecraft.core.RegistryAccess; import net.minecraft.core.RegistryAccess;
import net.minecraft.resources.ResourceLocation;
import net.minecraft.world.item.ItemStack; import net.minecraft.world.item.ItemStack;
import net.minecraft.world.item.crafting.Recipe; import net.minecraft.world.item.crafting.Recipe;
import net.minecraft.world.level.Level; import net.minecraft.world.level.Level;
@ -9,12 +8,6 @@ import net.neoforged.neoforge.items.wrapper.RecipeWrapper;
public abstract class ModRecipe implements Recipe<RecipeWrapper> { public abstract class ModRecipe implements Recipe<RecipeWrapper> {
public final ResourceLocation name;
public ModRecipe(ResourceLocation name) {
this.name = name;
}
@Override @Override
public boolean matches(RecipeWrapper inv, Level levelIn) { public boolean matches(RecipeWrapper inv, Level levelIn) {
// return true here so that we can easily get all recipes of a type from the recipe manager // return true here so that we can easily get all recipes of a type from the recipe manager
@ -31,9 +24,5 @@ public abstract class ModRecipe implements Recipe<RecipeWrapper> {
return false; return false;
} }
@Override
public ResourceLocation getId() {
return this.name;
}
} }

View file

@ -1,14 +1,13 @@
package de.ellpeck.naturesaura.recipes; package de.ellpeck.naturesaura.recipes;
import com.google.gson.JsonObject; import com.mojang.serialization.Codec;
import com.mojang.serialization.codecs.RecordCodecBuilder;
import net.minecraft.core.RegistryAccess; import net.minecraft.core.RegistryAccess;
import net.minecraft.network.FriendlyByteBuf; import net.minecraft.network.FriendlyByteBuf;
import net.minecraft.resources.ResourceLocation;
import net.minecraft.world.item.ItemStack; import net.minecraft.world.item.ItemStack;
import net.minecraft.world.item.crafting.Ingredient; import net.minecraft.world.item.crafting.Ingredient;
import net.minecraft.world.item.crafting.RecipeSerializer; import net.minecraft.world.item.crafting.RecipeSerializer;
import net.minecraft.world.item.crafting.RecipeType; import net.minecraft.world.item.crafting.RecipeType;
import net.neoforged.neoforge.common.crafting.CraftingHelper;
import javax.annotation.Nullable; import javax.annotation.Nullable;
@ -18,8 +17,7 @@ public class OfferingRecipe extends ModRecipe {
public final Ingredient startItem; public final Ingredient startItem;
public final ItemStack output; public final ItemStack output;
public OfferingRecipe(ResourceLocation name, Ingredient input, Ingredient startItem, ItemStack output) { public OfferingRecipe(Ingredient input, Ingredient startItem, ItemStack output) {
super(name);
this.input = input; this.input = input;
this.startItem = startItem; this.startItem = startItem;
this.output = output; this.output = output;
@ -42,23 +40,21 @@ public class OfferingRecipe extends ModRecipe {
public static class Serializer implements RecipeSerializer<OfferingRecipe> { public static class Serializer implements RecipeSerializer<OfferingRecipe> {
private static final Codec<OfferingRecipe> CODEC = RecordCodecBuilder.create(i -> i.group(
Ingredient.CODEC.fieldOf("input").forGetter(r -> r.input),
Ingredient.CODEC.fieldOf("start_item").forGetter(r -> r.startItem),
ItemStack.CODEC.fieldOf("output").forGetter(r -> r.output)
).apply(i, OfferingRecipe::new));
@Override @Override
public OfferingRecipe fromJson(ResourceLocation recipeId, JsonObject json) { public Codec<OfferingRecipe> codec() {
return new OfferingRecipe( return Serializer.CODEC;
recipeId,
Ingredient.fromJson(json.get("input")),
Ingredient.fromJson(json.get("start_item")),
CraftingHelper.getItemStack(json.getAsJsonObject("output"), true));
} }
@Nullable @Nullable
@Override @Override
public OfferingRecipe fromNetwork(ResourceLocation recipeId, FriendlyByteBuf buffer) { public OfferingRecipe fromNetwork(FriendlyByteBuf buffer) {
return new OfferingRecipe( return new OfferingRecipe(Ingredient.fromNetwork(buffer), Ingredient.fromNetwork(buffer), buffer.readItem());
recipeId,
Ingredient.fromNetwork(buffer),
Ingredient.fromNetwork(buffer),
buffer.readItem());
} }
@Override @Override
@ -67,5 +63,7 @@ public class OfferingRecipe extends ModRecipe {
recipe.startItem.toNetwork(buffer); recipe.startItem.toNetwork(buffer);
buffer.writeItem(recipe.output); buffer.writeItem(recipe.output);
} }
} }
} }

View file

@ -1,14 +1,13 @@
package de.ellpeck.naturesaura.recipes; package de.ellpeck.naturesaura.recipes;
import com.google.gson.JsonObject; import com.mojang.serialization.Codec;
import com.mojang.serialization.codecs.RecordCodecBuilder;
import net.minecraft.core.RegistryAccess; import net.minecraft.core.RegistryAccess;
import net.minecraft.network.FriendlyByteBuf; import net.minecraft.network.FriendlyByteBuf;
import net.minecraft.resources.ResourceLocation;
import net.minecraft.world.item.ItemStack; import net.minecraft.world.item.ItemStack;
import net.minecraft.world.item.crafting.Ingredient; import net.minecraft.world.item.crafting.Ingredient;
import net.minecraft.world.item.crafting.RecipeSerializer; import net.minecraft.world.item.crafting.RecipeSerializer;
import net.minecraft.world.item.crafting.RecipeType; import net.minecraft.world.item.crafting.RecipeType;
import net.neoforged.neoforge.common.crafting.CraftingHelper;
import javax.annotation.Nullable; import javax.annotation.Nullable;
import java.util.ArrayList; import java.util.ArrayList;
@ -17,12 +16,11 @@ import java.util.List;
public class TreeRitualRecipe extends ModRecipe { public class TreeRitualRecipe extends ModRecipe {
public final Ingredient saplingType; public final Ingredient saplingType;
public final Ingredient[] ingredients; public final List<Ingredient> ingredients;
public final ItemStack result; public final ItemStack result;
public final int time; public final int time;
public TreeRitualRecipe(ResourceLocation name, Ingredient saplingType, ItemStack result, int time, Ingredient... ingredients) { public TreeRitualRecipe(Ingredient saplingType, ItemStack result, int time, List<Ingredient> ingredients) {
super(name);
this.saplingType = saplingType; this.saplingType = saplingType;
this.ingredients = ingredients; this.ingredients = ingredients;
this.result = result; this.result = result;
@ -46,41 +44,37 @@ public class TreeRitualRecipe extends ModRecipe {
public static class Serializer implements RecipeSerializer<TreeRitualRecipe> { public static class Serializer implements RecipeSerializer<TreeRitualRecipe> {
private static final Codec<TreeRitualRecipe> CODEC = RecordCodecBuilder.create(i -> i.group(
Ingredient.CODEC.fieldOf("sapling").forGetter(r -> r.saplingType),
ItemStack.CODEC.fieldOf("result").forGetter(r -> r.result),
Codec.INT.fieldOf("time").forGetter(r -> r.time),
Ingredient.CODEC.listOf().fieldOf("ingredients").forGetter(recipe -> recipe.ingredients)
).apply(i, TreeRitualRecipe::new));
@Override @Override
public TreeRitualRecipe fromJson(ResourceLocation recipeId, JsonObject json) { public Codec<TreeRitualRecipe> codec() {
List<Ingredient> ings = new ArrayList<>(); return Serializer.CODEC;
for (var element : json.getAsJsonArray("ingredients"))
ings.add(Ingredient.fromJson(element));
return new TreeRitualRecipe(
recipeId,
Ingredient.fromJson(json.getAsJsonObject("sapling")),
CraftingHelper.getItemStack(json.getAsJsonObject("output"), true),
json.get("time").getAsInt(),
ings.toArray(new Ingredient[0]));
} }
@Nullable @Nullable
@Override @Override
public TreeRitualRecipe fromNetwork(ResourceLocation recipeId, FriendlyByteBuf buffer) { public TreeRitualRecipe fromNetwork(FriendlyByteBuf buffer) {
var ings = new Ingredient[buffer.readInt()]; var ingredients = new ArrayList<Ingredient>();
for (var i = 0; i < ings.length; i++) for (var i = buffer.readInt(); i > 0; i--)
ings[i] = Ingredient.fromNetwork(buffer); ingredients.add(Ingredient.fromNetwork(buffer));
return new TreeRitualRecipe( return new TreeRitualRecipe(Ingredient.fromNetwork(buffer), buffer.readItem(), buffer.readInt(), ingredients);
recipeId,
Ingredient.fromNetwork(buffer),
buffer.readItem(),
buffer.readInt(),
ings);
} }
@Override @Override
public void toNetwork(FriendlyByteBuf buffer, TreeRitualRecipe recipe) { public void toNetwork(FriendlyByteBuf buffer, TreeRitualRecipe recipe) {
buffer.writeInt(recipe.ingredients.length); buffer.writeInt(recipe.ingredients.size());
for (var ing : recipe.ingredients) for (var ing : recipe.ingredients)
ing.toNetwork(buffer); ing.toNetwork(buffer);
recipe.saplingType.toNetwork(buffer); recipe.saplingType.toNetwork(buffer);
buffer.writeItem(recipe.result); buffer.writeItem(recipe.result);
buffer.writeInt(recipe.time); buffer.writeInt(recipe.time);
} }
} }
} }

View file

@ -2,12 +2,12 @@ package de.ellpeck.naturesaura.reg;
import de.ellpeck.naturesaura.Helper; import de.ellpeck.naturesaura.Helper;
import de.ellpeck.naturesaura.NaturesAura; import de.ellpeck.naturesaura.NaturesAura;
import de.ellpeck.naturesaura.api.NaturesAuraAPI;
import de.ellpeck.naturesaura.api.misc.ILevelData; import de.ellpeck.naturesaura.api.misc.ILevelData;
import de.ellpeck.naturesaura.blocks.*; import de.ellpeck.naturesaura.blocks.*;
import de.ellpeck.naturesaura.blocks.tiles.BlockEntityAuraBloom; import de.ellpeck.naturesaura.blocks.tiles.BlockEntityAuraBloom;
import de.ellpeck.naturesaura.blocks.tiles.BlockEntityEnderCrate; import de.ellpeck.naturesaura.blocks.tiles.BlockEntityEnderCrate;
import de.ellpeck.naturesaura.blocks.tiles.ModBlockEntities; import de.ellpeck.naturesaura.blocks.tiles.ModBlockEntities;
import de.ellpeck.naturesaura.chunk.AuraChunkProvider;
import de.ellpeck.naturesaura.compat.patchouli.PatchouliCompat; import de.ellpeck.naturesaura.compat.patchouli.PatchouliCompat;
import de.ellpeck.naturesaura.enchant.AuraMendingEnchantment; import de.ellpeck.naturesaura.enchant.AuraMendingEnchantment;
import de.ellpeck.naturesaura.enchant.ModEnchantments; import de.ellpeck.naturesaura.enchant.ModEnchantments;
@ -22,7 +22,6 @@ import de.ellpeck.naturesaura.items.*;
import de.ellpeck.naturesaura.items.tools.*; import de.ellpeck.naturesaura.items.tools.*;
import de.ellpeck.naturesaura.potion.ModPotions; import de.ellpeck.naturesaura.potion.ModPotions;
import de.ellpeck.naturesaura.potion.PotionBreathless; import de.ellpeck.naturesaura.potion.PotionBreathless;
import de.ellpeck.naturesaura.recipes.EnabledCondition;
import de.ellpeck.naturesaura.recipes.ModRecipes; import de.ellpeck.naturesaura.recipes.ModRecipes;
import net.minecraft.core.registries.BuiltInRegistries; import net.minecraft.core.registries.BuiltInRegistries;
import net.minecraft.core.registries.Registries; import net.minecraft.core.registries.Registries;
@ -40,12 +39,15 @@ import net.minecraft.world.level.block.SoundType;
import net.minecraft.world.level.levelgen.structure.BuiltinStructures; import net.minecraft.world.level.levelgen.structure.BuiltinStructures;
import net.neoforged.bus.api.SubscribeEvent; import net.neoforged.bus.api.SubscribeEvent;
import net.neoforged.fml.common.Mod; import net.neoforged.fml.common.Mod;
import net.neoforged.neoforge.capabilities.Capabilities; import net.neoforged.neoforge.capabilities.Capabilities.EnergyStorage;
import net.neoforged.neoforge.capabilities.Capabilities.FluidHandler;
import net.neoforged.neoforge.capabilities.Capabilities.ItemHandler;
import net.neoforged.neoforge.capabilities.RegisterCapabilitiesEvent; import net.neoforged.neoforge.capabilities.RegisterCapabilitiesEvent;
import net.neoforged.neoforge.common.crafting.CraftingHelper;
import net.neoforged.neoforge.common.extensions.IMenuTypeExtension; import net.neoforged.neoforge.common.extensions.IMenuTypeExtension;
import net.neoforged.neoforge.items.IItemHandler; import net.neoforged.neoforge.items.IItemHandler;
import net.neoforged.neoforge.registries.NeoForgeRegistries;
import net.neoforged.neoforge.registries.RegisterEvent; import net.neoforged.neoforge.registries.RegisterEvent;
import vazkii.patchouli.api.PatchouliAPI;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.List; import java.util.List;
@ -305,7 +307,6 @@ public final class ModRegistry {
h.register(new ResourceLocation(NaturesAura.MOD_ID, "animal_spawner"), ModRecipes.ANIMAL_SPAWNER_SERIALIZER); h.register(new ResourceLocation(NaturesAura.MOD_ID, "animal_spawner"), ModRecipes.ANIMAL_SPAWNER_SERIALIZER);
h.register(new ResourceLocation(NaturesAura.MOD_ID, "offering"), ModRecipes.OFFERING_SERIALIZER); h.register(new ResourceLocation(NaturesAura.MOD_ID, "offering"), ModRecipes.OFFERING_SERIALIZER);
h.register(new ResourceLocation(NaturesAura.MOD_ID, "tree_ritual"), ModRecipes.TREE_RITUAL_SERIALIZER); h.register(new ResourceLocation(NaturesAura.MOD_ID, "tree_ritual"), ModRecipes.TREE_RITUAL_SERIALIZER);
CraftingHelper.register(new EnabledCondition.Serializer());
}); });
event.register(Registries.CREATIVE_MODE_TAB, h -> { event.register(Registries.CREATIVE_MODE_TAB, h -> {
@ -326,13 +327,29 @@ public final class ModRegistry {
.build() .build()
); );
}); });
event.register(NeoForgeRegistries.Keys.ATTACHMENT_TYPES, h -> {
h.register(new ResourceLocation(NaturesAura.MOD_ID, "aura_chunk"), NaturesAuraAPI.AURA_CHUNK_ATTACHMENT);
});
} }
@SubscribeEvent @SubscribeEvent
public static void registerCapabilities(RegisterCapabilitiesEvent event) { public static void registerCapabilities(RegisterCapabilitiesEvent event) {
event.registerBlockEntity(Capabilities.FluidHandler.BLOCK, ModBlockEntities.SPRING, (e, c) -> e.tank); event.registerBlockEntity(FluidHandler.BLOCK, ModBlockEntities.SPRING, (e, c) -> e.tank);
event.registerBlockEntity(Capabilities.EnergyStorage.BLOCK, ModBlockEntities.RF_CONVERTER, (e, c) -> e.storage);
event.registerBlockEntity(Capabilities.ItemHandler.BLOCK, ModBlockEntities.BLAST_FURNACE_BOOSTER, (e, c) -> e.getItemHandler()); event.registerBlockEntity(EnergyStorage.BLOCK, ModBlockEntities.RF_CONVERTER, (e, c) -> e.storage);
event.registerBlockEntity(NaturesAuraAPI.AURA_CONTAINER_BLOCK_CAPABILITY, ModBlockEntities.NATURE_ALTAR, (e, c) -> e.container);
event.registerBlockEntity(NaturesAuraAPI.AURA_CONTAINER_BLOCK_CAPABILITY, ModBlockEntities.ANCIENT_LEAVES, (e, c) -> e.container);
event.registerBlockEntity(NaturesAuraAPI.AURA_CONTAINER_BLOCK_CAPABILITY, ModBlockEntities.END_FLOWER, (e, c) -> e.container);
event.registerBlockEntity(ItemHandler.BLOCK, ModBlockEntities.BLAST_FURNACE_BOOSTER, (e, c) -> e.getItemHandler());
event.registerBlockEntity(ItemHandler.BLOCK, ModBlockEntities.OFFERING_TABLE, (e, c) -> e.items);
event.registerBlockEntity(ItemHandler.BLOCK, ModBlockEntities.GRATED_CHUTE, (e, c) -> e.items);
event.registerBlockEntity(ItemHandler.BLOCK, ModBlockEntities.NATURE_ALTAR, (e, c) -> e.items);
event.registerBlockEntity(ItemHandler.BLOCK, ModBlockEntities.WOOD_STAND, (e, c) -> e.items);
event.registerBlockEntity(ItemHandler.BLOCK, ModBlockEntities.ENDER_CRATE, (e, c) -> e.canOpen() ? e.wrappedEnderStorage : null);
event.registerBlockEntity(ItemHandler.BLOCK, ModBlockEntities.AURA_TIMER, (e, c) -> e.itemHandler);
} }
public static Block createFlowerPot(Block block) { public static Block createFlowerPot(Block block) {