2013-07-26 21:18:53 -07:00
|
|
|
package tconstruct.items;
|
|
|
|
|
|
|
|
|
|
import java.util.List;
|
|
|
|
|
|
2014-02-01 14:55:52 -05:00
|
|
|
import mantle.world.WorldHelper;
|
2013-12-31 11:26:08 -05:00
|
|
|
import net.minecraft.block.Block;
|
|
|
|
|
import net.minecraft.client.renderer.texture.IIconRegister;
|
2013-07-26 21:18:53 -07:00
|
|
|
import net.minecraft.creativetab.CreativeTabs;
|
|
|
|
|
import net.minecraft.entity.player.EntityPlayer;
|
2013-12-31 15:30:34 -05:00
|
|
|
import net.minecraft.init.Items;
|
2013-07-26 21:18:53 -07:00
|
|
|
import net.minecraft.item.Item;
|
|
|
|
|
import net.minecraft.item.ItemBucket;
|
|
|
|
|
import net.minecraft.item.ItemStack;
|
2013-12-31 11:26:08 -05:00
|
|
|
import net.minecraft.util.IIcon;
|
2013-07-26 21:18:53 -07:00
|
|
|
import net.minecraft.util.MathHelper;
|
|
|
|
|
import net.minecraft.util.MovingObjectPosition;
|
|
|
|
|
import net.minecraft.world.World;
|
2014-02-05 10:28:54 -05:00
|
|
|
import net.minecraftforge.fluids.BlockFluidFinite;
|
|
|
|
|
import tconstruct.TConstruct;
|
|
|
|
|
import tconstruct.common.TRepo;
|
2013-07-26 21:18:53 -07:00
|
|
|
import cpw.mods.fml.relauncher.Side;
|
|
|
|
|
import cpw.mods.fml.relauncher.SideOnly;
|
|
|
|
|
|
|
|
|
|
public class FilledBucket extends ItemBucket
|
|
|
|
|
{
|
|
|
|
|
|
2013-12-31 11:26:08 -05:00
|
|
|
public FilledBucket(Block b)
|
2013-07-26 21:18:53 -07:00
|
|
|
{
|
2013-12-31 11:26:08 -05:00
|
|
|
super(b);
|
2013-11-29 23:16:32 -05:00
|
|
|
//setTextureFile(TRepo.craftingTexture);
|
2013-07-26 21:18:53 -07:00
|
|
|
//setIconIndex(224);
|
|
|
|
|
setUnlocalizedName("tconstruct.bucket");
|
2013-12-31 15:30:34 -05:00
|
|
|
setContainerItem(Items.bucket);
|
2013-07-26 21:18:53 -07:00
|
|
|
this.setHasSubtypes(true);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public ItemStack onItemRightClick (ItemStack stack, World world, EntityPlayer player)
|
|
|
|
|
{
|
|
|
|
|
float var4 = 1.0F;
|
|
|
|
|
double trueX = player.prevPosX + (player.posX - player.prevPosX) * (double) var4;
|
|
|
|
|
double trueY = player.prevPosY + (player.posY - player.prevPosY) * (double) var4 + 1.62D - (double) player.yOffset;
|
|
|
|
|
double trueZ = player.prevPosZ + (player.posZ - player.prevPosZ) * (double) var4;
|
|
|
|
|
boolean wannabeFull = false;
|
|
|
|
|
MovingObjectPosition position = this.getMovingObjectPositionFromPlayer(world, player, wannabeFull);
|
|
|
|
|
|
|
|
|
|
if (position == null)
|
|
|
|
|
{
|
|
|
|
|
return stack;
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
/*FillBucketEvent event = new FillBucketEvent(player, stack, world, position);
|
|
|
|
|
if (MinecraftForge.EVENT_BUS.post(event))
|
|
|
|
|
{
|
|
|
|
|
return stack;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (event.getResult() == Event.Result.ALLOW)
|
|
|
|
|
{
|
|
|
|
|
if (player.capabilities.isCreativeMode)
|
|
|
|
|
{
|
|
|
|
|
return stack;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (--stack.stackSize <= 0)
|
|
|
|
|
{
|
|
|
|
|
return event.result;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (!player.inventory.addItemStackToInventory(event.result))
|
|
|
|
|
{
|
|
|
|
|
player.dropPlayerItem(event.result);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return stack;
|
|
|
|
|
}*/
|
|
|
|
|
|
2014-02-02 22:36:22 -05:00
|
|
|
if (position.typeOfHit == MovingObjectPosition.MovingObjectType.BLOCK)
|
2013-07-26 21:18:53 -07:00
|
|
|
{
|
|
|
|
|
int clickX = position.blockX;
|
|
|
|
|
int clickY = position.blockY;
|
|
|
|
|
int clickZ = position.blockZ;
|
|
|
|
|
|
|
|
|
|
if (!world.canMineBlock(player, clickX, clickY, clickZ))
|
|
|
|
|
{
|
|
|
|
|
return stack;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (position.sideHit == 0)
|
|
|
|
|
{
|
|
|
|
|
--clickY;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (position.sideHit == 1)
|
|
|
|
|
{
|
|
|
|
|
++clickY;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (position.sideHit == 2)
|
|
|
|
|
{
|
|
|
|
|
--clickZ;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (position.sideHit == 3)
|
|
|
|
|
{
|
|
|
|
|
++clickZ;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (position.sideHit == 4)
|
|
|
|
|
{
|
|
|
|
|
--clickX;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (position.sideHit == 5)
|
|
|
|
|
{
|
|
|
|
|
++clickX;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (!player.canPlayerEdit(clickX, clickY, clickZ, position.sideHit, stack))
|
|
|
|
|
{
|
|
|
|
|
return stack;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (this.tryPlaceContainedLiquid(world, clickX, clickY, clickZ, stack.getItemDamage()) && !player.capabilities.isCreativeMode)
|
|
|
|
|
{
|
2013-12-31 15:30:34 -05:00
|
|
|
return new ItemStack(Items.bucket);
|
2013-07-26 21:18:53 -07:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return stack;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2013-08-16 13:51:33 -07:00
|
|
|
public boolean tryPlaceContainedLiquid (World world, int clickX, int clickY, int clickZ, int type)
|
2013-07-26 21:18:53 -07:00
|
|
|
{
|
2014-02-05 08:28:53 -05:00
|
|
|
if (!WorldHelper.isAirBlock(world, clickX, clickY, clickZ) && world.getBlock(clickX, clickY, clickZ).getMaterial().isSolid())
|
2013-07-26 21:18:53 -07:00
|
|
|
{
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
2014-02-05 09:11:06 -05:00
|
|
|
try
|
|
|
|
|
{
|
2013-11-25 14:08:18 -05:00
|
|
|
int metadata = 0;
|
2013-11-29 23:16:32 -05:00
|
|
|
if (TRepo.fluidBlocks[type] instanceof BlockFluidFinite)
|
2013-11-25 14:08:18 -05:00
|
|
|
metadata = 7;
|
|
|
|
|
|
2014-02-05 08:28:53 -05:00
|
|
|
world.setBlock(clickX, clickY, clickZ, TRepo.fluidBlocks[type], metadata, 3); //TODO: Merge liquids
|
2014-02-05 09:11:06 -05:00
|
|
|
}
|
|
|
|
|
catch (ArrayIndexOutOfBoundsException ex)
|
|
|
|
|
{
|
2014-01-10 17:03:06 -05:00
|
|
|
TConstruct.logger.warn("AIOBE occured when placing bucket into world; " + ex);
|
2013-11-25 14:08:18 -05:00
|
|
|
return false;
|
|
|
|
|
}
|
2013-07-26 21:18:53 -07:00
|
|
|
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Override
|
2014-02-05 08:28:53 -05:00
|
|
|
public void getSubItems (Item b, CreativeTabs tab, List list)
|
2013-07-26 21:18:53 -07:00
|
|
|
{
|
|
|
|
|
for (int i = 0; i < icons.length; i++)
|
2013-12-31 11:26:08 -05:00
|
|
|
list.add(new ItemStack(b, 1, i));
|
2013-07-26 21:18:53 -07:00
|
|
|
}
|
|
|
|
|
|
2013-12-31 11:26:08 -05:00
|
|
|
public IIcon[] icons;
|
2013-07-26 21:18:53 -07:00
|
|
|
|
|
|
|
|
@SideOnly(Side.CLIENT)
|
2013-12-31 11:26:08 -05:00
|
|
|
public IIcon getIconFromDamage (int meta)
|
2013-07-26 21:18:53 -07:00
|
|
|
{
|
|
|
|
|
return icons[meta];
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@SideOnly(Side.CLIENT)
|
2013-12-31 11:26:08 -05:00
|
|
|
public void registerIcons (IIconRegister iconRegister)
|
2013-07-26 21:18:53 -07:00
|
|
|
{
|
2013-12-31 11:26:08 -05:00
|
|
|
this.icons = new IIcon[textureNames.length];
|
2013-07-26 21:18:53 -07:00
|
|
|
|
|
|
|
|
for (int i = 0; i < this.icons.length; ++i)
|
|
|
|
|
{
|
|
|
|
|
this.icons[i] = iconRegister.registerIcon("tinker:materials/bucket_" + textureNames[i]);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public String getUnlocalizedName (ItemStack stack)
|
|
|
|
|
{
|
|
|
|
|
int arr = MathHelper.clamp_int(stack.getItemDamage(), 0, materialNames.length);
|
|
|
|
|
return getUnlocalizedName() + "." + materialNames[arr];
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public static final String[] materialNames = new String[] { "Iron", "Gold", "Copper", "Tin", "Aluminum", "Cobalt", "Ardite", "Bronze", "AluBrass", "Manyullyn", "Alumite", "Obsidian", "Steel",
|
2013-11-25 14:08:18 -05:00
|
|
|
"Glass", "Stone", "Villager", "Cow", "Nickel", "Lead", "Silver", "Shiny", "Invar", "Electrum", "Ender", "Slime", "Glue", "PigIron" };
|
2013-07-26 21:18:53 -07:00
|
|
|
|
|
|
|
|
public static final String[] textureNames = new String[] { "iron", "gold", "copper", "tin", "aluminum", "cobalt", "ardite", "bronze", "alubrass", "manyullyn", "alumite", "obsidian", "steel",
|
2013-11-25 14:08:18 -05:00
|
|
|
"glass", "stone", "emerald", "blood", "nickel", "lead", "silver", "shiny", "invar", "electrum", "ender", "slime", "glue", "pigiron" };
|
2013-07-26 21:18:53 -07:00
|
|
|
}
|