mirror of
https://github.com/GTNewHorizons/TinkersConstruct.git
synced 2026-11-20 20:22:36 +00:00
107 lines
3.0 KiB
Java
107 lines
3.0 KiB
Java
package tconstruct.items.blocks;
|
|
|
|
import java.util.List;
|
|
|
|
import cpw.mods.fml.relauncher.Side;
|
|
import cpw.mods.fml.relauncher.SideOnly;
|
|
import net.minecraft.block.Block;
|
|
import net.minecraft.entity.player.EntityPlayer;
|
|
import net.minecraft.item.ItemBlock;
|
|
import net.minecraft.item.ItemStack;
|
|
import net.minecraft.util.MathHelper;
|
|
import net.minecraft.world.World;
|
|
|
|
public class BarricadeItem extends ItemBlock
|
|
{
|
|
private int bID;
|
|
|
|
public BarricadeItem(int id)
|
|
{
|
|
super(id);
|
|
this.bID = id + 256;
|
|
}
|
|
|
|
@Override
|
|
@SideOnly(Side.CLIENT)
|
|
public void addInformation (ItemStack stack, EntityPlayer player, List list, boolean par4)
|
|
{
|
|
list.add("Stacks up to 4 times");
|
|
}
|
|
|
|
public boolean onItemUse(ItemStack stack, EntityPlayer player, World world, int x, int y, int z, int side, float hitX, float hitY, float hitZ)
|
|
{
|
|
int i1 = world.getBlockId(x, y, z);
|
|
|
|
if (i1 == Block.snow.blockID && (world.getBlockMetadata(x, y, z) & 7) < 1)
|
|
{
|
|
side = 1;
|
|
}
|
|
else if (i1 != Block.vine.blockID && i1 != Block.tallGrass.blockID && i1 != Block.deadBush.blockID
|
|
&& (Block.blocksList[i1] == null || !Block.blocksList[i1].isBlockReplaceable(world, x, y, z)))
|
|
{
|
|
if (side == 0)
|
|
{
|
|
--y;
|
|
}
|
|
|
|
if (side == 1)
|
|
{
|
|
++y;
|
|
}
|
|
|
|
if (side == 2)
|
|
{
|
|
--z;
|
|
}
|
|
|
|
if (side == 3)
|
|
{
|
|
++z;
|
|
}
|
|
|
|
if (side == 4)
|
|
{
|
|
--x;
|
|
}
|
|
|
|
if (side == 5)
|
|
{
|
|
++x;
|
|
}
|
|
}
|
|
|
|
if (stack.stackSize == 0)
|
|
{
|
|
return false;
|
|
}
|
|
else if (!player.canPlayerEdit(x, y, z, side, stack))
|
|
{
|
|
return false;
|
|
}
|
|
else if (y == 255 && Block.blocksList[this.bID].blockMaterial.isSolid())
|
|
{
|
|
return false;
|
|
}
|
|
else if (world.canPlaceEntityOnSide(this.bID, x, y, z, false, side, player, stack))
|
|
{
|
|
Block block = Block.blocksList[this.bID];
|
|
//int meta = this.getMetadata(stack.getItemDamage());
|
|
int rotation = MathHelper.floor_double((double) (player.rotationYaw * 4.0F / 360.0F) + 0.5D) & 3;
|
|
int meta = rotation * 4;
|
|
int metadata = Block.blocksList[this.bID].onBlockPlaced(world, x, y, z, side, hitX, hitY, hitZ, meta);
|
|
|
|
if (placeBlockAt(stack, player, world, x, y, z, side, hitX, hitY, hitZ, metadata))
|
|
{
|
|
world.playSoundEffect((double)((float)x + 0.5F), (double)((float)y + 0.5F), (double)((float)z + 0.5F), block.stepSound.getPlaceSound(), (block.stepSound.getVolume() + 1.0F) / 2.0F, block.stepSound.getPitch() * 0.8F);
|
|
--stack.stackSize;
|
|
}
|
|
|
|
return true;
|
|
}
|
|
else
|
|
{
|
|
return false;
|
|
}
|
|
}
|
|
}
|