Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package com.camerpon900.realauto2.blocks.TileEntities;
- import com.camerpon900.realauto2.blocks.Blocks;
- import com.camerpon900.realauto2.utils.WorldHelper;
- import net.minecraft.entity.player.EntityPlayer;
- import net.minecraft.inventory.ISidedInventory;
- import net.minecraft.item.ItemStack;
- import net.minecraft.nbt.NBTTagCompound;
- import net.minecraft.nbt.NBTTagList;
- import net.minecraft.tileentity.TileEntity;
- import net.minecraft.world.World;
- import net.minecraft.world.biome.BiomeGenDesert;
- import net.minecraftforge.common.util.ForgeDirection;
- public class TileEntityEnergyCube extends TileEntity implements ISidedInventory {
- private ItemStack[] slots = new ItemStack[2];
- public int power = 0;
- private int maxPower = 5000000;
- private int inputSpeed = 20; //20 every tick
- public TileEntityEnergyCube() {
- }
- public void updateEntity() {
- chargeCube(worldObj);
- }
- public void readFromNBT(NBTTagCompound nbt) {
- super.readFromNBT(nbt);
- System.out.println("slots " + this.slots);
- System.out.println("reading nbt");
- NBTTagList list = nbt.getTagList("Slots", 10);
- NBTTagList powerList = nbt.getTagList("Power", power);
- this.slots = new ItemStack[getSizeInventory()];
- for (int i = 0; i < list.tagCount(); i++) {
- NBTTagCompound item = list.getCompoundTagAt(i);
- NBTTagCompound power = list.getCompoundTagAt(i);
- byte b = item.getByte("Item");
- int p = item.getInteger("Power");
- if (b >= 0 && b < this.slots.length) {
- this.slots[b] = ItemStack.loadItemStackFromNBT(item);
- }
- if (p >= 0 && p < this.maxPower) {
- this.power = power.getInteger("Power");
- }
- }
- }
- public void writeToNBT(NBTTagCompound nbt) {
- super.writeToNBT(nbt);
- System.out.println("Writing To NBT at x: " + xCoord + " y: " + yCoord + " z: " + zCoord);
- NBTTagList list = new NBTTagList();
- for (int i = 0; i < slots.length; i++) {
- if (this.slots[i] != null) {
- NBTTagCompound item = new NBTTagCompound();
- item.setByte("Item", (byte) i);
- this.slots[i].writeToNBT(item);
- list.appendTag(item);
- }
- }
- if (power >= 1) {
- NBTTagCompound power = new NBTTagCompound();
- power.setInteger("Power", this.power);
- list.appendTag(power);
- }
- nbt.setTag("Power", list);
- nbt.setTag("Slots", list);
- }
- public int getSizeInventory() {
- return this.slots.length;
- }
- public int[] getAccessibleSlotsFromSide(int p_94128_1_) {
- return new int[0];
- }
- public boolean canInsertItem(int p_102007_1_, ItemStack p_102007_2_, int p_102007_3_) {
- return this.isItemValidForSlot(p_102007_1_, p_102007_2_);
- }
- public boolean canExtractItem(int p_102008_1_, ItemStack p_102008_2_, int p_102008_3_) {
- return true;
- }
- public ItemStack getStackInSlot(int i) {
- return this.slots[i];
- }
- public ItemStack decrStackSize(int i, int j) {
- if (this.slots[i] != null) {
- System.out.println(this.slots[i]);
- ItemStack itemStack;
- if (this.slots[i].stackSize <= j) {
- itemStack = this.slots[i];
- this.slots[i] = null;
- return itemStack;
- } else {
- itemStack = this.slots[i].splitStack(j);
- if (this.slots[i].stackSize == 0) {
- this.slots[i] = null;
- }
- }
- return itemStack;
- }
- return null;
- }
- public ItemStack getStackInSlotOnClosing(int slot) {
- ItemStack stack = getStackInSlot(slot);
- if (stack != null) {
- setInventorySlotContents(slot, null);
- }
- return stack;
- }
- public void setInventorySlotContents(int i, ItemStack itemStack) {
- this.slots[i] = itemStack;
- if (itemStack != null && itemStack.stackSize > this.getInventoryStackLimit()) {
- itemStack.stackSize = this.getInventoryStackLimit();
- }
- }
- public String getInventoryName() {
- return null;
- }
- public boolean hasCustomInventoryName() {
- return false;
- }
- public int getInventoryStackLimit() {
- return 64;
- }
- public boolean isUseableByPlayer(EntityPlayer p_70300_1_) {
- return true;
- }
- public void openInventory() {
- }
- public void closeInventory() {
- }
- public boolean isItemValidForSlot(int p_94041_1_, ItemStack p_94041_2_) {
- return true;
- }
- public void charge() {
- }
- public void chargeCube(World world) {
- if (world.getBlock(xCoord + 1, yCoord, zCoord) == Blocks.blockBasicSolarPanel) {
- System.out.println("Test");
- TileEntity tileEntity = world.getTileEntity(xCoord + 1, yCoord, zCoord);
- }
- if (world.getBlock(xCoord - 1, yCoord, zCoord) == Blocks.blockBasicSolarPanel) {
- System.out.println("Test");
- TileEntity tileEntity = world.getTileEntity(xCoord - 1, yCoord, zCoord);
- }
- if (world.getBlock(xCoord, yCoord + 1, zCoord) == Blocks.blockBasicSolarPanel) {
- System.out.println("Test");
- TileEntity tileEntity = world.getTileEntity(xCoord, yCoord + 1, zCoord);
- }
- if (world.getBlock(xCoord, yCoord, zCoord + 1) == Blocks.blockBasicSolarPanel) {
- System.out.println("Test");
- TileEntity tileEntity = world.getTileEntity(xCoord, yCoord, zCoord + 1);
- }
- if (world.getBlock(xCoord, yCoord, zCoord - 1) == Blocks.blockBasicSolarPanel) {
- System.out.println("Test");
- TileEntity tileEntity = world.getTileEntity(xCoord, yCoord, zCoord - 1);
- if (tileEntity instanceof TileEntitySolarPanel) {
- ((TileEntitySolarPanel) tileEntity).power -= this.inputSpeed;
- if (((TileEntitySolarPanel) tileEntity).power != 0) {
- this.power += inputSpeed;
- }
- }
- }
- }
- public int getPowerScaled(int scaled) {
- return (int) scaled;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment