Toying with buckets

This commit is contained in:
Adubbz 2014-02-02 11:01:52 +11:00
parent 286a2f2824
commit 04a8bcf0c5
5 changed files with 126 additions and 239 deletions

View file

@ -1,6 +1,7 @@
package biomesoplenty.common.core;
import static biomesoplenty.common.core.BOPBlocks.registerBlock;
import static biomesoplenty.common.core.BOPItems.registerItem;
import net.minecraftforge.fluids.Fluid;
import net.minecraftforge.fluids.FluidRegistry;
import biomesoplenty.api.BOPBlockHelper;
@ -10,6 +11,7 @@ import biomesoplenty.common.fluids.SpringWaterFluid;
import biomesoplenty.common.fluids.blocks.BlockHoneyFluid;
import biomesoplenty.common.fluids.blocks.BlockPoisonFluid;
import biomesoplenty.common.fluids.blocks.BlockSpringWaterFluid;
import biomesoplenty.common.items.ItemBOPBucket;
public class BOPFluids
{
@ -17,7 +19,7 @@ public class BOPFluids
{
registerFluids();
registerFluidBlocks();
//initializeContainers();
registerFluidItems();
//registerItems();
}
@ -36,19 +38,10 @@ public class BOPFluids
registerBlock(new BlockHoneyFluid().func_149663_c("honey"));
}
/*private static void initializeContainers()
private static void registerFluidItems()
{
Fluids.bopBucket = Optional.of((new ItemBOPBucket(BOPConfigurationIDs.bopBucketID).setMaxStackSize(1).setUnlocalizedName("bop.bopBucket")));
FluidContainerRegistry.registerFluidContainer(Fluids.liquidPoisonFluid.get(), new ItemStack(Fluids.bopBucket.get(), 1, 1), new ItemStack(Item.bucketEmpty));
FluidContainerRegistry.registerFluidContainer(Fluids.honeyFluid.get(), new ItemStack(Fluids.bopBucket.get(), 1, 3), new ItemStack(Item.bucketEmpty));
FluidContainerRegistry.registerFluidContainer(Fluids.springWaterFluid.get(), new ItemStack(Fluids.bopBucket.get(), 1, 2), new ItemStack(Fluids.bopBucket.get(), 1, 0));
registerItem(new ItemBOPBucket().setUnlocalizedName("bopBucket"));
}
private static void registerItems()
{
registerItem(Fluids.bopBucket.get());
}*/
public static void registerFluid(Fluid fluid)
{

View file

@ -7,6 +7,7 @@ import biomesoplenty.common.eventhandler.entity.TemptEventHandler;
import biomesoplenty.common.eventhandler.gui.MainMenuEventHandler;
import biomesoplenty.common.eventhandler.gui.StartupWarningEventHandler;
import biomesoplenty.common.eventhandler.misc.BonemealEventHandler;
import biomesoplenty.common.eventhandler.misc.BucketEventHandler;
import biomesoplenty.common.eventhandler.misc.CapeEventHandler;
import biomesoplenty.common.eventhandler.network.ConnectionEventHandler;
import biomesoplenty.common.eventhandler.potions.PotionParalysisEventHandler;
@ -66,6 +67,7 @@ public class BOPEventHandlers
private static void registerMiscEventHandlers()
{
MinecraftForge.EVENT_BUS.register(new BonemealEventHandler());
MinecraftForge.EVENT_BUS.register(new BucketEventHandler());
MinecraftForge.EVENT_BUS.register(new CapeEventHandler());
}
}

View file

