2013-10-16 05:33:43 +00:00
|
|
|
package biomesoplenty.eventhandlers;
|
2013-05-25 04:08:06 +00:00
|
|
|
|
2013-06-21 09:32:10 +00:00
|
|
|
import net.minecraft.item.Item;
|
2013-05-25 04:08:06 +00:00
|
|
|
import net.minecraft.item.ItemStack;
|
|
|
|
import net.minecraft.util.MovingObjectPosition;
|
|
|
|
import net.minecraft.world.World;
|
|
|
|
import net.minecraftforge.event.Event.Result;
|
|
|
|
import net.minecraftforge.event.ForgeSubscribe;
|
|
|
|
import net.minecraftforge.event.entity.player.FillBucketEvent;
|
2013-07-22 07:44:39 +00:00
|
|
|
import net.minecraftforge.fluids.FluidContainerRegistry;
|
|
|
|
import net.minecraftforge.fluids.FluidRegistry;
|
|
|
|
import net.minecraftforge.fluids.FluidStack;
|
2013-07-09 04:10:57 +00:00
|
|
|
import biomesoplenty.api.Fluids;
|
2013-05-25 04:08:06 +00:00
|
|
|
|
2013-07-09 05:14:10 +00:00
|
|
|
public class FluidEventHandler
|
2013-05-25 04:08:06 +00:00
|
|
|
{
|
|
|
|
@ForgeSubscribe
|
2013-05-31 10:34:02 +00:00
|
|
|
public void onBucketFill(FillBucketEvent event)
|
2013-05-25 04:08:06 +00:00
|
|
|
{
|
2013-07-22 07:44:39 +00:00
|
|
|
World world = event.world;
|
|
|
|
MovingObjectPosition pos = event.target;
|
2013-05-25 04:08:06 +00:00
|
|
|
|
2013-07-22 07:44:39 +00:00
|
|
|
int blockID = world.getBlockId(pos.blockX, pos.blockY, pos.blockZ);
|
|
|
|
int meta = world.getBlockMetadata(pos.blockX, pos.blockY, pos.blockZ);
|
|
|
|
|
|
|
|
if ((blockID == Fluids.springWater.get().blockID) && meta == 0)
|
|
|
|
{
|
|
|
|
ItemStack filledContainer = FluidContainerRegistry.fillFluidContainer(new FluidStack(FluidRegistry.WATER, FluidContainerRegistry.BUCKET_VOLUME), event.current);
|
|
|
|
|
|
|
|
if (filledContainer != null)
|
|
|
|
{
|
|
|
|
world.setBlock(pos.blockX, pos.blockY, pos.blockZ, 0);
|
2013-05-25 04:08:06 +00:00
|
|
|
|
2013-07-22 07:44:39 +00:00
|
|
|
event.result = filledContainer;
|
|
|
|
event.setResult(Result.ALLOW);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
event.setResult(Result.DENY);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else if ((blockID == Fluids.liquidPoison.get().blockID) && meta == 0)
|
|
|
|
{
|
|
|
|
ItemStack filledContainer = FluidContainerRegistry.fillFluidContainer(new FluidStack(Fluids.liquidPoisonFluid.get(), FluidContainerRegistry.BUCKET_VOLUME), event.current);
|
|
|
|
|
|
|
|
if (filledContainer != null)
|
|
|
|
{
|
|
|
|
world.setBlock(pos.blockX, pos.blockY, pos.blockZ, 0);
|
|
|
|
|
|
|
|
event.result = filledContainer;
|
|
|
|
event.setResult(Result.ALLOW);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
event.setResult(Result.DENY);
|
|
|
|
}
|
|
|
|
}
|
2013-05-25 04:08:06 +00:00
|
|
|
}
|
|
|
|
|
2013-05-31 10:34:02 +00:00
|
|
|
public ItemStack fillCustomBucket(World world, MovingObjectPosition pos)
|
2013-05-25 04:08:06 +00:00
|
|
|
{
|
|
|
|
int blockID = world.getBlockId(pos.blockX, pos.blockY, pos.blockZ);
|
2013-05-29 01:05:27 +00:00
|
|
|
int meta = world.getBlockMetadata(pos.blockX, pos.blockY, pos.blockZ);
|
2013-05-25 04:08:06 +00:00
|
|
|
|
2013-07-09 04:10:57 +00:00
|
|
|
if ((blockID == Fluids.springWater.get().blockID) && meta == 0)
|
2013-05-25 04:08:06 +00:00
|
|
|
{
|
|
|
|
world.setBlock(pos.blockX, pos.blockY, pos.blockZ, 0);
|
|
|
|
|
2013-07-04 06:19:37 +00:00
|
|
|
return new ItemStack(Item.bucketWater);
|
2013-05-31 10:34:02 +00:00
|
|
|
}
|
|
|
|
|
2013-07-09 04:10:57 +00:00
|
|
|
if ((blockID == Fluids.liquidPoison.get().blockID) && meta == 0)
|
2013-05-25 13:22:37 +00:00
|
|
|
{
|
|
|
|
world.setBlock(pos.blockX, pos.blockY, pos.blockZ, 0);
|
|
|
|
|
2013-07-09 05:14:10 +00:00
|
|
|
return new ItemStack(Fluids.bopBucket.get(), 1, 1);
|
2013-07-09 03:37:21 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2013-05-31 10:34:02 +00:00
|
|
|
return null;
|
2013-07-09 03:37:21 +00:00
|
|
|
}
|
2013-05-25 04:08:06 +00:00
|
|
|
}
|
|
|
|
}
|