Jump to content

Saving a list of BlockEvents


gpouliot

Recommended Posts

I'm working on a mod to Record and then playback block events.  Specifically, it records place events and break events and then lets me replay the events either in forward or reverse order.

 

I've got that working simply by making a list of block events and adding the break or place events to the list as they occur.  It's then trivial to replay the events.

 

Now, I'm at the point where I want to save these block event lists to disk so that I can load them and recreate the block events at a later date.  When it comes to Java, I'm a little rusty so I was trying to find an example that I could work with. However, most tutorials are about creating new block types.  There doesn't seem to be a lot of examples of people wanting to save block events to disk (and then reload them).

 

As a test, when I run my Stop Recording command, it opens a file (in the Minecraft game world directory) and writes the x,y,z coordinates of the effected blocks.  That's easy.  Where I'm getting hung up is on the best way to go from a BlockEvent to a Text File and then back to a Block Event when I reload the data.

 

Does anyone know of any examples that might help?  Baring that, what would you guys suggest?  I don't need someone to do it for me, just point me in the right direction and I can take it from there.  Thanks.

 

 

Link to comment
Share on other sites

You only need to save the pertinent data(the block, the position and whether it is breaking or placing the block) which means you need to write that data to a text file or some other type of file then parse the fata when loading.

VANILLA MINECRAFT CLASSES ARE THE BEST RESOURCES WHEN MODDING

I will be posting 1.15.2 modding tutorials on this channel. If you want to be notified of it do the normal YouTube stuff like subscribing, ect.

Forge and vanilla BlockState generator.

Link to comment
Share on other sites

I guess where I'm getting hung up is the meta data.  If it wasn't for the meta data, I would just save the x,y,z coordinates, whether it was a place or break event and what type of block it is or was.  However, given that there is all sorts of meta data to contend with, I'm just having trouble wrapping my head around it.

Link to comment
Share on other sites

I guess where I'm getting hung up is the meta data.  If it wasn't for the meta data, I would just save the x,y,z coordinates, whether it was a place or break event and what type of block it is or was.  However, given that there is all sorts of meta data to contend with, I'm just having trouble wrapping my head around it.

Grab the blockstate and handle the data from that or in some cases where they override getStateFromMeta you could just write the meta then use that method to grab the correct blockstate.

VANILLA MINECRAFT CLASSES ARE THE BEST RESOURCES WHEN MODDING

I will be posting 1.15.2 modding tutorials on this channel. If you want to be notified of it do the normal YouTube stuff like subscribing, ect.

Forge and vanilla BlockState generator.

Link to comment
Share on other sites

I'll put a little code here to better show what I'm up against...

 

The three classes below do the lion's share of the work.  What makes them so easy and nice to work with is the fact that I don't have to create any BlockEvents myself.  When an event happens I simply add it to the list.  When I want to play or rewind the list, I simply iterate through the list and use setBlockState to make the needed changes.

 

Since I can't directly save and then reload BlockEvent's (that would be nice), I think I have to pull out the needed data, save it, reload it and then somehow create my own list of BlockEvents based on that loaded data.  It's much more complicated than simply adding existing block events to a list and replaying them when needed.

 

Alternatively, I'm thinking that instead of using a list of BlockEvents, maybe the better option is to create my own list with a custom data format that only stores the block position, block type, metadata and event type (place or break).  That way, saving and reloading the data would be relatively easy.  The only tricky part is making sure I properly handle the meta data and figure out how to correctly send the needed state information in the second argument of the setBlockState() command.

 

If anyone has done something similar, I'd love to see an example...  :)

 

public void record(BlockEvent event)
{
if(isRecording == true)
{
	if(event instanceof BreakEvent || event instanceof PlaceEvent)
	{
		events.add(event);
	}
}
}

 

 

