@SuppressWarnings({ "rawtypes", "unchecked" }) private IBlockState applyProperties(BlockStateContainer stateContainer, IBlockState newState, Map<Property<?>, Object> states) { for (Map.Entry<Property<?>, Object> state : states.entrySet()) { IProperty property = stateContainer.getProperty(state.getKey().getName()); Comparable value = (Comparable) state.getValue(); // we may need to adapt this value, depending on the source prop if (property instanceof PropertyDirection) { Direction dir = (Direction) value; value = ForgeAdapter.adapt(dir); } else if (property instanceof PropertyEnum) { String enumName = (String) value; value = ((PropertyEnum<?>) property).parseValue((String) value).or(() -> { throw new IllegalStateException("Enum property " + property.getName() + " does not contain " + enumName); }); } newState = newState.withProperty(property, value); } return newState; }
@Override public Map<String, ? extends Property<?>> getProperties(BlockType blockType) { Map<String, Property<?>> map = new TreeMap<>(); Collection<IProperty<?>> propertyKeys = Block.getBlockFromName(blockType.getId()) .getDefaultState() .getPropertyKeys(); for (IProperty<?> key : propertyKeys) { map.put(key.getName(), ForgeAdapter.adaptProperty(key)); } return map; }
@Override public BlockMaterial getMaterial(BlockType blockType) { return materialMap.computeIfAbsent(Block.getBlockFromName(blockType.getId()).getDefaultState().getMaterial(), m -> new ForgeBlockMaterial(m, super.getMaterial(blockType))); }
protected IBlockState pickDefaultState() { return blockState.getBaseState() .withProperty(UP, false) .withProperty(NORTH, false) .withProperty(SOUTH, false) .withProperty(WEST, false) .withProperty(EAST, false) .withProperty(VARIANT, EnumType.NORMAL); }
@Override public int getMetaFromState(IBlockState state) { switch (state.getValue(BotaniaStateProps.CARDINALS)) { case NORTH: return 0; case WEST: return 3; case EAST: return 1; case SOUTH: default: return 2; // wai vazkii senpai } }
@Override public BlockState getBlock(BlockVector3 position) { World world = getWorld(); BlockPos pos = new BlockPos(position.getBlockX(), position.getBlockY(), position.getBlockZ()); IBlockState mcState = world.getBlockState(pos); BlockType blockType = BlockType.REGISTRY.get(Block.REGISTRY.getNameForObject(mcState.getBlock()).toString()); return blockType.getState(adaptProperties(blockType, mcState.getProperties())); }
@Override public void simulateBlockMine(BlockVector3 position) { BlockPos pos = ForgeAdapter.toBlockPos(position); IBlockState state = getWorld().getBlockState(pos); state.getBlock().dropBlockAsItem(getWorld(), pos, state, 0); getWorld().setBlockToAir(pos); }
private static boolean hasSimpleModel( IBlockState blockState ) { if( blockState.getRenderType() != EnumBlockRenderType.MODEL || blockState instanceof IExtendedBlockState ) { return false; } return blockState.isFullCube(); }
@Override protected IBlockState pickDefaultState() { return blockState.getBaseState() .withProperty(FACING, EnumFacing.SOUTH) .withProperty(VARIANT, EnumPlantType.SUNFLOWER) .withProperty(HALF, BlockDoublePlant.EnumBlockHalf.LOWER) .withProperty(BotaniaStateProps.DOUBLEFLOWER_VARIANT_1, EnumDyeColor.WHITE); }
@Override protected IBlockState pickDefaultState() { return blockState.getBaseState() .withProperty(FACING, EnumFacing.SOUTH) .withProperty(VARIANT, EnumPlantType.SUNFLOWER) .withProperty(HALF, BlockDoublePlant.EnumBlockHalf.LOWER) .withProperty(BotaniaStateProps.DOUBLEFLOWER_VARIANT_2, EnumDyeColor.SILVER); }
@Override public int getMetaFromState(IBlockState state) { switch (state.getValue(BotaniaStateProps.ENCHANTER_DIRECTION)) { case Z: return 1; case X: default: return 0; } }
public BlockTinyPotato() { super(Material.CLOTH, LibBlockNames.TINY_POTATO); setHardness(0.25F); setDefaultState(blockState.getBaseState() .withProperty(BotaniaStateProps.CARDINALS, EnumFacing.SOUTH)); }
@Override public int getMetaFromState( final IBlockState state ) { return state.getValue( ENERGY_STORAGE ); }
public BlockPump() { super(Material.ROCK, LibBlockNames.PUMP); setHardness(2.0F); setResistance(10.0F); setSoundType(SoundType.STONE); setDefaultState(blockState.getBaseState().withProperty(Properties.StaticProperty, true).withProperty(BotaniaStateProps.CARDINALS, EnumFacing.SOUTH)); }
@Override public int getMetaFromState(IBlockState state) { switch (state.getValue(BotaniaStateProps.PAVEMENT_COLOR)) { case GREEN: return 5; case YELLOW: return 4; case RED: return 3; case BLUE: return 2; case BLACK: return 1; case WHITE: default: return 0; } }
public BlockForestDrum() { super(Material.WOOD, LibBlockNames.FOREST_DRUM); setHardness(2.0F); setSoundType(SoundType.WOOD); setDefaultState(blockState.getBaseState().withProperty(BotaniaStateProps.DRUM_VARIANT, DrumVariant.WILD)); }
@Override public int getMetaFromState(IBlockState state) { if (doubleSlab) { return 0; } else { return state.getValue(HALF) == EnumBlockHalf.TOP ? 8 : 0; } }
public BlockLightLauncher() { super(Material.WOOD, LibBlockNames.LIGHT_LAUNCHER); setHardness(2.0F); setSoundType(SoundType.WOOD); setDefaultState(blockState.getBaseState().withProperty(BotaniaStateProps.POWERED, false)); }
public BlockPlatform() { super(Material.WOOD, LibBlockNames.PLATFORM); setHardness(2.0F); setResistance(5.0F); setSoundType(SoundType.WOOD); setDefaultState(blockState.getBaseState().withProperty(BotaniaStateProps.PLATFORM_VARIANT, PlatformVariant.ABSTRUSE)); }