Jump to content

Recommended Posts

Posted

I keep crashing on right click

 

package com.linumhost.Items;


import com.linumhost.Blocks.Blocks;
import com.linumhost.TileEntity.TileEntityConduitPipe;

import net.minecraft.block.Block;
import net.minecraft.block.BlockAir;
import net.minecraft.block.material.Material;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.item.Item;
import net.minecraft.item.ItemStack;
import net.minecraft.tileentity.TileEntity;
import net.minecraft.world.World;

public class Wrench extends Item{


private static Block[] canWrench = new Block[1];
//private static TileEntity[] entityName = new TileEntity[1];

TileEntityConduitPipe entity = new TileEntityConduitPipe();

private boolean wrenchable;

public static void populateArray(){
	canWrench[0] = Blocks.conduit;

//	entityName[0] = new TileEntityConduitPipe();
}

public static void setupEntity(){

}

@Override
public boolean onItemUse(ItemStack item, EntityPlayer player, World world, int x, int y, int z, int side, float blockx, float blocky, float blockz) {
	    if(!world.isRemote) {
	    	for(int i = 0; i < canWrench.length; i++){
	    		if(world.getBlock(x, y, z) == canWrench[i]){
			    	System.out.println(canWrench[i]);
			    	//world.setBlock(posx, posy, posx, );
			    	wrenchable = true;
					world.removeTileEntity(x,y,z);
			    	this.breakBlock(world, x, y, z);
			    	break;
	    		}else if(world.getBlock(x, y, z) != canWrench[i]){
	    		    	System.out.println(canWrench[i]);
	    		    	wrenchable = false;
	    		    	break;
	    		}
	    	}
	    	return wrenchable;
	    }
		return false;
}

private void breakBlock(World world, int x, int y, int z){
	for(int i = 0; i < canWrench.length; i++){
		if(world.getBlock(x, y, z) == canWrench[i]){
			world.getBlock(x, y, z).dropBlockAsItem(world, x, y, z, world.getBlockMetadata(x, y, z), 0);
			world.setBlockToAir(x, y, z);
		}
	}
}

public void getWrenchableBlock(World world, int x, int y, int z){
    	
}

}

 

---- Minecraft Crash Report ----
// I let you down. Sorry 

Time: 1/29/15 10:56 PM
Description: Ticking memory connection

java.lang.RuntimeException: class com.linumhost.TileEntity.TileEntityConduitPipe is missing a mapping! This is a bug!
at net.minecraft.tileentity.TileEntity.writeToNBT(TileEntity.java:96)
at net.minecraftforge.common.util.BlockSnapshot.<init>(BlockSnapshot.java:52)
at net.minecraftforge.common.util.BlockSnapshot.<init>(BlockSnapshot.java:81)
at net.minecraftforge.common.util.BlockSnapshot.getBlockSnapshot(BlockSnapshot.java:107)
at net.minecraft.world.World.setBlock(World.java:515)
at net.minecraft.world.World.setBlockToAir(World.java:651)
at com.linumhost.Items.Wrench.breakBlock(Wrench.java:62)
at com.linumhost.Items.Wrench.onItemUse(Wrench.java:45)
at net.minecraftforge.common.ForgeHooks.onPlaceItemIntoWorld(ForgeHooks.java:456)
at net.minecraft.item.ItemStack.tryPlaceItemIntoWorld(ItemStack.java:142)
at net.minecraft.server.management.ItemInWorldManager.activateBlockOrUseItem(ItemInWorldManager.java:422)
at net.minecraft.network.NetHandlerPlayServer.processPlayerBlockPlacement(NetHandlerPlayServer.java:593)
at net.minecraft.network.play.client.C08PacketPlayerBlockPlacement.processPacket(C08PacketPlayerBlockPlacement.java:74)
at net.minecraft.network.play.client.C08PacketPlayerBlockPlacement.processPacket(C08PacketPlayerBlockPlacement.java:122)
at net.minecraft.network.NetworkManager.processReceivedPackets(NetworkManager.java:241)
at net.minecraft.network.NetworkSystem.networkTick(NetworkSystem.java:182)
at net.minecraft.server.MinecraftServer.updateTimeLightAndEntities(MinecraftServer.java:726)
at net.minecraft.server.MinecraftServer.tick(MinecraftServer.java:614)
at net.minecraft.server.integrated.IntegratedServer.tick(IntegratedServer.java:118)
at net.minecraft.server.MinecraftServer.run(MinecraftServer.java:485)
at net.minecraft.server.MinecraftServer$2.run(MinecraftServer.java:752)


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

