Jump to content

[1.7.2]Custom furnace like item not working(probably a noob mistake sorry)


Recommended Posts

Posted

Hi

 

Somehow my Custom furnace like block isn't working i probably made a noob error or something :3 sorry

 

container

package molecularscience.electrolyzer;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.entity.player.InventoryPlayer;
import net.minecraft.inventory.Container;
import net.minecraft.inventory.ICrafting;
import net.minecraft.inventory.Slot;
import net.minecraft.item.ItemStack;
import cpw.mods.fml.relauncher.Side;
import cpw.mods.fml.relauncher.SideOnly;

public class ContainerElectrolyzer extends Container {

        protected TileEntityElectrolyzer tileEntity;
        private int progress;

        public ContainerElectrolyzer (InventoryPlayer inventoryPlayer, TileEntityElectrolyzer te){
                tileEntity = te;
                addSlotToContainer(new Slot(tileEntity, 0, 22, );
                addSlotToContainer(new Slot(tileEntity, 1, 76, );
                addSlotToContainer(new Slot(tileEntity, 2, 49, 50));
                addSlotToContainer(new Slot(tileEntity, 3, 128, 29));
                bindPlayerInventory(inventoryPlayer);
        }

        @Override
        public boolean canInteractWith(EntityPlayer player) {
                return tileEntity.isUseableByPlayer(player);
        }


        protected void bindPlayerInventory(InventoryPlayer inventoryPlayer) {
                for (int i = 0; i < 3; i++) {
                        for (int j = 0; j < 9; j++) {
                                addSlotToContainer(new Slot(inventoryPlayer, j + i * 9 + 9,
                                                8 + j * 18, 99 + i * 18));
                        }
                }

                for (int i = 0; i < 9; i++) {
                        addSlotToContainer(new Slot(inventoryPlayer, i, 8 + i * 18, 157));
                }
        }

        @Override
        public ItemStack transferStackInSlot(EntityPlayer player, int slot) {
                ItemStack stack = null;
                Slot slotObject = (Slot) inventorySlots.get(slot);
                if (slotObject != null && slotObject.getHasStack()) {
                        ItemStack stackInSlot = slotObject.getStack();
                        stack = stackInSlot.copy();
                        if (slot < 9) {
                                if (!this.mergeItemStack(stackInSlot, 0, 35, true)) {
                                        return null;
                                }
                        }
                        else if (!this.mergeItemStack(stackInSlot, 0, 9, false)) {
                                return null;
                        }

                        if (stackInSlot.stackSize == 0) {
                                slotObject.putStack(null);
                        } else {
                                slotObject.onSlotChanged();
                        }

                        if (stackInSlot.stackSize == stack.stackSize) {
                                return null;
                        }
                        slotObject.onPickupFromSlot(player, stackInSlot);
                }
                return stack;
        }
        
    	public void addCraftingToCrafters(ICrafting crafting){
    		super.addCraftingToCrafters(crafting);
    	    crafting.sendProgressBarUpdate(this, 0, this.tileEntity.progress);
    	}
    	
    	public void detectAndSendChanges(){
    		super.detectAndSendChanges();
    		for (int i = 0; i < this.crafters.size(); ++i){
    			ICrafting icrafting = (ICrafting)this.crafters.get(i);
    			if (this.progress != this.tileEntity.progress){
    				icrafting.sendProgressBarUpdate(this, 0, this.tileEntity.progress);
    	        }
    	    }
    	    this.progress = this.tileEntity.progress;
    	}
    	
    	@SideOnly(Side.CLIENT)
    	public void updateProgressBar(int par1, int par2){
    		if (par1 == 0){
    			this.tileEntity.progress = par2;
    	    }
    	}
    	
}

 

TileEntity

package molecularscience.electrolyzer;

import cpw.mods.fml.relauncher.Side;
import cpw.mods.fml.relauncher.SideOnly;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.inventory.IInventory;
import net.minecraft.item.Item;
import net.minecraft.item.ItemStack;
import net.minecraft.nbt.NBTTagCompound;
import net.minecraft.nbt.NBTTagList;
import net.minecraft.tileentity.TileEntity;

public class TileEntityElectrolyzer extends TileEntity implements IInventory {

        private ItemStack[] inv;
    	private int time;
        public int progress;
        private int resultItem = 3;
        
        public TileEntityElectrolyzer(){
                inv = new ItemStack[4];
        }
        
        @Override
        public int getSizeInventory() {
                return inv.length;
        }

        @Override
        public ItemStack getStackInSlot(int slot) {
                return inv[slot];
        }
        
        @Override
        public void setInventorySlotContents(int slot, ItemStack stack) {
                inv[slot] = stack;
                if (stack != null && stack.stackSize > getInventoryStackLimit()) {
                        stack.stackSize = getInventoryStackLimit();
                }               
        }

        @Override
        public ItemStack decrStackSize(int slot, int amt) {
                ItemStack stack = getStackInSlot(slot);
                if (stack != null) {
                        if (stack.stackSize <= amt) {
                                setInventorySlotContents(slot, null);
                        } else {
                                stack = stack.splitStack(amt);
                                if (stack.stackSize == 0) {
                                        setInventorySlotContents(slot, null);
                                }
                        }
                }
                return stack;
        }
        
        @Override
    	public void updateEntity(){
    	   if(!worldObj.isRemote){
    		   int item = getAvailableSlot();
    		   if(inv[item] != null){
    			   Item type = inv[item].getItem();
    			   ItemStack result = ElectrolyzerResults.getResult(item, type);
    			   time = ElectrolyzerResults.getMaxTime(item, type);

    			   if(result != null){
    				   if(progress > time){
    						if (inv[resultItem] == null){
    							inv[resultItem] = result.copy();
    			            }
    						else if (inv[resultItem].isItemEqual(result)){
    							if(inv[resultItem].stackSize + result.stackSize <= getInventoryStackLimit()){
    								inv[resultItem].stackSize += result.stackSize;
    							}
    						}
    						if(inv[item] != null){
    							if(!((inv[item].stackSize - ElectrolyzerResults.getReduceItem(item, type)) < 0)){
    								inv[item].stackSize -= ElectrolyzerResults.getReduceItem(item, type);
    							}
    							if(inv[item].stackSize <= 0){
    								inv[item] = null;
    							}
    						}
    						progress = 0;
    				   }
    				   if(inv[resultItem] != null){
    						   if(inv[resultItem].isItemEqual(result)){
    							   if(inv[resultItem].stackSize < getInventoryStackLimit() || inv[resultItem].stackSize < result.getItem().getItemStackLimit()){
    								   if(inv[item] != null){
    									   if(!((inv[item].stackSize - ElectrolyzerResults.getReduceItem(item, type)) < 0)){
    										   if(inv[resultItem].stackSize + result.stackSize <= getInventoryStackLimit()){
    											   progress++;  
    										   }
    										   else{
    											   progress = 0;
    										   }
    									   }
    									   else{
    										   progress = 0;
    									   }
    								   }
    								   else{
    									   progress = 0;
    								   }  
    							   }
    							   else{
    								   progress = 0;
    							   }
    						   }
    						   else{
    							   progress = 0;
    						   }
    					   }
    					   else{
    						   progress = 0;
    					   }
    				   }
    				   else{
    					   if(inv[item] != null){
    						   if(!((inv[item].stackSize - ElectrolyzerResults.getReduceItem(item, type)) < 0)){
    								   progress++;  
    						   }
    						   else{
    							   progress = 0;
    						   }
    					   }
    					   else{
    						   progress = 0;
    					   }
    				   }
    			   }
    			   else{
    				   progress = 0;
    			   }
    		   }
    	   }

        @Override
        public ItemStack getStackInSlotOnClosing(int slot) {
                ItemStack stack = getStackInSlot(slot);
                if (stack != null) {
                        setInventorySlotContents(slot, null);
                }
                return stack;
        }
        
        @Override
        public int getInventoryStackLimit() {
                return 64;
        }

        @Override
        public boolean isUseableByPlayer(EntityPlayer player) {
                return worldObj.getTileEntity(xCoord, yCoord, zCoord) == this &&
                player.getDistanceSq(xCoord + 0.5, yCoord + 0.5, zCoord + 0.5) < 64;
        }

        public void openChest() {}

        public void closeChest() {}
        
        @Override
        public void readFromNBT(NBTTagCompound tagCompound) {
                super.readFromNBT(tagCompound);
                progress = tagCompound.getShort("progressTime");
                
        }

        @Override
        public void writeToNBT(NBTTagCompound tagCompound) {
                super.writeToNBT(tagCompound);
                tagCompound.setShort("progressTime", (short)progress);
                NBTTagList itemList = new NBTTagList();
                for (int i = 0; i < inv.length; i++) {
                        ItemStack stack = inv[i];
                        if (stack != null) {
                                NBTTagCompound tag = new NBTTagCompound();
                                tag.setByte("Slot", (byte) i);
                                stack.writeToNBT(tag);
                                itemList.appendTag(tag);
                        }
                }
                tagCompound.setTag("Inventory", itemList);
        }

			@Override
			public String getInventoryName() {
				return "molecularscience.tileentityelectrolyzer";
			}

		    @SideOnly(Side.CLIENT)
		    public int getCraftingProgressScaled(int par1){
		        //return this.progress * par1 / ElectrolyzerResults.getMaxTime(0, 0);
		    	return 0;
		    }
		    
			public int getAvailableSlot(){
				   for(int i = 0; i < inv.length - 1; i++){
					   if(inv[i] != null){
						   return i;
					   }
				   }
				   return 0;
				}
			public boolean isBusy(){
				return progress >= 0;
			}

			@Override
			public boolean hasCustomInventoryName() {
				// TODO Auto-generated method stub
				return false;
			}

			@Override
			public void openInventory() {
				// TODO Auto-generated method stub

			}

			@Override
			public void closeInventory() {
				// TODO Auto-generated method stub

			}

			@Override
			public boolean isItemValidForSlot(int var1, ItemStack var2) {
				// TODO Auto-generated method stub
				return false;
			}
}

 

Gui

package molecularscience.electrolyzer;

import net.minecraft.client.gui.inventory.GuiContainer;
import net.minecraft.entity.player.InventoryPlayer;
import net.minecraft.util.ResourceLocation;
import net.minecraft.util.StatCollector;

import org.lwjgl.opengl.GL11;

public class GuiElectrolyzer extends GuiContainer {

private static final ResourceLocation Guitexture = new ResourceLocation("molecularscience","textures/gui/container/guielectrolyzer.png");

    public GuiElectrolyzer (InventoryPlayer inventoryPlayer,
                    TileEntityElectrolyzer tileEntity) {
            super(new ContainerElectrolyzer(inventoryPlayer, tileEntity));
    }

    @Override
    protected void drawGuiContainerForegroundLayer(int param1, int param2) {

    }

    @Override
    protected void drawGuiContainerBackgroundLayer(float par1, int par2,
                    int par3) {
    		this.mc.getTextureManager().bindTexture(Guitexture);
            int x = (width - xSize) / 2;
            int y = (height - (ySize+27)) / 2;
            this.drawTexturedModalRect(x, y, 0, 0, xSize, ySize+27);
    }

}

 

results

package molecularscience.electrolyzer;

import java.util.HashMap;
import java.util.Map;

import molecularscience.moditems.BlocksItems;
import net.minecraft.block.Block;
import net.minecraft.item.Item;
import net.minecraft.item.ItemStack;

public class ElectrolyzerResults {

private static Map<Integer, Object[]> results = new HashMap<Integer, Object[]>();

public static void initResult(){
	addResult(0, 0, BlocksItems.Emptyjar, 1, BlocksItems.Sample, 1);
}
public static ItemStack getResult(int slot, Item type){
	for(int i = 0; i < results.size(); i++){
		if((int)results.get(i)[0] == slot){
			if(results.get(i)[1] == type){
				return new ItemStack((Item) results.get(i)[4], 1);
			}
		}
	}
	return null;
}

public static int getMaxTime(int slot, Item type){
	return 50;
}

public static int getReduceItem(int slot, Item type){
	for(int i = 0; i < results.size(); i++){
		if((int)results.get(i)[0] == slot){
			if(results.get(i)[1] == type){
				return (int)results.get(i)[2];
			}
		}
	}
	return 1;
}

private static void addResult(int id, int slot, Item type, int ammount, Item result, int size){
	results.put(id, new Object[]{slot, type, ammount, result, size});
}
}

 

slot

package molecularscience.electrolyzer;

import net.minecraft.inventory.IInventory;
import net.minecraft.inventory.Slot;
import net.minecraft.item.ItemStack;

public class SlotElectrolyzer extends Slot {

private TileEntityElectrolyzer teSmithingAnvil;

public SlotElectrolyzer(IInventory inventory, int id, int x, int y) {
	super(inventory, id, x, y);
	this.teSmithingAnvil = (TileEntityElectrolyzer) inventory;
}

@Override
public boolean isItemValid(ItemStack itemstack) {
	return teSmithingAnvil.isItemValidForSlot(slotNumber, itemstack);
}
}

 

Thanks for your help :D

I'm always happy to help others!

 

Java is not my main programming language but I have alot experience in PHP/HTML/JS/CSS3/C#/SQL

Posted

nothing it's supposed to return a item when i put it in slot 0 but nope..

 

I'm always happy to help others!

 

Java is not my main programming language but I have alot experience in PHP/HTML/JS/CSS3/C#/SQL

Posted

I was just playing with TransferStackInSlot() and I noticed that when it is successful, it must return an empty stack, not the original stack. The return stack is used to indicate that not all of the items could be transferred. If it has items left, there are put back into the original slot. This is for those people who shift-click and do not have enough room to hole all the crafts.

I noticed that your return either null or the original stack, I don't think it will work that way.

Posted

Would be cool, if u post what you exactly fixed, maybe there are people who have the same problem. so this could be a bit helpful after all. ;)

*********************************

**  Always remember you are unique,  **

**  just like everyone else                   **     

**********************************

Was my post helpful? Say thanks and

press the thank you button, on my post!!

God, damn it!

Posted

It where some broken if fuctions, basic java people can see my github.

I'm always happy to help others!

 

Java is not my main programming language but I have alot experience in PHP/HTML/JS/CSS3/C#/SQL

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Unfortunately, your content contains terms that we do not allow. Please edit your content to remove the highlighted words below.
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Announcements



