42 lines
1.3 KiB
Java
42 lines
1.3 KiB
Java
package WayofTime.alchemicalWizardry.common;
|
|
|
|
import net.minecraft.block.Block;
|
|
import net.minecraft.item.ItemStack;
|
|
import net.minecraft.util.MovingObjectPosition;
|
|
import net.minecraft.world.World;
|
|
import net.minecraftforge.event.entity.player.FillBucketEvent;
|
|
import WayofTime.alchemicalWizardry.ModBlocks;
|
|
import WayofTime.alchemicalWizardry.ModItems;
|
|
import cpw.mods.fml.common.eventhandler.Event.Result;
|
|
import cpw.mods.fml.common.eventhandler.SubscribeEvent;
|
|
|
|
public class LifeBucketHandler
|
|
{
|
|
@SubscribeEvent
|
|
public void onBucketFill(FillBucketEvent event)
|
|
{
|
|
ItemStack result = fillCustomBucket(event.world, event.target);
|
|
|
|
if (result == null)
|
|
{
|
|
return;
|
|
}
|
|
|
|
event.result = result;
|
|
event.setResult(Result.ALLOW);
|
|
}
|
|
|
|
public ItemStack fillCustomBucket(World world, MovingObjectPosition pos)
|
|
{
|
|
Block block = world.getBlock(pos.blockX, pos.blockY, pos.blockZ);
|
|
|
|
if (block!=null && (block.equals(ModBlocks.blockLifeEssence)) && world.getBlockMetadata(pos.blockX, pos.blockY, pos.blockZ) == 0)
|
|
{
|
|
world.setBlockToAir(pos.blockX, pos.blockY, pos.blockZ);
|
|
return new ItemStack(ModItems.bucketLife);
|
|
} else
|
|
{
|
|
return null;
|
|
}
|
|
}
|
|
} |