public void play(EntityPlayer player)
{
if(!events.isEmpty())
{
	for(BlockEvent event : events) {
		if(event instanceof BreakEvent)
		{
			player.worldObj.setBlockState(event.getPos(), Blocks.AIR.getDefaultState());
		}
		else if(event instanceof PlaceEvent) 
		{
			player.worldObj.setBlockState(event.getPos(), ((PlaceEvent) event).getState());
		}
	}
}
}

 

public void rewind(EntityPlayer player)
{
if(!events.isEmpty())
{
	ListIterator li = events.listIterator(events.size()); 

	while(li.hasPrevious()) {
		Object current = li.previous();
		if(current instanceof BreakEvent)
		{
			player.worldObj.setBlockState(((BlockEvent) current).getPos(), ((BlockEvent) current).getState());

		}
		else if(current instanceof PlaceEvent) 
		{
			player.worldObj.setBlockState(((BlockEvent) current).getPos(), ((PlaceEvent) current).getBlockSnapshot().getReplacedBlock());
		}
	}
}
}

 

 

Link to comment
Share on other sites

There is no direct way of saving BlockEvents or any class like that, because it is not a base field like ints and doubles are. You will have to save the data yourself. Meaning you need the blocks registryName, any blockstate information ie metadata or its properties, the position, and the type of event. Use WorldSavedData to save it to the world or alternatively an event for when the world loads/saves or capabilites for players.

VANILLA MINECRAFT CLASSES ARE THE BEST RESOURCES WHEN MODDING

I will be posting 1.15.2 modding tutorials on this channel. If you want to be notified of it do the normal YouTube stuff like subscribing, ect.

Forge and vanilla BlockState generator.

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.



  • Recently Browsing

    • No registered users viewing this page.
  • Posts

    • Turning the Tables: My Journey to Reclaim Stolen Bitcoins with Expert Help. When my Bitcoin wallet was hacked and my entire cryptocurrency portfolio was stolen, I felt utterly devastated and hopeless. Having worked hard to build up my digital assets, the sudden loss was gut-wrenching. It felt like my financial future had been ripped away in an instant, leaving me overwhelmed by a sense of betrayal and despair. In my search for help, I discovered TECH CYBER FORCE Recovery, a renowned cybersecurity firm specializing in cryptocurrency recovery. I was met with professionalism and empathy from my first contact with them. The team demonstrated a steadfast commitment to helping me retrieve my stolen Bitcoins. They understood the emotional toll of my situation and approached my case with genuine concern. TECH CYBER FORCE Recovery swung into action immediately, leveraging its extensive expertise in blockchain forensics and hacker tracking techniques. Their process was meticulous. They analyzed my transaction history, followed the digital trail left by the hackers, and worked diligently to pinpoint the location of the stolen funds. I was impressed by their technical prowess; they employed advanced cryptographic methods and strategic negotiations with the perpetrators, all while keeping me informed about their progress. The recovery process was complex and fraught with challenges. However, the tenacity displayed by the team was truly awe-inspiring. They navigated cryptocurrency crime's murky and ever-evolving landscape with skill and determination. After a series of strategic moves, they managed to recover the majority of my Bitcoins successfully.  
    • I removed giacomos_hud, oculus, (dont know what you mean with iris), enhanced_boss_bars, epicfight and essential.  Server still doesnt want to boot. new logs after removing: https://pastebin.com/LuM2PFtN I dont quite understand the "server side" and "client side" difference..
    • There are client side only mods in your server files   Remove giacomos_hud, oculus, iris, enhanced_boss_bars and epicfight You can keep these mods in your client Maybe also remove essentials
    • Here is my Log with java 17: https://pastebin.com/RPdWSjwq
    • Been working on creating a server for this mod, but i keep getting this error over and over again.  I have tried updating/changing the Forge launcher, Removing/replacing the ops.json and whitelist.json folders, and removing certain mods. Crash report log: https://pastebin.com/Bu046cVq Debug.log https://pastebin.com/7hKm40ke Latest.log https://pastebin.com/nCRLUH3b any help would be great thanks!
  • Topics

×
×
  • Create New...

Important Information

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