-- Head --
Stacktrace:
at net.minecraft.tileentity.TileEntity.writeToNBT(TileEntity.java:96)
at net.minecraftforge.common.util.BlockSnapshot.<init>(BlockSnapshot.java:52)
at net.minecraftforge.common.util.BlockSnapshot.<init>(BlockSnapshot.java:81)
at net.minecraftforge.common.util.BlockSnapshot.getBlockSnapshot(BlockSnapshot.java:107)
at net.minecraft.world.World.setBlock(World.java:515)
at net.minecraft.world.World.setBlockToAir(World.java:651)
at com.linumhost.Items.Wrench.breakBlock(Wrench.java:62)
at com.linumhost.Items.Wrench.onItemUse(Wrench.java:45)
at net.minecraftforge.common.ForgeHooks.onPlaceItemIntoWorld(ForgeHooks.java:456)
at net.minecraft.item.ItemStack.tryPlaceItemIntoWorld(ItemStack.java:142)
at net.minecraft.server.management.ItemInWorldManager.activateBlockOrUseItem(ItemInWorldManager.java:422)
at net.minecraft.network.NetHandlerPlayServer.processPlayerBlockPlacement(NetHandlerPlayServer.java:593)
at net.minecraft.network.play.client.C08PacketPlayerBlockPlacement.processPacket(C08PacketPlayerBlockPlacement.java:74)
at net.minecraft.network.play.client.C08PacketPlayerBlockPlacement.processPacket(C08PacketPlayerBlockPlacement.java:122)
at net.minecraft.network.NetworkManager.processReceivedPackets(NetworkManager.java:241)

-- Ticking connection --
Details:
Connection: net.minecraft.network.NetworkManager@4b256e18
Stacktrace:
at net.minecraft.network.NetworkSystem.networkTick(NetworkSystem.java:182)
at net.minecraft.server.MinecraftServer.updateTimeLightAndEntities(MinecraftServer.java:726)
at net.minecraft.server.MinecraftServer.tick(MinecraftServer.java:614)
at net.minecraft.server.integrated.IntegratedServer.tick(IntegratedServer.java:118)
at net.minecraft.server.MinecraftServer.run(MinecraftServer.java:485)
at net.minecraft.server.MinecraftServer$2.run(MinecraftServer.java:752)

