Change package name for realsies now :P

This commit is contained in:
Arona Jones committed 2014-12-15 00:11:48 +00:00
1 parent 4d8df815cc
commit dae454dc17
138 files changed
+491 -438

No files matched your search

@@ -0,0 +1,236 @@
package com.cricketcraft.chisel.block.tileentity;
import net.minecraft.entity.item.EntityItem;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.inventory.ISidedInventory;
import net.minecraft.item.ItemBlock;
import net.minecraft.item.ItemStack;
import net.minecraft.nbt.NBTTagCompound;
import net.minecraft.nbt.NBTTagList;
import net.minecraft.network.NetworkManager;
import net.minecraft.network.Packet;
import net.minecraft.network.play.server.S35PacketUpdateTileEntity;
import net.minecraft.tileentity.TileEntity;
import cpw.mods.fml.relauncher.Side;
import cpw.mods.fml.relauncher.SideOnly;
public class TileEntityAutoChisel extends TileEntity implements ISidedInventory {
private static EntityItem ghostItem;
boolean equal = false;
private ItemStack[] inventory = new ItemStack[3];
private String name = "autoChisel";
@Override
public boolean canUpdate() {
return true;
}
@Override
public ItemStack decrStackSize(int slot, int size) {
if (inventory[slot] != null) {
ItemStack is;
if (inventory[slot].stackSize <= size) {
is = inventory[slot];
inventory[slot] = null;
return is;
} else {
is = inventory[slot].splitStack(size);
if (inventory[slot].stackSize == 0)
inventory[slot] = null;
return is;
}
} else
return null;
}
@Override
public void readFromNBT(NBTTagCompound nbt) {
super.readFromNBT(nbt);
NBTTagList tags = nbt.getTagList("Items", 10);
inventory = new ItemStack[getSizeInventory()];
for (int i = 0; i < tags.tagCount(); i++) {
NBTTagCompound data = tags.getCompoundTagAt(i);
int j = data.getByte("Slot") & 255;
if (j >= 0 && j < inventory.length) {
inventory[j] = ItemStack.loadItemStackFromNBT(data);
}
}
if (nbt.hasKey("CustomName", 8)) {
this.name = nbt.getString("CustomName");
}
}
@Override
public void updateEntity() {
if (!worldObj.isRemote && worldObj.getWorldTime() % 20 == 0) {
if (inventory[0] != null && inventory[1] != null) {
if (inventory[0].getItem() instanceof ItemBlock && inventory[1].getItem() instanceof ItemBlock) {
if (inventory[0].getItem() == inventory[1].getItem()) {
equal = true;
} else {
equal = false;
}
if (equal) {
if (inventory[0].stackSize < 0) {
inventory[0] = null;
}
if (inventory[1].stackSize < 0) {
inventory[1] = null;
}
if (inventory[1].stackSize < 0) {
inventory[1] = null;
}
if (inventory[2] == null) {
setInventorySlotContents(2, new ItemStack(inventory[1].getItem(), 1, inventory[1].getItemDamage()));
decrStackSize(0, 1);
} else {
if (inventory[0].stackSize != 0 && inventory[2].stackSize <= getInventoryStackLimit()) {
decrStackSize(0, 1);
inventory[2].stackSize++;
} else {
inventory[0] = null;
}
}
}
}
}
}
markDirty();
}
@Override
public void writeToNBT(NBTTagCompound nbt) {
super.writeToNBT(nbt);
NBTTagList tags = new NBTTagList();
for (int i = 0; i < inventory.length; i++) {
if (inventory[i] != null) {
NBTTagCompound data = new NBTTagCompound();
data.setByte("Slot", (byte) i);
inventory[i].writeToNBT(data);
tags.appendTag(data);
}
}
nbt.setTag("Items", tags);
if (this.hasCustomInventoryName()) {
nbt.setString("CustomName", this.name);
}
}
@Override
public int getSizeInventory() {
return inventory.length;
}
@Override
public ItemStack getStackInSlot(int slot) {
return inventory[slot];
}
@Override
public ItemStack getStackInSlotOnClosing(int slot) {
if (inventory[slot] != null) {
ItemStack is = inventory[slot];
inventory[slot] = null;
return is;
} else
return null;
}
@Override
public void setInventorySlotContents(int slot, ItemStack stack) {
inventory[slot] = stack;
if (stack != null && stack.stackSize > getInventoryStackLimit()) {
stack.stackSize = getInventoryStackLimit();
}
markDirty();
}
@Override
public String getInventoryName() {
return name;
}
@Override
public final boolean isUseableByPlayer(EntityPlayer player) {
return true;
}
@Override
public int getInventoryStackLimit() {
return 64;
}
@Override
public boolean hasCustomInventoryName() {
return false;
}
@Override
public int[] getAccessibleSlotsFromSide(int side) {
return new int[3];
}
@Override
public boolean isItemValidForSlot(int slot, ItemStack itemStack) {
return true;
}
@Override
public boolean canInsertItem(int slot, ItemStack itemStack, int side) {
return false;
}
@Override
public boolean canExtractItem(int slot, ItemStack itemStack, int side) {
return true;
}
@Override
public void openInventory() {
}
@Override
public void closeInventory() {
NBTTagList tags = new NBTTagList();
System.out.print(tags);
}
@SideOnly(Side.CLIENT)
public EntityItem getItemForRendering(int slot) {
if (ghostItem == null) {
ghostItem = new EntityItem(worldObj);
ghostItem.hoverStart = 0.0F;
}
if (inventory[slot] == null) {
return null;
} else {
ghostItem.setEntityItemStack(new ItemStack(inventory[slot].getItem(), 1, inventory[slot].getItemDamage()));
return ghostItem;
}
}
@Override
public Packet getDescriptionPacket() {
NBTTagCompound tag = new NBTTagCompound();
writeToNBT(tag);
return new S35PacketUpdateTileEntity(xCoord, yCoord, zCoord, 1, tag);
}
@Override
public void onDataPacket(NetworkManager net, S35PacketUpdateTileEntity packet) {
readFromNBT(packet.func_148857_g());
}
}
@@ -0,0 +1,221 @@
package com.cricketcraft.chisel.block.tileentity;
import java.util.Iterator;
import java.util.List;
import com.cricketcraft.chisel.block.BlockPresent;
import com.cricketcraft.chisel.inventory.ContainerPresent;
import com.cricketcraft.chisel.inventory.InventoryLargePresent;
import net.minecraft.block.Block;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.inventory.IInventory;
import net.minecraft.tileentity.TileEntityChest;
import net.minecraft.util.AxisAlignedBB;
public class TileEntityPresent extends TileEntityChest {
public TileEntityPresent() {
}
@Override
public boolean isUseableByPlayer(EntityPlayer player) {
return this.worldObj.getTileEntity(xCoord, yCoord, zCoord) != this ? false : player.getDistanceSq(xCoord + 0.5D, yCoord + 0.5D, zCoord + 0.5D) <= 64.0D;
}
public void checkIfAdjacentBlocksAreMe(TileEntityPresent tile, int meta) {
if (tile.isInvalid()) {
this.adjacentChestChecked = false;
} else if (this.adjacentChestChecked) {
switch (meta) {
case 0:
if (this.adjacentChestZPos != tile) {
this.adjacentChestChecked = false;
}
break;
case 1:
if (this.adjacentChestXNeg != tile) {
this.adjacentChestChecked = false;
}
break;
case 2:
if (this.adjacentChestZNeg != tile) {
this.adjacentChestChecked = false;
}
break;
case 3:
if (this.adjacentChestXPos != tile) {
this.adjacentChestChecked = false;
}
}
}
}
public void checkForAdjacentPresents() {
if (!this.adjacentChestChecked) {
TileEntityPresent zNeg = (TileEntityPresent) this.adjacentChestZNeg;
TileEntityPresent xPos = (TileEntityPresent) this.adjacentChestXPos;
TileEntityPresent xNeg = (TileEntityPresent) this.adjacentChestXNeg;
TileEntityPresent zPos = (TileEntityPresent) this.adjacentChestZPos;
this.adjacentChestChecked = true;
if (this.isBlockPresent(xCoord - 1, yCoord, zCoord)) {
xNeg = (TileEntityPresent) this.worldObj.getTileEntity(xCoord - 1, yCoord, zCoord);
}
if (this.isBlockPresent(xCoord + 1, yCoord, zCoord)) {
xPos = (TileEntityPresent) this.worldObj.getTileEntity(xCoord + 1, yCoord, zCoord);
}
if (this.isBlockPresent(xCoord, yCoord, zCoord - 1)) {
zNeg = (TileEntityPresent) this.worldObj.getTileEntity(xCoord, yCoord, zCoord - 1);
}
if (this.isBlockPresent(xCoord, yCoord, zCoord + 1)) {
zPos = (TileEntityPresent) this.worldObj.getTileEntity(xCoord, yCoord, zCoord + 1);
}
if (this.adjacentChestZNeg != null) {
zNeg.checkIfAdjacentBlocksAreMe(this, 0);
}
if (this.adjacentChestZPos != null) {
zPos.checkIfAdjacentBlocksAreMe(this, 2);
}
if (this.adjacentChestXPos != null) {
xPos.checkIfAdjacentBlocksAreMe(this, 1);
}
if (this.adjacentChestXNeg != null) {
xNeg.checkIfAdjacentBlocksAreMe(this, 3);
}
this.adjacentChestXNeg = xNeg;
this.adjacentChestXPos = xPos;
this.adjacentChestZPos = zPos;
this.adjacentChestZNeg = zNeg;
}
}
private boolean isBlockPresent(int x, int y, int z) {
if (this.worldObj == null) {
return false;
} else {
Block block = this.worldObj.getBlock(x, y, z);
return block instanceof BlockPresent;
}
}
@Override
public void updateEntity() {
super.updateEntity();
checkForAdjacentPresents();
float f;
if (!worldObj.isRemote && numPlayersUsing != 0 && (+xCoord + yCoord + zCoord) % 200 == 0) {
numPlayersUsing = 0;
f = 5.0F;
List<?> list = worldObj.getEntitiesWithinAABB(EntityPlayer.class, AxisAlignedBB.getBoundingBox(xCoord - f, yCoord - f, zCoord - f, (xCoord + 1) + f, (yCoord + 1) + f, (zCoord + 1) + f));
Iterator<?> iterator = list.iterator();
while (iterator.hasNext()) {
EntityPlayer player = (EntityPlayer) iterator.next();
if (player.openContainer instanceof ContainerPresent) {
IInventory inventory = ((ContainerPresent) player.openContainer).getLowerPresentInventory();
if (inventory == this || inventory instanceof InventoryLargePresent && ((InventoryLargePresent) inventory).isPartOfLargePresent(this)) {
++numPlayersUsing;
}
}
}
}
prevLidAngle = lidAngle;
f = 0.1F;
double d2;
if (numPlayersUsing > 0 && lidAngle == 0.0F && adjacentChestZNeg == null && adjacentChestXNeg == null) {
double d1 = xCoord + 0.5D;
d2 = xCoord + 0.5D;
if (adjacentChestZPos != null) {
d2 += 0.5D;
}
if (adjacentChestXPos != null) {
d1 += 0.5D;
}
worldObj.playSoundEffect(d1, yCoord + 0.5D, d2, "random.chestopen", 0.5F, worldObj.rand.nextFloat() * 0.1F + 0.9F);
}
if (numPlayersUsing == 0 && lidAngle > 0.0F || numPlayersUsing > 0 && lidAngle < 1.0F) {
float f1 = lidAngle;
if (numPlayersUsing > 0) {
lidAngle += f;
} else {
lidAngle -= f;
}
if (lidAngle > 1.0F) {
lidAngle = 1.0F;
}
float f2 = 0.5F;
if (lidAngle < f2 && f1 >= f2 && adjacentChestZNeg == null && adjacentChestXNeg == null) {
d2 = xCoord + 0.5D;
double d0 = zCoord + 0.5D;
if (adjacentChestZPos != null) {
d0 += 0.5D;
}
if (adjacentChestXPos != null) {
d2 += 0.5D;
}
worldObj.playSoundEffect(d2, yCoord + 0.5D, d0, "random.chestclosed", 0.5F, worldObj.rand.nextFloat() * 0.1F + 0.9F);
}
if (lidAngle < 0.0F) {
lidAngle = 0.0F;
}
}
}
@Override
public void openInventory() {
if (numPlayersUsing < 0) {
numPlayersUsing = 0;
}
++numPlayersUsing;
worldObj.addBlockEvent(xCoord, yCoord, zCoord, getBlockType(), 1, numPlayersUsing);
worldObj.notifyBlocksOfNeighborChange(xCoord, yCoord, zCoord, getBlockType());
worldObj.notifyBlocksOfNeighborChange(xCoord, yCoord - 1, zCoord, getBlockType());
}
@Override
public void closeInventory() {
if (getBlockType() instanceof BlockPresent) {
--numPlayersUsing;
worldObj.addBlockEvent(xCoord, yCoord, zCoord, getBlockType(), 1, numPlayersUsing);
worldObj.notifyBlocksOfNeighborChange(xCoord, yCoord, zCoord, getBlockType());
worldObj.notifyBlocksOfNeighborChange(xCoord, yCoord - 1, zCoord, getBlockType());
}
}
@Override
public void invalidate() {
super.invalidate();
updateContainingBlockInfo();
checkForAdjacentPresents();
}
}