use of net.minecraft.tileentity.TileEntity in project PneumaticCraft by MineMaarten.
the class BlockOmnidirectionalHopper method collisionRayTrace.
@Override
public MovingObjectPosition collisionRayTrace(World world, int x, int y, int z, Vec3 origin, Vec3 direction) {
TileEntity te = world.getTileEntity(x, y, z);
if (te instanceof TileEntityOmnidirectionalHopper) {
ForgeDirection o = ((TileEntityOmnidirectionalHopper) te).getDirection();
boolean isColliding = false;
setBlockBounds(o.offsetX == 1 ? 10 / 16F : 0, o.offsetY == 1 ? 10 / 16F : 0, o.offsetZ == 1 ? 10 / 16F : 0, o.offsetX == -1 ? 6 / 16F : 1, o.offsetY == -1 ? 6 / 16F : 1, o.offsetZ == -1 ? 6 / 16F : 1);
if (super.collisionRayTrace(world, x, y, z, origin, direction) != null)
isColliding = true;
setBlockBounds(4 / 16F, 4 / 16F, 4 / 16F, 12 / 16F, 12 / 16F, 12 / 16F);
if (super.collisionRayTrace(world, x, y, z, origin, direction) != null)
isColliding = true;
setBlockBounds(0, 0, 0, 1, 1, 1);
return isColliding ? super.collisionRayTrace(world, x, y, z, origin, direction) : null;
}
return null;
}
use of net.minecraft.tileentity.TileEntity in project PneumaticCraft by MineMaarten.
the class BlockPneumaticCraft method dropInventory.
protected void dropInventory(World world, int x, int y, int z) {
TileEntity tileEntity = world.getTileEntity(x, y, z);
if (!(tileEntity instanceof IInventory))
return;
IInventory inventory = (IInventory) tileEntity;
Random rand = new Random();
for (int i = getInventoryDropStartSlot(inventory); i < getInventoryDropEndSlot(inventory); i++) {
ItemStack itemStack = inventory.getStackInSlot(i);
if (itemStack != null && itemStack.stackSize > 0) {
float dX = rand.nextFloat() * 0.8F + 0.1F;
float dY = rand.nextFloat() * 0.8F + 0.1F;
float dZ = rand.nextFloat() * 0.8F + 0.1F;
EntityItem entityItem = new EntityItem(world, x + dX, y + dY, z + dZ, new ItemStack(itemStack.getItem(), itemStack.stackSize, itemStack.getItemDamage()));
if (itemStack.hasTagCompound()) {
entityItem.getEntityItem().setTagCompound((NBTTagCompound) itemStack.getTagCompound().copy());
}
float factor = 0.05F;
entityItem.motionX = rand.nextGaussian() * factor;
entityItem.motionY = rand.nextGaussian() * factor + 0.2F;
entityItem.motionZ = rand.nextGaussian() * factor;
world.spawnEntityInWorld(entityItem);
itemStack.stackSize = 0;
}
}
}
use of net.minecraft.tileentity.TileEntity in project PneumaticCraft by MineMaarten.
the class BlockPneumaticCraft method rotateBlock.
@Override
public boolean rotateBlock(World world, EntityPlayer player, int x, int y, int z, ForgeDirection side) {
if (player.isSneaking()) {
if (!player.capabilities.isCreativeMode)
dropBlockAsItem(world, x, y, z, world.getBlockMetadata(x, y, z), 0);
world.setBlockToAir(x, y, z);
return true;
} else {
if (isRotatable()) {
int meta = world.getBlockMetadata(x, y, z);
if (!rotateCustom(world, x, y, z, side, meta)) {
int newMeta;
if (rotateForgeWay()) {
if (!canRotateToTopOrBottom())
side = ForgeDirection.UP;
newMeta = ForgeDirection.getOrientation(meta).getRotation(side).ordinal();
world.setBlockMetadataWithNotify(x, y, z, newMeta, 3);
} else {
newMeta = (meta + 1) % 6;
if (!canRotateToTopOrBottom()) {
if (newMeta == 0) {
newMeta = 2;
}
}
}
world.setBlockMetadataWithNotify(x, y, z, newMeta, 3);
}
TileEntity te = world.getTileEntity(x, y, z);
if (te instanceof TileEntityBase) {
((TileEntityBase) te).onBlockRotated();
}
return true;
} else {
return false;
}
}
}
use of net.minecraft.tileentity.TileEntity in project PneumaticCraft by MineMaarten.
the class BlockPneumaticCraft method onBlockActivated.
@Override
public boolean onBlockActivated(World world, int x, int y, int z, EntityPlayer player, int par6, float par7, float par8, float par9) {
if (player.isSneaking() || getGuiID() == null || isRotatable() && player.getCurrentEquippedItem() != null && (player.getCurrentEquippedItem().getItem() == Itemss.manometer || ModInteractionUtils.getInstance().isModdedWrench(player.getCurrentEquippedItem().getItem())))
return false;
else {
if (!world.isRemote) {
TileEntity te = world.getTileEntity(x, y, z);
List<ItemStack> returnedItems = new ArrayList<ItemStack>();
if (te != null && !FluidUtils.tryInsertingLiquid(te, player.getCurrentEquippedItem(), player.capabilities.isCreativeMode, returnedItems)) {
player.openGui(PneumaticCraft.instance, getGuiID().ordinal(), world, x, y, z);
} else {
if (player.getCurrentEquippedItem() != null && player.getCurrentEquippedItem().stackSize <= 0) {
player.setCurrentItemOrArmor(0, null);
}
for (ItemStack returnedItem : returnedItems) {
returnedItem = returnedItem.copy();
if (player.getCurrentEquippedItem() == null) {
player.setCurrentItemOrArmor(0, returnedItem);
} else {
player.inventory.addItemStackToInventory(returnedItem);
}
}
}
}
return true;
}
}
use of net.minecraft.tileentity.TileEntity in project PneumaticCraft by MineMaarten.
the class BlockPneumaticCraft method addInformation.
@SideOnly(Side.CLIENT)
public void addInformation(ItemStack stack, EntityPlayer player, List curInfo, boolean extraInfo) {
if (PneumaticCraft.proxy.isSneakingInGui()) {
TileEntity te = createNewTileEntity(player.worldObj, 0);
if (te instanceof TileEntityPneumaticBase) {
float pressure = ((TileEntityPneumaticBase) te).DANGER_PRESSURE;
curInfo.add(EnumChatFormatting.YELLOW + I18n.format("gui.tooltip.maxPressure", pressure));
}
}
String info = "gui.tab.info." + stack.getUnlocalizedName();
String translatedInfo = I18n.format(info);
if (!translatedInfo.equals(info)) {
if (PneumaticCraft.proxy.isSneakingInGui()) {
translatedInfo = EnumChatFormatting.AQUA + translatedInfo.substring(2);
if (!Loader.isModLoaded(ModIds.IGWMOD))
translatedInfo += " \\n \\n" + I18n.format("gui.tab.info.assistIGW");
curInfo.addAll(PneumaticCraftUtils.convertStringIntoList(translatedInfo, 60));
} else {
curInfo.add(EnumChatFormatting.AQUA + I18n.format("gui.tooltip.sneakForInfo"));
}
}
}
Aggregations