Skip to content

Commit

Permalink
a bunch more work on the port
Browse files Browse the repository at this point in the history
  • Loading branch information
Ellpeck committed Sep 25, 2024
1 parent 6525ff5 commit e50d3fc
Show file tree
Hide file tree
Showing 107 changed files with 1,320 additions and 1,267 deletions.
12 changes: 11 additions & 1 deletion src/main/java/de/ellpeck/naturesaura/Helper.java
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@
import de.ellpeck.naturesaura.api.misc.ILevelData;
import de.ellpeck.naturesaura.blocks.tiles.BlockEntityImpl;
import de.ellpeck.naturesaura.chunk.AuraChunk;
import de.ellpeck.naturesaura.compat.Compat;
import de.ellpeck.naturesaura.misc.LevelData;
import de.ellpeck.naturesaura.packet.PacketHandler;
import de.ellpeck.naturesaura.packet.PacketParticles;
Expand All @@ -15,6 +14,8 @@
import net.minecraft.core.BlockPos;
import net.minecraft.core.Registry;
import net.minecraft.core.registries.BuiltInRegistries;
import net.minecraft.nbt.IntArrayTag;
import net.minecraft.nbt.Tag;
import net.minecraft.resources.ResourceLocation;
import net.minecraft.server.level.ServerChunkCache;
import net.minecraft.server.level.ServerPlayer;
Expand Down Expand Up @@ -367,4 +368,13 @@ public static boolean toggleToolEnabled(Player player, ItemStack stack) {
return true;
}

public static BlockPos readBlockPos(Tag tag) {
if (tag instanceof IntArrayTag i) {
var arr = i.getAsIntArray();
if (arr.length == 3)
return new BlockPos(arr[0], arr[1], arr[2]);
}
return null;
}

}
208 changes: 104 additions & 104 deletions src/main/java/de/ellpeck/naturesaura/ModConfig.java

Large diffs are not rendered by default.

