Jump to content

[1.7.2] Recipe in custom furnace is taking the bucket instead of giving it back


DonKresenko

Recommended Posts

Hello all! I made a new furnace recently. That's all working fine, everything. I added the custom smelt recipe, the fuel is gold chunk. If you place a water bucket and 'smelt' it, it will take out the bucket as well. It should take the water bucket and give back the bucket. Any solutions? Please respond :)

_         

___ ___| |__  _ __ 

/ __/ __| '_ \| '_ \

\__ \__ \ | | | | | |

|___/___/_| |_|_| |_|

Link to comment
Share on other sites

TileEntity

package com.nuclearbanana.piecraft.saltex;

import net.minecraft.client.Minecraft;
import net.minecraft.client.renderer.entity.RenderItem;
import net.minecraft.client.renderer.entity.RenderManager;
import net.minecraft.entity.item.EntityItem;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.init.Items;
import net.minecraft.inventory.ISidedInventory;
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;
import net.minecraft.tileentity.TileEntityFurnace;

import org.lwjgl.opengl.GL11;

import cpw.mods.fml.common.registry.GameRegistry;
import cpw.mods.fml.relauncher.Side;
import cpw.mods.fml.relauncher.SideOnly;

public class TileEntitySaltExtractor extends TileEntity implements ISidedInventory {

private static final int[] slotsTop = new int[] { 0 };
private static final int[] slotsBottom = new int[] { 2, 1 };
private static final int[] slotsSides = new int[] { 1 };

private ItemStack[] furnaceItemStacks = new ItemStack[3];

public int furnaceBurnTime;
public int currentBurnTime;
public int furnaceCookTime;

private String furnaceName;

public void furnaceName(String string){
	this.furnaceName = string;
}

@Override
public int getSizeInventory() {
	return this.furnaceItemStacks.length;
}

@Override
public ItemStack getStackInSlot(int slot) {
	return this.furnaceItemStacks[slot];
}

@Override
public ItemStack decrStackSize(int par1, int par2) {
	if (this.furnaceItemStacks[par1] != null) {
		ItemStack itemstack;
		if (this.furnaceItemStacks[par1].stackSize <= par2) {
			itemstack = this.furnaceItemStacks[par1];
			this.furnaceItemStacks[par1] = null;
			return itemstack;
		} else {
			itemstack = this.furnaceItemStacks[par1].splitStack(par2);

			if (this.furnaceItemStacks[par1].stackSize == 0) {
				this.furnaceItemStacks[par1] = null;
			}
			return itemstack;
		}
	} else {
		return null;
	}
}

@Override
public ItemStack getStackInSlotOnClosing(int slot) {
	if (this.furnaceItemStacks[slot] != null) {
		ItemStack itemstack = this.furnaceItemStacks[slot];
		this.furnaceItemStacks[slot] = null;
		return itemstack;
	} else {
		return null;
	}
}

@Override
public void setInventorySlotContents(int slot, ItemStack itemstack) {
	this.furnaceItemStacks[slot] = itemstack;

	if (itemstack != null && itemstack.stackSize > this.getInventoryStackLimit()) {
		itemstack.stackSize = this.getInventoryStackLimit();
	}

}

@Override
public String getInventoryName() {
	return this.hasCustomInventoryName() ? this.furnaceName : "Salt Extractor";
}

@Override
public boolean hasCustomInventoryName() {
	return this.furnaceName != null && this.furnaceName.length() > 0;
}

@Override
public int getInventoryStackLimit() {
	return 64;
}

public void readFromNBT(NBTTagCompound tagCompound) {
	super.readFromNBT(tagCompound);
	NBTTagList tagList = tagCompound.getTagList("Items", 10);
	this.furnaceItemStacks = new ItemStack[this.getSizeInventory()];

	for (int i = 0; i < tagList.tagCount(); ++i) {
		NBTTagCompound tabCompound1 = tagList.getCompoundTagAt(i);
		byte byte0 = tabCompound1.getByte("Slot");

		if (byte0 >= 0 && byte0 < this.furnaceItemStacks.length) {
			this.furnaceItemStacks[byte0] = ItemStack.loadItemStackFromNBT(tabCompound1);
		}
	}

	this.furnaceBurnTime = tagCompound.getShort("BurnTime");
	this.furnaceCookTime = tagCompound.getShort("CookTime");
	this.currentBurnTime = getItemBurnTime(this.furnaceItemStacks[1]);

	if (tagCompound.hasKey("CustomName", ) {
		this.furnaceName = tagCompound.getString("CustomName");
	}
}

public void writeToNBT(NBTTagCompound tagCompound) {
	super.writeToNBT(tagCompound);
	tagCompound.setShort("BurnTime", (short) this.furnaceBurnTime);
	tagCompound.setShort("CookTime", (short) this.furnaceBurnTime);
	NBTTagList tagList = new NBTTagList();

	for (int i = 0; i < this.furnaceItemStacks.length; ++i) {
		if (this.furnaceItemStacks[i] != null) {
			NBTTagCompound tagCompound1 = new NBTTagCompound();
			tagCompound1.setByte("Slot", (byte) i);
			this.furnaceItemStacks[i].writeToNBT(tagCompound1);
			tagList.appendTag(tagCompound1);
		}
	}

	tagCompound.setTag("Items", tagList);

	if (this.hasCustomInventoryName()) {
		tagCompound.setString("CustomName", this.furnaceName);
	}
}

@SideOnly(Side.CLIENT)
public int getCookProgressScaled(int par1) {
	return this.furnaceCookTime * par1 / 200; // How long will be infusing
}

@SideOnly(Side.CLIENT)
public int getBurnTimeRemainingScaled(int par1) {
	if (this.currentBurnTime == 0) {
		this.currentBurnTime = 200;
	}

	return this.furnaceBurnTime * par1 / this.currentBurnTime;
}

public boolean isBurning() {
	return this.furnaceBurnTime > 0;
}

public void updateEntity() {
	boolean flag = this.furnaceBurnTime > 0;
	boolean flag1 = false;

	if (this.furnaceBurnTime > 0) {
		--this.furnaceBurnTime;
	}

	if (!this.worldObj.isRemote) {
		if (this.furnaceBurnTime == 0 && this.canSmelt()) {
			this.currentBurnTime = this.furnaceBurnTime = getItemBurnTime(this.furnaceItemStacks[1]);

			if (this.furnaceBurnTime > 0) {
				flag1 = true;
				if (this.furnaceItemStacks[1] != null) {
					--this.furnaceItemStacks[1].stackSize;

					if (this.furnaceItemStacks[1].stackSize == 0) {
						this.furnaceItemStacks[1] = furnaceItemStacks[1].getItem().getContainerItem(this.furnaceItemStacks[1]);
					}
				}
			}
		}

		if (this.isBurning() && this.canSmelt()) {
			++this.furnaceCookTime;
			if (this.furnaceCookTime == 200) { // menjaj i ovaj broj!
				this.furnaceCookTime = 0;
				this.smeltItem();
				flag1 = true;
			}
		} else {
			this.furnaceCookTime = 0;
		}
	}

	if (flag != this.furnaceBurnTime > 0) {
		flag1 = true;
		SaltExtractor.updateBlockState(this.furnaceBurnTime > 0, this.worldObj, this.xCoord, this.yCoord, this.zCoord);
	}

	if (flag1) {
		this.markDirty();
	}
}

private boolean canSmelt() {
	if (this.furnaceItemStacks[0] == null) {
		return false;
	} else {
		ItemStack itemstack = SaltExtractorRecipes.make().getSmeltingResult(this.furnaceItemStacks[0]);
		if (itemstack == null) return false;
		if (this.furnaceItemStacks[2] == null) return true;
		if (!this.furnaceItemStacks[2].isItemEqual(itemstack)) return false;
		int result = furnaceItemStacks[2].stackSize + itemstack.stackSize;
		return result <= getInventoryStackLimit() && result <= this.furnaceItemStacks[2].getMaxStackSize();
	}
}

public void smeltItem() {
	if (this.canSmelt()) {
		ItemStack itemstack = SaltExtractorRecipes.make().getSmeltingResult(this.furnaceItemStacks[0]);

		if (this.furnaceItemStacks[2] == null) {
			this.furnaceItemStacks[2] = itemstack.copy();
		} else if (this.furnaceItemStacks[2].getItem() == itemstack.getItem()) {
			this.furnaceItemStacks[2].stackSize += itemstack.stackSize;
		}

		--this.furnaceItemStacks[0].stackSize;

		if(this.furnaceItemStacks[0].stackSize <= 0){
			this.furnaceItemStacks[0] = null;
		}
	}
}

public static int getItemBurnTime(ItemStack itemstack){
	if(itemstack == null){
		return 0;
	}else{
		Item item = itemstack.getItem();

		/*if(item instanceof ItemBlock && Block.getBlockFromItem(item) != Blocks.air){
			Block block = Block.getBlockFromItem(item);

			if(block == Blocks.anvil)
				return 200;

			if(block.getMaterial() == Material.rock)
				return 300;
		}*/

		if(item == Items.redstone)
			return 2000;

		/*if(item instanceof ItemTool && ((ItemTool) item).getToolMaterialName().equals("EMERALD")) 
			return 300;
		*/
		return GameRegistry.getFuelValue(itemstack);
	}
}



public static boolean isItemFuel(ItemStack itemstack){
	return getItemBurnTime(itemstack) > 0;
}

@Override
public boolean isUseableByPlayer(EntityPlayer player) {
	return this.worldObj.getTileEntity(this.xCoord, this.yCoord, this.zCoord) != this ? false : player.getDistanceSq((double) this.xCoord + 0.5D, (double) this.yCoord + 0.5D, (double) this.zCoord + 0.5D) <= 64.0D;
}

@Override
public void openInventory() {

}

@Override
public void closeInventory() {

}

@Override
public boolean isItemValidForSlot(int par1, ItemStack itemstack) {
	return par1 == 2 ? false : (par1 == 1 ? isItemFuel(itemstack) : true);
}

@Override
public int[] getAccessibleSlotsFromSide(int par1)
    {
        return par1 == 0 ? slotsBottom : (par1 == 1 ? slotsTop : slotsSides);
    }

@Override
public boolean canInsertItem(int par1, ItemStack itemstack, int par3) {
	return this.isItemValidForSlot(par1, itemstack);
}

@Override
public boolean canExtractItem(int par1, ItemStack itemstack, int par3) {
	return par3 != 0 || par1 != 1 || itemstack.getItem() == Items.bucket;
}

//@Override
/*public void renderTileEntityAt(TileEntity entity, double x, double y, double z, float f) {

	GL11.glPushMatrix();
	ItemStack stack = new ItemStack(Items.iron_ingot, 1, 0);
	EntityItem entItem = new EntityItem(Minecraft.getMinecraft().thePlayer.getEntityWorld(), 0D, 0D, 0D, stack);
	//Without the below line, the item will spazz out
	entItem.hoverStart = 0.0F;
	RenderItem.renderInFrame = true;
	//Add the below line (without //'s) to make the item lie flat on the block
	GL11.glRotatef(180, 0, 1, 1);
	//Change the 0D's to different values to move it around
	RenderManager.instance.renderEntityWithPosYaw(entItem, 1.0D, 1.0D, 1.0D, 1.0F, 1.0F);
	RenderItem.renderInFrame = false;
	GL11.glPopMatrix();
}*/

}

 

RecipeHandler

package com.nuclearbanana.piecraft.saltex;

import java.util.HashMap;
import java.util.Iterator;
import java.util.Map;
import java.util.Map.Entry;

import com.nuclearbanana.piecraft.PieCraft;

import net.minecraft.block.Block;
import net.minecraft.init.Blocks;
import net.minecraft.init.Items;
import net.minecraft.item.Item;
import net.minecraft.item.ItemFishFood;
import net.minecraft.item.ItemStack;

public class SaltExtractorRecipes
{
    private static final SaltExtractorRecipes smeltingBase = new SaltExtractorRecipes();
    /**
     * The list of smelting results.
     */
    private Map smeltingList = new HashMap();
    private Map experienceList = new HashMap();

