TyrellPlayz Posted November 26, 2017 Posted November 26, 2017 I want to create a custom block state that will rotate the texture like EnumFacing but needs to also change it's texture. Here's what i have done so far (not 100% done) package com.tyrellplayz.tcm.blocks; import java.util.Locale; import com.tyrellplayz.tcm.EnumModBlocks; import net.minecraft.block.BlockHorizontal; import net.minecraft.block.BlockLog; import net.minecraft.block.BlockRailBase; import net.minecraft.block.material.MapColor; import net.minecraft.block.material.Material; import net.minecraft.block.properties.IProperty; import net.minecraft.block.properties.PropertyDirection; import net.minecraft.block.properties.PropertyEnum; import net.minecraft.block.state.BlockStateContainer; import net.minecraft.block.state.IBlockState; import net.minecraft.entity.EntityLivingBase; import net.minecraft.util.EnumFacing; import net.minecraft.util.EnumHand; import net.minecraft.util.IStringSerializable; import net.minecraft.util.Rotation; import net.minecraft.util.math.BlockPos; import net.minecraft.util.math.MathHelper; import net.minecraft.util.math.Vec3i; import net.minecraft.world.World; public class BlockTrafficLight extends ModBlock{ public static final PropertyEnum<BlockTrafficLight.EnumTrafficLightType> LIGHTTYPE = PropertyEnum.<BlockTrafficLight.EnumTrafficLightType>create("lighttype", BlockTrafficLight.EnumTrafficLightType.class); public BlockTrafficLight() { super(Material.IRON, EnumModBlocks.TRAFFICLIGHT); this.setLightLevel(1.0F); this.setDefaultState(this.blockState.getBaseState().withProperty(LIGHTTYPE, BlockTrafficLight.EnumTrafficLightType.RED_ON_N)); } @Override public boolean isFullBlock(IBlockState state) {return false;} @Override public boolean isFullCube(IBlockState state) {return false;} @Override public boolean isOpaqueCube(IBlockState state) {return false;} public IProperty<BlockTrafficLight.EnumTrafficLightType> getLightProperty(){ return LIGHTTYPE; } /** * Convert the given metadata into a BlockState for this Block */ public IBlockState getStateFromMeta(int meta){ return this.getDefaultState().withProperty(LIGHTTYPE, BlockTrafficLight.EnumTrafficLightType.byMetadata(meta)); } /** * Convert the BlockState into the correct metadata value */ public int getMetaFromState(IBlockState state){ return ((BlockTrafficLight.EnumTrafficLightType)state.getValue(LIGHTTYPE)).getMetadata(); } @Override protected BlockStateContainer createBlockState() {return new BlockStateContainer(this, LIGHTTYPE);} /* @Override public IBlockState getStateForPlacement(World world, BlockPos pos, EnumFacing facing, float hitX, float hitY, float hitZ, int meta, EntityLivingBase placer, EnumHand hand) { IBlockState state = super.getStateForPlacement(world, pos, facing, hitX, hitY, hitZ, meta, placer, hand); return state.withProperty(LIGHTTYPE, placer.getHorizontalFacing()); }*/ public static enum EnumTrafficLightType implements IStringSerializable{ RED_ON_N(0, "red_on_n", EnumFacing.NORTH), RED_ON_E(1, "red_on_e", EnumFacing.EAST), RED_ON_S(2, "red_on_s", EnumFacing.SOUTH), RED_ON_W(3, "red_on_w", EnumFacing.WEST), YELLOW_ON_N(4, "yellow_on_n", EnumFacing.NORTH), YELLOW_ON_E(5, "yellow_on_e", EnumFacing.EAST), YELLOW_ON_S(6, "yellow_on_s", EnumFacing.SOUTH), YELLOW_ON_W(7, "yellow_on_w", EnumFacing.WEST), GREEN_ON_N(8, "green_on_n", EnumFacing.NORTH), GREEN_ON_E(9, "green_on_e", EnumFacing.EAST), GREEN_ON_S(10, "green_on_s", EnumFacing.SOUTH), GREEN_ON_W(11, "green_on_w", EnumFacing.WEST), OFF_N(12, "off_n", EnumFacing.NORTH), OFF_E(13, "off_e", EnumFacing.EAST), OFF_S(14, "off_s", EnumFacing.SOUTH), OFF_W(15, "off_w", EnumFacing.WEST); private static final BlockTrafficLight.EnumTrafficLightType[] META_LOOKUP = new BlockTrafficLight.EnumTrafficLightType[values().length]; private final int meta; private final String name; private final EnumFacing facing; private EnumTrafficLightType(int meta, String name, EnumFacing facing){ this.meta = meta; this.name = name; this.facing = facing; } public int getMetadata(){return this.meta;} public EnumFacing getFacing(){return this.facing;} public String toString(){return this.name;} public static BlockTrafficLight.EnumTrafficLightType byMetadata(int meta){ if (meta < 0 || meta >= META_LOOKUP.length){ meta = 0; } return META_LOOKUP[meta]; } public String getName(){return this.name;} } } Quote
Choonster Posted November 26, 2017 Posted November 26, 2017 You've told us what you're trying to do, but you haven't told us what's not working or what you need help with. I'd recommend splitting the active light and facing into two separate properties, which will allow you to use Forge's blockstates format to specify the model once, the texture for each active light and the rotation for each facing rather than having to make a model for each combination of active light and facing. 1 Quote 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.
Recommended Posts
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.