Advertisement
Guest User

Disassembler

a guest
Jun 6th, 2016
51
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 8.08 KB | None | 0 0
  1.  
  2. package atomizer.tileentities;
  3.  
  4. import java.util.ArrayList;
  5.  
  6. import javax.swing.plaf.basic.BasicComboBoxUI.ItemHandler;
  7.  
  8. import atomizer.lib.Constants;
  9. import atomizer.recipes.AtomizerRecipes;
  10. import atomizer.recipes.RecipeDisassembler;
  11. import net.minecraft.entity.player.EntityPlayer;
  12. import net.minecraft.inventory.IInventory;
  13. import net.minecraft.item.Item;
  14. import net.minecraft.item.ItemStack;
  15. import net.minecraft.nbt.NBTTagCompound;
  16. import net.minecraft.nbt.NBTTagList;
  17. import net.minecraft.tileentity.TileEntity;
  18. import net.minecraft.tileentity.TileEntityFurnace;
  19. import net.minecraft.util.ChatComponentText;
  20. import net.minecraft.util.ChatComponentTranslation;
  21. import net.minecraft.util.EnumFacing;
  22. import net.minecraft.util.IChatComponent;
  23. import net.minecraft.util.ITickable;
  24. import net.minecraft.world.World;
  25. import net.minecraftforge.common.capabilities.Capability;
  26. import net.minecraftforge.common.capabilities.CapabilityInject;
  27. import net.minecraftforge.fml.common.registry.GameRegistry;
  28. import net.minecraftforge.items.IItemHandler;
  29. import net.minecraftforge.items.ItemStackHandler;
  30. import scala.collection.TraversableOnce.OnceCanBuildFrom;
  31.  
  32. public class TileEntityDisassembler1 extends TileEntity implements ITickable {
  33.  
  34.     public static final String UNLOCALIZED_TILEENTITY_NAME = "Disassembler1TileEntity";
  35.  
  36.     public static final int SLOT_INPUT = 0;
  37.     public static final int SLOT_FUEL = 1;
  38.     public static final int SLOT_OUTPUT1 = 2;
  39.     public static final int SLOT_OUTPUT2 = 3;
  40.     public static final int SLOT_LUCK = 4;
  41.  
  42.     private ItemStackHandler ish;
  43.     private int disassemblerFuelTime;
  44.     private int disassemblerMaxFuelTime;
  45.     private int disassemblerChrushingTime;
  46.  
  47.     @CapabilityInject(ItemHandler.class)
  48.     static Capability<ItemHandler> ITEM_HANDLER_CAPABILITY = null;
  49.  
  50.     private ArrayList aList = new ArrayList();
  51.  
  52.     public TileEntityDisassembler1() {
  53.         // Last Slot Variable + 1
  54.         ish = new ItemStackHandler(SLOT_LUCK + 1);
  55.     }
  56.  
  57.     /**
  58.      * Gets called every tick. 20 times per seconds
  59.      */
  60.     @Override
  61.     public void update() {
  62.         ItemStack input = this.ish.getStackInSlot(SLOT_INPUT);
  63.         ItemStack fuel = this.ish.getStackInSlot(SLOT_FUEL);
  64.  
  65.         // Testing Purpose
  66.         if (this.disassemblerFuelTime % 10 == 0) {
  67.             System.out.println("FuleTime: " + this.disassemblerFuelTime);
  68.         }
  69.         if (this.disassemblerChrushingTime % 10 == 0) {
  70.             System.out.println("CrushingTime: " + this.disassemblerChrushingTime);
  71.         }
  72.  
  73.         // If this TE has crushingTime left and has FuleTime left
  74.         // it is considered crushing right now. Therefore
  75.         // the crushing time will be decreased by one.
  76.         // If it is not crushing anymore, the crushing time will
  77.         // be set back to 100
  78.         if (this.isCrushing() && AtomizerRecipes.containsDisassemblerRecipe(input)) {
  79.             RecipeDisassembler rd = AtomizerRecipes.getDisassemblerRecipe(input);
  80.             if (ish.getStackInSlot(SLOT_OUTPUT1) == null || ish.getStackInSlot(SLOT_OUTPUT1).getItem() == null
  81.                     || ish.getStackInSlot(SLOT_OUTPUT1).getItem() == rd.getOutput()[0].getItem()) {
  82.                 --this.disassemblerChrushingTime;
  83.             }
  84.         } else {
  85.             this.disassemblerChrushingTime = 200;
  86.         }
  87.  
  88.         // If this TE has fuelTime left,
  89.         // it will get reduced by one
  90.         if (this.hasFuel()) {
  91.             --this.disassemblerFuelTime;
  92.         }
  93.  
  94.         // If the crushingTime meets 0 it should check, if there is any Fuel and
  95.         // if there is something to be processed
  96.         // then consumes one of this fuel and refreshes the chrushingTime
  97.         if (this.disassemblerFuelTime < 1) {
  98.             if (AtomizerRecipes.containsDisassemblerRecipe(input)) {
  99.                 System.out.println("Input has a Recipe");
  100.                 RecipeDisassembler rd = AtomizerRecipes.getDisassemblerRecipe(input);
  101.                 if (ish.getStackInSlot(SLOT_OUTPUT1) == null || ish.getStackInSlot(SLOT_OUTPUT1).getItem() == null) {
  102.                     System.out.println("Output 1 is empty");
  103.                     if (fuel != null && TileEntityFurnace.isItemFuel(fuel)) {
  104.                         System.out.println("Consuming Fuel");
  105.                         this.disassemblerFuelTime = TileEntityFurnace.getItemBurnTime(fuel);
  106.                         this.disassemblerMaxFuelTime = TileEntityFurnace.getItemBurnTime(fuel);
  107.                         this.ish.extractItem(SLOT_FUEL, 1, false);
  108.                     } else {
  109.                         System.out.println("No valid Fuel existant");
  110.                     }
  111.                 } else if (ish.getStackInSlot(SLOT_OUTPUT1).getItem() == rd.getOutput()[0].getItem()) {
  112.                     System.out.println("Output 1 is not empty but contains Recipe Output");
  113.                     if (fuel != null && TileEntityFurnace.isItemFuel(fuel)) {
  114.                         System.out.println("Consuming Fuel");
  115.                         this.disassemblerFuelTime = TileEntityFurnace.getItemBurnTime(fuel);
  116.                         this.disassemblerMaxFuelTime = TileEntityFurnace.getItemBurnTime(fuel);
  117.                         this.ish.extractItem(SLOT_FUEL, 1, false);
  118.                     } else {
  119.                         System.out.println("No valid Fuel existent");
  120.                     }
  121.                 } else {
  122.                     System.out.println("Output 1 is not clear for new Output!");
  123.                 }
  124.             } else {
  125.                 System.out.println("Input does not have a Recipe!");
  126.             }
  127.         } else {
  128.             System.out.println("Still Fuel left!");
  129.         }
  130.  
  131.         if (!this.worldObj.isRemote) {
  132.             if (this.disassemblerChrushingTime < 1) {
  133.                 for (RecipeDisassembler rd : AtomizerRecipes.disassembler.values()) {
  134.                     if (rd.getInput() != null && input != null && rd.getInput().getItem() != null
  135.                             && input.getItem() != null) {
  136.                         if (rd.getInput().getItem().equals(input.getItem())) {
  137.                             ItemStack output1 = rd.getOutput()[0];
  138.                             ItemStack output2 = rd.getOutput()[1];
  139.                             if (output1 != null) {
  140.                                 if (ish.getStackInSlot(SLOT_OUTPUT1) == null
  141.                                         || ish.getStackInSlot(SLOT_OUTPUT1).getItem().equals(output1.getItem())
  142.                                         || ish.getStackInSlot(SLOT_OUTPUT1).getItem() == null) {
  143.                                     if (ish.getStackInSlot(SLOT_OUTPUT2) == null || output2 == null
  144.                                             || ish.getStackInSlot(SLOT_OUTPUT2).getItem().equals(output2.getItem())
  145.                                             || ish.getStackInSlot(SLOT_OUTPUT2).getItem() == null) {
  146.                                         System.out.println("Stelle her");
  147.                                         ish.extractItem(SLOT_INPUT, 1, false);
  148.                                         ish.insertItem(SLOT_OUTPUT1, rd.getOutput()[0], false);
  149.                                         ish.insertItem(SLOT_OUTPUT2, rd.getOutput()[1], false);
  150.                                         if (rd.getLuck() != null) {
  151.                                             int luck = (int) (rd.getLuck().length * Math.random());
  152.                                             if (rd.getLuck()[luck] != null) {
  153.                                                 if (ish.getStackInSlot(SLOT_LUCK) == null
  154.                                                         || ish.getStackInSlot(SLOT_LUCK).getItem()
  155.                                                                 .equals(rd.getLuck()[luck].getItem())
  156.                                                         || ish.getStackInSlot(SLOT_LUCK).getItem() == null) {
  157.                                                     ish.insertItem(SLOT_LUCK, rd.getLuck()[luck], false);
  158.                                                 }
  159.                                             }
  160.                                         }
  161.                                     }
  162.                                 }
  163.                             }
  164.                         }
  165.                     }
  166.                 }
  167.             }
  168.         }
  169.     }
  170.  
  171.     /**
  172.      * Checks whether or not this TileEntity has crushing time left
  173.      *
  174.      * @return If the TileEntity is still crushing
  175.      */
  176.     public boolean hasFuel() {
  177.         return this.disassemblerFuelTime > 0;
  178.     }
  179.  
  180.     public boolean isCrushing() {
  181.         return this.disassemblerChrushingTime > 0 && this.hasFuel();
  182.     }
  183.  
  184.     public ItemStackHandler getItemStackHandler() {
  185.         return ish;
  186.     }
  187.  
  188.     /**
  189.      * Dient dem Speichern von Werten der TileEntity
  190.      *
  191.      */
  192.     @Override
  193.     public void writeToNBT(NBTTagCompound compound) {
  194.         super.writeToNBT(compound);
  195.     }
  196.  
  197.     /**
  198.      * TODO Überprüft, ob diese Fähigkeit vorhanden ist
  199.      */
  200.     @Override
  201.     public boolean hasCapability(Capability<?> capability, EnumFacing facing) {
  202.         if (capability == ITEM_HANDLER_CAPABILITY) {
  203.             return true;
  204.         }
  205.         return false;
  206.     }
  207.  
  208.     /**
  209.      * TODO Gibt die verlangte Fähigkeit zurück
  210.      */
  211.     @Override
  212.     public <T> T getCapability(Capability<T> capability, EnumFacing facing) {
  213.         if (capability == ITEM_HANDLER_CAPABILITY) {
  214.             return (T) ish;
  215.         }
  216.         return null;
  217.     }
  218.  
  219.     /**
  220.      * Dient dem Lesen von Werten der TileEntity
  221.      *
  222.      */
  223.     @Override
  224.     public void readFromNBT(NBTTagCompound compound) {
  225.         super.readFromNBT(compound);
  226.  
  227.     }
  228.  
  229.     public boolean isUsableByPlayer(EntityPlayer playerIn) {
  230.         return true;
  231.     }
  232.  
  233.     public int getFuelTime() {
  234.         return disassemblerFuelTime;
  235.     }
  236.  
  237.     public int getCrushTime() {
  238.         return disassemblerChrushingTime;
  239.     }
  240.  
  241.     public int getMaxFuelTime() {
  242.         return disassemblerMaxFuelTime;
  243.     }
  244. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement