Skip to content

Commit

Permalink
Fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
Technici4n committed Dec 11, 2023
1 parent aed6d0b commit 79836c3
Show file tree
Hide file tree
Showing 4 changed files with 31 additions and 15 deletions.
Original file line number Diff line number Diff line change
@@ -1,12 +1,13 @@
--- a/net/minecraft/world/level/block/AbstractCauldronBlock.java
+++ b/net/minecraft/world/level/block/AbstractCauldronBlock.java
@@ -102,4 +_,21 @@
@@ -102,4 +_,22 @@

protected void receiveStalactiteDrip(BlockState p_151975_, Level p_151976_, BlockPos p_151977_, Fluid p_151978_) {
}
+
+ @Override
+ public void onPlace(BlockState p_51978_, Level p_51979_, BlockPos p_51980_, BlockState p_51981_, boolean p_51982_) {
+ super.onPlace(p_51978_, p_51979_, p_51980_, p_51981_, p_51982_);
+ // Neo: Invalidate cauldron capabilities when a cauldron is added
+ if (net.neoforged.neoforge.fluids.CauldronFluidContent.getForBlock(p_51981_.getBlock()) == null) {
+ p_51979_.invalidateCapabilities(p_51980_);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -137,6 +137,9 @@ private BlockCapability(ResourceLocation name, Class<T> typeClass, Class<C> cont
@ApiStatus.Internal
@Nullable
public T getCapability(Level level, BlockPos pos, @Nullable BlockState state, @Nullable BlockEntity blockEntity, C context) {
// Convert pos to immutable, it's easy to forget otherwise
pos = pos.immutable();

// Get block state and block entity if they were not provided
if (blockEntity == null) {
if (state == null)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -108,9 +108,9 @@ public static CauldronFluidContent getForFluid(Fluid fluid) {
public static void init() {
var registerEvent = new RegisterCauldronFluidContentEvent();
// Vanilla registrations
registerEvent.register(Blocks.CAULDRON, Fluids.EMPTY, 1000, null);
registerEvent.register(Blocks.WATER_CAULDRON, Fluids.WATER, 1000, LayeredCauldronBlock.LEVEL);
registerEvent.register(Blocks.LAVA_CAULDRON, Fluids.LAVA, 1000, null);
registerEvent.register(Blocks.CAULDRON, Fluids.EMPTY, FluidType.BUCKET_VOLUME, null);
registerEvent.register(Blocks.WATER_CAULDRON, Fluids.WATER, FluidType.BUCKET_VOLUME, LayeredCauldronBlock.LEVEL);
registerEvent.register(Blocks.LAVA_CAULDRON, Fluids.LAVA, FluidType.BUCKET_VOLUME, null);
// Modded registrations
ModLoader.get().postEvent(registerEvent);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ public class CauldronWrapper implements IFluidHandler {

public CauldronWrapper(Level level, BlockPos pos) {
this.level = level;
this.pos = pos.immutable();
this.pos = pos;
}

@Override
Expand Down Expand Up @@ -95,47 +95,59 @@ public int fill(FluidStack resource, FluidAction action) {
int amountIncrements = insertContent.totalAmount / d;
int levelIncrements = insertContent.maxLevel / d;

int insertedIncrements = Math.min(resource.getAmount() / amountIncrements, (insertContent.maxLevel - currentContent.currentLevel(state)) / levelIncrements);
int currentLevel = currentContent.currentLevel(state);
int insertedIncrements = Math.min(resource.getAmount() / amountIncrements, (insertContent.maxLevel - currentLevel) / levelIncrements);
if (insertedIncrements > 0) {
updateLevel(insertContent, currentContent.currentLevel(state) + insertedIncrements * levelIncrements, action);
updateLevel(insertContent, currentLevel + insertedIncrements * levelIncrements, action);
}

return insertedIncrements * amountIncrements;
}

@Override
public FluidStack drain(FluidStack resource, FluidAction action) {
FluidStack current = getFluidInTank(0);
if (current.isFluidEqual(resource) && Objects.equals(current.getTag(), resource.getTag())) {
return drain(resource.getAmount(), action);
if (resource.isEmpty()) {
return FluidStack.EMPTY;
}

BlockState state = level.getBlockState(pos);
if (getContent(state).fluid == resource.getFluid() && null == resource.getTag()) {
return drain(state, resource.getAmount(), action);
} else {
return FluidStack.EMPTY;
}
}


@Override
public FluidStack drain(int maxDrain, FluidAction action) {
if (maxDrain <= 0) {
return FluidStack.EMPTY;
}

BlockState state = level.getBlockState(pos);
return drain(level.getBlockState(pos), maxDrain, action);
}

private FluidStack drain(BlockState state, int maxDrain, FluidAction action) {
CauldronFluidContent content = getContent(state);

// We can only extract increments based on the GCD between the number of levels and the total amount.
int d = IntMath.gcd(content.maxLevel, content.totalAmount);
int amountIncrements = content.totalAmount / d;
int levelIncrements = content.maxLevel / d;

int extractedIncrements = Math.min(maxDrain / amountIncrements, content.currentLevel(state) / levelIncrements);
int currentLevel = content.currentLevel(state);
int extractedIncrements = Math.min(maxDrain / amountIncrements, currentLevel / levelIncrements);
if (extractedIncrements > 0) {
int newLevel = content.currentLevel(state) - extractedIncrements * levelIncrements;
int newLevel = currentLevel - extractedIncrements * levelIncrements;
if (newLevel == 0) {
// Fully extract -> back to empty cauldron
level.setBlockAndUpdate(pos, Blocks.CAULDRON.defaultBlockState());
if (action.execute()) {
level.setBlockAndUpdate(pos, Blocks.CAULDRON.defaultBlockState());
}
} else {
// Otherwise just decrease levels
updateLevel(content, content.currentLevel(state) - extractedIncrements * levelIncrements, action);
updateLevel(content, newLevel, action);
}
}

Expand Down

0 comments on commit 79836c3

Please sign in to comment.