    /**
     * Used to call methods addSmelting and getSmeltingResult.
     */
    public static SaltExtractorRecipes make()
    {
        return smeltingBase;
    }

    private SaltExtractorRecipes()
    {
        this.infuseItem(Items.water_bucket, new ItemStack(PieCraft.Salt), 0.7F);
        
    }

    public void infuseBlock(Block block, ItemStack is, float xp)
    {
        this.infuseItem(Item.getItemFromBlock(block), is, xp);
    }

    public void infuseItem(Item p_151396_1_, ItemStack p_151396_2_, float p_151396_3_)
    {
        this.InfuseItemStack(new ItemStack(p_151396_1_, 1, 32767), p_151396_2_, p_151396_3_);
    }

    public void InfuseItemStack(ItemStack p_151394_1_, ItemStack p_151394_2_, float p_151394_3_)
    {
        this.smeltingList.put(p_151394_1_, p_151394_2_);
        this.experienceList.put(p_151394_2_, Float.valueOf(p_151394_3_));
    }

    /**
     * Returns the smelting result of an item.
     */
    public ItemStack getSmeltingResult(ItemStack p_151395_1_)
    {
        Iterator iterator = this.smeltingList.entrySet().iterator();
        Entry entry;

        do
        {
            if (!iterator.hasNext())
            {
                return null;
            }

            entry = (Entry)iterator.next();
        }
        while (!this.func_151397_a(p_151395_1_, (ItemStack)entry.getKey()));

        return (ItemStack)entry.getValue();
    }