-- System Details --
Details:
Minecraft Version: 1.7.10
Operating System: Windows 8.1 (amd64) version 6.3
Java Version: 1.8.0_25, Oracle Corporation
Java VM Version: Java HotSpot(TM) 64-Bit Server VM (mixed mode), Oracle Corporation
Memory: 697297448 bytes (664 MB) / 1037959168 bytes (989 MB) up to 1037959168 bytes (989 MB)
JVM Flags: 3 total; -Xincgc -Xmx1024M -Xms1024M
AABB Pool Size: 0 (0 bytes; 0 MB) allocated, 0 (0 bytes; 0 MB) used
IntCache: cache: 0, tcache: 0, allocated: 0, tallocated: 0
FML: MCP v9.05 FML v7.10.85.1230 Minecraft Forge 10.13.2.1230 5 mods loaded, 5 mods active
mcp{9.05} [Minecraft Coder Pack] (minecraft.jar) Unloaded->Constructed->Pre-initialized->Initialized->Post-initialized->Available->Available->Available->Available
FML{7.10.85.1230} [Forge Mod Loader] (forgeSrc-1.7.10-10.13.2.1230.jar) Unloaded->Constructed->Pre-initialized->Initialized->Post-initialized->Available->Available->Available->Available
Forge{10.13.2.1230} [Minecraft Forge] (forgeSrc-1.7.10-10.13.2.1230.jar) Unloaded->Constructed->Pre-initialized->Initialized->Post-initialized->Available->Available->Available->Available
servermod{1.0} [server Mod] (bin) Unloaded->Constructed->Pre-initialized->Initialized->Post-initialized->Available->Available->Available->Available
testmod{1.0} [Test Mod] (bin) Unloaded->Constructed->Pre-initialized->Initialized->Post-initialized->Available->Available->Available->Available
Profiler Position: N/A (disabled)
Vec3 Pool Size: 0 (0 bytes; 0 MB) allocated, 0 (0 bytes; 0 MB) used
Player Count: 1 / 8; [EntityPlayerMP['Player140'/236, l='New World', x=1641.38, y=4.00, z=254.37]]
Type: Integrated Server (map_client.txt)
Is Modded: Definitely; Client brand changed to 'fml,forge'

Posted

I honestly can't tell you how many things are wrong with that code, but I'll help with your error. You need to be registering your tile entity.

 

GameRegistry.registerTileEntity(<tileEntityClass>,<tileEntityName>);

-Mitchellbrine

 

Minecraft can do ANYTHING, it's coded in Java and you got the full power of Java behind you when you code. So nothing is impossible.

It may be freaking fucking hard though, but still possible ;)

 

If you create a topic on Modder Support, live by this motto:

I don't want your charity, I want your information
Posted

Yeah, there's a lot wrong with this code.

 

1. Don't make TE arrays/instances inside an ITEM class.

2. If you break the tile entity block, it removes the tile entity.

2.5. I mean, use the obfuscated method to break it, so #2 actually happens.

3. That list is going to say it's not wrenchable, unless the block is the first one on the list.

4. Don't make the field "private boolean wrenchable" if you're doing it per item in hand, not class. Use NBT.

-Mitchellbrine

 

Minecraft can do ANYTHING, it's coded in Java and you got the full power of Java behind you when you code. So nothing is impossible.

It may be freaking fucking hard though, but still possible ;)

 

If you create a topic on Modder Support, live by this motto:

I don't want your charity, I want your information
Posted

Hey, not sure if you know this or not but minecraft works on a model that revolves around events, all items and entities are static (All the same instances) what makes them different is either the Item Stack or Tile Entity based on location in world.

 

Having the an instance of a tile entity in an item will cause very strange behavior in minecraft.

 

As coolAlias and Mitchellbrine wrote, use NBT's for those, I suggest reading up on these tutorials:

 

Wuppy29

http://www.wuppy29.com/minecraft/modding-tutorials/forge-modding/#sthash.8TcgkQuu.dpbs

 

Pahimar

http://www.pahimar.com/tutorials/lets-mod/

 

When in doubt I usually check their tutorials out, also you might also be interested in reading up on some Java Best Practices Documentation, just Google "Java Best Coding Practices" and you'll find loads of info on how to make your code optimal, albeit it has nothing to do with Forge or Minecraft, making you code more optimal and neatly layed out using approved practices will make your life easier while debugging especially in a code base that has been decompiled and has loads of obfuscated methods and fields.

 

Lazy Link to Google :P

https://www.google.com/search?q=java+best+coding+practices&ie=utf-8&oe=utf-8

 

Speaking from experience here, I have written code that after a month I couldn't recognize my self... My way around it is to comment all my classes and some of the complicated methods this way even when you are asking for help people read the comments and instantly know what the particular piece of code is.

 

I hope these will help you in the future as they certainly did for me :)

I require Java, both the coffee and the code :)

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.