Posted January 9, 20187 yr Hello, I have made a block that, when powered, will replace itself w/ another block that you can then walk through. The only issue is that if i un-power the block, it doesn't revert back to the normal one. Here is both of the blocks code and the ModItems class: BlockSoulGlass: package com.pugz.minerealms.blocks; import com.pugz.minerealms.Main; import com.pugz.minerealms.init.ModBlocks; import net.minecraft.block.Block; import net.minecraft.block.SoundType; import net.minecraft.block.material.Material; import net.minecraft.block.state.IBlockState; import net.minecraft.creativetab.CreativeTabs; import net.minecraft.entity.Entity; import net.minecraft.init.Blocks; import net.minecraft.item.Item; import net.minecraft.item.ItemBlock; import net.minecraft.item.ItemStack; import net.minecraft.util.BlockRenderLayer; import net.minecraft.util.math.AxisAlignedBB; import net.minecraft.util.math.BlockPos; import net.minecraft.world.IBlockAccess; import net.minecraft.world.World; import net.minecraftforge.fml.relauncher.Side; import net.minecraftforge.fml.relauncher.SideOnly; import javax.annotation.Nullable; import java.util.Random; public class BlockSoulGlass extends Block { protected String name; private final boolean isOn; public BlockSoulGlass(boolean isOn, Material material, String name, SoundType soundtype) { super(material); this.name = name; this.isOn = isOn; setUnlocalizedName(name); setRegistryName(name); setSoundType(soundtype); setHardness(0.3F); setLightOpacity(3); setCreativeTab(CreativeTabs.DECORATIONS); } public void registerItemModel(ItemBlock itemBlock) { Main.proxy.registerItemRenderer(itemBlock, 0, name); } public Item createItemBlock() { return new ItemBlock(this).setRegistryName(getRegistryName()); } @Override public BlockSoulGlass setCreativeTab(CreativeTabs tab) { super.setCreativeTab(tab); return this; } @SideOnly(Side.CLIENT) public BlockRenderLayer getBlockLayer() { return BlockRenderLayer.TRANSLUCENT; } public void onEntityCollidedWithBlock(World worldIn, BlockPos pos, IBlockState state, Entity entityIn) { entityIn.motionX *= 0.4D; entityIn.motionZ *= 0.4D; } public void onBlockAdded(World worldIn, BlockPos pos, IBlockState state) { if (!worldIn.isRemote) { if (this.isOn && !worldIn.isBlockPowered(pos)) { worldIn.setBlockState(pos, ModBlocks.soulGlassOn.getDefaultState(), 2); } else if (!this.isOn && worldIn.isBlockPowered(pos)) { worldIn.setBlockState(pos, ModBlocks.soulGlassOn.getDefaultState(), 2); } } } public void neighborChanged(IBlockState state, World worldIn, BlockPos pos, Block blockIn, BlockPos fromPos) { if (!worldIn.isRemote) { if (this.isOn && !worldIn.isBlockPowered(pos)) { worldIn.scheduleUpdate(pos, ModBlocks.soulGlass, 4); } else if (!this.isOn && worldIn.isBlockPowered(pos)) { worldIn.setBlockState(pos, ModBlocks.soulGlassOn.getDefaultState(), 2); } } } public void updateTick(World worldIn, BlockPos pos, IBlockState state, Random rand) { if (!worldIn.isRemote) { if (this.isOn && !worldIn.isBlockPowered(pos)) { worldIn.setBlockState(pos, ModBlocks.soulGlass.getDefaultState(), 2); } } } protected ItemStack getSilkTouchDrop(IBlockState state) { return new ItemStack(ModBlocks.soulGlass); } } ModBlocks: package com.pugz.minerealms.init; import com.pugz.minerealms.blocks.BlockSoulGlass; import com.pugz.minerealms.blocks.BlockSoulGlassOn; import net.minecraft.block.Block; import net.minecraft.block.SoundType; import net.minecraft.block.material.Material; import net.minecraft.creativetab.CreativeTabs; import net.minecraft.item.Item; import net.minecraftforge.registries.IForgeRegistry; public class ModBlocks { public static BlockSoulGlass soulGlass = new BlockSoulGlass(false, Material.GLASS,"soul_glass", SoundType.GLASS).setCreativeTab(CreativeTabs.DECORATIONS); public static BlockSoulGlassOn soulGlassOn = new BlockSoulGlassOn(Material.GLASS,"soul_glass_on", SoundType.GLASS); public static void register(IForgeRegistry<Block> registry) { registry.registerAll( soulGlass, soulGlassOn ); } public static void registerItemBlocks(IForgeRegistry<Item> registry) { registry.registerAll( soulGlass.createItemBlock(), soulGlassOn.createItemBlock() ); } public static void registerModels() { } } BlockSoulGlassOn (Powered): package com.pugz.minerealms.blocks; import com.pugz.minerealms.Main; import com.pugz.minerealms.init.ModBlocks; import net.minecraft.block.Block; import net.minecraft.block.SoundType; import net.minecraft.block.material.Material; import net.minecraft.block.state.IBlockState; import net.minecraft.creativetab.CreativeTabs; import net.minecraft.entity.Entity; import net.minecraft.init.Blocks; import net.minecraft.item.Item; import net.minecraft.item.ItemBlock; import net.minecraft.item.ItemStack; import net.minecraft.util.BlockRenderLayer; import net.minecraft.util.math.AxisAlignedBB; import net.minecraft.util.math.BlockPos; import net.minecraft.world.IBlockAccess; import net.minecraft.world.World; import net.minecraftforge.fml.relauncher.Side; import net.minecraftforge.fml.relauncher.SideOnly; import javax.annotation.Nullable; import java.util.Random; public class BlockSoulGlassOn extends Block { protected String name; public BlockSoulGlassOn(Material material, String name, SoundType soundtype) { super(material); this.name = name; setUnlocalizedName(name); setRegistryName(name); setSoundType(soundtype); setHardness(0.3F); setLightOpacity(3); } public void registerItemModel(ItemBlock itemBlock) { Main.proxy.registerItemRenderer(itemBlock, 0, name); } public Item createItemBlock() { return new ItemBlock(this).setRegistryName(getRegistryName()); } @Override public BlockSoulGlassOn setCreativeTab(CreativeTabs tab) { super.setCreativeTab(tab); return this; } @SideOnly(Side.CLIENT) public BlockRenderLayer getBlockLayer() { return BlockRenderLayer.TRANSLUCENT; } @Nullable public AxisAlignedBB getCollisionBoundingBox(IBlockState blockState, IBlockAccess worldIn, BlockPos pos) { return NULL_AABB; } public void onEntityCollidedWithBlock(World worldIn, BlockPos pos, IBlockState state, Entity entityIn) { entityIn.motionX *= 0.4D; entityIn.motionY *= 0.2D; entityIn.motionZ *= 0.4D; } protected ItemStack getSilkTouchDrop(IBlockState state) { return new ItemStack(ModBlocks.soulGlass); } } Thanks!
January 9, 20187 yr Your SoulGlassOn class has precisely ZERO code related to changing states or determining if it has power. 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.
January 9, 20187 yr Author Yeah I know that but I don't know how I would detect the redstone power turning off.
January 9, 20187 yr The real question is, why you have this second class at all. Your first class (BlockSoulGlass) already does everything you need. The only problem is that it replaces itself with an entirely different class that doesn't know how to transform itself back. 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.
January 9, 20187 yr Author I need that second class because the block it changes into has different properties. (you can walk through it)
January 9, 20187 yr @Nullable public AxisAlignedBB getCollisionBoundingBox(IBlockState blockState, IBlockAccess worldIn, BlockPos pos) { return this.isOn ? NULL_AABB : FULL_AABB; } Seriously. You have an "is on" variable, which is completely and utterly unused (it's always false). When I did this, I did it with one freaking class and one freaking instance. I didn't need two blocks, I used the fact that it was being powered AS the conditional. http://www.minecraftforum.net/forums/mapping-and-modding-java-edition/minecraft-mods/1288280-1-4-7-1-6-x-1-7-10-phase-stone-updated-to-v4-1 The redstone phase stone acted like redstone, and could only be powered out to a certain distance (because that redstone information was what triggered the difference). 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.
January 9, 20187 yr A block object gets created once for every block, while starting up Minecraft. That means, you have exactly one isOn variable for all the blocks that might be in your world. In Minecraft, a block is represented with a Blockstate at a location in the world, meaning that you need the variable isOn(if you really want to use it) available in your blockstate.
January 9, 20187 yr 28 minutes ago, ArmamentHaki said: A block object gets created once for every block, while starting up Minecraft. That means, you have exactly one isOn variable for all the blocks that might be in your world. In Minecraft, a block is represented with a Blockstate at a location in the world, meaning that you need the variable isOn(if you really want to use it) available in your blockstate. Not actually relevant here: You can create two singleton instances, one with isOn set to true and one set to isOn set to false and switch between these blocks and be Just Fine. Some vanilla blocks do things this way (furnace, redstone ore...) The problem is that we don't have an instance with isOn set to true. 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.