Jump to content
View in the app

A better way to browse. Learn more.

Forge Forums

A full-screen app on your home screen with push notifications, badges and more.

To install this app on iOS and iPadOS
  1. Tap the Share icon in Safari
  2. Scroll the menu and tap Add to Home Screen.
  3. Tap Add in the top-right corner.
To install this app on Android
  1. Tap the 3-dot menu (⋮) in the top-right corner of the browser.
  2. Tap Add to Home screen or Install app.
  3. Confirm by tapping Install.

[solved]Blocks not saving meta data on server shutdown/ player logout?

Featured Replies

Posted

I use this following code to adjust the metadata for surrounding blocks

 

 

public static boolean soulDrain(int soulcost) //, int x, int y, int z)
{
	World world = worldPointer;
	int x = posX;
	int y = posY;
	int z = posZ;
	int cost = soulcost;

	soulCountTotal = (soulCountTotal - (cost * 5));

	 for (int var6 = x - 2; var6 <= x + 2; ++var6)
        {
            for (int var7 = z - 2; var7 <= z + 2; ++var7)
            {
                if (var6 > x - 2 && var6 < x + 2 && var7 == z - 1)
                {
                    var7 = z + 2;
                }
                    for (int var8 = y - 1; var8 <= y + 1; ++var8)
                    {
                        if (world.getBlockId(var6, var8, var7) == mod_HarkenScythe.HSSoulCrucible.blockID) //&& soulCountTotal > 0)
                        {
                        	int var11 = world.getBlockMetadata(var6, var8, var7);
                        	
                            if (!world.isAirBlock((var6 - x) / 2 + x, var8 + 1, (var7 - z) / 2 + z))
                            {
                                break;
                            }
                            
                            if (var11 > cost)
                            {
                            	world.setBlockMetadataWithNotify(var6, var8, var7, var11 - cost);
                            	cost = 0;
                            }
                            if (cost >= var11)
                            {
                            	world.setBlockMetadataWithNotify(var6, var8, var7, 0);
                            	cost -= var11;
                            }
                        }
                    }
            }
        }
	 System.out.println(cost);
	return true;
}

 

 

 

Now this works 100% while playing SP however while playing on servers the following happens.

 

First the BlockSoulCrucible in the area are affected by the method - works correct.

On server Log out, all BlockSoulCrucible's reset back their old Metadata- not correct.

 

Wondering why the Metadata is not saving or updating/saving upon logout.

Are you sure you call it only on server-side? Sounds to me you call this only client-side.

Don't ask for support per PM! They'll get ignored! | If a post helped you, click the "Thank You" button at the top right corner of said post! |

mah twitter

This thread makes me sad because people just post copy-paste-ready code when it's obvious that the OP has little to no programming experience. This is not how learning works.

  • Author

Correct, I had it calling from my Gui button action.

 

I now enabled the metadata change method on a Side.SERVER , which works great... however now my Gui does not update with the new Metadata info.

 

If I leave my Gui metadata change in tack and enable the new Side.SERVER method in my tileEntityCustom.class, it works great for servers.... however if you play single player, then the action is done twice T_T.

 

Gained SMP but lost SP =/

 

Any suggestions?

 

This is the code I use for my Gui Display text of Total Soul Count. I use a static variable that is on my BlockSoulAltar.

Which I force an update when the block is activated.

 

 

********************
//AutoCenters Numbers
int ws = 0;
if (BlockSoulAltar.soulCountTotal > 999)
{
	ws = -4;
}

//SoulCountTotal Display
fontRenderer.drawString(""+ BlockSoulAltar.soulCountTotal, 150 + ws, 24, 0xffffff);
***************************


@Override
protected void drawGuiContainerForegroundLayer()
{
// Draws The title of the Gui like "Furnace" for the furnace,
// It has 4 params
// @param "Tutorial Gui" this is the Name in String format
// @param int 6, this is the xCoord on the screen
// @param int 6, this is the yCoord on the screen
// @param 0xffffff, this is the color in hex, 0xffffff, is white, 0x000000 is black BTW
fontRenderer.drawString("Soul Altar", 6, 6, 4210752);
fontRenderer.drawString("Captured Souls", 94, 6, 4210752);

//AutoCenters Numbers
int ws = 0;
if (BlockSoulAltar.soulCountTotal > 999)
{
	ws = -4;
}

//SoulCountTotal Display
fontRenderer.drawString(""+ BlockSoulAltar.soulCountTotal, 150 + ws, 24, 0xffffff);

//SoulCostTotal Display
if (this.inventorySlots.getSlot(0).getStack() != null)
{
	fontRenderer.drawString(""+ this.SARL[1] * this.inventorySlots.getSlot(0).getStack().stackSize, 150, 51, 0xffffff);
}

// This draws the caption for the players inventory this is not needed as the above but is sometimes nice
fontRenderer.drawString(StatCollector.translateToLocal("container.inventory"), 6, ySize - 96 + 2, 4210752);
}

 

 

 

  • Author

Nvm, figured it out.

 

Placed this on my gui Button action method.

 

if (this.mc.isIntegratedServerRunning() == false)

{

this.containerSoulAltar.soulDrain(soulCostTotal / 5);

},

 

This way the extra method is disabled when not needed xD.

 

Thanks, helped me look in the right direction.

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...

Important Information

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

Configure browser push notifications

Chrome (Android)
  1. Tap the lock icon next to the address bar.
  2. Tap Permissions → Notifications.
  3. Adjust your preference.
Chrome (Desktop)
  1. Click the padlock icon in the address bar.
  2. Select Site settings.
  3. Find Notifications and adjust your preference.