From 348086dc624e3741fbefbf3eb69fe61c4d22b03d Mon Sep 17 00:00:00 2001 From: Ellpeck Date: Sun, 28 May 2017 01:49:57 +0200 Subject: [PATCH] made the water bowl spill Closes #785 --- .../mod/config/values/ConfigBoolValues.java | 1 + .../mod/items/ItemWaterBowl.java | 33 +++++++++++++++++-- .../assets/actuallyadditions/lang/en_US.lang | 2 +- 3 files changed, 32 insertions(+), 4 deletions(-) diff --git a/src/main/java/de/ellpeck/actuallyadditions/mod/config/values/ConfigBoolValues.java b/src/main/java/de/ellpeck/actuallyadditions/mod/config/values/ConfigBoolValues.java index a55e10542..5d864d84e 100644 --- a/src/main/java/de/ellpeck/actuallyadditions/mod/config/values/ConfigBoolValues.java +++ b/src/main/java/de/ellpeck/actuallyadditions/mod/config/values/ConfigBoolValues.java @@ -48,6 +48,7 @@ public enum ConfigBoolValues{ GEN_LUSH_CAVES("Generate Lush Caves", ConfigCategories.WORLD_GEN, true, "Should caves with trees and grass randomly generate underground?"), WATER_BOWL("Water Bowl", ConfigCategories.OTHER, true, "Should right-clicking a bowl on water blocks create a water bowl?"), + WATER_BOWL_LOSS("Water Bowl Spilling", ConfigCategories.OTHER, true, "Should the water bowl spill if you don't sneak while using it?"), TINY_COAL_STUFF("Tiny Coal", ConfigCategories.OTHER, true, "Should Tiny Coal and Tiny Charcoal be craftable"), LASER_RELAY_LOSS("Laser Relay Energy Loss", ConfigCategories.MACHINE_VALUES, true, "If Energy Laser Relays should have energy loss"), diff --git a/src/main/java/de/ellpeck/actuallyadditions/mod/items/ItemWaterBowl.java b/src/main/java/de/ellpeck/actuallyadditions/mod/items/ItemWaterBowl.java index 101d186c0..a8a3849ee 100644 --- a/src/main/java/de/ellpeck/actuallyadditions/mod/items/ItemWaterBowl.java +++ b/src/main/java/de/ellpeck/actuallyadditions/mod/items/ItemWaterBowl.java @@ -18,6 +18,7 @@ import net.minecraft.block.Block; import net.minecraft.block.BlockLiquid; import net.minecraft.block.material.Material; import net.minecraft.block.state.IBlockState; +import net.minecraft.entity.Entity; import net.minecraft.entity.item.EntityItem; import net.minecraft.entity.player.EntityPlayer; import net.minecraft.init.Blocks; @@ -107,7 +108,7 @@ public class ItemWaterBowl extends ItemBase{ if(!player.canPlayerEdit(pos1, trace.sideHit, stack)){ return new ActionResult(EnumActionResult.FAIL, stack); } - else if(this.tryPlaceContainedLiquid(player, world, pos1)){ + else if(this.tryPlaceContainedLiquid(player, world, pos1, false)){ return !player.capabilities.isCreativeMode ? new ActionResult(EnumActionResult.SUCCESS, new ItemStack(Items.BOWL)) : new ActionResult(EnumActionResult.SUCCESS, stack); } else{ @@ -117,7 +118,25 @@ public class ItemWaterBowl extends ItemBase{ } } - public boolean tryPlaceContainedLiquid(EntityPlayer player, World world, BlockPos pos){ + @Override + public void onUpdate(ItemStack stack, World world, Entity entity, int itemSlot, boolean isSelected){ + if(!world.isRemote){ + if(ConfigBoolValues.WATER_BOWL_LOSS.isEnabled()){ + 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)){ + player.inventory.setInventorySlotContents(itemSlot, new ItemStack(Items.BOWL)); + } + } + } + } + } + } + } + + public boolean tryPlaceContainedLiquid(EntityPlayer player, World world, BlockPos pos, boolean finite){ IBlockState state = world.getBlockState(pos); Material material = state.getMaterial(); boolean nonSolid = !material.isSolid(); @@ -140,7 +159,15 @@ public class ItemWaterBowl extends ItemBase{ } world.playSound(player, pos, SoundEvents.ITEM_BUCKET_EMPTY, SoundCategory.BLOCKS, 1.0F, 1.0F); - world.setBlockState(pos, Blocks.FLOWING_WATER.getDefaultState(), 3); + + IBlockState placeState; + if(finite){ + placeState = Blocks.FLOWING_WATER.getDefaultState(); + } + else{ + placeState = Blocks.FLOWING_WATER.getDefaultState(); + } + world.setBlockState(pos, placeState, 3); } return true; diff --git a/src/main/resources/assets/actuallyadditions/lang/en_US.lang b/src/main/resources/assets/actuallyadditions/lang/en_US.lang index 82feecea4..d4ada89b0 100644 --- a/src/main/resources/assets/actuallyadditions/lang/en_US.lang +++ b/src/main/resources/assets/actuallyadditions/lang/en_US.lang @@ -1147,7 +1147,7 @@ booklet.actuallyadditions.chapter.lushCaves.name=Lush Caves booklet.actuallyadditions.chapter.lushCaves.text.1=If you have ever done any Cave exploration, you will have probably noticed some caves that have trees and grass inside of them. These can be found at any height underground all over the world, and they can be very valuable when needing wood for torches and tools at some point. Sometimes, there might also be some treasure hidden in the trees! If you didn't ever see one before, look on the next page for a picture! booklet.actuallyadditions.chapter.waterBowl.name=Bowl of Water -booklet.actuallyadditions.chapter.waterBowl.text.1=The Bowl of Water can be obtained by right-cliking a bowl on water anywhere in the world. When the Bowl of Water is then right-clicked onto a block, the water will be placed, much like a Bucket. This can be used, for example, for early game farms. +booklet.actuallyadditions.chapter.waterBowl.text.1=The Bowl of Water can be obtained by right-cliking a bowl on water anywhere in the world. When the Bowl of Water is then right-clicked onto a block, the water will be placed, much like a Bucket. This can be used, for example, for early game farms. If you don't move around carefully enough, however, the water might spill out of it! booklet.actuallyadditions.chapter.playerInterface.name=Player Interface booklet.actuallyadditions.chapter.playerInterface.text.1=The Player Interface works in a similar way to the Phantomface, except it is connected to a player instead of a block, and the connection is established by placing it down. When inputting items, they will move to the player's inventory. Also, when inputting CF, it will charge the items in the player's inventory. It has a default range of blocks, however, it can be expanded by placing up to 3 Phantom Boosters on top of it.