Posted June 5, 20214 yr I want to make a block, that works similar to an end portal frame block in minecraft. The player should be able to rightclick on it, and the block should change to an active state. From all I know minecraft uses Blockstateproberties for that, but up now I didn't had to make my own property, I only used the standart ones (like FACING for example). I have no idea how to register a new Property. For testing purposes I tried to give my block the property "EYE", the one that is used for end portal frames, but it didn't seem to work. My code: package eleocraft.ancientguardian.objects.blocks; import net.minecraft.block.Block; import net.minecraft.block.BlockState; import net.minecraft.entity.player.PlayerEntity; import net.minecraft.state.BooleanProperty; import net.minecraft.state.properties.BlockStateProperties; import net.minecraft.util.ActionResultType; import net.minecraft.util.Hand; import net.minecraft.util.ResourceLocation; import net.minecraft.util.math.BlockPos; import net.minecraft.util.math.BlockRayTraceResult; import net.minecraft.util.math.shapes.ISelectionContext; import net.minecraft.util.math.shapes.VoxelShape; import net.minecraft.util.math.vector.Vector3d; import net.minecraft.world.IBlockReader; import net.minecraft.world.World; import net.minecraftforge.registries.ForgeRegistries; public class BaseBlock extends Block { private static final Vector3d BASE_MIN_CORNER = new Vector3d(0.0, 0.0, 0.0); private static final Vector3d BASE_MAX_CORNER = new Vector3d(16.0, 8.0, 16.0); private static final VoxelShape BASE = Block.makeCuboidShape(BASE_MIN_CORNER.getX(), BASE_MIN_CORNER.getY(), BASE_MIN_CORNER.getZ(), BASE_MAX_CORNER.getX(), BASE_MAX_CORNER.getY(), BASE_MAX_CORNER.getZ()); public static BooleanProperty ACTIVE = BlockStateProperties.EYE; public BaseBlock(Properties properties) { super(properties); this.setDefaultState(this.stateContainer.getBaseState().with(ACTIVE, Boolean.valueOf(false))); } @Override public VoxelShape getShape(BlockState state, IBlockReader worldIn, BlockPos pos, ISelectionContext context) { return BASE; } @Override public ActionResultType onBlockActivated(BlockState state, World worldIn, BlockPos pos, PlayerEntity player, Hand handIn, BlockRayTraceResult hit) { if (player.inventory.getCurrentItem().getItem() == ForgeRegistries.ITEMS.getValue(new ResourceLocation("ancientguardian:ancient_crystal")) && state.get(ACTIVE).equals(Boolean.valueOf(false))) { System.out.println("It worked"); worldIn.setBlockState(pos, this.stateContainer.getBaseState().with(ACTIVE, Boolean.valueOf(true))); player.inventory.getCurrentItem().setCount(player.inventory.getCurrentItem().getCount() - 1); return ActionResultType.SUCCESS; } return ActionResultType.FAIL; } }
June 5, 20214 yr You need this. Not sure what the Mojang mapped name for the method is. https://github.com/Draco18s/ReasonableRealism/blob/1.14.4/src/main/java/com/draco18s/harderores/block/AxelBlock.java#L61 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.
June 6, 20214 yr Author Thanks for the reply, that was all I was searching for. For anyone who is interested: the interesting file (at least for me) was ReasonableRealism/src/main/java/com/draco18s/hardlib/api/block/state/BlockProperties.java
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.