mirror of
https://github.com/Ellpeck/ActuallyAdditions.git
synced 2024-11-22 23:28:35 +01:00
Added water bowl
This commit is contained in:
parent
a4c751b47f
commit
c53ea72404
8 changed files with 159 additions and 1 deletions
|
@ -139,6 +139,7 @@ public class CreativeTab extends CreativeTabs{
|
||||||
this.add(InitItems.itemCrateKeeper);
|
this.add(InitItems.itemCrateKeeper);
|
||||||
this.add(InitItems.itemChestToCrateUpgrade);
|
this.add(InitItems.itemChestToCrateUpgrade);
|
||||||
this.add(InitItems.itemSpawnerChanger);
|
this.add(InitItems.itemSpawnerChanger);
|
||||||
|
this.add(InitItems.itemWaterBowl);
|
||||||
|
|
||||||
this.add(InitItems.itemDrill);
|
this.add(InitItems.itemDrill);
|
||||||
this.add(InitItems.itemDrillUpgradeSpeed);
|
this.add(InitItems.itemDrillUpgradeSpeed);
|
||||||
|
|
|
@ -16,7 +16,11 @@ import de.ellpeck.actuallyadditions.mod.items.ItemWingsOfTheBats;
|
||||||
import de.ellpeck.actuallyadditions.mod.items.metalists.TheMiscItems;
|
import de.ellpeck.actuallyadditions.mod.items.metalists.TheMiscItems;
|
||||||
import de.ellpeck.actuallyadditions.mod.misc.WorldData;
|
import de.ellpeck.actuallyadditions.mod.misc.WorldData;
|
||||||
import de.ellpeck.actuallyadditions.mod.util.Util;
|
import de.ellpeck.actuallyadditions.mod.util.Util;
|
||||||
|
import de.ellpeck.actuallyadditions.mod.util.WorldUtil;
|
||||||
import de.ellpeck.actuallyadditions.mod.util.playerdata.PlayerServerData;
|
import de.ellpeck.actuallyadditions.mod.util.playerdata.PlayerServerData;
|
||||||
|
import net.minecraft.block.BlockLiquid;
|
||||||
|
import net.minecraft.block.material.Material;
|
||||||
|
import net.minecraft.block.state.IBlockState;
|
||||||
import net.minecraft.entity.EntityCreature;
|
import net.minecraft.entity.EntityCreature;
|
||||||
import net.minecraft.entity.EntityLivingBase;
|
import net.minecraft.entity.EntityLivingBase;
|
||||||
import net.minecraft.entity.item.EntityItem;
|
import net.minecraft.entity.item.EntityItem;
|
||||||
|
@ -25,12 +29,18 @@ import net.minecraft.entity.passive.EntityBat;
|
||||||
import net.minecraft.entity.passive.EntityOcelot;
|
import net.minecraft.entity.passive.EntityOcelot;
|
||||||
import net.minecraft.entity.player.EntityPlayer;
|
import net.minecraft.entity.player.EntityPlayer;
|
||||||
import net.minecraft.init.Blocks;
|
import net.minecraft.init.Blocks;
|
||||||
|
import net.minecraft.init.Items;
|
||||||
|
import net.minecraft.init.SoundEvents;
|
||||||
import net.minecraft.item.ItemStack;
|
import net.minecraft.item.ItemStack;
|
||||||
import net.minecraft.nbt.NBTTagCompound;
|
import net.minecraft.nbt.NBTTagCompound;
|
||||||
import net.minecraft.nbt.NBTTagList;
|
import net.minecraft.nbt.NBTTagList;
|
||||||
|
import net.minecraft.util.ActionResult;
|
||||||
|
import net.minecraft.util.math.RayTraceResult;
|
||||||
|
import net.minecraftforge.event.ForgeEventFactory;
|
||||||
import net.minecraftforge.event.entity.living.LivingDeathEvent;
|
import net.minecraftforge.event.entity.living.LivingDeathEvent;
|
||||||
import net.minecraftforge.event.entity.living.LivingDropsEvent;
|
import net.minecraftforge.event.entity.living.LivingDropsEvent;
|
||||||
import net.minecraftforge.event.entity.living.LivingEvent.LivingUpdateEvent;
|
import net.minecraftforge.event.entity.living.LivingEvent.LivingUpdateEvent;
|
||||||
|
import net.minecraftforge.event.entity.player.PlayerInteractEvent;
|
||||||
import net.minecraftforge.fml.common.eventhandler.SubscribeEvent;
|
import net.minecraftforge.fml.common.eventhandler.SubscribeEvent;
|
||||||
|
|
||||||
import java.util.UUID;
|
import java.util.UUID;
|
||||||
|
@ -81,6 +91,38 @@ public class EntityLivingEvents{
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@SubscribeEvent
|
||||||
|
public void onPlayerInteractEvent(PlayerInteractEvent event){
|
||||||
|
if(event.getWorld() != null){
|
||||||
|
if(event.getItemStack() != null && event.getItemStack().getItem() == Items.BOWL){
|
||||||
|
RayTraceResult trace = WorldUtil.getNearestBlockWithDefaultReachDistance(event.getWorld(), event.getEntityPlayer(), true, false, false);
|
||||||
|
ActionResult<ItemStack> result = ForgeEventFactory.onBucketUse(event.getEntityPlayer(), event.getWorld(), event.getItemStack(), trace);
|
||||||
|
if(result == null && trace != null && trace.getBlockPos() != null){
|
||||||
|
if(event.getEntityPlayer().canPlayerEdit(trace.getBlockPos().offset(trace.sideHit), trace.sideHit, event.getItemStack())){
|
||||||
|
IBlockState state = event.getWorld().getBlockState(trace.getBlockPos());
|
||||||
|
Material material = state.getMaterial();
|
||||||
|
|
||||||
|
if(material == Material.WATER && state.getValue(BlockLiquid.LEVEL) == 0){
|
||||||
|
event.getEntityPlayer().playSound(SoundEvents.ITEM_BUCKET_FILL, 1.0F, 1.0F);
|
||||||
|
|
||||||
|
if(!event.getWorld().isRemote){
|
||||||
|
event.getWorld().setBlockState(trace.getBlockPos(), Blocks.AIR.getDefaultState(), 11);
|
||||||
|
event.getItemStack().stackSize--;
|
||||||
|
|
||||||
|
ItemStack bowl = new ItemStack(InitItems.itemWaterBowl);
|
||||||
|
if(!event.getEntityPlayer().inventory.addItemStackToInventory(bowl.copy())){
|
||||||
|
EntityItem entityItem = new EntityItem(event.getWorld(), event.getEntityPlayer().posX, event.getEntityPlayer().posY, event.getEntityPlayer().posZ, bowl.copy());
|
||||||
|
entityItem.setPickupDelay(0);
|
||||||
|
event.getWorld().spawnEntityInWorld(entityItem);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
@SubscribeEvent
|
@SubscribeEvent
|
||||||
public void onEntityDropEvent(LivingDropsEvent event){
|
public void onEntityDropEvent(LivingDropsEvent event){
|
||||||
if(event.getEntityLiving().worldObj != null && !event.getEntityLiving().worldObj.isRemote && event.getSource().getEntity() instanceof EntityPlayer){
|
if(event.getEntityLiving().worldObj != null && !event.getEntityLiving().worldObj.isRemote && event.getSource().getEntity() instanceof EntityPlayer){
|
||||||
|
|
|
@ -207,11 +207,14 @@ public class InitItems{
|
||||||
public static Item itemBootsCrystalWhite;
|
public static Item itemBootsCrystalWhite;
|
||||||
public static Item itemPaxelCrystalWhite;
|
public static Item itemPaxelCrystalWhite;
|
||||||
|
|
||||||
|
public static Item itemWaterBowl;
|
||||||
|
|
||||||
public static Item itemRarmorModuleReconstructor;
|
public static Item itemRarmorModuleReconstructor;
|
||||||
|
|
||||||
public static void init(){
|
public static void init(){
|
||||||
ModUtil.LOGGER.info("Initializing Items...");
|
ModUtil.LOGGER.info("Initializing Items...");
|
||||||
|
|
||||||
|
itemWaterBowl = new ItemWaterBowl("itemWaterBowl");
|
||||||
itemSpawnerChanger = new ItemSpawnerChanger("itemSpawnerChanger");
|
itemSpawnerChanger = new ItemSpawnerChanger("itemSpawnerChanger");
|
||||||
itemMisc = new ItemMisc("itemMisc");
|
itemMisc = new ItemMisc("itemMisc");
|
||||||
itemCrateKeeper = new ItemGeneric("itemCrateKeeper");
|
itemCrateKeeper = new ItemGeneric("itemCrateKeeper");
|
||||||
|
|
|
@ -0,0 +1,101 @@
|
||||||
|
/*
|
||||||
|
* This file ("ItemWaterBowl.java") is part of the Actually Additions mod for Minecraft.
|
||||||
|
* It is created and owned by Ellpeck and distributed
|
||||||
|
* under the Actually Additions License to be found at
|
||||||
|
* http://ellpeck.de/actaddlicense
|
||||||
|
* View the source code at https://github.com/Ellpeck/ActuallyAdditions
|
||||||
|
*
|
||||||
|
* © 2015-2016 Ellpeck
|
||||||
|
*/
|
||||||
|
|
||||||
|
package de.ellpeck.actuallyadditions.mod.items;
|
||||||
|
|
||||||
|
import de.ellpeck.actuallyadditions.mod.items.base.ItemBase;
|
||||||
|
import de.ellpeck.actuallyadditions.mod.util.PosUtil;
|
||||||
|
import de.ellpeck.actuallyadditions.mod.util.WorldUtil;
|
||||||
|
import net.minecraft.block.material.Material;
|
||||||
|
import net.minecraft.block.state.IBlockState;
|
||||||
|
import net.minecraft.entity.player.EntityPlayer;
|
||||||
|
import net.minecraft.init.Blocks;
|
||||||
|
import net.minecraft.init.Items;
|
||||||
|
import net.minecraft.init.SoundEvents;
|
||||||
|
import net.minecraft.item.ItemStack;
|
||||||
|
import net.minecraft.util.*;
|
||||||
|
import net.minecraft.util.math.BlockPos;
|
||||||
|
import net.minecraft.util.math.RayTraceResult;
|
||||||
|
import net.minecraft.world.World;
|
||||||
|
import net.minecraftforge.event.ForgeEventFactory;
|
||||||
|
|
||||||
|
public class ItemWaterBowl extends ItemBase{
|
||||||
|
|
||||||
|
public ItemWaterBowl(String name){
|
||||||
|
super(name);
|
||||||
|
this.setMaxStackSize(1);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public ActionResult<ItemStack> onItemRightClick(ItemStack stack, World world, EntityPlayer player, EnumHand hand){
|
||||||
|
RayTraceResult trace = WorldUtil.getNearestBlockWithDefaultReachDistance(world, player);
|
||||||
|
ActionResult<ItemStack> result = ForgeEventFactory.onBucketUse(player, world, stack, trace);
|
||||||
|
if(result != null){
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
|
if(trace == null){
|
||||||
|
return new ActionResult(EnumActionResult.PASS, stack);
|
||||||
|
}
|
||||||
|
else if(trace.typeOfHit != RayTraceResult.Type.BLOCK){
|
||||||
|
return new ActionResult(EnumActionResult.PASS, stack);
|
||||||
|
}
|
||||||
|
else{
|
||||||
|
BlockPos pos = trace.getBlockPos();
|
||||||
|
|
||||||
|
if(!world.isBlockModifiable(player, pos)){
|
||||||
|
return new ActionResult(EnumActionResult.FAIL, stack);
|
||||||
|
}
|
||||||
|
else{
|
||||||
|
BlockPos pos1 = PosUtil.getBlock(pos, world).isReplaceable(world, pos) && trace.sideHit == EnumFacing.UP ? pos : pos.offset(trace.sideHit);
|
||||||
|
|
||||||
|
if(!player.canPlayerEdit(pos1, trace.sideHit, stack)){
|
||||||
|
return new ActionResult(EnumActionResult.FAIL, stack);
|
||||||
|
}
|
||||||
|
else if(this.tryPlaceContainedLiquid(player, world, pos1)){
|
||||||
|
return !player.capabilities.isCreativeMode ? new ActionResult(EnumActionResult.SUCCESS, new ItemStack(Items.BOWL)) : new ActionResult(EnumActionResult.SUCCESS, stack);
|
||||||
|
}
|
||||||
|
else{
|
||||||
|
return new ActionResult(EnumActionResult.FAIL, stack);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public boolean tryPlaceContainedLiquid(EntityPlayer player, World world, BlockPos pos){
|
||||||
|
IBlockState state = world.getBlockState(pos);
|
||||||
|
Material material = state.getMaterial();
|
||||||
|
boolean nonSolid = !material.isSolid();
|
||||||
|
boolean replaceable = state.getBlock().isReplaceable(world, pos);
|
||||||
|
|
||||||
|
if(!world.isAirBlock(pos) && !nonSolid && !replaceable){
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
else{
|
||||||
|
if(world.provider.doesWaterVaporize()){
|
||||||
|
world.playSound(player, pos, SoundEvents.BLOCK_FIRE_EXTINGUISH, SoundCategory.BLOCKS, 0.5F, 2.6F+(world.rand.nextFloat()-world.rand.nextFloat())*0.8F);
|
||||||
|
|
||||||
|
for(int k = 0; k < 8; k++){
|
||||||
|
world.spawnParticle(EnumParticleTypes.SMOKE_LARGE, (double)pos.getX()+Math.random(), (double)pos.getY()+Math.random(), (double)pos.getZ()+Math.random(), 0.0D, 0.0D, 0.0D);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else{
|
||||||
|
if(!world.isRemote && (nonSolid || replaceable) && !material.isLiquid()){
|
||||||
|
world.destroyBlock(pos, true);
|
||||||
|
}
|
||||||
|
|
||||||
|
world.playSound(player, pos, SoundEvents.ITEM_BUCKET_EMPTY, SoundCategory.BLOCKS, 1.0F, 1.0F);
|
||||||
|
world.setBlockState(pos, Blocks.FLOWING_WATER.getDefaultState(), 3);
|
||||||
|
}
|
||||||
|
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
|
@ -295,7 +295,11 @@ public class WorldUtil{
|
||||||
}
|
}
|
||||||
|
|
||||||
public static RayTraceResult getNearestBlockWithDefaultReachDistance(World world, EntityPlayer player){
|
public static RayTraceResult getNearestBlockWithDefaultReachDistance(World world, EntityPlayer player){
|
||||||
return getMovingObjectPosWithReachDistance(world, player, player instanceof EntityPlayerMP ? ((EntityPlayerMP)player).interactionManager.getBlockReachDistance() : 5.0D, false, true, false);
|
return getNearestBlockWithDefaultReachDistance(world, player, false, true, false);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static RayTraceResult getNearestBlockWithDefaultReachDistance(World world, EntityPlayer player, boolean stopOnLiquids, boolean ignoreBlockWithoutBoundingBox, boolean returnLastUncollidableBlock){
|
||||||
|
return getMovingObjectPosWithReachDistance(world, player, player instanceof EntityPlayerMP ? ((EntityPlayerMP)player).interactionManager.getBlockReachDistance() : 5.0D, stopOnLiquids, ignoreBlockWithoutBoundingBox, returnLastUncollidableBlock);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
|
@ -487,6 +487,7 @@ item.actuallyadditions.itemMiscEnderStar.name=Ender Star
|
||||||
item.actuallyadditions.itemSpawnerChanger.name=Spawner Changer
|
item.actuallyadditions.itemSpawnerChanger.name=Spawner Changer
|
||||||
item.actuallyadditions.itemMiscSpawnerShard.name=Spawner Shards
|
item.actuallyadditions.itemMiscSpawnerShard.name=Spawner Shards
|
||||||
item.actuallyadditions.itemMinecartFireworkBox.name=Firework Box Cart
|
item.actuallyadditions.itemMinecartFireworkBox.name=Firework Box Cart
|
||||||
|
item.actuallyadditions.itemWaterBowl.name=Bowl of Water
|
||||||
|
|
||||||
#Tooltips
|
#Tooltips
|
||||||
tooltip.actuallyadditions.onSuffix.desc=On
|
tooltip.actuallyadditions.onSuffix.desc=On
|
||||||
|
|
|
@ -0,0 +1,6 @@
|
||||||
|
{
|
||||||
|
"parent": "actuallyadditions:item/standardItem",
|
||||||
|
"textures": {
|
||||||
|
"layer0": "actuallyadditions:items/itemWaterBowl"
|
||||||
|
}
|
||||||
|
}
|
Binary file not shown.
After Width: | Height: | Size: 300 B |
Loading…
Reference in a new issue