public IProperty<BlockFlower.EnumFlowerType> getTypeProperty() { if (this.type == null) { this.type = PropertyEnum.<BlockFlower.EnumFlowerType>create("type", BlockFlower.EnumFlowerType.class, new Predicate<BlockFlower.EnumFlowerType>() { public boolean apply(BlockFlower.EnumFlowerType p_apply_1_) { return p_apply_1_.getBlockType() == BlockFlower.this.getBlockType(); } }); } return this.type; }
/** * Gets the property for the given subtypes. Returns the same instance of a property for the same array of subtypes. * Order of the subtypes does not matter. */ public static PropertyEnum<EnumSubtype> getSubtypeProperty(int[] subtypes) { int[] sortedSubtypes = Arrays.stream(subtypes) .distinct() .sorted() .toArray(); return subtypeProperties.computeIfAbsent(new IntArray(sortedSubtypes), BlockHelper::createSubtypeProperty); }
@Test public void test_getSubtypeProperty() { PropertyEnum<EnumSubtype> property = BlockHelper.getSubtypeProperty(new int[] {0, 5}); Collection<EnumSubtype> allowedValues = property.getAllowedValues(); assertEquals(2, allowedValues.size()); assertTrue(allowedValues.contains(EnumSubtype.SUBTYPE0)); assertTrue(allowedValues.contains(EnumSubtype.SUBTYPE5)); }
@Test public void test_getSubtypeProperty_ignoresDuplicates() { PropertyEnum<EnumSubtype> property = BlockHelper.getSubtypeProperty(new int[] {0, 0, 5, 5}); Collection<EnumSubtype> allowedValues = property.getAllowedValues(); assertEquals(2, allowedValues.size()); assertTrue(allowedValues.contains(EnumSubtype.SUBTYPE0)); assertTrue(allowedValues.contains(EnumSubtype.SUBTYPE5)); }
@Test public void test_getSubtypeProperty_ignoresDuplicates2() { PropertyEnum<EnumSubtype> property1 = BlockHelper.getSubtypeProperty(new int[] {0, 0, 5, 5}); PropertyEnum<EnumSubtype> property2 = BlockHelper.getSubtypeProperty(new int[] {0, 5}); assertSame(property1, property2); }
@Test public void test_getSubtypeProperty_multipleCallsReturnsSameProperty() { PropertyEnum<EnumSubtype> property1 = BlockHelper.getSubtypeProperty(new int[] {0, 5}); PropertyEnum<EnumSubtype> property2 = BlockHelper.getSubtypeProperty(new int[] {0, 5}); assertSame(property1, property2); }
@Test public void test_getSubtypeProperty_subtypeOrderDoesNotMatter() { PropertyEnum<EnumSubtype> property1 = BlockHelper.getSubtypeProperty(new int[] {0, 5}); PropertyEnum<EnumSubtype> property2 = BlockHelper.getSubtypeProperty(new int[] {5, 0}); assertSame(property1, property2); }
public IProperty<BlockFlower.EnumFlowerType> getTypeProperty() { if (this.type == null) { this.type = PropertyEnum.<BlockFlower.EnumFlowerType>create("type", BlockFlower.EnumFlowerType.class, new Predicate<BlockFlower.EnumFlowerType>() { public boolean apply(@Nullable BlockFlower.EnumFlowerType p_apply_1_) { return p_apply_1_.getBlockType() == BlockFlower.this.getBlockType(); } }); } return this.type; }
private void setRover(World world, int x, int y, int z){ world.setBlockState(new BlockPos(x, y, z), Blocks.coal_block.getDefaultState()); world.setBlockState(new BlockPos(x + 4, y, z), Blocks.coal_block.getDefaultState()); world.setBlockState(new BlockPos(x + 4, y, z + 3), Blocks.coal_block.getDefaultState()); world.setBlockState(new BlockPos(x, y, z + 3), Blocks.coal_block.getDefaultState()); world.setBlockState(new BlockPos(x, y + 1, z + 1), Blocks.iron_block.getDefaultState()); world.setBlockState(new BlockPos(x + 1, y + 1, z + 1), Blocks.iron_block.getDefaultState()); world.setBlockState(new BlockPos(x + 2, y + 1, z + 1), Blocks.iron_block.getDefaultState()); world.setBlockState(new BlockPos(x + 3, y + 1, z + 1), Blocks.iron_block.getDefaultState()); world.setBlockState(new BlockPos(x, y + 1, z + 2), Blocks.iron_block.getDefaultState()); world.setBlockState(new BlockPos(x + 1, y + 1, z + 2), Blocks.iron_block.getDefaultState()); world.setBlockState(new BlockPos(x + 2, y + 1, z + 2), Blocks.iron_block.getDefaultState()); world.setBlockState(new BlockPos(x + 3, y + 1, z + 2), Blocks.iron_block.getDefaultState()); world.setBlockState(new BlockPos(x + 4, y + 1, z + 1), Blocks.stone.getDefaultState()); world.setBlockState(new BlockPos(x + 4, y + 1, z + 2), Blocks.stone.getDefaultState()); world.setBlockState(new BlockPos(x, y + 2, z + 1), Blocks.stained_glass.getDefaultState().withProperty(PropertyEnum.<EnumDyeColor>create("color", EnumDyeColor.class), EnumDyeColor.YELLOW)); world.setBlockState(new BlockPos(x, y + 2, z + 2), Blocks.stained_glass.getDefaultState().withProperty(PropertyEnum.<EnumDyeColor>create("color", EnumDyeColor.class), EnumDyeColor.YELLOW)); world.setBlockState(new BlockPos(x + 4, y + 2, z + 1), Blocks.stained_glass.getDefaultState().withProperty(PropertyEnum.<EnumDyeColor>create("color", EnumDyeColor.class), EnumDyeColor.RED)); world.setBlockState(new BlockPos(x + 4, y + 2, z + 2), Blocks.stained_glass.getDefaultState().withProperty(PropertyEnum.<EnumDyeColor>create("color", EnumDyeColor.class), EnumDyeColor.RED)); world.setBlockState(new BlockPos(x + 1, y + 2, z + 1), Blocks.iron_block.getDefaultState()); world.setBlockState(new BlockPos(x + 2, y + 2, z + 1), Blocks.iron_block.getDefaultState()); world.setBlockState(new BlockPos(x + 3, y + 2, z + 1), Blocks.iron_block.getDefaultState()); world.setBlockState(new BlockPos(x + 1, y + 2, z + 2), Blocks.iron_block.getDefaultState()); world.setBlockState(new BlockPos(x + 2, y + 2, z + 2), Blocks.iron_block.getDefaultState()); world.setBlockState(new BlockPos(x + 3, y + 2, z + 2), Blocks.iron_block.getDefaultState()); world.setBlockState(new BlockPos(x + 2, y + 3, z + 1), Blocks.iron_block.getDefaultState()); world.setBlockState(new BlockPos(x + 2, y + 3, z + 2), Blocks.iron_block.getDefaultState()); }
/** Apply state information for this block. * @return The IBlockState with tile entity information added. */ public IBlockState applyActualState(IBlockState state, PropertyEnum<E> partProperty) { state = this.part == null ? state : state.withProperty(partProperty, this.part); state = this.facing == null ? state : state.withProperty(BlockContainerMulti.FACING, this.facing); return state; }
private static boolean rotateBlockToward(World worldIn, BlockPos pos, EnumFacing preferred, PropertyEnum prop) { IBlockState stored = worldIn.getBlockState(pos); Block block = stored.getBlock(); IBlockState actual = stored.getActualState(worldIn, pos); if (actual.getValue(prop) == preferred) { return true; } for (Object ignored : prop.getAllowedValues()) { if (preferred.getAxis() == EnumFacing.Axis.Y) block.rotateBlock(worldIn, pos, EnumFacing.WEST); else block.rotateBlock(worldIn, pos, EnumFacing.UP); stored = worldIn.getBlockState(pos); block = stored.getBlock(); actual = stored.getActualState(worldIn, pos); if (actual.getValue(prop) == preferred) { return true; } } return false; }
public static BlockProperty of(IProperty property) { if (property instanceof PropertyBool) { return new NeptuneBlockBooleanProperty((PropertyBool) property); } else if (property instanceof PropertyDirection) { return new NeptuneBlockDirectionProperty((PropertyDirection) property); } else if (property instanceof PropertyEnum) { return new NeptuneBlockEnumProperty((PropertyEnum) property); } else if (property instanceof PropertyInteger) { return new NeptuneBlockIntegerProperty((PropertyInteger) property); } return new NeptuneBlockProperty(property); }
private static PropertyEnum<EnumSubtype> createSubtypeProperty(IntArray subtypes) { return PropertyEnum.create("subtype", EnumSubtype.class, EnumSubtype.getValues(subtypes.array)); }
public EnumBlockStateMapper(PropertyEnum<T> prop){ this.prop = prop; }
public EnumBlock(Material material, PropertyEnum<E> prop, Class<E> clazz) { super(preInit(material, prop)); this.prop = prop; values = clazz.getEnumConstants(); }
private static Material preInit(Material material, PropertyEnum<?> property) { tmp = property; return material; }
public BlockStateMachine(BlockMachine block, PropertyEnum<?> prop) { super(block, prop, facingProperty, activeProperty); }
public BlockStateFacing(Block block, PropertyEnum<?> typeProperty) { super(block, facingProperty, typeProperty); }
@Override public PropertyEnum<EPartSawpit> getPartProperty() { return PART; }
/** @return The PropertyEnum for this multiblock's parts. */ public abstract PropertyEnum<E> getPartProperty();
@Override public PropertyEnum<EPartStone> getPartProperty() { return PART; }
@Override public PropertyEnum<EPartClay> getPartProperty() { return PART; }
@Override public PropertyEnum<EPartWoodworking> getPartProperty() { return PART; }
@Override public PropertyEnum<EPartTextiles> getPartProperty() { return PART; }
@Override public PropertyEnum<EPartMason> getPartProperty() { return PART; }
@Override public PropertyEnum<EPartForge> getPartProperty() { return PART; }
@Override public PropertyEnum<EPartCandlemaker> getPartProperty() { return PART; }
@Override public PropertyEnum<EPartArmourer> getPartProperty() { return PART; }
@Override public boolean buildStructure(World world, BlockPos pos, EnumFacing facing, ItemStack stack, EntityPlayer player) { if (this != M) { return false; } BlockContainerMulti<EPartArmourer> block = GeoBlocks.CRAFTING_ARMOURER; IBlockState state = block.getDefaultState(); PropertyEnum<EPartArmourer> prop = block.getPartProperty(); // Prepare map of properties Map<BlockPos, EPartArmourer> map = Maps.newHashMap(); map.put(pos, M); map.put(pos.offset(facing.rotateYCCW()), L); map.put(pos.offset(facing.rotateYCCW()).up(), T); map.put(pos.offset(facing.rotateY()), R); // Check validity for (Entry<BlockPos, EPartArmourer> entry : map.entrySet()) { IBlockState placeState = state .withProperty(prop, entry.getValue()); if (!block.isValid(world, entry.getKey(), null, false, placeState, player)) { return false; } } // Place all map.keySet().forEach((p) -> world.setBlockState(p, state)); // Set up tileentities map.entrySet().forEach((e) -> { TECraftingArmourer te = (TECraftingArmourer) world .getTileEntity(e.getKey()); te.setWeathering(stack.getMaxDamage() - stack.getItemDamage()); te.setState(facing, e.getValue()); }); return true; }
@Override public boolean buildStructure(World world, BlockPos pos, EnumFacing facing, ItemStack stack, EntityPlayer player) { if (this != BM) { return false; } BlockContainerMulti<EPartStone> block = GeoBlocks.FURNACE_STONE; IBlockState state = block.getDefaultState(); PropertyEnum<EPartStone> prop = block.getPartProperty(); // Prepare map of properties Map<BlockPos, EPartStone> map = Maps.newHashMap(); map.put(pos, BM); map.put(pos.offset(facing.rotateY().getOpposite()), BL); map.put(pos.offset(facing.rotateY()), BR); map.put(pos.offset(facing.rotateY().getOpposite()).up(), TL); map.put(pos.up(), TM); map.put(pos.offset(facing.rotateY()).up(), TR); // Check validity for (Entry<BlockPos, EPartStone> entry : map.entrySet()) { IBlockState placeState = state .withProperty(prop, entry.getValue()); if (!block.isValid(world, entry.getKey(), null, false, placeState, player)) { return false; } } // Place all map.keySet().forEach((p) -> world.setBlockState(p, state)); // Set up tileentities map.entrySet().forEach((e) -> ((TEFurnaceStone) world .getTileEntity(e.getKey())).setState(facing, e.getValue())); return true; }
@Override public boolean buildStructure(World world, BlockPos pos, EnumFacing facing, ItemStack stack, EntityPlayer player) { if (this != FRONT) { return false; } BlockContainerMulti<EPartCandlemaker> block = GeoBlocks.CRAFTING_CANDLEMAKER; IBlockState state = block.getDefaultState(); PropertyEnum<EPartCandlemaker> prop = block.getPartProperty(); // Prepare map of properties Map<BlockPos, EPartCandlemaker> map = Maps.newHashMap(); map.put(pos, FRONT); map.put(pos.offset(facing), BACK); // Check validity for (Entry<BlockPos, EPartCandlemaker> entry : map.entrySet()) { IBlockState placeState = state .withProperty(prop, entry.getValue()); if (!block.isValid(world, entry.getKey(), null, false, placeState, player)) { return false; } } // Place all map.keySet().forEach((p) -> world.setBlockState(p, state)); // Set up tileentities map.entrySet().forEach((e) -> { TECraftingCandlemaker te = (TECraftingCandlemaker) world .getTileEntity(e.getKey()); te.setWeathering(stack.getMaxDamage() - stack.getItemDamage()); te.setState(facing, e.getValue()); }); return true; }
@Override public boolean buildStructure(World world, BlockPos pos, EnumFacing facing, ItemStack stack, EntityPlayer player) { if (this != FM) { return false; } BlockContainerMulti<EPartMason> block = GeoBlocks.CRAFTING_MASON; IBlockState state = block.getDefaultState(); PropertyEnum<EPartMason> prop = block.getPartProperty(); // Prepare map of properties Map<BlockPos, EPartMason> map = Maps.newHashMap(); map.put(pos, FM); map.put(pos.offset(facing.rotateY().getOpposite()), FL); map.put(pos.offset(facing), BM); map.put(pos.offset(facing.rotateY()), FR); map.put(pos.offset(facing.rotateY()).offset(facing), BR); // Check validity for (Entry<BlockPos, EPartMason> entry : map.entrySet()) { IBlockState placeState = state .withProperty(prop, entry.getValue()); if (!block.isValid(world, entry.getKey(), null, false, placeState, player)) { return false; } } // Place all map.keySet().forEach((p) -> world.setBlockState(p, state)); // Set up tileentities map.entrySet().forEach((e) -> { TECraftingMason te = (TECraftingMason) world .getTileEntity(e.getKey()); te.setWeathering(stack.getMaxDamage() - stack.getItemDamage()); te.setState(facing, e.getValue()); }); return true; }
@Override public boolean buildStructure(World world, BlockPos pos, EnumFacing facing, ItemStack stack, EntityPlayer player) { if (this != FM) { return false; } BlockContainerMulti<EPartWoodworking> block = GeoBlocks.CRAFTING_WOODWORKING; IBlockState state = block.getDefaultState(); PropertyEnum<EPartWoodworking> prop = block.getPartProperty(); // Prepare map of properties Map<BlockPos, EPartWoodworking> map = Maps.newHashMap(); map.put(pos, FM); map.put(pos.offset(facing.rotateY().getOpposite()), FL); map.put(pos.offset(facing.rotateY().getOpposite()) .offset(facing), BL); map.put(pos.offset(facing), BM); map.put(pos.offset(facing).offset(facing.rotateY()), BR); map.put(pos.offset(facing.rotateY()), FR); // Check validity for (Entry<BlockPos, EPartWoodworking> entry : map.entrySet()) { IBlockState placeState = state .withProperty(prop, entry.getValue()); if (!block.isValid(world, entry.getKey(), null, false, placeState, player)) { return false; } } // Place all map.keySet().forEach((p) -> world.setBlockState(p, state)); // Set up tileentities map.entrySet().forEach((e) -> { TECraftingWoodworking te = (TECraftingWoodworking) world .getTileEntity(e.getKey()); te.setWeathering(stack.getMaxDamage() - stack.getItemDamage()); te.setState(facing, e.getValue()); }); return true; }
@Override public boolean buildStructure(World world, BlockPos pos, EnumFacing facing, ItemStack stack, EntityPlayer player) { if (this != FRONT) { return false; } BlockContainerMulti<EPartTextiles> block = GeoBlocks.CRAFTING_TEXTILES; IBlockState state = block.getDefaultState(); PropertyEnum<EPartTextiles> prop = block.getPartProperty(); // Prepare map of properties Map<BlockPos, EPartTextiles> map = Maps.newHashMap(); map.put(pos, FRONT); map.put(pos.offset(facing), BACK); // Check validity for (Entry<BlockPos, EPartTextiles> entry : map.entrySet()) { IBlockState placeState = state .withProperty(prop, entry.getValue()); if (!block.isValid(world, entry.getKey(), null, false, placeState, player)) { return false; } } // Place all map.keySet().forEach((p) -> world.setBlockState(p, state)); // Set up tileentities map.entrySet().forEach((e) -> { TECraftingTextiles te = (TECraftingTextiles) world .getTileEntity(e.getKey()); te.setWeathering(stack.getMaxDamage() - stack.getItemDamage()); te.setState(facing, e.getValue()); }); return true; }