Posted August 24, 201510 yr I want to write String save in box . Refer name player of string in server. If non owner box can't break. But if owner box can break. Minecraft mc; public void onBlockAdded(World world,int par1, int par2, int par3) { String var4 = mc.thePlayer.getCommandSenderName(); if(var4 == mc.thePlayer.getCommandSenderName()){ }else{ this.setBlockUnbreakable(); } } how to write it ?
August 24, 201510 yr I want to write String save in box . Refer name player in server. If non owner box can't break. But if owner box can break. Minecraft mc; public void onBlockAdded(World world,int par1, int par2, int par3) { String var4 = mc.thePlayer.getCommandSenderName(); if(var4 == mc.thePlayer.getCommandSenderName()){ }else{ this.setBlockUnbreakable(); } } how to write it ? this code is a total mess. you should better delete it and hope noone will ever find it again. The method u are seeking is onBlockPlaced, it gives you an EntityLivingBase where u can get the players name from. If u call setBlockUnbreakable u will set ALL of your blocks unbreakable, because the Block class is for EVERY SINGE BLOCK of that block placed. if you want them to be different you need to use a TileEntity
August 24, 201510 yr Author Oh Thank you very much. in EntityLivingBase. How to use it ? i'm sorry I rookie forge java.
August 25, 201510 yr Author - If setBlockUnbreakable it set box all. Should what used instead ? - I use TileEntity in how to write ?
August 25, 201510 yr Author I want to write String save in box . Refer name player in server. If non owner box can't break. But if owner box can break. Minecraft mc; public void onBlockAdded(World world,int par1, int par2, int par3) { String var4 = mc.thePlayer.getCommandSenderName(); if(var4 == mc.thePlayer.getCommandSenderName()){ }else{ this.setBlockUnbreakable(); } } how to write it ? this code is a total mess. you should better delete it and hope noone will ever find it again. The method u are seeking is onBlockPlaced, it gives you an EntityLivingBase where u can get the players name from. If u call setBlockUnbreakable u will set ALL of your blocks unbreakable, because the Block class is for EVERY SINGE BLOCK of that block placed. if you want them to be different you need to use a TileEntity - If setBlockUnbreakable it set box all. Should what used instead ? - I use TileEntity in how to write ?
August 25, 201510 yr MyTileEntity te = (MyTileEntity) world.getTileEntity(x,y,z) (for 1.8 use BlockPos instead of x,y,z)
August 25, 201510 yr Author Can I'll lock a block by setBlockUnbreackable? If not. What I should to change?
August 25, 201510 yr Hook into the playerinteract event and check for player leftclick on block as the action and that the block is your block and set the result to DENY. This is a good reference to keep on hand: http://www.minecraftforge.net/wiki/Event_Reference Current Project: Armerger Planned mods: Light Drafter | Ore Swords Looking for help getting a mod off the ground? Coding | Textures
August 25, 201510 yr No need to use events if it's your own Block . Override Block#getPlayerRelativeBlockHardness to return -1.0f to prevent a player from starting to mine the Block and override Block#removedByPlayer to return false to prevent a player from breaking the Block (probably not strictly needed for vanilla, but mods with AoE mining tools like Tinkers Construct may break a Block without checking its hardness). Please don't PM me to ask for help. Asking your question in a public thread preserves it for people who are having the same problem in the future.
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.