Skip to content

Commit

Permalink
Update to MC 1.21
Browse files Browse the repository at this point in the history
  • Loading branch information
rubensworks committed Jul 1, 2024
1 parent 7f9dc54 commit 61cf625
Show file tree
Hide file tree
Showing 9 changed files with 108 additions and 94 deletions.
14 changes: 8 additions & 6 deletions build.gradle
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
plugins {
id 'net.neoforged.gradle.userdev' version '7.0.97'
id 'net.neoforged.gradle.userdev' version '7.0.145'
id 'net.darkhax.curseforgegradle' version '1.0.8'
id 'com.diffplug.spotless' version '5.14.3'
id 'com.modrinth.minotaur' version '2.+'
Expand Down Expand Up @@ -31,7 +31,7 @@ base {
}

// Set Java details
java.toolchain.languageVersion = JavaLanguageVersion.of(17)
java.toolchain.languageVersion = JavaLanguageVersion.of(21)
compileJava.options.compilerArgs << "-Xmaxerrs" << "9999"
println('Java: ' + System.getProperty('java.version') + ' JVM: ' + System.getProperty('java.vm.version') + '(' + System.getProperty('java.vendor') + ') Arch: ' + System.getProperty('os.arch'))

Expand Down Expand Up @@ -75,10 +75,10 @@ dependencies {
}

// Project lombok
compileOnly 'org.projectlombok:lombok:1.18.22'
annotationProcessor 'org.projectlombok:lombok:1.18.22'
testCompileOnly 'org.projectlombok:lombok:1.18.22'
testAnnotationProcessor 'org.projectlombok:lombok:1.18.22'
compileOnly 'org.projectlombok:lombok:1.18.30'
annotationProcessor 'org.projectlombok:lombok:1.18.30'
testCompileOnly 'org.projectlombok:lombok:1.18.30'
testAnnotationProcessor 'org.projectlombok:lombok:1.18.30'
}

