Posted November 25, 20159 yr So basically, I'm making a mod that, among other things, will include two special blocks: A wireless button that is linked to a wireless redstone power source. Upon being placed, the player will receive the button, linked to the power source. Theoretically, pressing the button should result in the power source emitting a redstone signal, even if they're not connected. However, this doesn't work. Could somebody please help me with this? WirelessRedstoneSource.class [embed=425,349]public class WirelessRedstoneSource extends Block { private boolean activated; public WirelessRedstoneSource() { super(Material.iron); setStepSound(soundTypeAnvil); setBlockName("wirelessRedstoneSource"); setCreativeTab(CreativeTabs.tabRedstone); setTickRandomly(true); } public void activate() { this.activated = true; } public void deactivate() { this.activated = false; } @Override public int tickRate(World world) { return 20; } @Override public void updateTick(World world, int x, int y , int z, Random rand) { if (!world.isRemote) { if (activated) { checkActivated(world, x, y, z); world.notifyBlocksOfNeighborChange(x, y, z, this); world.notifyBlockOfNeighborChange(x, y + 1, z, this); } } } private void checkActivated(World world, int x, int y, int z) { if (activated) { world.scheduleBlockUpdate(x, y, z, this, this.tickRate(world)); } } @Override public boolean onBlockActivated(World world, int x, int y, int z, EntityPlayer player, int face, float xf, float yf, float zf) { if (world.isRemote) { return true; } else { world.notifyBlocksOfNeighborChange(x, y, z, this); return true; } } @Override public void onBlockPlacedBy(World world, int x, int y, int z, EntityLivingBase placer, ItemStack is) { if(!(placer instanceof EntityPlayer)) { return; } EntityPlayer player = (EntityPlayer) placer; if(!(player.inventory.addItemStackToInventory(new ItemStack(RHPMBlocks.wirelessButton.setSource(x, y, z))))) { world.spawnEntityInWorld(new EntityItem(world, (double) x, (double) y, (double) z, new ItemStack(RHPMBlocks.wirelessButton))); } } public int isProvidingWeakPower(IBlockAccess iba, int x, int y, int z, int meta) { return activated ? 15 : 0; } public int isProvidingStrongPower(IBlockAccess iba, int x, int y, int z, int meta) { return activated ? 15 : 0; } public boolean canProvidePower() { return true; } }[/embed] WirelessButton.class [embed=425,349]public class WirelessButton extends BlockButton { private int x, y, z; public WirelessButton() { super(true); setStepSound(soundTypeAnvil); setBlockName("wirelessButton"); } @SideOnly(Side.CLIENT) public IIcon getIcon(int face, int meta) { return Blocks.redstone_block.getBlockTextureFromSide(face); } public boolean onBlockActivated(World world, int x, int y, int z, EntityPlayer player, int face, float xf, float yf, float zf) { if(world.getBlock(x, y, z) != RHPMBlocks.wirelessRedstoneSource) { return false; } world.markBlockRangeForRenderUpdate(x, y, z, x, y, z); world.playSoundEffect((double)x + 0.5D, (double)y + 0.5D, (double)z + 0.5D, "random.click", 0.3F, 0.6F); world.scheduleBlockUpdate(x, y, z, this, this.tickRate(world)); WirelessRedstoneSource wrs = (WirelessRedstoneSource) world.getBlock(this.x, this.y, this.z); wrs.activate(); return true; } public WirelessButton setSource(int x, int y, int z) { this.x = x; this.y = y; this.z = z; return this; } }[/embed]
November 25, 20159 yr Blocks are singletons. Any variable in them will be shared with all blocks, just like a static variable. So you can not save activated state in the Block directly. However, you can use a TileEntity to save the state, or better, block metadata. 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/
November 25, 20159 yr And ItemStack nbt Apparently I'm a complete and utter jerk and come to this forum just like to make fun of people, be confrontational, and make your personal life miserable. If you think this is the case, JUST REPORT ME. Otherwise you're just going to get reported when you reply to my posts and point it out, because odds are, I was trying to be nice. Exception: If you do not understand Java, I WILL NOT HELP YOU and your thread will get locked. DO NOT PM ME WITH PROBLEMS. No help will be given.
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.