@ -0,0 +1,52 @@
package biomesoplenty.common.eventhandler.misc;
import net.minecraft.block.Block;
import net.minecraft.init.Items;
import net.minecraft.item.ItemStack;
import net.minecraft.world.World;
import net.minecraftforge.event.entity.player.FillBucketEvent;
import net.minecraftforge.fluids.Fluid;
import net.minecraftforge.fluids.FluidContainerRegistry;
import net.minecraftforge.fluids.FluidRegistry;
import net.minecraftforge.fluids.FluidStack;
import net.minecraftforge.fluids.IFluidBlock;
import biomesoplenty.api.BOPItemHelper;
import biomesoplenty.common.items.ItemBOPBucket;
import cpw.mods.fml.common.eventhandler.Event.Result;
import cpw.mods.fml.common.eventhandler.SubscribeEvent;
public class BucketEventHandler
{
@SubscribeEvent
public void onBucketFill(FillBucketEvent event)
{
ItemBOPBucket bopBucket = (ItemBOPBucket)BOPItemHelper.get("bopBucket");
ItemStack bopBucketStack = new ItemStack(bopBucket);
World world = event.world;
int x = event.target.blockX;
int y = event.target.blockY;
int z = event.target.blockZ;
//TODO: getBlock()
Block block = world.func_147439_a(x, y, z);
Fluid fluidBlockFluid = FluidRegistry.lookupFluidForBlock(block);
if (fluidBlockFluid != null)
{
String fluidName = fluidBlockFluid.getName();
if ((fluidName.equals("poison") || fluidName.equals("honey")))
{
bopBucket.fill(bopBucketStack, new FluidStack(fluidBlockFluid, FluidContainerRegistry.BUCKET_VOLUME), true);
world.func_147468_f(x, y, z);
event.result = bopBucketStack;
event.setResult(Result.ALLOW);
}
}
}
}

View file

