Jump to content

Recommended Posts

Posted

Hi everybody!

 

I started modding the other day and made some good progress but now I've hit a wall.

My idea is this: I have a semi-expensive to craft block a player can right click. The block (a TileEntity obviously) stores the player's name.

I then listen to the LivingDeathEvent event. If a player dies I cancel the event, set his health to half a heart and teleport him on top of the block he was "bound" to.

Now...I've managed the right-clicking, the event handling and the teleporting but it all works a bit wonky probably due to massive syncing issues I'm currently not able to comprehend.

Currently I'm doing something like this: a player clicks the block -> the TileEntity registers at a central class which holds a static collection of all active resurrection blocks (i.e. TileEntities). If the LivingDeathEvent occurs it checks if it was a player and then iterates over all elements (TileEntities) in the collection to check if the player was "bound" to one of them. Which one of these things do I need to handle on which side (client/server)? Do I need packages or am I overlooking something obvious?

 

Here's some random code:

click on the block

@Override
public boolean onBlockActivated(World world, int x, int y, int z, EntityPlayer player, int par6, float par7, float par8, float par9) {
    TileEntityResurrectionBlock base = (TileEntityResurrectionBlock)world.getBlockTileEntity(x, y, z);
    if (base != null) {
        if (player.isSneaking()) {
            if (base.isBound()) {
                if(!world.isRemote) player.addChatMessage(MessagesEn.SOMEONE_ELSE_BOUND);
            } else {
                base.setBinding(player.getEntityName());
                if(!world.isRemote) player.addChatMessage(MessagesEn.NOW_BOUND);
            }
        } else {
            if (base.isBound()) {
                if(!world.isRemote) player.addChatMessage(MessagesEn.PLAYER_BOUND + base.getBoundPlayer());
            } else {
                if(!world.isRemote) player.addChatMessage(MessagesEn.NOT_BOUND);
            }
        }
    }
    return false;
}

 

setBinding in TileEntityResurrectionBlock

public void setBinding(String playerName) {
    boundPlayer = playerName;
    BlockManager.addBlock(this);
}

 

BlockManager

public class BlockManager {
    private static List blocks = new ArrayList();

    public static void addBlock(TileEntityResurrectionBlock base) {
        //if(!Minecraft.getMinecraft().theWorld.isRemote) return;
        Iterator it = blocks.iterator();
        // check if this player already has a bound vita-chamber anywhere
        // and remove that one
        while (it.hasNext()) {
            TileEntityResurrectionBlock b = (TileEntityResurrectionBlock)it.next();
            if (b.getBoundPlayer().equals(base.getBoundPlayer())) {
                b.setBoundPlayer("");
                it.remove();
            }
        }

        blocks.add(base);
    }

    public static void removeBlock(TileEntityResurrectionBlock base) {
        //if(Minecraft.getMinecraft().theWorld.isRemote) return;
        blocks.remove(base);
    }

    public static TileEntityResurrectionBlock isPlayerBoundAnywhere(String playerName) {
        Iterator it = blocks.iterator();
        boolean isBound = false;
        while (it.hasNext()) {
            TileEntityResurrectionBlock base = (TileEntityResurrectionBlock)it.next();
            if (base.getBoundPlayer().equals(playerName)) {
                return base;
            }
        }
        return null;
    }
}

 

Cheers

- Chris

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



×
×
  • Create New...

Important Information

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