Made it so that buckets would work on tanks and fluids in tanks would have textures

This commit is contained in:
SoundLogic 2014-08-15 19:26:54 -05:00
parent 9e1ef8dd5c
commit 956ba866db
5 changed files with 72 additions and 7 deletions

View file

@ -1,17 +1,31 @@
package biomesoplenty.common.eventhandler.misc;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.init.Items;
import net.minecraft.item.ItemStack;
import net.minecraft.tileentity.TileEntity;
import net.minecraft.world.World;
import net.minecraftforge.client.event.TextureStitchEvent;
import net.minecraftforge.common.util.ForgeDirection;
import net.minecraftforge.event.entity.player.FillBucketEvent;
import net.minecraftforge.event.entity.player.PlayerInteractEvent;
import net.minecraftforge.event.entity.player.PlayerUseItemEvent;
import net.minecraftforge.fluids.Fluid;
import net.minecraftforge.fluids.FluidContainerRegistry;
import net.minecraftforge.fluids.FluidRegistry;
import net.minecraftforge.fluids.FluidStack;
import net.minecraftforge.fluids.IFluidHandler;
import biomesoplenty.api.content.BOPCBlocks;
import biomesoplenty.api.content.BOPCFluids;
import biomesoplenty.api.content.BOPCItems;
import biomesoplenty.common.fluids.blocks.BlockBloodFluid;
import biomesoplenty.common.fluids.blocks.BlockHoneyFluid;
import biomesoplenty.common.fluids.blocks.BlockPoisonFluid;
import biomesoplenty.common.items.ItemBOPBucket;
import cpw.mods.fml.common.eventhandler.Event.Result;
import cpw.mods.fml.common.eventhandler.SubscribeEvent;
import cpw.mods.fml.relauncher.Side;
import cpw.mods.fml.relauncher.SideOnly;
public class BucketEventHandler
{
@ -29,10 +43,34 @@ public class BucketEventHandler
Fluid fluid = FluidRegistry.lookupFluidForBlock(world.getBlock(x, y, z));
if (fluid == null)
{
TileEntity tile=event.world.getTileEntity(x, y, z);
if(tile != null && tile instanceof IFluidHandler)
{
IFluidHandler tank = (IFluidHandler)tile;
FluidStack fluidStack = tank.drain(ForgeDirection.UNKNOWN, FluidContainerRegistry.BUCKET_VOLUME, false);
if(fluidStack==null)
return;
if(fluidStack.amount < FluidContainerRegistry.BUCKET_VOLUME)
return;
if(fluidStack.getFluid()==BOPCFluids.blood || fluidStack.getFluid()==BOPCFluids.honey || fluidStack.getFluid()==BOPCFluids.poison)
{
tank.drain(ForgeDirection.UNKNOWN, FluidContainerRegistry.BUCKET_VOLUME , true);
ItemStack filled=new ItemStack(BOPCItems.bopBucket);
((ItemBOPBucket)BOPCItems.bopBucket).fill(filled, fluidStack, true);
event.result=filled;
event.setResult(Result.ALLOW);
return;
}
}
}
if (fluid != null)
{
if ((fluid == BOPCFluids.poison && world.getBlockMetadata(x, y, z) == 0) || (fluid == BOPCFluids.blood && world.getBlockMetadata(x, y, z) == 0) || (fluid == BOPCFluids.honey && world.getBlockMetadata(x, y, z) == 7))
{
bopBucket.fill(bopBucketStack, new FluidStack(fluid, FluidContainerRegistry.BUCKET_VOLUME), true);
world.setBlockToAir(x, y, z);
@ -42,4 +80,13 @@ public class BucketEventHandler
}
}
}
}
@SubscribeEvent
@SideOnly(Side.CLIENT)
public void textureHook(TextureStitchEvent.Post event) {
if (event.map.getTextureType() == 0) {
BOPCFluids.blood.setIcons(BlockBloodFluid.bloodStillIcon, BlockBloodFluid.bloodFlowingIcon);
BOPCFluids.honey.setIcons(BlockHoneyFluid.honeyStillIcon, BlockHoneyFluid.honeyFlowingIcon);
BOPCFluids.poison.setIcons(BlockPoisonFluid.liquidPoisonStillIcon, BlockPoisonFluid.liquidPoisonFlowingIcon);
}
}}

