Jump to content

Recommended Posts

Posted

I have a field of type String on a TileEntity provided by a block. When I break and then pick up the block, I want the string on the ItemStack in the player's inventory. My intention is to use the string when I place the block again with method

 

	public void onBlockPlacedBy(World w, BlockPos pos, IBlockState state, EntityLivingBase placer, ItemStack stack) {

 

I have overridden

	public void harvestBlock(World worldIn, EntityPlayer playerIn, BlockPos pos, IBlockState state, TileEntity te) {

 

which gives me the string, but I don't know how to put it on the ItemStack's NBT when the player picks the block up. Any help appreciated.

Posted

Here is my getDops modeled on BlockFlowerPot:

 

 

@Override
public List<ItemStack> getDrops(IBlockAccess world, BlockPos pos, IBlockState state, int fortune) {
	List<ItemStack> itemStacks = super.getDrops(world, pos, state, fortune);
	TileEntity te = world.getTileEntity(pos);
	if (te == null) {
		System.out.println("Could not write path to tag. te=" + te);
		return itemStacks;
	}

	if (te instanceof BlockSavedTileEntity) {
		String path = ((BlockSavedTileEntity) te).getPath();
		ItemStack stack = new ItemStack(this);
		NBTTagCompound tag = stack.getTagCompound();
		((BlockSavedTileEntity) te).writeToNBT(tag);
		System.out.println("tag=" + tag);
		itemStacks.add(stack);
	} else {
		System.out.println("Could not write path to tag. TileEntity not a BlockSavedTileEntity. te=" + te);
	}

	return itemStacks;
}

 

 

 

but te is coming up null (maybe because it was broken?). Do I still need to override harvestBlock and pass string path somehow? Or is there a problem with my TileEntity?

 

 

 

package org.snowyegret.mojo.block;

import net.minecraft.block.Block;
import net.minecraft.nbt.NBTTagCompound;
import net.minecraft.network.NetworkManager;
import net.minecraft.network.Packet;
import net.minecraft.network.play.server.S35PacketUpdateTileEntity;
import net.minecraft.tileentity.TileEntity;

public class BlockSavedTileEntity extends TileEntity {

private String path;

public void setPath(String path) {
	this.path = path;
}

public String getPath() {
	return path;
}

@Override
public void writeToNBT(NBTTagCompound tag) {
	if (path == null) {
		System.out.println("Could not write path to tag. path=" + path);
	} else {
		tag.setString(BlockSaved.KEY_PATH, path);
		super.writeToNBT(tag);
	}
}

@Override
public void readFromNBT(NBTTagCompound tag) {
	path = tag.getString(BlockSaved.KEY_PATH);
	super.readFromNBT(tag);
}

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

@Override
public void onDataPacket(NetworkManager net, S35PacketUpdateTileEntity pkt) {
	readFromNBT(pkt.getNbtCompound());
	super.readFromNBT(pkt.getNbtCompound());
}

}

 

 

Posted

Is there something else I have missed? Now the block does not drop when I break it. (Same behavior when I don't override harvestBlock)

 

 

 

@Override
public boolean removedByPlayer(World world, BlockPos pos, EntityPlayer player, boolean willHarvest) {
	System.out.println("willHarvest=" + willHarvest);
	new Throwable().printStackTrace();
	if (willHarvest) {
		// Delay deletion of the block until after getDrops
		return true;
	}
	return super.removedByPlayer(world, pos, player, willHarvest);
}

@Override
public void harvestBlock(World world, EntityPlayer player, BlockPos pos, IBlockState state, TileEntity te) {
	System.out.println("te=" + te);
	super.harvestBlock(world, player, pos, state, te);
	world.setBlockToAir(pos);
}

 

 

 

Here my console. Is it normal that removeByPlayer is called twice with different values for willHarvest?

 

 

 

[13:39:11] [server thread/INFO] [sTDOUT]: [org.snowyegret.mojo.item.spell.other.SpellSave:setText:87]: path=/tmp/Foo8418776298188150160.save
[13:39:13] [Client thread/INFO] [sTDOUT]: [org.snowyegret.mojo.block.BlockSaved:removedByPlayer:135]: willHarvest=false
[13:39:13] [Client thread/INFO] [sTDERR]: [java.lang.Throwable$WrappedPrintStream:println:748]: java.lang.Throwable
[13:39:13] [Client thread/INFO] [sTDERR]: [java.lang.Throwable$WrappedPrintStream:println:748]: 	at org.snowyegret.mojo.block.BlockSaved.removedByPlayer(BlockSaved.java:136)
[13:39:13] [Client thread/INFO] [sTDERR]: [java.lang.Throwable$WrappedPrintStream:println:748]: 	at net.minecraft.client.multiplayer.PlayerControllerMP.onPlayerDestroyBlock(PlayerControllerMP.java:165)
[13:39:13] [Client thread/INFO] [sTDERR]: [java.lang.Throwable$WrappedPrintStream:println:748]: 	at net.minecraft.client.multiplayer.PlayerControllerMP.func_180511_b(PlayerControllerMP.java:252)
[13:39:13] [Client thread/INFO] [sTDERR]: [java.lang.Throwable$WrappedPrintStream:println:748]: 	at net.minecraft.client.Minecraft.clickMouse(Minecraft.java:1520)
[13:39:13] [Client thread/INFO] [sTDERR]: [java.lang.Throwable$WrappedPrintStream:println:748]: 	at net.minecraft.client.Minecraft.runTick(Minecraft.java:2127)
[13:39:13] [Client thread/INFO] [sTDERR]: [java.lang.Throwable$WrappedPrintStream:println:748]: 	at net.minecraft.client.Minecraft.runGameLoop(Minecraft.java:1088)
[13:39:13] [Client thread/INFO] [sTDERR]: [java.lang.Throwable$WrappedPrintStream:println:748]: 	at net.minecraft.client.Minecraft.run(Minecraft.java:376)
[13:39:13] [Client thread/INFO] [sTDERR]: [java.lang.Throwable$WrappedPrintStream:println:748]: 	at net.minecraft.client.main.Main.main(Main.java:117)
[13:39:13] [Client thread/INFO] [sTDERR]: [java.lang.Throwable$WrappedPrintStream:println:748]: 	at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
[13:39:13] [Client thread/INFO] [sTDERR]: [java.lang.Throwable$WrappedPrintStream:println:748]: 	at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
[13:39:13] [Client thread/INFO] [sTDERR]: [java.lang.Throwable$WrappedPrintStream:println:748]: 	at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
[13:39:13] [Client thread/INFO] [sTDERR]: [java.lang.Throwable$WrappedPrintStream:println:748]: 	at java.lang.reflect.Method.invoke(Method.java:497)
[13:39:13] [Client thread/INFO] [sTDERR]: [java.lang.Throwable$WrappedPrintStream:println:748]: 	at net.minecraft.launchwrapper.Launch.launch(Launch.java:135)
[13:39:13] [Client thread/INFO] [sTDERR]: [java.lang.Throwable$WrappedPrintStream:println:748]: 	at net.minecraft.launchwrapper.Launch.main(Launch.java:28)
[13:39:13] [Client thread/INFO] [sTDERR]: [java.lang.Throwable$WrappedPrintStream:println:748]: 	at net.minecraftforge.gradle.GradleStartCommon.launch(Unknown Source)
[13:39:13] [Client thread/INFO] [sTDERR]: [java.lang.Throwable$WrappedPrintStream:println:748]: 	at GradleStart.main(Unknown Source)
[13:39:13] [server thread/INFO] [sTDOUT]: [org.snowyegret.mojo.block.BlockSaved:removedByPlayer:135]: willHarvest=true
[13:39:13] [server thread/INFO] [sTDERR]: [java.lang.Throwable$WrappedPrintStream:println:748]: java.lang.Throwable
[13:39:13] [server thread/INFO] [sTDERR]: [java.lang.Throwable$WrappedPrintStream:println:748]: 	at org.snowyegret.mojo.block.BlockSaved.removedByPlayer(BlockSaved.java:136)
[13:39:13] [server thread/INFO] [sTDERR]: [java.lang.Throwable$WrappedPrintStream:println:748]: 	at net.minecraft.server.management.ItemInWorldManager.removeBlock(ItemInWorldManager.java:296)
[13:39:13] [server thread/INFO] [sTDERR]: [java.lang.Throwable$WrappedPrintStream:println:748]: 	at net.minecraft.server.management.ItemInWorldManager.tryHarvestBlock(ItemInWorldManager.java:349)
[13:39:13] [server thread/INFO] [sTDERR]: [java.lang.Throwable$WrappedPrintStream:println:748]: 	at net.minecraft.server.management.ItemInWorldManager.onBlockClicked(ItemInWorldManager.java:233)
[13:39:13] [server thread/INFO] [sTDERR]: [java.lang.Throwable$WrappedPrintStream:println:748]: 	at net.minecraft.network.NetHandlerPlayServer.processPlayerDigging(NetHandlerPlayServer.java:552)
[13:39:13] [server thread/INFO] [sTDERR]: [java.lang.Throwable$WrappedPrintStream:println:748]: 	at net.minecraft.network.play.client.C07PacketPlayerDigging.processPacket(C07PacketPlayerDigging.java:53)
[13:39:13] [server thread/INFO] [sTDERR]: [java.lang.Throwable$WrappedPrintStream:println:748]: 	at net.minecraft.network.play.client.C07PacketPlayerDigging.processPacket(C07PacketPlayerDigging.java:76)
[13:39:13] [server thread/INFO] [sTDERR]: [java.lang.Throwable$WrappedPrintStream:println:748]: 	at net.minecraft.network.PacketThreadUtil$1.run(PacketThreadUtil.java:24)
[13:39:13] [server thread/INFO] [sTDERR]: [java.lang.Throwable$WrappedPrintStream:println:748]: 	at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:511)
[13:39:13] [server thread/INFO] [sTDERR]: [java.lang.Throwable$WrappedPrintStream:println:748]: 	at java.util.concurrent.FutureTask.run(FutureTask.java:266)
[13:39:13] [server thread/INFO] [sTDERR]: [java.lang.Throwable$WrappedPrintStream:println:748]: 	at net.minecraftforge.fml.common.FMLCommonHandler.callFuture(FMLCommonHandler.java:714)
[13:39:13] [server thread/INFO] [sTDERR]: [java.lang.Throwable$WrappedPrintStream:println:748]: 	at net.minecraft.server.MinecraftServer.updateTimeLightAndEntities(MinecraftServer.java:727)
[13:39:13] [server thread/INFO] [sTDERR]: [java.lang.Throwable$WrappedPrintStream:println:748]: 	at net.minecraft.server.MinecraftServer.tick(MinecraftServer.java:669)
[13:39:13] [server thread/INFO] [sTDERR]: [java.lang.Throwable$WrappedPrintStream:println:748]: 	at net.minecraft.server.integrated.IntegratedServer.tick(IntegratedServer.java:171)
[13:39:13] [server thread/INFO] [sTDERR]: [java.lang.Throwable$WrappedPrintStream:println:748]: 	at net.minecraft.server.MinecraftServer.run(MinecraftServer.java:540)
[13:39:13] [server thread/INFO] [sTDERR]: [java.lang.Throwable$WrappedPrintStream:println:748]: 	at java.lang.Thread.run(Thread.java:745)
[13:39:13] [server thread/INFO] [sTDOUT]: [org.snowyegret.mojo.block.BlockSaved:harvestBlock:146]: te=org.snowyegret.mojo.block.BlockSavedTileEntity@3209ab1
[

 

 

 

 

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

    • I can't figure out if you're looking for help trying to steal someone elses work, or cheat at the game....
    • Title: Why Is It So Hard to Rename and Restructure Mods Like Xray or AntiXray? 🤔 Post text: Hey everyone! I’ve been digging into Minecraft modding for a while and have one big question that I can’t figure out on my own. Maybe someone with more experience could help or give me some advice. Here’s the issue: When I take a “normal” Minecraft mod — for example, one that just adds some blocks or new items — I can easily change its structure, package names, or even rebrand it entirely. It’s straightforward. But as soon as I try this with cheat-type mods like XrayMod or AntiXray, everything falls apart. Even if I just rename the classes, refactor the packages, or hide its identity somehow, the mod either breaks or stops working properly. XrayMod in particular is proving to be a nightmare to modify without losing its core function. So my question is — why is this so much harder with cheat mods like Xray? Is there something fundamentally different about how they’re coded, loaded, or protected that prevents simple renaming or restructuring? And if so, how can I actually learn to understand someone else’s cheat mod enough to safely refactor it without breaking the core features? I’ve already been spending over two months trying to figure this out and haven’t gotten anywhere. It feels like there must be some trick or knowledge I’m missing. Would really appreciate any thoughts, tips, or references — maybe there are guides or techniques for understanding cheat-mod internals? Or if you’ve successfully “disguised” a cheat mod like Xray before, I’d love to hear how you did it. Thanks in advance for any help or discussion. ✌️
    • just started making cinamatic contect check it out on my channel or check out my facebook page    Humbug City Minecraft Youtube https://www.youtube.com/watch?v=v2N6OveKwno https://www.facebook.com/profile.php?id=61575866982337  
    • Where did you get the schematic? Source/Link? And do use an own modpack or a pre-configured from curseforge? If yes, which one On a later time, I can make some tests on my own - but I need the schematic and the modpack name
  • Topics

×
×
  • Create New...

Important Information

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