  • Recently Browsing

    • No registered users viewing this page.
  • Posts

    • When I first heard about Bitcoin back in 2018, I was skeptical. The idea of a decentralized, digital currency seemed too good to be true. But I was intrigued as I learned more about the technology behind it and its potential. I started small, investing just a few hundred dollars, dipping my toes into the cryptocurrency waters. At first, it was exhilarating to watch the value of my investment grow exponentially. I felt like I was part of the future, an early adopter of this revolutionary new asset. But that euphoria was short-lived. One day, I logged into my digital wallet only to find it empty - my Bitcoin had vanished without a trace. It turned out that the online exchange I had trusted had been hacked, and my funds were stolen. I was devastated, both financially and emotionally. All the potential I had seen in Bitcoin was tainted by the harsh reality that with decentralization came a lack of regulation and oversight. My hard-earned money was gone, lost to the ether of the digital world. This experience taught me a painful lesson about the price of trust in the uncharted territory of cryptocurrency. While the technology holds incredible promise, the risks can be catastrophic if you don't approach it with extreme caution. My Bitcoin investment gamble had failed, and I was left to pick up the pieces, wiser but poorer for having placed my faith in the wrong hands. My sincere appreciation goes to MUYERN TRUST HACKER. You are my hero in recovering my lost funds. Send a direct m a i l ( muyerntrusted ( @ ) mail-me ( . )c o m ) or message on whats app : + 1 ( 4-4-0 ) ( 3 -3 -5 ) ( 0-2-0-5 )
    • You could try posting a log (if there is no log at all, it may be the launcher you are using, the FAQ may have info on how to enable the log) as described in the FAQ, however this will probably need to be reported to/remedied by the mod author.
    • So me and a couple of friends are playing with a shitpost mod pack and one of the mods in the pack is corail tombstone and for some reason there is a problem with it, where on death to fire the player will get kicked out of the server and the tombstone will not spawn basically deleting an entire inventory, it doesn't matter what type of fire it is, whether it's from vanilla fire/lava, or from modded fire like ice&fire/lycanites and it's common enough to where everyone on the server has experienced at least once or twice and it doesn't give any crash log. a solution to this would be much appreciated thank you!
    • It is 1.12.2 - I have no idea if there is a 1.12 pack
  • Topics

×
×
  • Create New...

Important Information

By using this site, you agree to our Terms of Use.