Jump to content

Recommended Posts

Posted

So I am messing around with forge 1.9, and a machine. It will craft circuits in a crafting table kind of thing. However, whenever I create a new ItemStack in the output slot, I get an error.

 

TileEntity Class:

 

package com.thatcreepyuncle.logicalTech.tileEntity;

import com.thatcreepyuncle.logicalTech.crafting.CircuitWorkbenchCraftingManager;

import io.netty.util.internal.SystemPropertyUtil;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.inventory.ISidedInventory;
import net.minecraft.item.ItemStack;
import net.minecraft.nbt.NBTTagCompound;
import net.minecraft.nbt.NBTTagList;
import net.minecraft.network.NetworkManager;
import net.minecraft.network.Packet;
import net.minecraft.network.play.server.SPacketUpdateTileEntity;
import net.minecraft.tileentity.TileEntity;
import net.minecraft.util.EnumFacing;
import net.minecraft.util.ITickable;
import net.minecraft.util.text.ITextComponent;
import net.minecraft.util.text.TextComponentString;

public class TileEntityCircuitWorkbench extends TileEntity implements ITickable, ISidedInventory {

private static final int[] slots = new int[] { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10 };

public ItemStack[] inventory = new ItemStack[11];
private String customName = "circuit_workbench";
public CircuitWorkbenchCraftingManager manager;


public TileEntityCircuitWorkbench() {
	manager = new CircuitWorkbenchCraftingManager(this);
	System.out.println("Google");
}

@Override
public void update() {
		manager.update();
}

public int getSizeInventory() {
	return 11;
}

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

@Override
public ItemStack decrStackSize(int par1, int par2) {
	if (this.inventory[par1] != null) {
		ItemStack var3;

		if (this.inventory[par1].stackSize <= par2) {
			var3 = this.inventory[par1];
			this.inventory[par1] = null;
			this.markDirty();
			return var3;
		}
		var3 = this.inventory[par1].splitStack(par2);

		if (this.inventory[par1].stackSize == 0) {
			this.inventory[par1] = null;
		}

		this.markDirty();
		return var3;
	}
	return null;
}

@Override
public ItemStack removeStackFromSlot(int par1) {
	if (this.inventory[par1] != null) {
		ItemStack var2 = this.inventory[par1];
		this.inventory[par1] = null;
		return var2;
	}
	return null;
}

@Override
public void setInventorySlotContents(int index, ItemStack stack) {
	this.inventory[index] = stack;

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

/**
 * Reads a tile entity from NBT.
 */
public void readFromNBT(NBTTagCompound tagCompound) {
	super.readFromNBT(tagCompound);
	NBTTagList tagList = (NBTTagList) tagCompound.getTag("Items");
	this.inventory = new ItemStack[this.getSizeInventory()];

	for (int count = 0; count < tagList.tagCount(); ++count) {
		NBTTagCompound nbt = (NBTTagCompound) tagList.getCompoundTagAt(count);
		int slot = nbt.getByte("Slot") & 255;

		if (slot >= 0 && slot < this.inventory.length) {
			this.inventory[slot] = ItemStack.loadItemStackFromNBT(nbt);
		}
	}

	if (tagCompound.hasKey("CustomName", ) {
		this.customName = tagCompound.getString("CustomName");
	}
	inventory[0] = null;
}

@Override
public void writeToNBT(NBTTagCompound par1NBTTagCompound) {
	super.writeToNBT(par1NBTTagCompound);
	NBTTagList var2 = new NBTTagList();

	for (int var3 = 0; var3 < this.inventory.length; ++var3) {
		if (this.inventory[var3] != null) {
			NBTTagCompound var4 = new NBTTagCompound();
			var4.setByte("Slot", (byte) var3);
			this.inventory[var3].writeToNBT(var4);
			var2.appendTag(var4);
		}
	}

	par1NBTTagCompound.setTag("Items", var2);
}

@Override
public void onDataPacket(NetworkManager net, SPacketUpdateTileEntity pkt) {
	NBTTagCompound tagCom = pkt.getNbtCompound();
	this.readFromNBT(tagCom);
}

@Override
public Packet getDescriptionPacket() {
	NBTTagCompound tagCom = new NBTTagCompound();
	this.writeToNBT(tagCom);
	return new SPacketUpdateTileEntity(pos, getBlockMetadata(), tagCom);
}

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

@Override
public boolean isUseableByPlayer(EntityPlayer par1EntityPlayer) {
	return this.worldObj.getTileEntity(pos) != this ? false
			: par1EntityPlayer.getDistanceSq(this.pos.getX() + 0.5D, this.pos.getY() + 0.5D, this.pos.getZ() + 0.5D) <= 64.0D;
}

@Override
public void invalidate() {
	this.updateContainingBlockInfo();
	super.invalidate();
}

@Override
public boolean isItemValidForSlot(int par1, ItemStack par2ItemStack) {
	return true;
}

@Override
public String getName() {
	return this.hasCustomName() ? this.customName : "container.compacter";
}

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

@Override
public ITextComponent getDisplayName() {
	return new TextComponentString(getName());
}

@Override
public void openInventory(EntityPlayer playerIn) {
}

@Override
public void closeInventory(EntityPlayer playerIn) {
}

@Override
public int getField(int id) {
	return 0;
}

@Override
public void setField(int id, int value) {
}

@Override
public int getFieldCount() {
	return 0;
}

@Override
public void clear() {
	for (int i = 0; i < inventory.length; i++) {
		inventory[i] = null;
	}
}

@Override
public int[] getSlotsForFace(EnumFacing side) {
	return slots;
}

@Override
public boolean canInsertItem(int index, ItemStack stack, EnumFacing direction) {
	return true;
}

@Override
public boolean canExtractItem(int index, ItemStack stack, EnumFacing direction) {

	return false;
}

}

 

Crafting Manager:

 

package com.thatcreepyuncle.logicalTech.crafting;

import com.thatcreepyuncle.logicalTech.tileEntity.TileEntityCircuitWorkbench;
import com.thatcreepyuncle.logicalTech.util.FuelHandler;

import net.minecraft.client.Minecraft;
import net.minecraft.init.Blocks;
import net.minecraft.init.Items;
import net.minecraft.item.Item;
import net.minecraft.item.ItemStack;

public class CircuitWorkbenchCraftingManager {

// Blocks to Items!
private final Item redstoneBlock = Item.getItemFromBlock(Blocks.redstone_block);
private final Item ironBlock = Item.getItemFromBlock(Blocks.iron_block);

/*
 * CRAFTING RECIPES
 */
private final Item[] toolsCircuitInput = new Item[] { redstoneBlock, Items.golden_pickaxe, redstoneBlock, Items.golden_axe, ironBlock,
		Items.golden_sword, redstoneBlock, Items.golden_shovel, redstoneBlock, Items.diamond };
/*
 * END OF CRAFTING RECIPES
 */

private TileEntityCircuitWorkbench tile;

public boolean crafting = false;
private Item itemCrafting;
public int cookTime = 0;
public int fuelTime;

public CircuitWorkbenchCraftingManager(TileEntityCircuitWorkbench t) {
	tile = t;
}

// 2-11 = Input, 0 = Fuel, 1 = output
public void update() {
	if (!crafting) {
		checkCraft();
	} else {
		System.out.println(this.cookTime);
		handleFuel();
		handleCraft();
	}
	for (int i = 0; i < this.tile.inventory.length; i++) {
		if (this.tile.inventory[i] != null)
			if (this.tile.inventory[i].stackSize <= 0) {
				this.tile.inventory[i] = null;
			}
	}
}

private void handleFuel() {
	if(fuelTime <= 0 && tile.inventory[1] != null){
		if(FuelHandler.isFuel(this.tile.inventory[1].getItem())){
			fuelTime = FuelHandler.calcFuel(this.tile.inventory[1]);
		}
	}
}

private void startCraft(Item[] recipe, ItemStack[] input){
	crafting = true;
	for (int i = 0; i < input.length; i++) {
		input[i].stackSize--;
	}
	cookTime = 1000;
}

private void handleCraft() {
	if(fuelTime > 0){
		if(cookTime > 0){
			cookTime--;
			fuelTime--;
		}else{
			craft();
			crafting = false;
		}
	}
}

private void checkCraft() {
	Item[] input = new Item[9];
	ItemStack[] inputStacks = new ItemStack[9];
	for (int i = 0; i < 9; i++) {
		if (tile.inventory[i + 2] == null) {
			break;
		}
		inputStacks[i] = tile.inventory[i + 2];
		input[i] = tile.inventory[i + 2].getItem();
	}
	if (canCraft(input, this.toolsCircuitInput)) {
		startCraft(this.toolsCircuitInput, inputStacks);
	}
}

private void craft() {
	System.out.println("Crafting:");
	if (this.tile.inventory[0] == null) {
		System.out.println("Inventory[0]");
		this.tile.inventory[0] = new ItemStack(itemCrafting);
	} else {
		System.out.println("Googles");
		this.tile.inventory[0].stackSize++;
	}
}

private boolean canCraft(Item[] input, Item[] recipe) {
	if (tile.inventory[0] != null) {
		if (tile.inventory[0].getItem() == recipe[9] && tile.inventory[0].stackSize < 64) {
			for (int i = 0; i < input.length; i++) {
				if (input[i] != recipe[i]) {
					return false;
				}
			}
			return true;
		}
	} else {
		for (int i = 0; i < input.length; i++) {
			if (input[i] != recipe[i]) {
				return false;
			}
		}
		return true;
	}
	return false;
}
}

 

Crash Log:

 

A detailed walkthrough of the error, its code path and all known details is as follows:
---------------------------------------------------------------------------------------

-- Head --
Stacktrace:
at net.minecraft.client.renderer.RenderItem.renderItemOverlayIntoGUI(RenderItem.java:428)
at net.minecraft.client.gui.inventory.GuiContainer.drawSlot(GuiContainer.java:319)
at net.minecraft.client.gui.inventory.GuiContainer.drawScreen(GuiContainer.java:118)
at net.minecraftforge.client.ForgeHooksClient.drawScreen(ForgeHooksClient.java:353)

-- Screen render details --
Details:
Screen name: com.thatcreepyuncle.logicalTech.gui.CircuitWorkbenchGui
Mouse location: Scaled: (403, 214). Absolute: (806, 51)
Screen size: Scaled: (427, 240). Absolute: (854, 480). Scale factor of 2

-- Affected level --
Details:
Level name: MpServer
All players: 1 total; [EntityPlayerSP['Player962'/0, l='MpServer', x=8.20, y=4.00, z=4.30]]
Chunk stats: MultiplayerChunkCache: 289, 289
Level seed: 0
Level generator: ID 01 - flat, ver 0. Features enabled: false
Level generator options: 
Level spawn location: World: (8,4,, Chunk: (at 8,0,8 in 0,0; contains blocks 0,0,0 to 15,255,15), Region: (0,0; contains chunks 0,0 to 31,31, blocks 0,0,0 to 511,255,511)
Level time: 122022 game time, 1304 day time
Level dimension: 0
Level storage version: 0x00000 - Unknown?
Level weather: Rain time: 0 (now: false), thunder time: 0 (now: false)
Level game mode: Game mode: creative (ID 1). Hardcore: false. Cheats: false
Forced entities: 1 total; [EntityPlayerSP['Player962'/0, l='MpServer', x=8.20, y=4.00, z=4.30]]
Retry entities: 0 total; []
Server brand: fml,forge
Server type: Integrated singleplayer server
Stacktrace:
at net.minecraft.client.multiplayer.WorldClient.addWorldInfoToCrashReport(WorldClient.java:445)
at net.minecraft.client.Minecraft.addGraphicsAndWorldToCrashReport(Minecraft.java:2766)
at net.minecraft.client.Minecraft.run(Minecraft.java:422)
at net.minecraft.client.main.Main.main(Main.java:118)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:497)
at net.minecraft.launchwrapper.Launch.launch(Launch.java:135)
at net.minecraft.launchwrapper.Launch.main(Launch.java:28)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:497)
at net.minecraftforge.gradle.GradleStartCommon.launch(GradleStartCommon.java:97)
at GradleStart.main(GradleStart.java:26)

-- System Details --
Details:
Minecraft Version: 1.9
Operating System: Windows 10 (amd64) version 10.0
Java Version: 1.8.0_65, Oracle Corporation
Java VM Version: Java HotSpot(TM) 64-Bit Server VM (mixed mode), Oracle Corporation
Memory: 551814400 bytes (526 MB) / 1038876672 bytes (990 MB) up to 1038876672 bytes (990 MB)
JVM Flags: 3 total; -Xincgc -Xmx1024M -Xms1024M
IntCache: cache: 0, tcache: 0, allocated: 0, tallocated: 0
FML: MCP 9.23 Powered by Forge 12.16.1.1887 4 mods loaded, 4 mods active
States: 'U' = Unloaded 'L' = Loaded 'C' = Constructed 'H' = Pre-initialized 'I' = Initialized 'J' = Post-initialized 'A' = Available 'D' = Disabled 'E' = Errored
UCHIJAAAA	mcp{9.19} [Minecraft Coder Pack] (minecraft.jar) 
UCHIJAAAA	FML{8.0.99.99} [Forge Mod Loader] (forgeSrc-1.9-12.16.1.1887.jar) 
UCHIJAAAA	Forge{12.16.1.1887} [Minecraft Forge] (forgeSrc-1.9-12.16.1.1887.jar) 
UCHIJAAAA	ltech{1.0} [ltech] (bin) 
Loaded coremods (and transformers): 
GL info: ' Vendor: 'ATI Technologies Inc.' Version: '4.5.13416 Compatibility Profile Context 15.300.1025.1001' Renderer: 'AMD Radeon R7 200 Series'
Launched Version: 1.9
LWJGL: 2.9.4
OpenGL: AMD Radeon R7 200 Series GL version 4.5.13416 Compatibility Profile Context 15.300.1025.1001, ATI Technologies Inc.
GL Caps: Using GL 1.3 multitexturing.
Using GL 1.3 texture combiners.
Using framebuffer objects because OpenGL 3.0 is supported and separate blending is supported.
Shaders are available because OpenGL 2.1 is supported.
VBOs are available because OpenGL 1.5 is supported.

Using VBOs: No
Is Modded: Definitely; Client brand changed to 'fml,forge'
Type: Client (map_client.txt)
Resource Packs: 
Current Language: English (US)
Profiler Position: N/A (disabled)
CPU: 4x AMD FX(tm)-4300 Quad-Core Processor 
[10:45:17] [Client thread/INFO] [sTDOUT]: [net.minecraft.init.Bootstrap:printToSYSOUT:646]: #@!@# Game crashed! Crash report saved to: #@!@# C:\Users\Noah\Desktop\Computer Mod 1.9\run\.\crash-reports\crash-2016-07-05_10.45.17-client.txt
AL lib: (EE) alc_cleanup: 1 device not closed
Java HotSpot(TM) 64-Bit Server VM warning: Using incremental CMS is deprecated and will likely be removed in a future release

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



×
×
  • Create New...

Important Information

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