    private boolean func_151397_a(ItemStack p_151397_1_, ItemStack p_151397_2_)
    {
        return p_151397_2_.getItem() == p_151397_1_.getItem() && (p_151397_2_.getItemDamage() == 32767 || p_151397_2_.getItemDamage() == p_151397_1_.getItemDamage());
    }

    public Map getSmeltingList()
    {
        return this.smeltingList;
    }

    public float func_151398_b(ItemStack p_151398_1_)
    {
        float ret = p_151398_1_.getItem().getSmeltingExperience(p_151398_1_);
        if (ret != -1) return ret;

        Iterator iterator = this.experienceList.entrySet().iterator();
        Entry entry;

        do
        {
            if (!iterator.hasNext())
            {
                return 0.0F;
            }

            entry = (Entry)iterator.next();
        }
        while (!this.func_151397_a(p_151398_1_, (ItemStack)entry.getKey()));

        return ((Float)entry.getValue()).floatValue();
    }
}

 

GuiHandler

package com.nuclearbanana.piecraft.saltex;

import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.world.World;
import cpw.mods.fml.common.network.IGuiHandler;

public class PieGuiHandler implements IGuiHandler {

public PieGuiHandler (){

}

@Override
public Object getServerGuiElement(int ID, EntityPlayer player, World world, int x, int y, int z) {
	if(ID == 0){
		TileEntitySaltExtractor tileEntityFurnace = (TileEntitySaltExtractor) world.getTileEntity(x, y, z);
		return new ContainerSaltExtractor(player.inventory, tileEntityFurnace);
	}
	return null;
}

@Override
public Object getClientGuiElement(int ID, EntityPlayer player, World world, int x, int y, int z) {
	if(ID == 0){
		TileEntitySaltExtractor tileEntityTestContainer = (TileEntitySaltExtractor) world.getTileEntity(x, y, z);
		return new GuiSaltExtractor(player.inventory, tileEntityTestContainer);
	}
	return null;
}

}

 

Hope anyone can help :)

