Jump to content
Search In
  • More options...
Find results that contain...
Find results in...

[1.7.10]Item being added to array twice?


ashjack
 Share

Recommended Posts

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);
}

Link to comment
Share on other sites

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

Link to comment
Share on other sites

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/

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

 Share

×
×
  • Create New...

Important Information

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