Jump to content

Recommended Posts

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

Posted

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

Posted
  On 1/17/2015 at 2:55 PM, diesieben07 said:

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/

Posted
  On 1/17/2015 at 2:55 PM, diesieben07 said:

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.

Posted

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.

Posted

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.

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

    • Hello all. I'm currently grappling with the updateShape method in a custom class extending Block.  My code currently looks like this: The conditionals in CheckState are there to switch blockstate properties, which is working fine, as it functions correctly every time in getStateForPlacement.  The problem I'm running into is that when I update a state, the blocks seem to call CheckState with the position of the block which was changed updated last.  If I build a wall I can see the same change propagate across. My question thus is this: is updateShape sending its return to the neighbouring block?  Is each block not independently executing the updateShape method, thus inserting its own current position?  The first statement appears to be true, and the second false (each block is not independently executing the method). I have tried to fix this by saving the block's own position to a variable myPos at inception, and then feeding this in as CheckState(myPos) but this causes a worse outcome, where all blocks take the update of the first modified block, rather than just their neighbour.  This raises more questions than it answers, obviously: how is a different instance's variable propagating here?  I also tried changing it so that CheckState did not take a BlockPos, but had myPos built into the body - same problem. I have previously looked at neighbourUpdate and onNeighbourUpdate, but could not find a way to get this to work at all.  One post on here about updatePostPlacement and other methods has proven itself long superceded.  All other sources on the net seem to be out of date. Many thanks in advance for any help you might offer me, it's been several days now of trying to get this work and several weeks of generally trying to get round this roadblock.  - Sandermall
    • sorry, I might be stupid, but how do I open it? because the only options I have are too X out, copy it, which doesn't work and send crash report, which doesn't show it to me, also, sorry for taking so long.
    • Can you reproduce this with version 55.0.21? A whole lot of plant placement issues were just fixed in this PR.
    • Necro'ing that thread to ask if you found a solution ? I'm encountering the same crash on loading the world. I created the world in Creative to test my MP, went into survival to test combat, died, crashed on respawn and since then crash on loading the world. Deactivating Oculus isn't fixing it either, and I don't have Optifine (Twilight forest is incompatible)
  • Topics

×
×
  • Create New...

Important Information

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