Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package mrkirby153.periodicraft;
- import net.minecraft.src.EntityItem;
- import net.minecraft.src.EntityPlayer;
- import net.minecraft.src.ItemStack;
- import net.minecraft.src.NBTTagCompound;
- import net.minecraft.src.TileEntity;
- import net.minecraft.src.World;
- public class TileEntityPAM extends TileEntity {
- private int[] recipieLst = new int[]{0, 0, 0, 0, 0, 0, 0, 0, 0};
- private int[] recipieMeta = new int[]{0, 0, 0, 0, 0, 0, 0, 0, 0};
- /**
- * Begins the process of determining what goes into the block
- * @param player
- * @param world
- */
- public void create(EntityPlayer player, World world){
- System.out.println("Recipie ID:" + recipieLst[0] +" " + recipieLst[1] +" "+ recipieLst[2] +" "+ recipieLst[3] +" "+ recipieLst[4] +" "+ recipieLst[5] +" "+ recipieLst[6] +" "+ recipieLst[7] +" "+ recipieLst[8]);
- System.out.println("Recipie Meta:" + recipieMeta[0] +" " + recipieMeta[1] +" "+ recipieMeta[2] +" "+ recipieMeta[3] +" "+ recipieMeta[4] +" "+ recipieMeta[5] +" "+ recipieMeta[6] +" "+ recipieMeta[7] +" "+ recipieMeta[8]);
- if(player.getHeldItem() != null && player.getHeldItem().getItemDamage() == 0){
- for(int i = 1; i < recipieLst.length; i++){
- recipieLst[i-1]= recipieLst[i];
- }
- for(int i = 1; i < recipieMeta.length; i++){
- recipieMeta[i-1]= recipieMeta[i];
- }
- // System.out.println("Recipie ID:" + recipieLst[0] +" "+ recipieLst[2] +" "+ recipieLst[3] +" "+ recipieLst[4] +" "+ recipieLst[5] +" "+ recipieLst[6] +" "+ recipieLst[7] +" "+ recipieLst[8]);
- if(recipieLst[0] == 0){
- this.compareStack(player, world);
- player.destroyCurrentEquippedItem();
- }
- }else{
- if(recipieLst[8] == 0){
- player.addChatMessage("There's nothing stored in this block");
- }else{
- if(!player.isSneaking() && player.getItemInUse() == null){
- player.addChatMessage("There's stuff in this block!");
- }
- }
- }
- }
- /**
- * Checks weather the item stack is > 9, then sets all the arrays in the list to the item id. if its greater, spits out items for the player to collect
- * PAM SPECIFIC
- * @param player
- * @param world
- */
- private void compareStack(EntityPlayer player, World world) {
- int stackId = player.getHeldItem().itemID;
- int itemStack = player.getHeldItem().stackSize;
- int metadata = player.getHeldItem().getItemDamage();
- System.out.println(metadata);
- if(itemStack <= recipieLst.length){
- for(int i = 0; i < itemStack; i++){
- recipieLst[i] = stackId;
- recipieMeta[i] = metadata;
- }
- }else{
- for(int i = 1; i < itemStack - (recipieLst.length - 1); i++)
- this.dropItemInWorld(world, stackId, metadata);
- for(int i = 1; i < recipieLst.length; i++){
- recipieLst[i] = player.getHeldItem().itemID;
- }
- }
- }
- /**
- * Drops items into the world.
- * @param world
- * @param itemStack
- * @param metadata
- */
- private void dropItemInWorld(World world, int itemStack, int metadata) {
- EntityItem i = new EntityItem(world, (double)((float)xCoord + 0.01), (double)((float)yCoord + 1), (double)((float)zCoord + 0.01), new ItemStack(itemStack, 1, metadata));
- world.spawnEntityInWorld(i);
- }
- @Override
- public void writeToNBT(NBTTagCompound nbt) {
- super.writeToNBT(nbt);
- nbt.setIntArray("recipieLst", recipieLst);
- nbt.setIntArray("recipieMeta", recipieMeta);
- }
- @Override
- public void readFromNBT(NBTTagCompound nbt) {
- super.readFromNBT(nbt);
- recipieLst = nbt.getIntArray("recipieLst");
- recipieMeta = nbt.getIntArray("recipieMeta");
- if(recipieLst.length == 0) recipieLst = new int[9];
- if(recipieMeta.length == 0) recipieMeta = new int[9];
- }
- /**
- * Clears the TileEntityPAM's recipie.
- * PAM SPECIFIC
- * @param world
- * @author mrkirby153
- */
- public void clearRecipie(World world) {
- this.dumpInventory(world);
- this.resetValues();
- }
- private void resetValues() {
- for(int i = 0; i < recipieLst.length; i++){
- recipieLst[i] = 0;
- }
- }
- private void dumpInventory(World world) {
- for(int i = 0; i < recipieLst.length; i++){
- if(!(recipieLst[i] == 0))
- this.dropItemInWorld(world, recipieLst[i], recipieMeta[i]);
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment