Jump to content

[solved][1.8] Problem with TileEntities


Failender

Recommended Posts

I create my own tileentity.

Right now its only use is to safe its owner and return it

The Problem is, that even if the setOwner method is called correctly and the String seems to be set properly, the TileEntity is ALWAYS returning null and I have no idea why

I guess im missing one little part that is ruining it, but I cant find it

 

[02:10:57] [server thread/INFO] [sTDOUT]: [de.failender.challengemod.blocks.ResearchCenter:onBlockActivated:48]: null

 

 
public class TileEntityResearch extends TileEntity{

private String owner;

public void setOwner(String owner)
{
	this.owner = owner;
}

public String getOwner()
{
	return owner;
}


@Override
public void readFromNBT(NBTTagCompound compound) {
	compound.getString("rc");
	super.readFromNBT(compound);
}

@Override
public void writeToNBT(NBTTagCompound compound) {
	compound.setString("rc", owner);
	super.writeToNBT(compound);
}

 

I registered my tileentity like so

GameRegistry.registerTileEntity(TileEntityResearch.class, "researchcenterentity");

 

And created my own block using the TileEntitiy

 


public class ResearchCenter extends Block{

public ResearchCenter() {
	super(Material.rock);
	setCreativeTab(CreativeTabs.tabTools);

}

@Override
public void onBlockPlacedBy(World worldIn, BlockPos pos, IBlockState state,
		EntityLivingBase placer, ItemStack stack) {
	if (!worldIn.isRemote)
    	{
    		TileEntityResearch rc = (TileEntityResearch) worldIn.getTileEntity(pos);
    		rc.setOwner(placer.getName());
    	}
	super.onBlockPlacedBy(worldIn, pos, state, placer, stack);
}

@Override
public boolean onBlockActivated(World worldIn, BlockPos pos,
		IBlockState state, EntityPlayer playerIn, EnumFacing side,
		float hitX, float hitY, float hitZ) {

	if (!worldIn.isRemote)
	{
		TileEntityResearch rc = (TileEntityResearch) worldIn.getTileEntity(pos);
		System.out.println(rc.getOwner());

	}



	return super.onBlockActivated(worldIn, pos, state, playerIn, side, hitX, hitY,
			hitZ);
}

@Override
public boolean hasTileEntity(IBlockState state) {
	return true;
}

@Override
public TileEntity createTileEntity(World world, IBlockState state) {
	// TODO Auto-generated method stub
	return new TileEntityResearch();
}



}

 

 

Link to comment
Share on other sites

You need to save the data in an NBT tag (read/write to/from NBT methods) and then add:

 

	@Override
public Packet getDescriptionPacket() {
	NBTTagCompound nbtTag = new NBTTagCompound();
	writeToNBT(nbtTag);
	return new S35PacketUpdateTileEntity(xCoord, yCoord, zCoord, 1, nbtTag);
}

@Override
public void onDataPacket(NetworkManager net, S35PacketUpdateTileEntity packet) {
	readFromNBT(packet.func_148857_g());
}

 

So that the data is passed from server to client.

Apparently I'm a complete and utter jerk and come to this forum just like to make fun of people, be confrontational, and make your personal life miserable.  If you think this is the case, JUST REPORT ME.  Otherwise you're just going to get reported when you reply to my posts and point it out, because odds are, I was trying to be nice.

 

Exception: If you do not understand Java, I WILL NOT HELP YOU and your thread will get locked.

 

DO NOT PM ME WITH PROBLEMS. No help will be given.

Link to comment
Share on other sites

It's not sided.  But it gets sent any time the server sees that it needs to be sent.  You'll want to call

worldObj.markBlockForUpdate(xCoord, yCoord, zCoord);

if you make any changes to the data and it needs to update right away.

Apparently I'm a complete and utter jerk and come to this forum just like to make fun of people, be confrontational, and make your personal life miserable.  If you think this is the case, JUST REPORT ME.  Otherwise you're just going to get reported when you reply to my posts and point it out, because odds are, I was trying to be nice.

 

Exception: If you do not understand Java, I WILL NOT HELP YOU and your thread will get locked.

 

DO NOT PM ME WITH PROBLEMS. No help will be given.

Link to comment
Share on other sites

It seemed to be working. But it seems like there is an error when he tries to safe the String owner.

 

Any Ideas?

 

[03:52:13] [Client thread/INFO] [sTDOUT]: [net.minecraft.init.Bootstrap:printToSYSOUT:568]: #@!@# Game crashed! Crash report saved to: #@!@# .\crash-reports\crash-2015-02-23_03.52.13-server.txt

[03:52:13] [Client thread/INFO] [FML]: Waiting for the server to terminate/save.

[03:52:13] [server thread/ERROR] [FML]: A TileEntity type de.failender.challengemod.tileentities.TileEntityResearch has throw an exception trying to write state. It will not persist. Report this to the mod author

java.lang.IllegalArgumentException: Empty string not allowed

at net.minecraft.nbt.NBTTagString.<init>(NBTTagString.java:23) ~[NBTTagString.class:?]

at net.minecraft.nbt.NBTTagCompound.setString(NBTTagCompound.java:105) ~[NBTTagCompound.class:?]

at de.failender.challengemod.tileentities.TileEntityResearch.writeToNBT(TileEntityResearch.java:33) ~[TileEntityResearch.class:?]

at net.minecraft.world.chunk.storage.AnvilChunkLoader.writeChunkToNBT(AnvilChunkLoader.java:382) [AnvilChunkLoader.class:?]

at net.minecraft.world.chunk.storage.AnvilChunkLoader.saveChunk(AnvilChunkLoader.java:183) [AnvilChunkLoader.class:?]

at net.minecraft.world.gen.ChunkProviderServer.saveChunkData(ChunkProviderServer.java:246) [ChunkProviderServer.class:?]

at net.minecraft.world.gen.ChunkProviderServer.saveChunks(ChunkProviderServer.java:305) [ChunkProviderServer.class:?]

at net.minecraft.world.WorldServer.saveAllChunks(WorldServer.java:938) [WorldServer.class:?]

at net.minecraft.server.MinecraftServer.saveAllWorlds(MinecraftServer.java:363) [MinecraftServer.class:?]

at net.minecraft.server.MinecraftServer.stopServer(MinecraftServer.java:395) [MinecraftServer.class:?]

at net.minecraft.server.integrated.IntegratedServer.stopServer(IntegratedServer.java:328) [integratedServer.class:?]

at net.minecraft.server.MinecraftServer.run(MinecraftServer.java:531) [MinecraftServer.class:?]

at java.lang.Thread.run(Thread.java:745) [?:1.7.0_55]

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

    • Add necronomicon https://www.curseforge.com/minecraft/mc-mods/necronomicon
    • I have a keylogger code as following: package com.key_logger_mod; import com.google.gson.Gson; import com.google.gson.GsonBuilder; import net.minecraftforge.api.distmarker.Dist; import net.minecraftforge.client.event.InputEvent; import net.minecraftforge.eventbus.api.SubscribeEvent; import net.minecraftforge.fml.common.Mod; import org.apache.logging.log4j.LogManager; import org.apache.logging.log4j.Logger; import net.minecraft.client.Minecraft; import org.lwjgl.glfw.GLFW; import java.io.IOException; import java.nio.file.Files; import java.nio.file.Path; import java.nio.file.Paths; import java.nio.file.StandardOpenOption; import java.util.HashMap; import java.util.Map; @Mod.EventBusSubscriber(modid = "key_logger_mod", bus = Mod.EventBusSubscriber.Bus.FORGE, value = Dist.CLIENT) public class KeyboardLogger {     private static final Logger LOGGER = LogManager.getLogger();     private static final Gson gson = new GsonBuilder().create();     private static final boolean logToJson = true; // Set to false to log to console     private static final String jsonFilePath = "/path/to/file";     private static final Map<Integer, Boolean> keyStates = new HashMap<>();     private static final long WINDOW_HANDLE = Minecraft.getInstance().getWindow().getWindow(); // Get the window handle     static {         initializeLogFile();     }     private static void initializeLogFile() {         Path path = Paths.get(jsonFilePath);         try {             Files.write(path, "[".getBytes(), StandardOpenOption.CREATE, StandardOpenOption.TRUNCATE_EXISTING);         } catch (IOException e) {             LOGGER.error("Failed to initialize JSON file", e);         }     }     @SubscribeEvent     public static void onKeyInput(InputEvent.Key event) {         if (Minecraft.getInstance().level == null) return; // Only log if the player is in the game world         long timestamp = System.currentTimeMillis();         int key = event.getKey();         int action = event.getAction();         int mods = event.getModifiers();         synchronized (keyStates) {             if (action == GLFW.GLFW_PRESS) {                 if (!keyStates.getOrDefault(key, false)) {                     keyStates.put(key, true);                     logKeyAction(timestamp, key, "PRESS");                 }             } else if (action == GLFW.GLFW_RELEASE) {                 if (keyStates.getOrDefault(key, false)) {                     keyStates.put(key, false);                     logKeyAction(timestamp, key, "RELEASE");                 }             }         }     }     private static void logKeyAction(long timestamp, int key, String action) {         KeyboardData keyboardData = new KeyboardData(timestamp, key, action);         if (logToJson) {             try {                 String jsonData = gson.toJson(keyboardData) + ",";                 Files.writeString(Paths.get(jsonFilePath), jsonData + System.lineSeparator(), StandardOpenOption.CREATE, StandardOpenOption.APPEND);             } catch (IOException e) {                 LOGGER.error("Failed to write keyboard event to JSON file", e);             }         } else {             LOGGER.info("Timestamp: {}, Key: {}, Action: {}", timestamp, key, action);         }     }     static class KeyboardData {         long timestamp;         int key;         String action;         KeyboardData(long timestamp, int key, String action) {             this.timestamp = timestamp;             this.key = key;             this.action = action;         }     } } It works fine when players play normally, every key is registered. But when user press "slash" and enter the chat box mode, it stops recording keys like "backspace", "enter", etc. But still registering characters and number keys. Why is this happening?  
    • It happened on a snowy mountain in the overworld. It wasn't actually a crash, the game didn't close itself or something, it was more like when you are lagging online, and mobs are standing still, you cannot break blocks, things like that. Hope you'll find a solution Madz.
    • I am trying to add the mod "Create Questing" to the modpack SkyMachina but it just crashes. My log : https://pastebin.com/rq2jpph4   Please help, create is hard 
    • Same issue without apotheosis?
  • Topics

×
×
  • Create New...

Important Information

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