mirror of
https://github.com/GTNewHorizons/Chisel.git
synced 2026-11-19 12:09:12 +00:00
Rewrite presents. Still a bit WIP, needs sounds and lid animation
This commit is contained in:
1 parent
583b2b4806
commit
dd300f70aa
12 files changed
+543
-564
No files matched your search
@@ -1,19 +1,16 @@
|
||||
package com.cricketcraft.chisel.block;
|
||||
|
||||
import java.util.Iterator;
|
||||
import java.util.Random;
|
||||
import java.util.List;
|
||||
|
||||
import net.minecraft.block.Block;
|
||||
import net.minecraft.block.BlockChest;
|
||||
import net.minecraft.block.material.Material;
|
||||
import net.minecraft.client.renderer.texture.IIconRegister;
|
||||
import net.minecraft.entity.Entity;
|
||||
import net.minecraft.creativetab.CreativeTabs;
|
||||
import net.minecraft.entity.EntityLivingBase;
|
||||
import net.minecraft.entity.item.EntityItem;
|
||||
import net.minecraft.entity.passive.EntityOcelot;
|
||||
import net.minecraft.entity.player.EntityPlayer;
|
||||
import net.minecraft.inventory.Container;
|
||||
import net.minecraft.inventory.IInventory;
|
||||
import net.minecraft.item.Item;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.nbt.NBTTagCompound;
|
||||
import net.minecraft.tileentity.TileEntity;
|
||||
import net.minecraft.util.AxisAlignedBB;
|
||||
import net.minecraft.util.MathHelper;
|
||||
@@ -21,46 +18,42 @@ import net.minecraft.world.IBlockAccess;
|
||||
import net.minecraft.world.World;
|
||||
import net.minecraftforge.common.util.ForgeDirection;
|
||||
|
||||
import com.cricketcraft.chisel.Chisel;
|
||||
import com.cricketcraft.chisel.api.ICarvable;
|
||||
import com.cricketcraft.chisel.block.tileentity.TileEntityPresent;
|
||||
import com.cricketcraft.chisel.carving.CarvableHelper;
|
||||
import com.cricketcraft.chisel.carving.CarvableVariation;
|
||||
import com.cricketcraft.chisel.inventory.InventoryLargePresent;
|
||||
|
||||
import cpw.mods.fml.relauncher.Side;
|
||||
import cpw.mods.fml.relauncher.SideOnly;
|
||||
|
||||
public class BlockPresent extends BlockChest implements ICarvable {
|
||||
public class BlockPresent extends Block implements ICarvable {
|
||||
|
||||
private final Random random = new Random();
|
||||
private int type;
|
||||
public CarvableHelper carverHelper;
|
||||
|
||||
private float minX, minY, minZ, maxX, maxY, maxZ;
|
||||
|
||||
public BlockPresent(int type) {
|
||||
super(1);
|
||||
this.type = type;
|
||||
public BlockPresent() {
|
||||
super(Material.wood);
|
||||
carverHelper = new CarvableHelper();
|
||||
setBlockBounds(0.0625F, 0.0F, 0.0625F, 0.9375F, 0875F, 0.9365F);
|
||||
minX = 0.0625F;
|
||||
minZ = 0.0625F;
|
||||
maxX = 0.9375F;
|
||||
maxY = 0.875F;
|
||||
maxZ = 0.9375F;
|
||||
setBlockBounds(minX, minY, minZ, maxX, maxY, maxZ);
|
||||
}
|
||||
|
||||
public String getKindOfChest(int type) {
|
||||
public String getModelTexture(int type) {
|
||||
return "textures/blocks/present/presentChest" + type;
|
||||
}
|
||||
|
||||
private static boolean isCatSittingOnMe(World world, int x, int y, int z) {
|
||||
Iterator iterator = world.getEntitiesWithinAABB(EntityOcelot.class, AxisAlignedBB.getBoundingBox(x, y + 1, z, x + 1, y + 2, z + 1)).iterator();
|
||||
EntityOcelot ocelot;
|
||||
|
||||
do {
|
||||
if (!iterator.hasNext()) {
|
||||
return false;
|
||||
}
|
||||
|
||||
Entity entity = (Entity) iterator.next();
|
||||
ocelot = (EntityOcelot) entity;
|
||||
} while (!ocelot.isSitting());
|
||||
|
||||
return true;
|
||||
|
||||
@SuppressWarnings({ "unchecked", "rawtypes" })
|
||||
@Override
|
||||
public void getSubBlocks(Item item, CreativeTabs tab, List list) {
|
||||
for (int i = 0; i < 16; i++) {
|
||||
list.add(new ItemStack(item, 1, i));
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -79,96 +72,23 @@ public class BlockPresent extends BlockChest implements ICarvable {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onBlockPlacedBy(World world, int x, int y, int z, EntityLivingBase entityLivingBase, ItemStack itemStack) {
|
||||
Block front = world.getBlock(x, y, z - 1);
|
||||
Block back = world.getBlock(x, y, z + 1);
|
||||
Block left = world.getBlock(x - 1, y, z);
|
||||
Block right = world.getBlock(x + 1, y, z);
|
||||
byte metadata = 0;
|
||||
int rot = MathHelper.floor_double((entityLivingBase.rotationYaw * 4.0F / 360.0F) + 0.5D) & 3;
|
||||
|
||||
if (rot == 0) {
|
||||
metadata = 2;
|
||||
}
|
||||
|
||||
if (rot == 1) {
|
||||
metadata = 5;
|
||||
}
|
||||
|
||||
if (rot == 2) {
|
||||
metadata = 3;
|
||||
}
|
||||
|
||||
if (rot == 3) {
|
||||
metadata = 4;
|
||||
}
|
||||
|
||||
if (front != this && back != this && left != this && right != this) {
|
||||
world.setBlockMetadataWithNotify(x, y, z, metadata, 3);
|
||||
} else {
|
||||
if ((front == this || back == this) && (metadata == 4 || metadata == 5)) {
|
||||
if (front == this) {
|
||||
world.setBlockMetadataWithNotify(x, y, z - 1, metadata, 3);
|
||||
} else {
|
||||
world.setBlockMetadataWithNotify(x, y, z + 1, metadata, 3);
|
||||
}
|
||||
|
||||
world.setBlockMetadataWithNotify(x, y, z, metadata, 3);
|
||||
}
|
||||
|
||||
if ((left == this || right == this) && (metadata == 2 || metadata == 3)) {
|
||||
if (left == this) {
|
||||
world.setBlockMetadataWithNotify(x - 1, y, z, metadata, 3);
|
||||
} else {
|
||||
world.setBlockMetadataWithNotify(x + 1, y, z, metadata, 3);
|
||||
}
|
||||
|
||||
world.setBlockMetadataWithNotify(x, y, z, metadata, 3);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean canPlaceBlockAt(World world, int x, int y, int z) {
|
||||
int l = 0;
|
||||
|
||||
if (world.getBlock(x - 1, y, z) == this) {
|
||||
++l;
|
||||
}
|
||||
|
||||
if (world.getBlock(x + 1, y, z) == this) {
|
||||
++l;
|
||||
}
|
||||
|
||||
if (world.getBlock(x, y, z - 1) == this) {
|
||||
++l;
|
||||
}
|
||||
|
||||
if (world.getBlock(x, y, z + 1) == this) {
|
||||
++l;
|
||||
}
|
||||
|
||||
return l > 1 ? false : (areSurroundingBlocksMe(world, x, y - 1, z) ? false : (areSurroundingBlocksMe(world, x, y + 1, z) ? false : (areSurroundingBlocksMe(world, x, y, z - 1) ? false
|
||||
: !areSurroundingBlocksMe(world, x, y, z + 1))));
|
||||
}
|
||||
|
||||
private boolean areSurroundingBlocksMe(World world, int x, int y, int z) {
|
||||
return world.getBlock(x, y, z) != this ? false : (world.getBlock(x - 1, y, z) == this ? true : (world.getBlock(x + 1, y, z) == this ? true : (world.getBlock(x, y, z - 1) == this ? true
|
||||
: world.getBlock(x, y, z + 1) == this)));
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onNeighborBlockChange(World world, int x, int y, int z, Block neighbor) {
|
||||
super.onNeighborBlockChange(world, x, y, z, neighbor);
|
||||
TileEntityPresent tileEntityPresent = (TileEntityPresent) world.getTileEntity(x, y, z);
|
||||
|
||||
if (tileEntityPresent != null) {
|
||||
tileEntityPresent.updateContainingBlockInfo();
|
||||
public void onBlockPlacedBy(World world, int x, int y, int z, EntityLivingBase player, ItemStack stack) {
|
||||
super.onBlockPlacedBy(world, x, y, z, player, stack);
|
||||
int heading = MathHelper.floor_double(player.rotationYaw * 4.0F / 360.0F + 0.5D) & 3;
|
||||
TileEntityPresent te = (TileEntityPresent) world.getTileEntity(x, y, z);
|
||||
world.setBlockMetadataWithNotify(x, y, z, heading, 3);
|
||||
te.findConnections();
|
||||
if (te.isConnected()) {
|
||||
TileEntityPresent other = te.getConnection();
|
||||
world.setBlockMetadataWithNotify(other.xCoord, other.yCoord, other.zCoord, heading, 3);
|
||||
}
|
||||
te.setType(stack.getItemDamage());
|
||||
world.markBlockForUpdate(x, y, z);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void breakBlock(World world, int x, int y, int z, Block present, int meta) {
|
||||
|
||||
TileEntityPresent tileEntityPresent = (TileEntityPresent) world.getTileEntity(x, y, z);
|
||||
|
||||
if (tileEntityPresent != null) {
|
||||
@@ -176,28 +96,7 @@ public class BlockPresent extends BlockChest implements ICarvable {
|
||||
ItemStack itemStack = tileEntityPresent.getStackInSlot(c);
|
||||
|
||||
if (itemStack != null) {
|
||||
float f = random.nextFloat() * 0.8F + 0.1F;
|
||||
float f1 = random.nextFloat() * 0.8F + 0.1F;
|
||||
EntityItem entityItem;
|
||||
|
||||
for (float f2 = random.nextFloat() * 0.8F + 0.1F; itemStack.stackSize > 0; world.spawnEntityInWorld(entityItem)) {
|
||||
int stack = random.nextInt(21) + 10;
|
||||
|
||||
if (stack > itemStack.stackSize) {
|
||||
stack = itemStack.stackSize;
|
||||
}
|
||||
|
||||
itemStack.stackSize -= stack;
|
||||
entityItem = new EntityItem(world, x + f, y + f1, z + f2, new ItemStack(itemStack.getItem(), stack, itemStack.getItemDamage()));
|
||||
float motion = 0.05F;
|
||||
entityItem.motionX = random.nextGaussian() * motion;
|
||||
entityItem.motionY = random.nextGaussian() * motion + 0.2F;
|
||||
entityItem.motionZ = random.nextGaussian() * motion;
|
||||
|
||||
if (itemStack.hasTagCompound()) {
|
||||
entityItem.getEntityItem().setTagCompound((NBTTagCompound) itemStack.getTagCompound().copy());
|
||||
}
|
||||
}
|
||||
dropBlockAsItem(world, x, y, z, itemStack);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -208,23 +107,75 @@ public class BlockPresent extends BlockChest implements ICarvable {
|
||||
}
|
||||
|
||||
@Override
|
||||
public TileEntity createNewTileEntity(World world, int par2) {
|
||||
return new TileEntityPresent(type);
|
||||
public boolean onBlockActivated(World world, int x, int y, int z, EntityPlayer player, int hitX, float hitY, float hitZ, float p_149727_9_) {
|
||||
if (!world.isSideSolid(x, y + 1, z, ForgeDirection.DOWN)) {
|
||||
player.openGui(Chisel.instance, 2, world, x, y, z);
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int isProvidingWeakPower(IBlockAccess world, int x, int y, int z, int direction) {
|
||||
if (!canProvidePower()) {
|
||||
return 0;
|
||||
public AxisAlignedBB getSelectedBoundingBoxFromPool(World world, int x, int y, int z) {
|
||||
return getBoundingBox((TileEntityPresent) world.getTileEntity(x, y, z));
|
||||
}
|
||||
|
||||
@Override
|
||||
public AxisAlignedBB getCollisionBoundingBoxFromPool(World world, int x, int y, int z) {
|
||||
return getBoundingBox((TileEntityPresent) world.getTileEntity(x, y, z));
|
||||
}
|
||||
|
||||
public AxisAlignedBB getBoundingBox(TileEntityPresent me) {
|
||||
if (me == null) {
|
||||
return AxisAlignedBB.getBoundingBox(minX, minY, minZ, maxX, maxY, maxZ);
|
||||
}
|
||||
int x = me.xCoord, y = me.yCoord, z = me.zCoord;
|
||||
if (me.isConnected()) {
|
||||
ForgeDirection dir = me.getConnectionDir();
|
||||
if (dir != ForgeDirection.NORTH && (!me.isParent() || dir == ForgeDirection.SOUTH)) {
|
||||
return AxisAlignedBB.getBoundingBox(x + minX, y + minY, z + minZ, x + maxX + dir.offsetX, y + maxY, z + maxZ + dir.offsetZ);
|
||||
} else {
|
||||
return AxisAlignedBB.getBoundingBox(x + dir.offsetX + minX, y + minY, z + dir.offsetZ + minZ, x + maxX, y + maxY, z + maxZ);
|
||||
}
|
||||
}
|
||||
return AxisAlignedBB.getBoundingBox(x + minX, y + minY, z + minZ, x + maxX, y + maxY, z + maxZ);
|
||||
}
|
||||
|
||||
public void setBlockBoundsBasedOnState(IBlockAccess world, int x, int y, int z)
|
||||
{
|
||||
TileEntityPresent te = (TileEntityPresent) world.getTileEntity(x, y, z);
|
||||
if (!te.isConnected()) {
|
||||
setBlockBounds(0.0625F, 0, 0.0625F, 0.9375F, 0.875F, 0.9365F);
|
||||
} else {
|
||||
int players = ((TileEntityPresent) world.getTileEntity(x, y, z)).numPlayersUsing;
|
||||
return MathHelper.clamp_int(players, 0, 15);
|
||||
ForgeDirection dir = te.getConnectionDir();
|
||||
switch (dir) {
|
||||
case EAST:
|
||||
setBlockBounds(0.0625F, 0, 0.0625F, 1, 0.875F, 0.9365F);
|
||||
break;
|
||||
case NORTH:
|
||||
setBlockBounds(0.0625F, 0, 0, 0.9375F, 0.875F, 0.9365F);
|
||||
break;
|
||||
case SOUTH:
|
||||
setBlockBounds(0.0625F, 0, 0.0625F, 0.9375F, 0.875F, 1);
|
||||
break;
|
||||
case WEST:
|
||||
setBlockBounds(0, 0, 0.0625F, 0.9375F, 0.875F, 0.9365F);
|
||||
break;
|
||||
default:
|
||||
setBlockBounds(0.0625F, 0, 0.0625F, 0.9375F, 0.875F, 0.9365F);
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean hasTileEntity(int metadata) {
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int isProvidingStrongPower(IBlockAccess world, int x, int y, int z, int strength) {
|
||||
return strength == 1 ? isProvidingWeakPower(world, x, y, z, strength) : 0;
|
||||
public TileEntity createTileEntity(World world, int metadata) {
|
||||
return new TileEntityPresent();
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -234,7 +185,11 @@ public class BlockPresent extends BlockChest implements ICarvable {
|
||||
|
||||
@Override
|
||||
public int getComparatorInputOverride(World world, int x, int y, int z, int strength) {
|
||||
return Container.calcRedstoneFromInventory(getInventory(world, x, y, z));
|
||||
TileEntity te = world.getTileEntity(x, y, z);
|
||||
if (te instanceof TileEntityPresent) {
|
||||
return Container.calcRedstoneFromInventory((TileEntityPresent) te);
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -243,47 +198,10 @@ public class BlockPresent extends BlockChest implements ICarvable {
|
||||
this.blockIcon = register.registerIcon("planks_oak");
|
||||
}
|
||||
|
||||
public IInventory getInventory(World world, int x, int y, int z) {
|
||||
Object object = world.getTileEntity(x, y, z);
|
||||
|
||||
if (object == null) {
|
||||
return null;
|
||||
} else if (world.isSideSolid(x, y + 1, z, ForgeDirection.DOWN)) {
|
||||
return null;
|
||||
} else if (isCatSittingOnMe(world, x, y, z)) {
|
||||
return null;
|
||||
} else if (world.getBlock(x - 1, y, z) == this && (world.isSideSolid(x - 1, y + 1, z, ForgeDirection.DOWN) || isCatSittingOnMe(world, x, y - 1, z))) {
|
||||
return null;
|
||||
} else if (world.getBlock(x + 1, y, z) == this && (world.isSideSolid(x + 1, y + 1, z, ForgeDirection.DOWN) || isCatSittingOnMe(world, x, y + 1, z))) {
|
||||
return null;
|
||||
} else if (world.getBlock(x, y, z - 1) == this && (world.isSideSolid(x, y + 1, z - 1, ForgeDirection.DOWN) || isCatSittingOnMe(world, x, y, z - 1))) {
|
||||
return null;
|
||||
} else if (world.getBlock(x, y, z + 1) == this && (world.isSideSolid(x, y + 1, z + 1, ForgeDirection.DOWN) || isCatSittingOnMe(world, x, y, z + 1))) {
|
||||
return null;
|
||||
} else {
|
||||
if (world.getBlock(x - 1, y, z) == this) {
|
||||
object = new InventoryLargePresent("container.chestDouble", (TileEntityPresent) world.getTileEntity(x - 1, y, z), (IInventory) object);
|
||||
}
|
||||
|
||||
if (world.getBlock(x + 1, y, z) == this) {
|
||||
object = new InventoryLargePresent("container.chestDouble", (TileEntityPresent) world.getTileEntity(x + 1, y, z), (IInventory) object);
|
||||
}
|
||||
|
||||
if (world.getBlock(x, y, z - 1) == this) {
|
||||
object = new InventoryLargePresent("container.chestDouble", (TileEntityPresent) world.getTileEntity(x, y, z - 1), (IInventory) object);
|
||||
}
|
||||
|
||||
if (world.getBlock(x, y, z + 1) == this) {
|
||||
object = new InventoryLargePresent("container.chestDouble", (TileEntityPresent) world.getTileEntity(x, y, z + 1), (IInventory) object);
|
||||
}
|
||||
|
||||
return (IInventory) object;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public CarvableVariation getVariation(IBlockAccess world, int x, int y, int z, int metadata) {
|
||||
return carverHelper.getVariation(metadata);
|
||||
TileEntity te = world.getTileEntity(x, y, z);
|
||||
return te instanceof TileEntityPresent ? carverHelper.getVariation(((TileEntityPresent) te).getType()) : carverHelper.getVariation(metadata);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -1,110 +1,271 @@
|
||||
package com.cricketcraft.chisel.block.tileentity;
|
||||
|
||||
import java.util.Iterator;
|
||||
import java.util.List;
|
||||
|
||||
import net.minecraft.entity.player.EntityPlayer;
|
||||
import net.minecraft.inventory.ContainerChest;
|
||||
import net.minecraft.inventory.IInventory;
|
||||
import net.minecraft.tileentity.TileEntityChest;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.nbt.NBTTagCompound;
|
||||
import net.minecraft.nbt.NBTTagList;
|
||||
import net.minecraft.tileentity.TileEntity;
|
||||
import net.minecraft.util.AxisAlignedBB;
|
||||
import net.minecraftforge.common.util.ForgeDirection;
|
||||
|
||||
import com.cricketcraft.chisel.inventory.ContainerPresent;
|
||||
import com.cricketcraft.chisel.inventory.InventoryLargePresent;
|
||||
import com.cricketcraft.chisel.init.ChiselBlocks;
|
||||
import com.cricketcraft.chisel.network.PacketHandler;
|
||||
import com.cricketcraft.chisel.network.message.MessagePresentConnect;
|
||||
|
||||
public class TileEntityPresent extends TileEntityChest {
|
||||
public class TileEntityPresent extends TileEntity implements IInventory {
|
||||
|
||||
public int type;
|
||||
private int ticksSinceSync;
|
||||
|
||||
public TileEntityPresent(int type) {
|
||||
this.type = type;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isUseableByPlayer(EntityPlayer player) {
|
||||
return this.worldObj.getTileEntity(this.xCoord, this.yCoord, this.zCoord) != this ? false : player.getDistanceSq(this.xCoord + 0.5D, this.yCoord + 0.5D, this.zCoord + 0.5D) <= 64.0D;
|
||||
}
|
||||
private TileEntityPresent connection = null;
|
||||
private ForgeDirection cachedDir = null;
|
||||
private boolean isParent;
|
||||
private ItemStack[] inventory = new ItemStack[27];
|
||||
private int type;
|
||||
private boolean autoSearch = true;
|
||||
|
||||
@Override
|
||||
public void updateEntity() {
|
||||
super.updateEntity();
|
||||
this.checkForAdjacentChests();
|
||||
++this.ticksSinceSync;
|
||||
float f;
|
||||
if (isConnected() && connection.isInvalid()) {
|
||||
disconnect();
|
||||
}
|
||||
|
||||
if (!this.worldObj.isRemote && this.numPlayersUsing != 0 && (this.ticksSinceSync + this.xCoord + this.yCoord + this.zCoord) % 200 == 0) {
|
||||
this.numPlayersUsing = 0;
|
||||
f = 5.0F;
|
||||
List list = this.worldObj.getEntitiesWithinAABB(EntityPlayer.class, AxisAlignedBB.getBoundingBox(this.xCoord - f, this.yCoord - f,
|
||||
this.zCoord - f, this.xCoord + 1 + f, this.yCoord + 1 + f, this.zCoord + 1 + f));
|
||||
Iterator iterator = list.iterator();
|
||||
if (autoSearch && worldObj != null /* ugh */) {
|
||||
if (cachedDir != null) {
|
||||
connectTo(cachedDir);
|
||||
} else {
|
||||
findConnections();
|
||||
}
|
||||
autoSearch = false;
|
||||
}
|
||||
}
|
||||
|
||||
while (iterator.hasNext()) {
|
||||
EntityPlayer entityplayer = (EntityPlayer) iterator.next();
|
||||
public boolean isConnected() {
|
||||
return connection != null;
|
||||
}
|
||||
|
||||
if (entityplayer.openContainer instanceof ContainerPresent) {
|
||||
IInventory iinventory = ((ContainerChest) entityplayer.openContainer).getLowerChestInventory();
|
||||
private boolean connectTo(TileEntityPresent present, ForgeDirection dir) {
|
||||
if (present.type == type && !present.isConnected() && Math.abs(present.xCoord - xCoord + present.yCoord - yCoord + present.zCoord - zCoord) == 1) {
|
||||
connection = present;
|
||||
connection.connection = this;
|
||||
connection.cachedDir = dir.getOpposite();
|
||||
cachedDir = dir;
|
||||
isParent = !present.isParent;
|
||||
PacketHandler.INSTANCE.sendToDimension(new MessagePresentConnect(this, dir, true), worldObj.provider.dimensionId);
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
if (iinventory == this || iinventory instanceof InventoryLargePresent && ((InventoryLargePresent) iinventory).isPartOfLargePresent(this)) {
|
||||
++this.numPlayersUsing;
|
||||
public boolean connectTo(ForgeDirection dir) {
|
||||
TileEntity te = worldObj.getTileEntity(xCoord + dir.offsetX, yCoord + dir.offsetY, zCoord + dir.offsetZ);
|
||||
if (te instanceof TileEntityPresent) {
|
||||
return connectTo((TileEntityPresent) te, dir);
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
public void disconnect() {
|
||||
if (isConnected()) {
|
||||
this.connection.cachedDir = null;
|
||||
this.connection.connection = null;
|
||||
this.cachedDir = null;
|
||||
this.connection = null;
|
||||
PacketHandler.INSTANCE.sendToDimension(new MessagePresentConnect(this, ForgeDirection.UNKNOWN, false), worldObj.provider.dimensionId);
|
||||
}
|
||||
}
|
||||
|
||||
public TileEntityPresent getConnection() {
|
||||
return connection;
|
||||
}
|
||||
|
||||
public ForgeDirection getConnectionDir() {
|
||||
return cachedDir == null ? ForgeDirection.UNKNOWN : cachedDir;
|
||||
}
|
||||
|
||||
public boolean isParent() {
|
||||
return isParent || !isConnected();
|
||||
}
|
||||
|
||||
public int getType() {
|
||||
return type;
|
||||
}
|
||||
|
||||
public void setType(int type) {
|
||||
this.type = type;
|
||||
}
|
||||
|
||||
public void findConnections() {
|
||||
if (!isConnected()) {
|
||||
for (ForgeDirection dir : ForgeDirection.VALID_DIRECTIONS) {
|
||||
if (dir != ForgeDirection.UP && dir != ForgeDirection.DOWN) {
|
||||
if (connectTo(dir)) {
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public TileEntityPresent getParent() {
|
||||
return isParent || connection == null ? this : connection;
|
||||
}
|
||||
|
||||
this.prevLidAngle = this.lidAngle;
|
||||
f = 0.1F;
|
||||
double d2;
|
||||
@Override
|
||||
public AxisAlignedBB getRenderBoundingBox() {
|
||||
return ChiselBlocks.present.getBoundingBox(this);
|
||||
}
|
||||
|
||||
if (this.numPlayersUsing > 0 && this.lidAngle == 0.0F && this.adjacentChestZNeg == null && this.adjacentChestXNeg == null) {
|
||||
double d1 = this.xCoord + 0.5D;
|
||||
d2 = this.zCoord + 0.5D;
|
||||
@Override
|
||||
public void writeToNBT(NBTTagCompound tag)
|
||||
{
|
||||
super.writeToNBT(tag);
|
||||
NBTTagList nbttaglist = new NBTTagList();
|
||||
|
||||
if (this.adjacentChestZPos != null) {
|
||||
d2 += 0.5D;
|
||||
for (int i = 0; i < inventory.length; ++i)
|
||||
{
|
||||
if (inventory[i] != null)
|
||||
{
|
||||
NBTTagCompound nbttagcompound1 = new NBTTagCompound();
|
||||
nbttagcompound1.setByte("Slot", (byte) i);
|
||||
inventory[i].writeToNBT(nbttagcompound1);
|
||||
nbttaglist.appendTag(nbttagcompound1);
|
||||
}
|
||||
|
||||
if (this.adjacentChestXPos != null) {
|
||||
d1 += 0.5D;
|
||||
}
|
||||
|
||||
this.worldObj.playSoundEffect(d1, this.yCoord + 0.5D, d2, "random.chestopen", 0.5F, this.worldObj.rand.nextFloat() * 0.1F + 0.9F);
|
||||
}
|
||||
|
||||
if (this.numPlayersUsing == 0 && this.lidAngle > 0.0F || this.numPlayersUsing > 0 && this.lidAngle < 1.0F) {
|
||||
float f1 = this.lidAngle;
|
||||
|
||||
if (this.numPlayersUsing > 0) {
|
||||
this.lidAngle += f;
|
||||
} else {
|
||||
this.lidAngle -= f;
|
||||
}
|
||||
|
||||
if (this.lidAngle > 1.0F) {
|
||||
this.lidAngle = 1.0F;
|
||||
}
|
||||
|
||||
float f2 = 0.5F;
|
||||
|
||||
if (this.lidAngle < f2 && f1 >= f2 && this.adjacentChestZNeg == null && this.adjacentChestXNeg == null) {
|
||||
d2 = this.xCoord + 0.5D;
|
||||
double d0 = this.zCoord + 0.5D;
|
||||
|
||||
if (this.adjacentChestZPos != null) {
|
||||
d0 += 0.5D;
|
||||
}
|
||||
|
||||
if (this.adjacentChestXPos != null) {
|
||||
d2 += 0.5D;
|
||||
}
|
||||
|
||||
this.worldObj.playSoundEffect(d2, this.yCoord + 0.5D, d0, "random.chestclosed", 0.5F, this.worldObj.rand.nextFloat() * 0.1F + 0.9F);
|
||||
}
|
||||
|
||||
if (this.lidAngle < 0.0F) {
|
||||
this.lidAngle = 0.0F;
|
||||
}
|
||||
tag.setTag("Items", nbttaglist);
|
||||
tag.setBoolean("isParent", isParent);
|
||||
tag.setInteger("presentType", type);
|
||||
if (cachedDir != null) {
|
||||
tag.setInteger("conDir", cachedDir.ordinal());
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void readFromNBT(NBTTagCompound tag)
|
||||
{
|
||||
super.readFromNBT(tag);
|
||||
NBTTagList nbttaglist = tag.getTagList("Items", 10);
|
||||
inventory = new ItemStack[this.getSizeInventory()];
|
||||
|
||||
for (int i = 0; i < nbttaglist.tagCount(); ++i)
|
||||
{
|
||||
NBTTagCompound nbttagcompound1 = nbttaglist.getCompoundTagAt(i);
|
||||
int j = nbttagcompound1.getByte("Slot") & 255;
|
||||
|
||||
if (j >= 0 && j < inventory.length)
|
||||
{
|
||||
inventory[j] = ItemStack.loadItemStackFromNBT(nbttagcompound1);
|
||||
}
|
||||
}
|
||||
|
||||
this.isParent = tag.getBoolean("isParent");
|
||||
|
||||
this.type = tag.getInteger("presentType");
|
||||
if (tag.hasKey("conDir")) {
|
||||
cachedDir = ForgeDirection.values()[tag.getInteger("conDir")];
|
||||
}
|
||||
autoSearch = true;
|
||||
}
|
||||
|
||||
/* IInventory */
|
||||
|
||||
@Override
|
||||
public int getSizeInventory() {
|
||||
return isConnected() ? inventory.length + connection.inventory.length : inventory.length;
|
||||
}
|
||||
|
||||
@Override
|
||||
public ItemStack getStackInSlot(int slot) {
|
||||
if (slot >= inventory.length) {
|
||||
return isConnected() ? connection.inventory[slot % inventory.length] : null;
|
||||
} else {
|
||||
return inventory[slot];
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public ItemStack decrStackSize(int slot, int amount)
|
||||
{
|
||||
ItemStack[] inv = inventory;
|
||||
if (isConnected() && slot >= inventory.length) {
|
||||
inv = connection.inventory;
|
||||
}
|
||||
|
||||
if (inv[slot] != null)
|
||||
{
|
||||
ItemStack itemstack;
|
||||
|
||||
if (inv[slot].stackSize <= amount)
|
||||
{
|
||||
itemstack = inv[slot];
|
||||
inv[slot] = null;
|
||||
this.markDirty();
|
||||
return itemstack;
|
||||
}
|
||||
else
|
||||
{
|
||||
itemstack = inv[slot].splitStack(amount);
|
||||
|
||||
if (inv[slot].stackSize == 0)
|
||||
{
|
||||
inv[slot] = null;
|
||||
}
|
||||
|
||||
this.markDirty();
|
||||
return itemstack;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public ItemStack getStackInSlotOnClosing(int slot) {
|
||||
return getStackInSlot(slot);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setInventorySlotContents(int slot, ItemStack stack) {
|
||||
if (slot < inventory.length) {
|
||||
inventory[slot] = stack;
|
||||
} else if (isConnected()) {
|
||||
connection.inventory[slot % inventory.length] = stack;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getInventoryName() {
|
||||
return "chisel.present";
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean hasCustomInventoryName() {
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getInventoryStackLimit() {
|
||||
return 64;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isUseableByPlayer(EntityPlayer p_70300_1_) {
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void openInventory() {
|
||||
;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void closeInventory() {
|
||||
;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isItemValidForSlot(int p_94041_1_, ItemStack p_94041_2_) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user