10 changes: 5 additions & 5 deletions src/main/java/de/ellpeck/naturesaura/NaturesAura.java
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,7 @@
import de.ellpeck.naturesaura.proxy.IProxy;
import de.ellpeck.naturesaura.proxy.ServerProxy;
import de.ellpeck.naturesaura.recipes.ModRecipes;
import net.neoforged.bus.api.IEventBus;
import net.neoforged.fml.ModLoadingContext;
import net.neoforged.fml.ModContainer;
import net.neoforged.fml.common.Mod;
import net.neoforged.fml.event.lifecycle.FMLCommonSetupEvent;
import net.neoforged.fml.loading.FMLEnvironment;
Expand All @@ -30,15 +29,16 @@ public final class NaturesAura {
public static NaturesAura instance;
public static IProxy proxy;

public NaturesAura(IEventBus eventBus) {
public NaturesAura(ModContainer container) {
NaturesAura.instance = this;
NaturesAura.proxy = FMLEnvironment.dist.isClient() ? new ClientProxy() : new ServerProxy();

eventBus.addListener(this::setup);
container.getEventBus().addListener(this::setup);
container.getEventBus().register(NaturesAura.proxy);

var builder = new ModConfigSpec.Builder();
ModConfig.instance = new ModConfig(builder);
ModLoadingContext.get().registerConfig(net.neoforged.fml.config.ModConfig.Type.COMMON, builder.build());
container.registerConfig(net.neoforged.fml.config.ModConfig.Type.COMMON, builder.build());
}

public void setup(FMLCommonSetupEvent event) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@
import de.ellpeck.naturesaura.reg.IModItem;
import de.ellpeck.naturesaura.reg.ModRegistry;
import net.minecraft.core.BlockPos;
import net.minecraft.core.Registry;
import net.minecraft.core.registries.Registries;
import net.minecraft.server.level.ServerLevel;
import net.minecraft.util.RandomSource;
Expand All @@ -19,11 +18,9 @@
import net.minecraft.world.level.block.*;
import net.minecraft.world.level.block.state.BlockState;
import net.minecraft.world.level.block.state.StateDefinition;
import net.minecraft.world.level.levelgen.feature.ConfiguredFeature;
import net.minecraft.world.phys.shapes.CollisionContext;
import net.minecraft.world.phys.shapes.VoxelShape;
import net.neoforged.neoforge.event.EventHooks;
import net.neoforged.bus.api.Event;

public class BlockAncientSapling extends BushBlock implements BonemealableBlock, IModItem, ICustomBlockState, ICustomItemModel {

Expand Down Expand Up @@ -75,9 +72,12 @@ public boolean isBonemealSuccess(Level level, RandomSource rand, BlockPos pos, B
public void performBonemeal(ServerLevel level, RandomSource rand, BlockPos pos, BlockState state) {
if (state.getValue(SaplingBlock.STAGE) == 0) {
level.setBlock(pos, state.cycle(SaplingBlock.STAGE), 4);
} else if (!EventHooks.blockGrowFeature(level, rand, pos, null).getResult().equals(Event.Result.DENY)) {
Registry<ConfiguredFeature<?, ?>> registry = level.registryAccess().registryOrThrow(Registries.CONFIGURED_FEATURE);
registry.getHolderOrThrow(ModFeatures.Configured.ANCIENT_TREE).value().place(level, level.getChunkSource().getGenerator(), rand, pos);
} else {
var event = EventHooks.fireBlockGrowFeature(level, rand, pos, null);
if (!event.isCanceled()) {
var registry = level.registryAccess().registryOrThrow(Registries.CONFIGURED_FEATURE);
registry.getHolderOrThrow(ModFeatures.Configured.ANCIENT_TREE).value().place(level, level.getChunkSource().getGenerator(), rand, pos);
}
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,11 +17,12 @@
import net.minecraft.world.phys.AABB;
import net.neoforged.api.distmarker.Dist;
import net.neoforged.api.distmarker.OnlyIn;
import net.neoforged.bus.api.SubscribeEvent;
import net.neoforged.neoforge.common.NeoForge;
import net.neoforged.neoforge.event.entity.living.*;
import net.neoforged.neoforge.event.entity.living.LivingDeathEvent;
import net.neoforged.neoforge.event.entity.living.LivingDropsEvent;
import net.neoforged.neoforge.event.entity.living.LivingExperienceDropEvent;
import net.neoforged.bus.api.SubscribeEvent;
import net.neoforged.neoforge.event.entity.living.LivingEvent;
import net.neoforged.neoforge.event.tick.EntityTickEvent;

public class BlockAnimalGenerator extends BlockContainerImpl implements IVisualizable, ICustomBlockState {

Expand All @@ -32,7 +33,7 @@ public BlockAnimalGenerator() {
}

@SubscribeEvent
public void onLivingUpdate(LivingEvent.LivingTickEvent event) {
public void onLivingUpdate(EntityTickEvent event) {
var entity = event.getEntity();
if (entity.level().isClientSide || entity.level().getGameTime() % 40 != 0 || !(entity instanceof Animal) || entity instanceof Npc)
return;
Expand Down Expand Up @@ -70,10 +71,10 @@ public void onEntityDeath(LivingDeathEvent event) {

var genPos = gen.getBlockPos();
PacketHandler.sendToAllAround(entity.level(), pos, 32, new PacketParticles(
(float) entity.getX(), (float) entity.getY(), (float) entity.getZ(), PacketParticles.Type.ANIMAL_GEN_CONSUME,
child ? 1 : 0,
(int) (entity.getEyeHeight() * 10F),
genPos.getX(), genPos.getY(), genPos.getZ()));
(float) entity.getX(), (float) entity.getY(), (float) entity.getZ(), PacketParticles.Type.ANIMAL_GEN_CONSUME,
child ? 1 : 0,
(int) (entity.getEyeHeight() * 10F),
genPos.getX(), genPos.getY(), genPos.getZ()));

return true;
});
Expand Down Expand Up @@ -108,8 +109,9 @@ public int getVisualizationColor(Level level, BlockPos pos) {
@Override
public void generateCustomBlockState(BlockStateGenerator generator) {
generator.simpleBlock(this, generator.models().cubeBottomTop(this.getBaseName(),
generator.modLoc("block/" + this.getBaseName()),
generator.modLoc("block/" + this.getBaseName() + "_bottom"),
generator.modLoc("block/" + this.getBaseName() + "_top")));
generator.modLoc("block/" + this.getBaseName()),
generator.modLoc("block/" + this.getBaseName() + "_bottom"),
generator.modLoc("block/" + this.getBaseName() + "_top")));
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,9 @@
import net.minecraft.server.level.ServerLevel;
import net.minecraft.util.RandomSource;
import net.minecraft.world.InteractionHand;
import net.minecraft.world.InteractionResult;
import net.minecraft.world.ItemInteractionResult;
import net.minecraft.world.entity.player.Player;
import net.minecraft.world.item.ItemStack;
import net.minecraft.world.level.BlockGetter;
import net.minecraft.world.level.Level;
import net.minecraft.world.level.block.Block;
Expand Down Expand Up @@ -52,9 +53,8 @@ protected void createBlockStateDefinition(StateDefinition.Builder<Block, BlockSt
}

@Override
@SuppressWarnings("deprecation")
public InteractionResult use(BlockState state, Level levelIn, BlockPos pos, Player player, InteractionHand handIn, BlockHitResult p_225533_6_) {
return Helper.putStackOnTile(player, handIn, pos, 0, true);
protected ItemInteractionResult useItemOn(ItemStack stack, BlockState state, Level level, BlockPos pos, Player player, InteractionHand hand, BlockHitResult hitResult) {
return Helper.putStackOnTile(player, hand, pos, 0, true);
}

@Override
Expand All @@ -80,4 +80,5 @@ public void tick(BlockState state, ServerLevel levelIn, BlockPos pos, RandomSour
public void registerTESR() {
BlockEntityRenderers.register(ModBlockEntities.AURA_TIMER, RenderAuraTimer::new);
}

}
19 changes: 9 additions & 10 deletions src/main/java/de/ellpeck/naturesaura/blocks/BlockEnderCrate.java
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
import net.minecraft.world.InteractionHand;
import net.minecraft.world.InteractionResult;
import net.minecraft.world.entity.player.Player;
import net.minecraft.world.item.Item;
import net.minecraft.world.item.ItemStack;
import net.minecraft.world.item.Items;
import net.minecraft.world.item.TooltipFlag;
Expand Down Expand Up @@ -85,10 +86,9 @@ public void onAnvilUpdate(AnvilUpdateEvent event) {
}

@Override
@SuppressWarnings("deprecation")
public InteractionResult use(BlockState state, Level levelIn, BlockPos pos, Player player, InteractionHand handIn, BlockHitResult hit) {
if (!levelIn.isClientSide) {
var tile = levelIn.getBlockEntity(pos);
protected InteractionResult useWithoutItem(BlockState state, Level level, BlockPos pos, Player player, BlockHitResult hitResult) {
if (!level.isClientSide) {
var tile = level.getBlockEntity(pos);
if (tile instanceof BlockEntityEnderCrate crate && crate.canOpen() && crate.canUseRightNow(2500)) {
crate.drainAura(2500);
player.openMenu(crate, pos);
Expand All @@ -98,9 +98,8 @@ public InteractionResult use(BlockState state, Level levelIn, BlockPos pos, Play
}

@Override
@OnlyIn(Dist.CLIENT)
public void appendHoverText(ItemStack stack, @Nullable BlockGetter levelIn, List<Component> tooltip, TooltipFlag flagIn) {
BlockEnderCrate.addEnderNameInfo(stack, tooltip);
public void appendHoverText(ItemStack stack, Item.TooltipContext context, List<Component> tooltipComponents, TooltipFlag tooltipFlag) {
BlockEnderCrate.addEnderNameInfo(stack, tooltipComponents);
}

@Override
Expand All @@ -122,9 +121,9 @@ public void animateTick(BlockState stateIn, Level levelIn, BlockPos pos, RandomS
@Override
public void generateCustomBlockState(BlockStateGenerator generator) {
generator.simpleBlock(this, generator.models().cubeBottomTop(this.getBaseName(),
generator.modLoc("block/" + this.getBaseName()),
generator.modLoc("block/" + this.getBaseName() + "_bottom"),
generator.modLoc("block/" + this.getBaseName() + "_top")));
generator.modLoc("block/" + this.getBaseName()),
generator.modLoc("block/" + this.getBaseName() + "_bottom"),
generator.modLoc("block/" + this.getBaseName() + "_top")));
}

@Override
Expand Down
30 changes: 15 additions & 15 deletions src/main/java/de/ellpeck/naturesaura/blocks/BlockFieldCreator.java
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,9 @@
import net.minecraft.network.chat.Component;
import net.minecraft.util.RandomSource;
import net.minecraft.world.InteractionHand;
import net.minecraft.world.InteractionResult;
import net.minecraft.world.ItemInteractionResult;
import net.minecraft.world.entity.player.Player;
import net.minecraft.world.item.ItemStack;
import net.minecraft.world.level.Level;
import net.minecraft.world.level.block.SoundType;
import net.minecraft.world.level.block.state.BlockState;
Expand All @@ -25,19 +26,18 @@ public BlockFieldCreator() {
}

@Override
@SuppressWarnings("deprecation")
public InteractionResult use(BlockState state, Level levelIn, BlockPos pos, Player player, InteractionHand handIn, BlockHitResult result) {
var tile = levelIn.getBlockEntity(pos);
protected ItemInteractionResult useItemOn(ItemStack stack, BlockState state, Level level, BlockPos pos, Player player, InteractionHand hand, BlockHitResult hitResult) {
var tile = level.getBlockEntity(pos);
if (tile instanceof BlockEntityFieldCreator) {
if (!levelIn.isClientSide) {
if (!level.isClientSide) {
var key = NaturesAura.MOD_ID + ":field_creator_pos";
var compound = player.getPersistentData();
if (!player.isShiftKeyDown() && compound.contains(key)) {
var stored = BlockPos.of(compound.getLong(key));
var creator = (BlockEntityFieldCreator) tile;
if (!pos.equals(stored)) {
if (creator.isCloseEnough(stored)) {
var otherTile = levelIn.getBlockEntity(stored);
var otherTile = level.getBlockEntity(stored);
if (otherTile instanceof BlockEntityFieldCreator otherCreator) {
creator.connectionOffset = stored.subtract(pos);
creator.isMain = true;
Expand All @@ -60,9 +60,9 @@ public InteractionResult use(BlockState state, Level levelIn, BlockPos pos, Play
player.displayClientMessage(Component.translatable("info." + NaturesAura.MOD_ID + ".stored_pos"), true);
}
}
return InteractionResult.SUCCESS;
return ItemInteractionResult.SUCCESS;
} else
return InteractionResult.FAIL;
return ItemInteractionResult.FAIL;
}

@Override
Expand All @@ -73,13 +73,13 @@ public void animateTick(BlockState stateIn, Level levelIn, BlockPos pos, RandomS
var connected = creator.getConnectedPos();
if (connected != null)
NaturesAuraAPI.instance().spawnParticleStream(
pos.getX() + 0.25F + rand.nextFloat() * 0.5F,
pos.getY() + 0.25F + rand.nextFloat() * 0.5F,
pos.getZ() + 0.25F + rand.nextFloat() * 0.5F,
connected.getX() + 0.25F + rand.nextFloat() * 0.5F,
connected.getY() + 0.25F + rand.nextFloat() * 0.5F,
connected.getZ() + 0.25F + rand.nextFloat() * 0.5F,
0.65F, 0x4245f4, 1F
pos.getX() + 0.25F + rand.nextFloat() * 0.5F,
pos.getY() + 0.25F + rand.nextFloat() * 0.5F,
pos.getZ() + 0.25F + rand.nextFloat() * 0.5F,
connected.getX() + 0.25F + rand.nextFloat() * 0.5F,
connected.getY() + 0.25F + rand.nextFloat() * 0.5F,
connected.getZ() + 0.25F + rand.nextFloat() * 0.5F,
0.65F, 0x4245f4, 1F
);
}
}
Expand Down
25 changes: 11 additions & 14 deletions src/main/java/de/ellpeck/naturesaura/blocks/BlockGratedChute.java
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@
import net.minecraft.core.BlockPos;
import net.minecraft.core.Direction;
import net.minecraft.util.Mth;
import net.minecraft.world.InteractionHand;
import net.minecraft.world.InteractionResult;
import net.minecraft.world.entity.player.Player;
import net.minecraft.world.item.context.BlockPlaceContext;
Expand All @@ -18,7 +17,6 @@
import net.minecraft.world.level.block.HopperBlock;
import net.minecraft.world.level.block.RenderShape;
import net.minecraft.world.level.block.SoundType;
import net.minecraft.world.level.block.entity.Hopper;
import net.minecraft.world.level.block.state.BlockState;
import net.minecraft.world.level.block.state.StateDefinition;
import net.minecraft.world.level.block.state.properties.DirectionProperty;
Expand All @@ -28,27 +26,27 @@
import net.minecraft.world.phys.shapes.Shapes;
import net.minecraft.world.phys.shapes.VoxelShape;
import net.neoforged.neoforge.capabilities.Capabilities;
import net.neoforged.neoforge.items.IItemHandler;

import javax.annotation.Nullable;

public class BlockGratedChute extends BlockContainerImpl implements ICustomBlockState, ICustomItemModel {

public static final DirectionProperty FACING = HopperBlock.FACING;
private static final VoxelShape INSIDE = Block.box(2.0, 11.0, 2.0, 14.0, 16.0, 14.0);
private static final VoxelShape INPUT_SHAPE = Block.box(0.0D, 10.0D, 0.0D, 16.0D, 16.0D, 16.0D);
private static final VoxelShape MIDDLE_SHAPE = Block.box(4.0D, 4.0D, 4.0D, 12.0D, 10.0D, 12.0D);
private static final VoxelShape INPUT_MIDDLE_SHAPE = Shapes.or(BlockGratedChute.MIDDLE_SHAPE, BlockGratedChute.INPUT_SHAPE);
private static final VoxelShape COMBINED_SHAPE = Shapes.join(BlockGratedChute.INPUT_MIDDLE_SHAPE, Hopper.INSIDE, BooleanOp.ONLY_FIRST);
private static final VoxelShape COMBINED_SHAPE = Shapes.join(BlockGratedChute.INPUT_MIDDLE_SHAPE, BlockGratedChute.INSIDE, BooleanOp.ONLY_FIRST);
private static final VoxelShape DOWN_SHAPE = Shapes.or(BlockGratedChute.COMBINED_SHAPE, Block.box(6.0D, 0.0D, 6.0D, 10.0D, 4.0D, 10.0D));
private static final VoxelShape EAST_SHAPE = Shapes.or(BlockGratedChute.COMBINED_SHAPE, Block.box(12.0D, 4.0D, 6.0D, 16.0D, 8.0D, 10.0D));
private static final VoxelShape NORTH_SHAPE = Shapes.or(BlockGratedChute.COMBINED_SHAPE, Block.box(6.0D, 4.0D, 0.0D, 10.0D, 8.0D, 4.0D));
private static final VoxelShape SOUTH_SHAPE = Shapes.or(BlockGratedChute.COMBINED_SHAPE, Block.box(6.0D, 4.0D, 12.0D, 10.0D, 8.0D, 16.0D));
private static final VoxelShape WEST_SHAPE = Shapes.or(BlockGratedChute.COMBINED_SHAPE, Block.box(0.0D, 4.0D, 6.0D, 4.0D, 8.0D, 10.0D));
private static final VoxelShape DOWN_RAYTRACE_SHAPE = Hopper.INSIDE;
private static final VoxelShape EAST_RAYTRACE_SHAPE = Shapes.or(Hopper.INSIDE, Block.box(12.0D, 8.0D, 6.0D, 16.0D, 10.0D, 10.0D));
private static final VoxelShape NORTH_RAYTRACE_SHAPE = Shapes.or(Hopper.INSIDE, Block.box(6.0D, 8.0D, 0.0D, 10.0D, 10.0D, 4.0D));
private static final VoxelShape SOUTH_RAYTRACE_SHAPE = Shapes.or(Hopper.INSIDE, Block.box(6.0D, 8.0D, 12.0D, 10.0D, 10.0D, 16.0D));
private static final VoxelShape WEST_RAYTRACE_SHAPE = Shapes.or(Hopper.INSIDE, Block.box(0.0D, 8.0D, 6.0D, 4.0D, 10.0D, 10.0D));
private static final VoxelShape DOWN_RAYTRACE_SHAPE = BlockGratedChute.INSIDE;
private static final VoxelShape EAST_RAYTRACE_SHAPE = Shapes.or(BlockGratedChute.INSIDE, Block.box(12.0D, 8.0D, 6.0D, 16.0D, 10.0D, 10.0D));
private static final VoxelShape NORTH_RAYTRACE_SHAPE = Shapes.or(BlockGratedChute.INSIDE, Block.box(6.0D, 8.0D, 0.0D, 10.0D, 10.0D, 4.0D));
private static final VoxelShape SOUTH_RAYTRACE_SHAPE = Shapes.or(BlockGratedChute.INSIDE, Block.box(6.0D, 8.0D, 12.0D, 10.0D, 10.0D, 16.0D));
private static final VoxelShape WEST_RAYTRACE_SHAPE = Shapes.or(BlockGratedChute.INSIDE, Block.box(0.0D, 8.0D, 6.0D, 4.0D, 10.0D, 10.0D));

public BlockGratedChute() {
super("grated_chute", BlockEntityGratedChute.class, Properties.of().strength(3.0F, 8.0F).sound(SoundType.METAL));
Expand Down Expand Up @@ -81,17 +79,16 @@ public VoxelShape getInteractionShape(BlockState state, BlockGetter levelIn, Blo
case SOUTH -> BlockGratedChute.SOUTH_RAYTRACE_SHAPE;
case WEST -> BlockGratedChute.WEST_RAYTRACE_SHAPE;
case EAST -> BlockGratedChute.EAST_RAYTRACE_SHAPE;
default -> Hopper.INSIDE;
default -> BlockGratedChute.INSIDE;
};
}

@Override
@SuppressWarnings("deprecation")
public InteractionResult use(BlockState state, Level levelIn, BlockPos pos, Player player, InteractionHand handIn, BlockHitResult hit) {
var tile = levelIn.getBlockEntity(pos);
protected InteractionResult useWithoutItem(BlockState state, Level level, BlockPos pos, Player player, BlockHitResult hitResult) {
var tile = level.getBlockEntity(pos);
if (!(tile instanceof BlockEntityGratedChute chute))
return InteractionResult.FAIL;
if (!levelIn.isClientSide) {
if (!level.isClientSide) {
chute.isBlacklist = !chute.isBlacklist;
chute.sendToClients();
}
Expand Down
Loading

0 comments on commit e50d3fc

Please sign in to comment.