@ -1,255 +1,95 @@
/*TODO: FEATURE <Once Fluids Are Updated> package biomesoplenty.items;
package biomesoplenty.common.items;
import java.util.List;
import java.util.HashMap;
import net.minecraft.client.renderer.texture.IconRegister;
import net.minecraft.creativetab.CreativeTabs;
import net.minecraft.block.Block;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.item.Item;
import net.minecraft.init.Items;
import net.minecraft.item.ItemStack;
import net.minecraft.util.EnumMovingObjectType;
import net.minecraft.util.Icon;
import net.minecraft.util.MovingObjectPosition;
import net.minecraft.util.StatCollector;
import net.minecraft.world.World;
import net.minecraftforge.fluids.BlockFluidBase;
import net.minecraftforge.fluids.Fluid;
import net.minecraftforge.fluids.FluidContainerRegistry;
import net.minecraftforge.fluids.FluidRegistry;
import net.minecraftforge.fluids.FluidStack;
import net.minecraftforge.fluids.ItemFluidContainer;
import biomesoplenty.BiomesOPlenty;
import biomesoplenty.api.Fluids;
import cpw.mods.fml.relauncher.Side;
import cpw.mods.fml.relauncher.SideOnly;
public class ItemBOPBucket extends Item
public class ItemBOPBucket extends ItemFluidContainer
{
private int isFull;
private static final String[] bucketTypes = new String[] {"amethyst_empty", "liquid_poison", "amethyst_spring_water", "honey"};
@SideOnly(Side.CLIENT)
private Icon[] textures;
public ItemBOPBucket(int i)
public ItemBOPBucket()
{
super(i);
this.setHasSubtypes(true);
super(0);
this.maxStackSize = 1;
this.capacity = FluidContainerRegistry.BUCKET_VOLUME;
this.setCreativeTab(BiomesOPlenty.tabBiomesOPlenty);
}
@Override
public ItemStack onItemRightClick(ItemStack itemstack, World world, EntityPlayer player)
/*@Override
public ItemStack onItemRightClick(ItemStack itemStack, World world, EntityPlayer player)
{
float f = 1.0F;
double d0 = player.prevPosX + (player.posX - player.prevPosX) * f;
double d1 = player.prevPosY + (player.posY - player.prevPosY) * f + 1.62D - player.yOffset;
double d2 = player.prevPosZ + (player.posZ - player.prevPosZ) * f;
isFull = getLiquidIDFromMeta(itemstack.getItemDamage());
boolean flag = isFull == 0;
MovingObjectPosition pos = this.getMovingObjectPositionFromPlayer(world, player, true);
if (itemstack.getItemDamage() == 0)
String bucketType = itemStack.hasTagCompound() && itemStack.getTagCompound().hasKey("type") ? itemStack.getTagCompound().getString("type") : "";
FluidStack fluid = getFluid(itemStack);
if (pos != null)
{
MovingObjectPosition pos = this.getMovingObjectPositionFromPlayer(world, player, true);
if (pos == null)
{
return itemstack;
}
else
{
int blockID = world.getBlockId(pos.blockX, pos.blockY, pos.blockZ);
int meta = world.getBlockMetadata(pos.blockX, pos.blockY, pos.blockZ);
int x = pos.blockX;
int y = pos.blockY;
int z = pos.blockZ;
if ((blockID == Fluids.springWater.get().blockID) && meta == 0)
{
if (player.capabilities.isCreativeMode)
{
world.setBlock(pos.blockX, pos.blockY, pos.blockZ, 0);
return itemstack;
}
if (--itemstack.stackSize <= 0)
{
world.setBlock(pos.blockX, pos.blockY, pos.blockZ, 0);
return new ItemStack(Fluids.bopBucket.get(), 1, 2);
}
if (!player.inventory.addItemStackToInventory(new ItemStack(Fluids.bopBucket.get(), 1, 2)))
{
world.setBlock(pos.blockX, pos.blockY, pos.blockZ, 0);
player.dropPlayerItem(new ItemStack(Fluids.bopBucket.get(), 1, 2));
}
return itemstack;
}
else
{
return itemstack;
}
}
}
else
{
MovingObjectPosition pos = this.getMovingObjectPositionFromPlayer(world, player, flag);
if (pos == null)
{
return itemstack;
}
else if (pos.typeOfHit == EnumMovingObjectType.TILE)
if (fluid == null || fluid.amount != capacity)
{
int i = pos.blockX;
int j = pos.blockY;
int k = pos.blockZ;
//TODO: getBlock()
Block block = world.func_147439_a(x, y, z);
if (!world.canMineBlock(player, i, j, k))
return itemstack;
if (isFull < 0)
return new ItemStack(Item.bucketEmpty);
if (pos.sideHit == 0)
if (block instanceof BlockFluidBase)
{
--j;
BlockFluidBase fluidBlock = (BlockFluidBase)block;
Fluid fluidBlockFluid = FluidRegistry.lookupFluidForBlock(fluidBlock);
String fluidName = fluidBlockFluid != null ? allowedFluids.get(fluidBlockFluid.getName()) : null;
if (fluidName != null && fluidName.equals(bucketType))
{
FluidStack blockFluid = fluidBlock.drain(world, x, y, z, true);
this.fill(itemStack, new FluidStack(blockFluid, capacity), true);
return itemStack;
}
}
}
else if (fluid != null)
{
Block block = fluid.getFluid().getBlock();
if (pos.sideHit == 1)
if (block != null)
{
++j;
}
if (pos.sideHit == 2)
{
--k;
}
if (pos.sideHit == 3)
{
++k;
}
if (pos.sideHit == 4)
{
--i;
}
if (pos.sideHit == 5)
{
++i;
}
if (!player.canPlayerEdit(i, j, k, pos.sideHit, itemstack))
return itemstack;
if (this.tryPlaceContainedLiquid(world, d0, d1, d2, i, j, k) && !player.capabilities.isCreativeMode)
{
if (itemstack.getItemDamage() != 2)
return new ItemStack(Item.bucketEmpty);
else
return new ItemStack(Fluids.bopBucket.get(), 1, 0);
world.func_147449_b(x, y, z, block);
return new ItemStack(Items.bucket);
}
}
}
return itemstack;
}
/**
* Attempts to place the liquid contained inside the bucket.
*/
/*public boolean tryPlaceContainedLiquid(World par1World, double par2, double par4, double par6, int par8, int par9, int par10)
{
if (isFull <= 0)
return false;
else if (!par1World.isAirBlock(par8, par9, par10) && par1World.getBlockMaterial(par8, par9, par10).isSolid())
return false;
else
{
if (par1World.provider.isHellWorld && isFull == Fluids.springWater.get().blockID)
{
par1World.playSoundEffect(par2 + 0.5D, par4 + 0.5D, par6 + 0.5D, "random.fizz", 0.5F, 2.6F + (par1World.rand.nextFloat() - par1World.rand.nextFloat()) * 0.8F);
for (int l = 0; l < 8; ++l)
{
par1World.spawnParticle("largesmoke", par8 + Math.random(), par9 + Math.random(), par10 + Math.random(), 0.0D, 0.0D, 0.0D);
}
}
else if (isFull == Fluids.honey.get().blockID)
{
par1World.setBlock(par8, par9, par10, isFull, 7, 3);
}
else
{
par1World.setBlock(par8, par9, par10, isFull, 0, 3);
}
return true;
}
}
return itemStack;
}*/
@Override
public boolean hasContainerItem()
@Override
public String getItemStackDisplayName(ItemStack itemStack)
{
return true;
FluidStack fluidStack = FluidContainerRegistry.getFluidForFilledItem(itemStack);
String fluidName = fluidStack != null ? fluidStack.getFluid().getName() : "";
System.out.println(fluidName);
return ("" + StatCollector.translateToLocal(this.getUnlocalizedNameInefficiently(itemStack) + fluidName + ".name")).trim();
}
@Override
public ItemStack getContainerItemStack(ItemStack itemstack)
{
return itemstack.getItemDamage() == 2 ? new ItemStack(Fluids.bopBucket.get(), 1, 0) : new ItemStack(Item.bucketEmpty, 1);
}
private static int getLiquidIDFromMeta(int meta)
{
switch (meta)
{
case 1:
return Fluids.liquidPoison.get().blockID;
case 2:
return Fluids.springWater.get().blockID;
case 3:
return Fluids.honey.get().blockID;
default:
return Fluids.liquidPoison.get().blockID;
}
}
@SuppressWarnings({ "rawtypes", "unchecked" })
@Override
public void getSubItems(int par1, CreativeTabs par2CreativeTabs, List par3List)
{
for (int i = 0; i < bucketTypes.length; ++i)
{
par3List.add(new ItemStack(par1, 1, i));
}
}
@Override
public String getUnlocalizedName(ItemStack itemStack)
{
int meta = itemStack.getItemDamage();
if (meta < 0 || meta >= bucketTypes.length) {
meta = 0;
}
return super.getUnlocalizedName() + "." + bucketTypes[meta];
}
@Override
@SideOnly(Side.CLIENT)
public void registerIcons(IconRegister iconRegister)
{
textures = new Icon[bucketTypes.length];
for (int i = 0; i < bucketTypes.length; ++i) {
textures[i] = iconRegister.registerIcon("biomesoplenty:" + "bucket_" + bucketTypes[i]);
}
}
@Override
public Icon getIconFromDamage(int meta)
{
return textures[meta];
}
}*/
}

View file

@ -392,7 +392,7 @@ item.biomeFinder.name=Biome Radar
item.biomeEssence.name=Biome Essence
item.bopBucket.amethyst_empty.name=Amethyst Bucket
item.bopBucket.amethyst_spring_water.name=Spring Water Amethyst Bucket
item.bopBucket.spring_water.name=Spring Water Amethyst Bucket
item.bopBucket.liquid_poison.name=Liquid Poison Bucket
item.bopBucket.honey.name=Honey Bucket