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.

Featured Replies

Posted

So I have been updating a mod from 1.6.4 to 1.7.10, and some code that adds a custom class to an array when you place a block seems to add said class to an array twice. Here is the code:

@Override
public void onBlockAdded(World world, int i, int j, int k)
{
hasPlaced = true;
Marker ma;
markers.add(ma = new Marker(i, j, k, world.provider.dimensionId));
String markerCaption = "";
String helpText = "";

if (markers.size() == 1)
{
markerCaption = "Front-Left";
helpText = "You can place two more markers to mark out an area for a farm or mine etc. If you wish to do this, place another marker at the front-right position now";
System.out.println(markers.size());
}
else if (markers.size() == 2)
{
markerCaption = "Front-Right";
helpText = "Finally, place a marker at the Rear-Left position";
System.out.println(markers.size());
}
else if (markers.size() == 3)
{

markerCaption = "Rear-Left";
helpText = "You're done, now you can place down a mining box, farming box or right-click the front-left marker to copy a structure!";
System.out.println(markers.size());
}

else
{
System.out.println(markers.size());
markerCaption = "Too many Markers!";
}

if (markers.size() < 4)
{
V3 pos = new V3((double)i, (double)j, (double)k, world.provider.dimensionId);
pos.y += 0.01d;

if (ModSimukraft.configEnableMarkerAlignmentBeams)
{
EntityAlignBeam beam = new EntityAlignBeam(world);
ma.caption = markerCaption;
beam.setLocationAndAngles(pos.x, pos.y, pos.z, 0f, 0f);
beam.yaw = 0f;

if (!world.isRemote)
{
world.spawnEntityInWorld(beam);
}

ma.beams.add(beam);
EntityAlignBeam beam2 = new EntityAlignBeam(world);
beam2.setLocationAndAngles(pos.x, pos.y, pos.z, 90f, 0f);
beam2.yaw = 90f;

if (!world.isRemote)
{
world.spawnEntityInWorld(beam2);
}

ma.beams.add(beam2);
EntityAlignBeam beam3 = new EntityAlignBeam(world);
beam3.setLocationAndAngles(pos.x, pos.y, pos.z, 180f, 0f);
beam3.yaw = 180f;

if (!world.isRemote)
{
world.spawnEntityInWorld(beam3);
}

ma.beams.add(beam3);
EntityAlignBeam beam4 = new EntityAlignBeam(world);
beam4.setLocationAndAngles(pos.x, pos.y, pos.z, 270f, 0f);
beam4.yaw = 270f;

if (!world.isRemote)
{
world.spawnEntityInWorld(beam4);
}

ma.beams.add(beam4);
}
}

if (!helpText.contentEquals(""))
{
ModSimukraft.sendChat(helpText);
}

super.onBlockAdded(world, i, j, k);
}

  • Author

So I should check to see what side is being run, and only add it if it client sided?

  • Author

Well, only the person placing the markers should see the effects of them, so I guess that's the way to go.

  • Author

The effects are the spawning of a few lines to show how big an area will be, the area is marked out by the markers that are placed. Also, it checks to see how many markers have been placed, and any more than three means it will not work, however, since it adds two to the array, it thinks I have placed three when in fact I have only placed two

  • Author

I used @SideOnly(Side.SERVER) but the code doesn't run properly. Could I consider making a packet message for this function?

You will need to do this serverside.

Use an

IExtendedEntityProperties

to keep track of which blocks the player has placed. Use

onBlockPlacedBy

to detect when it is placed.

Don't PM me with questions. They will be ignored! Make a thread on the appropriate board for support.

 

1.12 -> 1.13 primer by williewillus.

 

1.7.10 and older versions of Minecraft are no longer supported due to it's age! Update to the latest version for support.

 

http://www.howoldisminecraft1710.today/

  • Author

You will need to do this serverside.

Use an

IExtendedEntityProperties

to keep track of which blocks the player has placed. Use

onBlockPlacedBy

to detect when it is placed.

 

onBlockPlacedBy does not override any method.

  • Author

Surely if onBlockPlacedBy errors if you give it an @Override then the method doesn't already exist, meaning it won't be called when placing a block? I may be wrong, but that's what I think.

  • Author

Ah, okay, I understand now, if the parameters are not correct, Java sees it as a new function. However, this function is also run on both the integrated server and the client, and I still need to add a marker to the array.

  • Author

What do you mean it's in the wrong place? I'm really sorry that I seem so stupid, it's just I'm not very experienced with Java. C# is my specialty.

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.