View file

@ -8,7 +8,5 @@ public class BloodFluid extends Fluid
public BloodFluid(String fluidName)
{
super(fluidName);
this.setIcons(BlockBloodFluid.bloodStillIcon, BlockBloodFluid.bloodFlowingIcon);
}
}

View file

@ -1,6 +1,8 @@
package biomesoplenty.common.fluids;
import net.minecraft.block.BlockLiquid;
import net.minecraftforge.fluids.Fluid;
import biomesoplenty.common.fluids.blocks.BlockHoneyFluid;
import biomesoplenty.common.fluids.blocks.BlockPoisonFluid;
public class HoneyFluid extends Fluid
@ -11,6 +13,5 @@ public class HoneyFluid extends Fluid
this.setViscosity(1500);
this.setIcons(BlockPoisonFluid.liquidPoisonStillIcon, BlockPoisonFluid.liquidPoisonFlowingIcon);
}
}

View file

@ -9,6 +9,5 @@ public class PoisonFluid extends Fluid
{
super(fluidName);
this.setIcons(BlockPoisonFluid.liquidPoisonStillIcon, BlockPoisonFluid.liquidPoisonFlowingIcon);
}
}

View file

@ -3,6 +3,7 @@ package biomesoplenty.common.items;
import java.util.HashMap;
import java.util.List;
import net.minecraft.block.Block;
import net.minecraft.block.material.Material;
import net.minecraft.client.renderer.texture.IIconRegister;
import net.minecraft.creativetab.CreativeTabs;
@ -10,17 +11,21 @@ import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.init.Items;
import net.minecraft.item.Item;
import net.minecraft.item.ItemStack;
import net.minecraft.tileentity.TileEntity;
import net.minecraft.util.IIcon;
import net.minecraft.util.MovingObjectPosition;
import net.minecraft.util.StatCollector;
import net.minecraft.world.World;
import net.minecraftforge.fluids.FluidContainerRegistry;
import net.minecraftforge.fluids.FluidStack;
import net.minecraftforge.fluids.FluidTank;
import net.minecraftforge.fluids.IFluidHandler;
import net.minecraftforge.fluids.ItemFluidContainer;
import biomesoplenty.BiomesOPlenty;
import biomesoplenty.api.content.BOPCFluids;
import cpw.mods.fml.relauncher.Side;
import cpw.mods.fml.relauncher.SideOnly;
import net.minecraftforge.fluids.IFluidTank;
public class ItemBOPBucket extends ItemFluidContainer
{
@ -39,13 +44,27 @@ public class ItemBOPBucket extends ItemFluidContainer
public ItemStack onItemRightClick(ItemStack itemStack, World world, EntityPlayer player)
{
MovingObjectPosition movingobjectposition = this.getMovingObjectPositionFromPlayer(world, player, false);
if (movingobjectposition != null)
{
int i = movingobjectposition.blockX;
int j = movingobjectposition.blockY;
int k = movingobjectposition.blockZ;
TileEntity tile=world.getTileEntity(i, j, k);
if(tile != null && tile instanceof IFluidHandler)
{
System.out.print("into tank");
IFluidHandler tank=(IFluidHandler)tile;
if(tank.fill(null,this.getFluid(itemStack), false) == this.getCapacity(itemStack))
{
tank.fill(null,this.getFluid(itemStack), true);
if(!player.capabilities.isCreativeMode)
return new ItemStack(Items.bucket);
}
return itemStack;
}
if (movingobjectposition.sideHit == 0)
{
--j;
@ -100,6 +119,7 @@ public class ItemBOPBucket extends ItemFluidContainer
}
else
{
Material material = world.getBlock(x, y, z).getMaterial();
boolean isSolid = material.isSolid();