Conversation
src/main/java/com/fouristhenumber/utilitiesinexcess/common/blocks/BlockDrum.java
Outdated
Show resolved
Hide resolved
src/main/java/com/fouristhenumber/utilitiesinexcess/common/blocks/BlockDrum.java
Outdated
Show resolved
Hide resolved
src/main/java/com/fouristhenumber/utilitiesinexcess/common/blocks/BlockDrum.java
Outdated
Show resolved
Hide resolved
src/main/java/com/fouristhenumber/utilitiesinexcess/common/blocks/BlockDrum.java
Outdated
Show resolved
Hide resolved
src/main/java/com/fouristhenumber/utilitiesinexcess/common/blocks/BlockDrum.java
Outdated
Show resolved
Hide resolved
|
Love the IFluidContainerItem support, but... I tried to fill a drum while holding a stack of Certus Quartz Tanks with 16000L water and they all just gone tank.-.drum.mp4 |
…Excess into kath/fix-drums
8e67beb to
8b936a8
Compare
SuperSoupr
left a comment
There was a problem hiding this comment.
Mostly nits but some fixes needed as well, otherwise LGTM 👍
src/main/java/com/fouristhenumber/utilitiesinexcess/common/blocks/BlockDrum.java
Outdated
Show resolved
Hide resolved
src/main/java/com/fouristhenumber/utilitiesinexcess/common/blocks/BlockDrum.java
Outdated
Show resolved
Hide resolved
src/main/java/com/fouristhenumber/utilitiesinexcess/common/blocks/BlockDrum.java
Outdated
Show resolved
Hide resolved
src/main/java/com/fouristhenumber/utilitiesinexcess/common/blocks/BlockDrum.java
Outdated
Show resolved
Hide resolved
src/main/java/com/fouristhenumber/utilitiesinexcess/common/blocks/BlockDrum.java
Outdated
Show resolved
Hide resolved
src/main/java/com/fouristhenumber/utilitiesinexcess/common/blocks/BlockDrum.java
Outdated
Show resolved
Hide resolved
src/main/java/com/fouristhenumber/utilitiesinexcess/common/blocks/BlockDrum.java
Outdated
Show resolved
Hide resolved
src/main/java/com/fouristhenumber/utilitiesinexcess/common/tileentities/TileEntityDrum.java
Outdated
Show resolved
Hide resolved
| public class DrumConfig { | ||
|
|
||
| @Config.DefaultBoolean(true) | ||
| @Config.Comment("Change it to MB vs L's") | ||
| public static boolean unitToDisplay; | ||
|
|
||
| } |
There was a problem hiding this comment.
Sorry I didn't think of this before but can you add a config for the size of the regular and bedrockium drums?
a69c1e1 to
89550df
Compare
src/main/java/com/fouristhenumber/utilitiesinexcess/common/blocks/BlockDrum.java
Show resolved
Hide resolved
| player.addChatComponentMessage( | ||
| new ChatComponentTranslation( | ||
| "%s %s", | ||
| NumberFormat.DEFAULT.format(drumTank.getFluidAmount()), | ||
| DrumConfig.unitToDisplay ? "mB" : "L")); |
src/main/java/com/fouristhenumber/utilitiesinexcess/common/blocks/BlockDrum.java
Show resolved
Hide resolved
There was a problem hiding this comment.
I don't know how to fix this, but there is a desync between the client and server here. The client doesn't get told how full the drum is when it's loaded. Not sure of how impactful this is but the onBlockActivated logic is wrong on the client because of it
| @@ -51,50 +55,205 @@ public boolean hasTileEntity(int metadata) { | |||
| @Override | |||
| public boolean onBlockActivated(World world, int x, int y, int z, EntityPlayer player, int side, float hitX, | |||
There was a problem hiding this comment.
This method is HUGE and should be divided into smaller parts.
Here is how I would refactor the current code to improve readability (logic kept the same):
@Override
public boolean onBlockActivated(
World world, int x, int y, int z,
EntityPlayer player, int side,
float hitX, float hitY, float hitZ
) {
TileEntity te = world.getTileEntity(x, y, z);
if (!(te instanceof TileEntityDrum drum)) {
return false;
}
FluidTank tank = drum.tank;
FluidStack fluid = tank.getFluid();
ItemStack held = player.inventory.getCurrentItem();
if (held == null) {
return handleEmptyHand(world, player, tank);
}
Item item = held.getItem();
return fluid == null
? handleEmptyDrum(world, x, y, z, player, tank, held, item)
: handleFilledDrum(world, x, y, z, player, tank, fluid, held, item);
}
private boolean handleEmptyHand(World world, EntityPlayer player, FluidTank tank) {
if (world.isRemote) {
return false;
}
player.addChatComponentMessage(
new ChatComponentTranslation(
"%s %s",
NumberFormat.DEFAULT.format(tank.getFluidAmount()),
DrumConfig.unitToDisplay ? "mB" : "L"
)
);
return true;
}
private boolean handleEmptyDrum(
World world, int x, int y, int z,
EntityPlayer player,
FluidTank tank,
ItemStack stack,
Item item
) {
if (item instanceof IFluidContainerItem container) {
return fillDrumFromContainer(world, x, y, z, player, tank, stack, container);
}
if (item instanceof ItemBucket) {
return fillDrumFromBucket(world, x, y, z, player, tank, stack);
}
return true;
}
private boolean fillDrumFromContainer(
World world, int x, int y, int z,
EntityPlayer player,
FluidTank tank,
ItemStack stack,
IFluidContainerItem container
) {
FluidStack fluid = container.getFluid(stack);
if (fluid == null) {
return true;
}
int fillAmount = Math.min(tank.getCapacity(), fluid.amount);
FluidStack toFill = fluid.copy();
toFill.amount = fillAmount;
int filled = tank.fill(toFill, true);
container.drain(stack, filled, true);
if (!world.isRemote) {
player.addChatComponentMessage(
new ChatComponentTranslation(
"message.drum.filled",
filled,
fluid.getLocalizedName()
)
);
}
world.markBlockForUpdate(x, y, z);
return true;
}
private boolean fillDrumFromBucket(
World world, int x, int y, int z,
EntityPlayer player,
FluidTank tank,
ItemStack stack
) {
FluidStack bucketFluid = FluidContainerRegistry.getFluidForFilledItem(stack);
if (bucketFluid == null) {
return false;
}
int filled = tank.fill(bucketFluid.copy(), true);
if (filled <= 0) {
return false;
}
if (!world.isRemote) {
consumeItemStack(player, stack, new ItemStack(Items.bucket));
player.addChatComponentMessage(
new ChatComponentTranslation(
"message.drum.filled",
filled,
bucketFluid.getLocalizedName()
)
);
}
world.markBlockForUpdate(x, y, z);
return true;
}
private boolean handleFilledDrum(
World world, int x, int y, int z,
EntityPlayer player,
FluidTank tank,
FluidStack fluid,
ItemStack stack,
Item item
) {
if (item instanceof IFluidContainerItem container) {
return drainDrumIntoContainer(world, x, y, z, player, tank, fluid, stack, container);
}
if (item instanceof ItemBucket) {
return handleBucketDrain(world, x, y, z, player, tank, fluid, stack);
}
return true;
}| return true; | ||
| } | ||
|
|
||
| private static void consumeItemStack(EntityPlayer player, ItemStack hand, ItemStack result) { |
There was a problem hiding this comment.
nesting could be reduced here
private static void consumeItemStack(
EntityPlayer player,
ItemStack hand,
ItemStack result
) {
InventoryPlayer inv = player.inventory;
if (hand.stackSize == 1) {
inv.setInventorySlotContents(inv.currentItem, result);
finalizeInventoryChange(player);
return;
}
hand.stackSize--;
if (!inv.addItemStackToInventory(result)) {
player.dropPlayerItemWithRandomChoice(result, false);
}
finalizeInventoryChange(player);
}
private static void finalizeInventoryChange(EntityPlayer player) {
player.inventoryContainer.detectAndSendChanges();
player.inventory.markDirty();
}
Drums w/ buckets now work as intended in every single way