-
Notifications
You must be signed in to change notification settings - Fork 9
refactor Drums, #55
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Draft
Spicierspace153
wants to merge
21
commits into
master
Choose a base branch
from
kath/fix-drums
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Draft
refactor Drums, #55
Changes from 4 commits
Commits
Show all changes
21 commits
Select commit
Hold shift + click to select a range
9244473
actually give the bucket back on both sides
Spicierspace153 506f295
refactor BlockDrum.java#onBlockActivated to actually work as intended
Spicierspace153 f6ae2c7
cleanup and finish
Spicierspace153 b3d0fb4
chat components
Spicierspace153 9387f06
this appears to be wrong but. ahhhhhhhhhhhh
Spicierspace153 4e998fc
Spotless apply for branch kath/fix-drums for #55 (#56)
github-actions[bot] 9bb2f50
works now :wowa:
Spicierspace153 07168c4
Merge branch 'kath/fix-drums' of github.com:GTNewHorizons/UtilitiesIn…
Spicierspace153 a375e4f
cut off one head two grow back
Spicierspace153 4f300a2
Spotless apply for branch kath/fix-drums for #55 (#57)
github-actions[bot] a0ac1f3
Merge branch 'master' into kath/fix-drums
Spicierspace153 cebe461
halfway ? done
Spicierspace153 8e67beb
Spotless apply for branch kath/fix-drums for #55 (#99)
github-actions[bot] 2479af4
other half
Spicierspace153 8b936a8
spotless but i missed a case
Spicierspace153 8a03f54
im a bad programmer
Spicierspace153 5745589
im a bad programmer
Spicierspace153 a5a0641
address comments
Spicierspace153 89550df
address comments
Spicierspace153 56ce020
oops all issues
Spicierspace153 50a59c6
ij should commit htis
Spicierspace153 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Some comments aren't visible on the classic Files Changed page.
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -9,16 +9,17 @@ | |
| import net.minecraft.entity.EntityLivingBase; | ||
| import net.minecraft.entity.item.EntityItem; | ||
| import net.minecraft.entity.player.EntityPlayer; | ||
| import net.minecraft.item.Item; | ||
| import net.minecraft.item.ItemBlock; | ||
| import net.minecraft.item.ItemStack; | ||
| import net.minecraft.nbt.NBTTagCompound; | ||
| import net.minecraft.tileentity.TileEntity; | ||
| import net.minecraft.util.ChatComponentTranslation; | ||
| import net.minecraft.util.StatCollector; | ||
| import net.minecraft.world.World; | ||
| import net.minecraftforge.common.util.ForgeDirection; | ||
| import net.minecraftforge.fluids.FluidContainerRegistry; | ||
| import net.minecraftforge.fluids.FluidStack; | ||
| import net.minecraftforge.fluids.FluidTank; | ||
| import net.minecraftforge.fluids.IFluidContainerItem; | ||
|
|
||
| import com.cleanroommc.modularui.utils.NumberFormat; | ||
|
|
@@ -51,48 +52,117 @@ 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. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This method is HUGE and should be divided into smaller parts. @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;
} |
||
| float hitY, float hitZ) { | ||
| if (world.isRemote) { | ||
| return true; | ||
|
|
||
| ItemStack heldItem = player.getCurrentEquippedItem(); | ||
| if (heldItem == null) { | ||
| return false; | ||
Spicierspace153 marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| } | ||
|
|
||
| TileEntity tile = world.getTileEntity(x, y, z); | ||
| if (tile instanceof TileEntityDrum drum) { | ||
| ItemStack heldItem = player.getCurrentEquippedItem(); | ||
| FluidStack heldFluid = FluidContainerRegistry.getFluidForFilledItem(heldItem); | ||
| if (!(tile instanceof TileEntityDrum drum)) { | ||
| return false; | ||
| } | ||
|
|
||
| if (FluidContainerRegistry.isFilledContainer(heldItem)) { | ||
| FluidTank tank = drum.tank; | ||
|
|
||
| if (drum.tank.getFluid() == null) { | ||
| drum.setFluid(new FluidStack(heldFluid.getFluid(), 0)); | ||
| } | ||
| if (FluidContainerRegistry.isEmptyContainer(heldItem)) { | ||
| FluidStack stored = tank.getFluid(); | ||
| if (stored == null || stored.amount <= 0) { | ||
| return false; | ||
Spicierspace153 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| } | ||
|
|
||
| FluidStack available = new FluidStack(stored.getFluid(), Math.min(1000, stored.amount)); | ||
Spicierspace153 marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| ItemStack filledContainer = FluidContainerRegistry.fillFluidContainer(available, heldItem); | ||
| if (filledContainer == null) { | ||
| return false; | ||
| } | ||
|
|
||
| if (drum.fill(ForgeDirection.UP, heldFluid, true) == heldFluid.amount) { | ||
| FluidContainerRegistry.drainFluidContainer(heldItem); | ||
| ItemStack emptyContainer = FluidContainerRegistry.drainFluidContainer(heldItem); | ||
| emptyContainer.stackSize = 1; | ||
| FluidStack fluidInContainer = FluidContainerRegistry.getFluidForFilledItem(filledContainer); | ||
| if (fluidInContainer == null) return false; | ||
|
|
||
| tank.drain(fluidInContainer.amount, true); | ||
|
|
||
| if (!player.capabilities.isCreativeMode) { | ||
| if (heldItem.stackSize == 1) { | ||
| player.inventory.setInventorySlotContents(player.inventory.currentItem, filledContainer); | ||
| } else { | ||
| heldItem.stackSize--; | ||
| player.inventory.setInventorySlotContents(player.inventory.currentItem, heldItem); | ||
| player.inventory.addItemStackToInventory(emptyContainer); | ||
|
|
||
| player.addChatMessage( | ||
| new ChatComponentTranslation( | ||
| "tile.drum.chat.filled", | ||
| drum.tank.getFluid() | ||
| .getLocalizedName(), | ||
| NumberFormat.DEFAULT.format(drum.tank.getFluid().amount))); | ||
| if (!player.inventory.addItemStackToInventory(filledContainer)) { | ||
| player.dropPlayerItemWithRandomChoice(filledContainer, false); | ||
| } | ||
|
|
||
| } | ||
| if (!world.isRemote) { | ||
| if (drum.tank.getFluid() == null) { | ||
| player.addChatMessage(new ChatComponentTranslation("tile.drum.chat.empty")); | ||
Spicierspace153 marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| } else { | ||
| player.addChatMessage( | ||
| new ChatComponentTranslation( | ||
| "tile.drum.chat.filled", | ||
| drum.tank.getFluid() | ||
| .getLocalizedName(), | ||
| NumberFormat.DEFAULT.format(drum.tank.getFluid().amount))); | ||
| } | ||
| } | ||
| } else if (FluidContainerRegistry.isEmptyContainer(heldItem)) { | ||
| if (drum.tank.getFluid() != null) { | ||
| FluidStack drainedFluid = drum.drain(ForgeDirection.UP, 1000, true); | ||
|
|
||
| if (drainedFluid.amount == 1000) { | ||
| ItemStack filledContainer = FluidContainerRegistry.fillFluidContainer(drainedFluid, heldItem); | ||
| player.inventory.setInventorySlotContents(player.inventory.currentItem, filledContainer); | ||
| player.inventory.markDirty(); | ||
| } | ||
|
|
||
| drum.markDirty(); | ||
| world.markBlockForUpdate(x, y, z); | ||
| return true; | ||
| } | ||
|
|
||
| FluidStack fluid = null; | ||
| Item item = heldItem.getItem(); | ||
|
|
||
| if (item instanceof IFluidContainerItem fluidContainer) { | ||
| fluid = fluidContainer.getFluid(heldItem); | ||
| } else { | ||
| fluid = FluidContainerRegistry.getFluidForFilledItem(heldItem); | ||
| } | ||
|
|
||
| if (fluid != null && fluid.getFluid() != null) { | ||
| int filled = tank.fill(fluid, true); | ||
| if (filled > 0) { | ||
| ItemStack emptyContainer = null; | ||
|
|
||
| if (item instanceof IFluidContainerItem fluidContainer) { | ||
| fluidContainer.drain(heldItem, filled, true); | ||
Spicierspace153 marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| emptyContainer = heldItem; | ||
| } else { | ||
| emptyContainer = FluidContainerRegistry.drainFluidContainer(heldItem); | ||
| } | ||
|
|
||
| if (!player.capabilities.isCreativeMode) { | ||
| if (heldItem.stackSize == 1) { | ||
| player.inventory.setInventorySlotContents(player.inventory.currentItem, emptyContainer); | ||
| } else { | ||
| heldItem.stackSize--; | ||
| if (emptyContainer != null && !player.inventory.addItemStackToInventory(emptyContainer)) { | ||
| player.dropPlayerItemWithRandomChoice(emptyContainer, false); | ||
| } | ||
|
|
||
| } | ||
| if (world.isRemote) { | ||
| player.addChatMessage( | ||
| new ChatComponentTranslation( | ||
| "tile.drum.chat.filled", | ||
| drum.tank.getFluid() | ||
| .getLocalizedName(), | ||
| NumberFormat.DEFAULT.format(drum.tank.getFluid().amount))); | ||
| } | ||
|
|
||
| player.inventory.markDirty(); | ||
| } | ||
|
|
||
| drum.markDirty(); | ||
| world.markBlockForUpdate(x, y, z); | ||
| return true; | ||
| } | ||
| } | ||
|
|
||
| return true; | ||
| return false; | ||
| } | ||
|
|
||
| @Override | ||
|
|
||
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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