_         

___ ___| |__  _ __ 

/ __/ __| '_ \| '_ \

\__ \__ \ | | | | | |

|___/___/_| |_|_| |_|

Link to comment
Share on other sites

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

    • Hi, has anyone dealt with gradlew :runClient crashing on start before? I've currently made a forge 1.18.2 mod with the latest mdk and I use IntelliJ IDEA 2024.1 as my IDE, and now whenever I try to run the `:runClient` command with gradle, it works at first, but then the process stops reporting this issue: `Caused by: java.lang.reflect.InvocationTargetException` and `Caused by: java.lang.NoSuchMethodError: 'int net.minecraft.util.Mth.m_14045_(int, int, int)'`. I've pasted the full runClient gradle log in this message. I investigated this issue further on the forge forums to find that not much people had encountered it, and those who did encounter it somehow fixed it with fixes that does not work for me like deleting cache and let gradle redownload the cache or anything and that this issue is caused by a "Corrupted Cache", or whatever the heck that meant. I tried cloning my entire repo (https://github.com/Type-32/PreciseManufacturing) to another directory to "start fresh" but the same issue persists. I created a new project with a clean forge mod 1.18.2 template but the issue persists. I tried all the fixes I can find but none of them worked. even `.\gradlew --refresh-dependencies` didn't work. I am getting desparate for any help now ~~this is so freaking frustrating~~ This is my build.gradle file plugins { id 'eclipse' id 'idea' id 'net.minecraftforge.gradle' version '[6.0.16,6.2)' id 'org.parchmentmc.librarian.forgegradle' version '1.+' } group = mod_group_id version = mod_version base { archivesName = mod_id } java { toolchain.languageVersion = JavaLanguageVersion.of(17) } minecraft { mappings channel: mapping_channel, version: mapping_version copyIdeResources = true runs { // applies to all the run configs below configureEach { workingDirectory project.file('run') property 'forge.logging.markers', 'REGISTRIES' property 'forge.logging.console.level', 'debug' mods { "${mod_id}" { source sourceSets.main } } } client { // Comma-separated list of namespaces to load gametests from. Empty = all namespaces. property 'forge.enabledGameTestNamespaces', mod_id property 'mixin.env.remapRefMap', 'true' property 'mixin.env.refMapRemappingFile', "${projectDir}/build/createSrgToMcp/output.srg" } server { property 'forge.enabledGameTestNamespaces', mod_id args '--nogui' } gameTestServer { property 'forge.enabledGameTestNamespaces', mod_id } data { // example of overriding the workingDirectory set in configureEach above workingDirectory project.file('run-data') // Specify the modid for data generation, where to output the resulting resource, and where to look for existing resources. args '--mod', mod_id, '--all', '--output', file('src/generated/resources/'), '--existing', file('src/main/resources/') } } } jarJar.enable() reobf { jarJar { } } tasks.jarJar.finalizedBy('reobfJarJar') // Include resources generated by data generators. sourceSets.main.resources { srcDir 'src/generated/resources' } repositories { maven { name = 'tterrag maven' url = 'https://maven.tterrag.com/' } mavenLocal() } dependencies { minecraft "net.minecraftforge:forge:${minecraft_version}-${forge_version}" implementation fg.deobf("com.simibubi.create:create-${create_minecraft_version}:${create_version}:slim") { transitive = false } implementation fg.deobf("com.jozufozu.flywheel:flywheel-forge-${flywheel_minecraft_version}:${flywheel_version}") implementation fg.deobf("com.tterrag.registrate:Registrate:${registrate_version}") // [MC<minecraft_version>,MC<next_minecraft_version>) jarJar(group: 'com.tterrag.registrate', name: 'Registrate', version: "[MC1.18.2,MC1.19)") // Example mod dependency with JEI - using fg.deobf() ensures the dependency is remapped to your development mappings // The JEI API is declared for compile time use, while the full JEI artifact is used at runtime // compileOnly fg.deobf("mezz.jei:jei-${mc_version}-common-api:${jei_version}") // compileOnly fg.deobf("mezz.jei:jei-${mc_version}-forge-api:${jei_version}") // runtimeOnly fg.deobf("mezz.jei:jei-${mc_version}-forge:${jei_version}") // Example mod dependency using a mod jar from ./libs with a flat dir repository // This maps to ./libs/coolmod-${mc_version}-${coolmod_version}.jar // The group id is ignored when searching -- in this case, it is "blank" // implementation fg.deobf("blank:coolmod-${mc_version}:${coolmod_version}") } tasks.named('processResources', ProcessResources).configure { var replaceProperties = [ minecraft_version: minecraft_version, minecraft_version_range: minecraft_version_range, forge_version: forge_version, forge_version_range: forge_version_range, loader_version_range: loader_version_range, mod_id: mod_id, mod_name: mod_name, mod_license: mod_license, mod_version: mod_version, mod_authors: mod_authors, mod_description: mod_description, ] inputs.properties replaceProperties filesMatching(['META-INF/mods.toml', 'pack.mcmeta']) { expand replaceProperties + [project: project] }} // Example for how to get properties into the manifest for reading at runtime. tasks.named('jar', Jar).configure { manifest { attributes([ "Specification-Title": mod_id, "Specification-Vendor": mod_authors, "Specification-Version": "1", // We are version 1 of ourselves "Implementation-Title": project.name, "Implementation-Version": project.jar.archiveVersion, "Implementation-Vendor": mod_authors, "Implementation-Timestamp": new Date().format("yyyy-MM-dd'T'HH:mm:ssZ") ]) } // This is the preferred method to reobfuscate your jar file finalizedBy 'reobfJar' } tasks.withType(JavaCompile).configureEach { options.encoding = 'UTF-8' // Use the UTF-8 charset for Java compilation }  
    • pastebin.com and paste.ee couldn't handle the debug and crash log sizes, apologies I have to send it on mega, and I hope it's not a problem Basically, Minecraft turns on normally but when I try to create a world, it goes to 100%, joining world, saving world and crashes   debug log https://mega.nz/file/kP1nGDKZ decryption key: C_VSH-IO6Kpi9IdqUs2Z0KDu0Fpujmen_I3rI1yUyVw crash log https://mega.nz/file/RXVEhRpZ 0r05xiqoGmL8rQEXjYaf8Q8BO-XbJGzpeBDek3aqb0w
  • Topics

×
×
  • Create New...

Important Information

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