Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public class ContainerTeleporterBlock extends Container{
- private final TeleporterTE te;
- /** Do not edit these values directly */
- private int currentEnergy;
- private int eupu;
- public ContainerTeleporterBlock(IInventory playerInv, TeleporterTE te) {
- this.te = te;
- //te slot 0, slot id 0
- this.addSlotToContainer(new EnergyCapsuleSlot(te, 0, 36, 2));
- //te slot 1, slot id 1
- this.addSlotToContainer(new CordeCacheSlot(te, 1, 72, 2));
- //Player Inventory Slots 9-35, Slot IDs 2-29
- for(int y = 0; y < 3; y++){
- for(int x = 0; x < 9; x++){
- this.addSlotToContainer(new Slot(playerInv, x + y * 9 + 9, 8 + x * 18, 48 + y * 18));
- }
- }
- // Player Inventory, Slot 0-8, Slot IDs 28-36
- for (int x = 0; x < 9; ++x) {
- this.addSlotToContainer(new Slot(playerInv, x, 8 + x * 18, 105));
- }
- }
- @Override
- public ItemStack transferStackInSlot(EntityPlayer playerIn, int fromSlot) {
- ItemStack previous = null;
- Slot slot = (Slot) this.inventorySlots.get(fromSlot);
- if (slot != null && slot.getHasStack()) {
- ItemStack current = slot.getStack();
- previous = current.copy();
- if (fromSlot < 2) {
- // From TE Inventory to Player Inventory
- if (!this.mergeItemStack(current, 2, 29, true))
- return null;
- } else {
- // From Player Inventory to TE Inventory
- if (!this.mergeItemStack(current, 0, 2, false))
- return null;
- }
- if (current.stackSize == 0)
- slot.putStack((ItemStack) null);
- else
- slot.onSlotChanged();
- if (current.stackSize == previous.stackSize)
- return null;
- slot.onPickupFromSlot(playerIn, current);
- }
- return previous;
- }
- @Override
- protected boolean mergeItemStack(ItemStack stack, int start, int end, boolean backwards)
- {
- boolean flag1 = false;
- int k = (backwards ? end - 1 : start);
- Slot slot;
- ItemStack itemstack1;
- if (stack.isStackable())
- {
- while (stack.stackSize > 0 && (!backwards && k < end || backwards && k >= start))
- {
- slot = (Slot) inventorySlots.get(k);
- itemstack1 = slot.getStack();
- if (!slot.isItemValid(stack)) {
- k += (backwards ? -1 : 1);
- continue;
- }
- if (itemstack1 != null && itemstack1.getItem() == stack.getItem() &&
- (!stack.getHasSubtypes() || stack.getItemDamage() == itemstack1.getItemDamage()) && ItemStack.areItemStackTagsEqual(stack, itemstack1))
- {
- int l = itemstack1.stackSize + stack.stackSize;
- if (l <= stack.getMaxStackSize() && l <= slot.getSlotStackLimit()) {
- stack.stackSize = 0;
- itemstack1.stackSize = l;
- te.markDirty();;
- flag1 = true;
- } else if (itemstack1.stackSize < stack.getMaxStackSize() && l < slot.getSlotStackLimit()) {
- stack.stackSize -= stack.getMaxStackSize() - itemstack1.stackSize;
- itemstack1.stackSize = stack.getMaxStackSize();
- te.markDirty();;
- flag1 = true;
- }
- }
- k += (backwards ? -1 : 1);
- }
- }
- if (stack.stackSize > 0)
- {
- k = (backwards ? end - 1 : start);
- while (!backwards && k < end || backwards && k >= start) {
- slot = (Slot) inventorySlots.get(k);
- itemstack1 = slot.getStack();
- if (!slot.isItemValid(stack)) {
- k += (backwards ? -1 : 1);
- continue;
- }
- if (itemstack1 == null) {
- int l = stack.stackSize;
- if (l <= slot.getSlotStackLimit()) {
- slot.putStack(stack.copy());
- stack.stackSize = 0;
- te.markDirty();;
- flag1 = true;
- break;
- } else {
- putStackInSlot(k, new ItemStack(stack.getItem(), slot.getSlotStackLimit(), stack.getItemDamage()));
- stack.stackSize -= slot.getSlotStackLimit();
- te.markDirty();;
- flag1 = true;
- }
- }
- k += (backwards ? -1 : 1);
- }
- }
- return flag1;
- }
- /**
- * ATTENTION! This class only updates when the player is in the inventory
- */
- @Override
- public void detectAndSendChanges() {
- super.detectAndSendChanges();
- for(int i = 0; i < this.crafters.size(); i++){
- ICrafting icrafting = (ICrafting)this.crafters.get(i);
- if(this.currentEnergy != this.te.getField(0)){
- icrafting.sendProgressBarUpdate(this, 0, this.te.getField(0));
- }
- if(this.eupu != te.getField(1)){
- icrafting.sendProgressBarUpdate(this, 1, this.te.getField(1));
- }
- }
- }
- @Override
- public void updateProgressBar(int id, int data) {
- this.te.setField(id, data);
- }
- @Override
- public boolean canInteractWith(EntityPlayer playerIn) {
- return this.te.isUseableByPlayer(playerIn);
- }
- /** Causes the game not to update. Fix somehow?
- * When this is removed, it works just fine except for the fact that if you remove a corde cache
- * from one block, the one it was pointing to doesn't update... IDK WHY!
- *
- * QUICK IDEA
- * Redo the initialize thing I had going on in the tile entity, so it only updates once
- * then let this do all the updating (i.e. let this use both server and client) Only if server finds tile entity though
- *
- */
- @Override
- public ItemStack slotClick(int slotId, int clickedButton, int mode, EntityPlayer player) {
- return super.slotClick(slotId, clickedButton, mode, player);
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement