make water bowl not spill when you're standing

Closes #794
This commit is contained in:
Ellpeck 2017-06-16 22:38:09 +02:00
parent 1bae941349
commit 5cb59dbd83

View file

@ -25,6 +25,7 @@ import net.minecraft.init.Blocks;
import net.minecraft.init.Items;
import net.minecraft.init.SoundEvents;
import net.minecraft.item.ItemStack;
import net.minecraft.nbt.NBTTagCompound;
import net.minecraft.util.*;
import net.minecraft.util.math.BlockPos;
import net.minecraft.util.math.RayTraceResult;
@ -122,8 +123,19 @@ public class ItemWaterBowl extends ItemBase{
public void onUpdate(ItemStack stack, World world, Entity entity, int itemSlot, boolean isSelected){
if(!world.isRemote){
if(ConfigBoolValues.WATER_BOWL_LOSS.isEnabled()){
if(world.getTotalWorldTime()%10 == 0 && world.rand.nextFloat() >= 0.5F){
int lastX = 0;
int lastY = 0;
if(stack.hasTagCompound()){
NBTTagCompound compound = stack.getTagCompound();
lastX = compound.getInteger("lastX");
lastY = compound.getInteger("lastY");
}
boolean change = false;
if((lastX != 0 && lastX != (int)entity.posX) || (lastY != 0 && lastY != (int)entity.posY)){
if(!entity.isSneaking()){
if(world.getTotalWorldTime()%10 == 0 && world.rand.nextFloat() >= 0.8F){
if(entity instanceof EntityPlayer){
EntityPlayer player = (EntityPlayer)entity;
if(this.tryPlaceContainedLiquid(player, world, player.getPosition(), true)){
@ -131,10 +143,27 @@ public class ItemWaterBowl extends ItemBase{
}
}
}
change = true;
}
if(change || lastX == 0 || lastY == 0){
if(!stack.hasTagCompound()){
stack.setTagCompound(new NBTTagCompound());
}
NBTTagCompound compound = stack.getTagCompound();
compound.setInteger("lastX", (int)entity.posX);
compound.setInteger("lastY", (int)entity.posY);
}
}
}
}
}
@Override
public boolean shouldCauseReequipAnimation(ItemStack oldStack, ItemStack newStack, boolean slotChanged){
return !ItemStack.areItemsEqual(oldStack, newStack);
}
public boolean tryPlaceContainedLiquid(EntityPlayer player, World world, BlockPos pos, boolean finite){
IBlockState state = world.getBlockState(pos);