runs {
Expand Down Expand Up @@ -261,6 +261,8 @@ publishing {

idea {
module {
downloadSources = true
downloadJavadoc = true
for (String excludeDirName in ["run", "out", "logs", "gradle"]) {
File excludeDir = new File(projectDir, excludeDirName)
excludeDirs.add(excludeDir)
Expand Down
6 changes: 3 additions & 3 deletions gradle.properties
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
mod_id=flopper
mod_version=1.1.5
minecraft_version=1.20.4
neoforge_version=20.4.160-beta
cyclopscore_version=1.19.0-408
minecraft_version=1.21
neoforge_version=21.0.43-beta
cyclopscore_version=1.19.1-451
release_type=release
fingerprint=bd0353b3e8a2810d60dd584e256e364bc3bedd44

Expand Down
2 changes: 1 addition & 1 deletion gradle/wrapper/gradle-wrapper.properties
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-8.1.1-bin.zip
distributionUrl=https\://services.gradle.org/distributions/gradle-8.7-bin.zip
networkTimeout=10000
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists
6 changes: 3 additions & 3 deletions src/main/java/org/cyclops/flopper/RegistryEntries.java
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,8 @@
*/
public class RegistryEntries {

public static final DeferredHolder<Item, Item> ITEM_FLOPPER = DeferredHolder.create(Registries.ITEM, new ResourceLocation("flopper:flopper"));
public static final DeferredHolder<Block, Block> BLOCK_FLOPPER = DeferredHolder.create(Registries.BLOCK, new ResourceLocation("flopper:flopper"));
public static final DeferredHolder<BlockEntityType<?>, BlockEntityType<BlockEntityFlopper>> BLOCK_ENTITY_FLOPPER = DeferredHolder.create(Registries.BLOCK_ENTITY_TYPE, new ResourceLocation("flopper:flopper"));
public static final DeferredHolder<Item, Item> ITEM_FLOPPER = DeferredHolder.create(Registries.ITEM, ResourceLocation.parse("flopper:flopper"));
public static final DeferredHolder<Block, Block> BLOCK_FLOPPER = DeferredHolder.create(Registries.BLOCK, ResourceLocation.parse("flopper:flopper"));
public static final DeferredHolder<BlockEntityType<?>, BlockEntityType<BlockEntityFlopper>> BLOCK_ENTITY_FLOPPER = DeferredHolder.create(Registries.BLOCK_ENTITY_TYPE, ResourceLocation.parse("flopper:flopper"));

}
147 changes: 79 additions & 68 deletions src/main/java/org/cyclops/flopper/block/BlockFlopper.java
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
import net.minecraft.sounds.SoundSource;
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.item.context.BlockPlaceContext;
Expand All @@ -21,7 +22,6 @@
import net.minecraft.world.level.block.entity.BlockEntity;
import net.minecraft.world.level.block.entity.BlockEntityTicker;
import net.minecraft.world.level.block.entity.BlockEntityType;
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.BlockStateProperties;
Expand All @@ -33,17 +33,16 @@
import net.minecraft.world.phys.shapes.CollisionContext;
import net.minecraft.world.phys.shapes.Shapes;
import net.minecraft.world.phys.shapes.VoxelShape;
import net.neoforged.bus.api.Event;
import net.neoforged.bus.api.SubscribeEvent;
import net.neoforged.neoforge.capabilities.Capabilities;
import net.neoforged.neoforge.common.NeoForge;
import net.neoforged.neoforge.common.SoundActions;
import net.neoforged.neoforge.common.util.TriState;
import net.neoforged.neoforge.event.entity.player.PlayerInteractEvent;
import net.neoforged.neoforge.fluids.FluidActionResult;
import net.neoforged.neoforge.fluids.FluidStack;
import net.neoforged.neoforge.fluids.FluidUtil;
import net.neoforged.neoforge.fluids.capability.IFluidHandler;
import net.neoforged.neoforge.items.ItemHandlerHelper;
import org.cyclops.cyclopscore.block.BlockWithEntity;
import org.cyclops.cyclopscore.blockentity.CyclopsBlockEntity;
import org.cyclops.cyclopscore.helper.BlockEntityHelpers;
Expand All @@ -68,20 +67,21 @@ public class BlockFlopper extends BlockWithEntity {
public static final BooleanProperty ENABLED = BlockStateProperties.ENABLED;

// Copied from HopperBlock, to avoid conflicts with other mods messing with the hopper
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(MIDDLE_SHAPE, INPUT_SHAPE);
private static final VoxelShape BASE_SHAPE = Shapes.join(INPUT_MIDDLE_SHAPE, Hopper.INSIDE, BooleanOp.ONLY_FIRST);
private static final VoxelShape DOWN_SHAPE = Shapes.or(BASE_SHAPE, Block.box(6.0D, 0.0D, 6.0D, 10.0D, 4.0D, 10.0D));
private static final VoxelShape EAST_SHAPE = Shapes.or(BASE_SHAPE, Block.box(12.0D, 4.0D, 6.0D, 16.0D, 8.0D, 10.0D));
private static final VoxelShape NORTH_SHAPE = Shapes.or(BASE_SHAPE, Block.box(6.0D, 4.0D, 0.0D, 10.0D, 8.0D, 4.0D));
private static final VoxelShape SOUTH_SHAPE = Shapes.or(BASE_SHAPE, Block.box(6.0D, 4.0D, 12.0D, 10.0D, 8.0D, 16.0D));
private static final VoxelShape WEST_SHAPE = Shapes.or(BASE_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 TOP = Block.box(0.0, 10.0, 0.0, 16.0, 16.0, 16.0);
private static final VoxelShape FUNNEL = Block.box(4.0, 4.0, 4.0, 12.0, 10.0, 12.0);
private static final VoxelShape CONVEX_BASE = Shapes.or(FUNNEL, TOP);
private static final VoxelShape INSIDE = box(2.0, 11.0, 2.0, 14.0, 16.0, 14.0);
private static final VoxelShape BASE = Shapes.join(CONVEX_BASE, INSIDE, BooleanOp.ONLY_FIRST);
private static final VoxelShape DOWN_SHAPE = Shapes.or(BASE, Block.box(6.0, 0.0, 6.0, 10.0, 4.0, 10.0));
private static final VoxelShape EAST_SHAPE = Shapes.or(BASE, Block.box(12.0, 4.0, 6.0, 16.0, 8.0, 10.0));
private static final VoxelShape NORTH_SHAPE = Shapes.or(BASE, Block.box(6.0, 4.0, 0.0, 10.0, 8.0, 4.0));
private static final VoxelShape SOUTH_SHAPE = Shapes.or(BASE, Block.box(6.0, 4.0, 12.0, 10.0, 8.0, 16.0));
private static final VoxelShape WEST_SHAPE = Shapes.or(BASE, Block.box(0.0, 4.0, 6.0, 4.0, 8.0, 10.0));
private static final VoxelShape DOWN_INTERACTION_SHAPE = INSIDE;
private static final VoxelShape EAST_INTERACTION_SHAPE = Shapes.or(INSIDE, Block.box(12.0, 8.0, 6.0, 16.0, 10.0, 10.0));
private static final VoxelShape NORTH_INTERACTION_SHAPE = Shapes.or(INSIDE, Block.box(6.0, 8.0, 0.0, 10.0, 10.0, 4.0));
private static final VoxelShape SOUTH_INTERACTION_SHAPE = Shapes.or(INSIDE, Block.box(6.0, 8.0, 12.0, 10.0, 10.0, 16.0));
private static final VoxelShape WEST_INTERACTION_SHAPE = Shapes.or(INSIDE, Block.box(0.0, 8.0, 6.0, 4.0, 10.0, 10.0));

public BlockFlopper(Properties properties, BiFunction<BlockPos, BlockState, CyclopsBlockEntity> blockEntitySupplier) {
super(properties, blockEntitySupplier);
Expand Down Expand Up @@ -122,7 +122,7 @@ public VoxelShape getShape(BlockState state, BlockGetter worldIn, BlockPos pos,
case EAST:
return EAST_SHAPE;
default:
return BASE_SHAPE;
return BASE;
}
}

Expand All @@ -131,17 +131,17 @@ public VoxelShape getInteractionShape(BlockState state, BlockGetter worldIn, Blo
// Copied from HopperBlock, to avoid conflicts with other mods messing with the hopper
switch((Direction)state.getValue(FACING)) {
case DOWN:
return DOWN_RAYTRACE_SHAPE;
return DOWN_INTERACTION_SHAPE;
case NORTH:
return NORTH_RAYTRACE_SHAPE;
return NORTH_INTERACTION_SHAPE;
case SOUTH:
return SOUTH_RAYTRACE_SHAPE;
return SOUTH_INTERACTION_SHAPE;
case WEST:
return WEST_RAYTRACE_SHAPE;
return WEST_INTERACTION_SHAPE;
case EAST:
return EAST_RAYTRACE_SHAPE;
return EAST_INTERACTION_SHAPE;
default:
return Hopper.INSIDE;
return INSIDE;
}
}

Expand Down Expand Up @@ -192,70 +192,81 @@ public BlockState mirror(BlockState state, Mirror mirrorIn) {
}

@Override
public boolean isPathfindable(BlockState state, BlockGetter worldIn, BlockPos pos, PathComputationType type) {
public boolean isPathfindable(BlockState state, PathComputationType type) {
return false;
}

@Override
public InteractionResult use(BlockState blockState, Level world, BlockPos blockPos, Player player, InteractionHand hand, BlockHitResult rayTraceResult) {
InteractionResult activatedSuper = super.use(blockState, world, blockPos, player, hand, rayTraceResult);
protected InteractionResult useWithoutItem(BlockState blockState, Level level, BlockPos pos, Player player, BlockHitResult rayTraceResult) {
InteractionResult activatedSuper = super.useWithoutItem(blockState, level, pos, player, rayTraceResult);
if (activatedSuper.consumesAction()) {
return activatedSuper;
}
return BlockEntityHelpers.getCapability(world, blockPos, Capabilities.FluidHandler.BLOCK)

return BlockEntityHelpers.getCapability(level, pos, Capabilities.FluidHandler.BLOCK)
.map(fluidHandler -> {
ItemStack itemStack = player.getItemInHand(hand);
if (itemStack.isEmpty()) {
if (BlockFlopperConfig.showContentsStatusMessageOnClick) {
// If the hand is empty, show the tank contents
FluidStack fluidStack = fluidHandler.drain(Integer.MAX_VALUE, IFluidHandler.FluidAction.SIMULATE);
if (fluidStack.isEmpty()) {
player.displayClientMessage(Component.literal("0 / "
+ String.format("%,d", fluidHandler.getTankCapacity(0))), true);
} else {
player.displayClientMessage(Component.translatable(fluidStack.getTranslationKey())
.append(Component.literal(": "
+ String.format("%,d", fluidStack.getAmount()) + " / "
+ String.format("%,d", fluidHandler.getTankCapacity(0)))), true);
}
return InteractionResult.SUCCESS;
if (BlockFlopperConfig.showContentsStatusMessageOnClick) {
// If the hand is empty, show the tank contents
FluidStack fluidStack = fluidHandler.drain(Integer.MAX_VALUE, IFluidHandler.FluidAction.SIMULATE);
if (fluidStack.isEmpty()) {
player.displayClientMessage(Component.literal("0 / "
+ String.format("%,d", fluidHandler.getTankCapacity(0))), true);
} else {
player.displayClientMessage(fluidStack.getHoverName().plainCopy()
.append(Component.literal(": "
+ String.format("%,d", fluidStack.getAmount()) + " / "
+ String.format("%,d", fluidHandler.getTankCapacity(0)))), true);
}
} else {
if (!player.isCrouching()
&& tryEmptyContainer(itemStack, fluidHandler, FluidHelpers.BUCKET_VOLUME, player, false).isSuccess()) {
// Move fluid from the item into the tank if not sneaking
FluidActionResult result = FluidUtil.tryEmptyContainer(itemStack, fluidHandler, FluidHelpers.BUCKET_VOLUME, player, true);
if (result.isSuccess()) {
ItemStack drainedItem = result.getResult();
if (!player.isCreative()) {
InventoryHelpers.tryReAddToStack(player, itemStack, drainedItem, hand);
}
return InteractionResult.SUCCESS;
}
return InteractionResult.PASS;
})
.orElse(InteractionResult.PASS);
}

@Override
protected ItemInteractionResult useItemOn(ItemStack itemStack, BlockState blockState, Level level, BlockPos pos, Player player, InteractionHand hand, BlockHitResult rayTraceResult) {
ItemInteractionResult activatedSuper = super.useItemOn(itemStack, blockState, level, pos, player, hand, rayTraceResult);
if (activatedSuper.consumesAction()) {
return activatedSuper;
}

return BlockEntityHelpers.getCapability(level, pos, Capabilities.FluidHandler.BLOCK)
.map(fluidHandler -> {
if (!player.isCrouching()
&& tryEmptyContainer(itemStack, fluidHandler, FluidHelpers.BUCKET_VOLUME, player, false).isSuccess()) {
// Move fluid from the item into the tank if not sneaking
FluidActionResult result = FluidUtil.tryEmptyContainer(itemStack, fluidHandler, FluidHelpers.BUCKET_VOLUME, player, true);
if (result.isSuccess()) {
ItemStack drainedItem = result.getResult();
if (!player.isCreative()) {
InventoryHelpers.tryReAddToStack(player, itemStack, drainedItem, hand);
}
return InteractionResult.SUCCESS;
} else if (player.isCrouching()
&& FluidUtil.tryFillContainer(itemStack, fluidHandler, FluidHelpers.BUCKET_VOLUME, player, false).isSuccess()) {
// Move fluid from the tank into the item if sneaking
FluidActionResult result = FluidUtil.tryFillContainer(itemStack, fluidHandler, FluidHelpers.BUCKET_VOLUME, player, true);
if (result.isSuccess()) {
ItemStack filledItem = result.getResult();
if (!player.isCreative()) {
InventoryHelpers.tryReAddToStack(player, itemStack, filledItem, hand);
}
}
return ItemInteractionResult.SUCCESS;
} else if (player.isCrouching()
&& FluidUtil.tryFillContainer(itemStack, fluidHandler, FluidHelpers.BUCKET_VOLUME, player, false).isSuccess()) {
// Move fluid from the tank into the item if sneaking
FluidActionResult result = FluidUtil.tryFillContainer(itemStack, fluidHandler, FluidHelpers.BUCKET_VOLUME, player, true);
if (result.isSuccess()) {
ItemStack filledItem = result.getResult();
if (!player.isCreative()) {
InventoryHelpers.tryReAddToStack(player, itemStack, filledItem, hand);
}
return InteractionResult.SUCCESS;
}
return ItemInteractionResult.SUCCESS;
}
return InteractionResult.PASS;
return ItemInteractionResult.PASS_TO_DEFAULT_BLOCK_INTERACTION;
})
.orElse(InteractionResult.PASS);
.orElse(ItemInteractionResult.PASS_TO_DEFAULT_BLOCK_INTERACTION);
}

// A modified/fixed version of FluidUtil#tryEmptyContainer
// TODO: Remove this once Forge fixes it.
@Nonnull
public static FluidActionResult tryEmptyContainer(@Nonnull ItemStack container, IFluidHandler fluidDestination, int maxAmount, @Nullable Player player, boolean doDrain)
{
ItemStack containerCopy = ItemHandlerHelper.copyStackWithSize(container, 1); // do not modify the input
ItemStack containerCopy = container.copyWithCount(1); // do not modify the input
return FluidUtil.getFluidHandler(containerCopy)
.map(containerFluidHandler -> {
FluidStack transfer = FluidUtil.tryFluidTransfer(fluidDestination, containerFluidHandler, maxAmount, doDrain);
Expand Down Expand Up @@ -294,7 +305,7 @@ public void onRightClick(PlayerInteractEvent.RightClickBlock event) {
if (!event.getItemStack().isEmpty()
&& event.getLevel().getBlockState(event.getPos()).getBlock() == this
&& event.getItemStack().getCapability(Capabilities.FluidHandler.ITEM) != null) {
event.setUseBlock(Event.Result.ALLOW);
event.setUseBlock(TriState.TRUE);
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import net.minecraft.core.BlockPos;
import net.minecraft.core.Direction;
import net.minecraft.core.HolderLookup;
import net.minecraft.nbt.CompoundTag;
import net.minecraft.sounds.SoundEvent;
import net.minecraft.sounds.SoundSource;
Expand Down Expand Up @@ -66,16 +67,16 @@ public int getTransferCooldown() {
}

@Override
public void read(CompoundTag tag) {
super.read(tag);
tank.readFromNBT(tag.getCompound("tank"));
public void read(CompoundTag tag, HolderLookup.Provider provider) {
super.read(tag, provider);
tank.readFromNBT(provider, tag.getCompound("tank"));
}

@Override
public void saveAdditional(CompoundTag tag) {
super.saveAdditional(tag);
public void saveAdditional(CompoundTag tag, HolderLookup.Provider provider) {
super.saveAdditional(tag, provider);
CompoundTag tagTank = new CompoundTag();
tank.writeToNBT(tagTank);
tank.writeToNBT(provider, tagTank);
tag.put("tank", tagTank);
}

Expand Down
Loading

0 comments on commit 61cf625

Please sign in to comment.