Skip to content

Commit

Permalink
RC#2 - fix dupe fluids in tank
Browse files Browse the repository at this point in the history
  • Loading branch information
aagrishankov committed Sep 20, 2020
1 parent 550442b commit 66ce5b4
Showing 1 changed file with 24 additions and 21 deletions.
45 changes: 24 additions & 21 deletions src/main/scala/extracells/block/BlockCertusTank.java
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ public TileEntity createNewTileEntity(World var1, int var2) {
public ItemStack getDropWithNBT(World world, int x, int y, int z) {
NBTTagCompound tileEntity = new NBTTagCompound();
TileEntity worldTE = world.getTileEntity(x, y, z);
if (worldTE instanceof TileEntityCertusTank) {
if (worldTE != null && worldTE instanceof TileEntityCertusTank) {

This comment has been minimized.

Copy link
@Sirse

Sirse Sep 21, 2020

null априори не может быть инстансом какого-либо класса, поэтому nullcheck перед instanceof бесполезен :)

ItemStack dropStack = new ItemStack(
BlockEnum.CERTUSTANK.getBlock(), 1);

Expand All @@ -73,15 +73,15 @@ public ItemStack getDropWithNBT(World world, int x, int y, int z) {
@Override
public IIcon getIcon(int side, int b) {
switch (b) {
case 1:
return this.sideTopIcon;
case 2:
return this.sideBottomIcon;
case 3:
return this.sideMiddleIcon;
default:
return side == 0 ? this.bottomIcon : side == 1 ? this.topIcon
: this.sideIcon;
case 1:
return this.sideTopIcon;
case 2:
return this.sideBottomIcon;
case 3:
return this.sideMiddleIcon;
default:
return side == 0 ? this.bottomIcon : side == 1 ? this.topIcon
: this.sideIcon;
}
}

Expand Down Expand Up @@ -117,15 +117,15 @@ public boolean isOpaqueCube() {

@Override
public boolean onBlockActivated(World worldObj, int x, int y, int z,
EntityPlayer entityplayer, int blockID, float offsetX,
float offsetY, float offsetZ) {
EntityPlayer entityplayer, int blockID, float offsetX,
float offsetY, float offsetZ) {
ItemStack current = entityplayer.inventory.getCurrentItem();

if (entityplayer.isSneaking() && current != null) {
try {
if (current.getItem() instanceof IToolWrench
&& ((IToolWrench) current.getItem()).canWrench(
entityplayer, x, y, z)) {
entityplayer, x, y, z)) {
dropBlockAsItem(worldObj, x, y, z,
getDropWithNBT(worldObj, x, y, z));
worldObj.setBlockToAir(x, y, z);
Expand All @@ -138,7 +138,7 @@ public boolean onBlockActivated(World worldObj, int x, int y, int z,
}
if (current.getItem() instanceof IAEWrench
&& ((IAEWrench) current.getItem()).canWrench(current,
entityplayer, x, y, z)) {
entityplayer, x, y, z)) {
dropBlockAsItem(worldObj, x, y, z,
getDropWithNBT(worldObj, x, y, z));
worldObj.setBlockToAir(x, y, z);
Expand Down Expand Up @@ -196,14 +196,17 @@ public boolean onBlockActivated(World worldObj, int x, int y, int z,

if (liquid != null) {
if (!entityplayer.capabilities.isCreativeMode) {
if (current.stackSize == 1) {
entityplayer.inventory.mainInventory[entityplayer.inventory.currentItem] = filled;
if (current.stackSize > 1) {
if (!entityplayer.inventory.addItemStackToInventory(filled)) {
return false;
} else {
entityplayer.inventory.mainInventory[entityplayer.inventory.currentItem].stackSize -= 1;
}
} else {
entityplayer.inventory.mainInventory[entityplayer.inventory.currentItem].stackSize--;
if (!entityplayer.inventory.addItemStackToInventory(filled))
entityplayer.entityDropItem(filled, 0);
entityplayer.inventory.mainInventory[entityplayer.inventory.currentItem] = filled;
}
}
tank.drain(ForgeDirection.UNKNOWN, liquid.amount, true);
return true;
}
}
Expand All @@ -214,7 +217,7 @@ public boolean onBlockActivated(World worldObj, int x, int y, int z,

@Override
public void onNeighborBlockChange(World world, int x, int y, int z,
Block neighborBlock) {
Block neighborBlock) {
if (!world.isRemote) {

ChannelHandler.sendPacketToAllPlayers(world.getTileEntity(x, y, z).getDescriptionPacket(), world);
Expand All @@ -236,4 +239,4 @@ public void registerBlockIcons(IIconRegister iconregister) {
public boolean renderAsNormalBlock() {
return false;
}
}
}

0 comments on commit 66ce5b4

Please sign in to comment.