public boolean matchState(IBlockState p_matchState_1_, Map<IProperty, List<Comparable>> p_matchState_2_) { for (IProperty iproperty : p_matchState_2_.keySet()) { List<Comparable> list = (List)p_matchState_2_.get(iproperty); Comparable comparable = p_matchState_1_.getValue(iproperty); if (comparable == null) { return false; } if (!list.contains(comparable)) { return false; } } return true; }
public boolean canPlaceBlockOnSide(World worldIn, BlockPos pos, EnumFacing side, EntityPlayer player, ItemStack stack) { BlockPos blockpos = pos; IProperty<?> iproperty = this.singleSlab.getVariantProperty(); Comparable<?> comparable = this.singleSlab.getTypeForItem(stack); IBlockState iblockstate = worldIn.getBlockState(pos); if (iblockstate.getBlock() == this.singleSlab) { boolean flag = iblockstate.getValue(BlockSlab.HALF) == BlockSlab.EnumBlockHalf.TOP; if ((side == EnumFacing.UP && !flag || side == EnumFacing.DOWN && flag) && comparable == iblockstate.getValue(iproperty)) { return true; } } pos = pos.offset(side); IBlockState iblockstate1 = worldIn.getBlockState(pos); return iblockstate1.getBlock() == this.singleSlab && comparable == iblockstate1.getValue(iproperty) ? true : super.canPlaceBlockOnSide(worldIn, blockpos, side, player, stack); }
public IProperty<Boolean> getProperty(EnumFacing facing) { switch (facing) { case EAST: return EAST; case WEST: return WEST; case NORTH: return NORTH; case SOUTH: return SOUTH; case UP: return UP; case DOWN: return DOWN; default: return EAST; } }
public String getPropertyString(Map<IProperty, Comparable> p_178131_1_) { StringBuilder stringbuilder = new StringBuilder(); for (Entry<IProperty, Comparable> entry : p_178131_1_.entrySet()) { if (stringbuilder.length() != 0) { stringbuilder.append(","); } IProperty iproperty = (IProperty)entry.getKey(); Comparable comparable = (Comparable)entry.getValue(); stringbuilder.append(iproperty.getName()); stringbuilder.append("="); stringbuilder.append(iproperty.getName(comparable)); } if (stringbuilder.length() == 0) { stringbuilder.append("normal"); } return stringbuilder.toString(); }
/** Attempt to parse string as a Variation, allowing for block properties having different names to the enum values<br> * (eg blue_orchid vs orchidBlue etc.) * @param part the string (potentially in the 'wrong' format, eg 'orchidBlue') * @param is the ItemStack from which this string came (eg from is.getUnlocalisedName) * @return a Variation, if one exists, that matches the part string passed in, or one of the ItemStacks current property values. */ public static Variation attemptToGetAsVariant(String part, ItemStack is) { if (is.getItem() instanceof ItemBlock) { // Unlocalised name doesn't always match the names we use in types.xsd // (which are the names displayed by Minecraft when using the F3 debug etc.) ItemBlock ib = (ItemBlock)(is.getItem()); IBlockState bs = ib.block.getStateFromMeta(is.getMetadata()); for (IProperty prop : (java.util.Set<IProperty>)bs.getProperties().keySet()) { Comparable<?> comp = bs.getValue(prop); Variation var = attemptToGetAsVariant(comp.toString()); if (var != null) return var; } return null; } else return attemptToGetAsVariant(part); }
public static <T extends Comparable<T>> String validateProperty(Block block, IProperty<T> property) { String s = property.getName(); if (!NAME_PATTERN.matcher(s).matches()) { throw new IllegalArgumentException("Block: " + block.getClass() + " has invalidly named property: " + s); } else { for (T t : property.getAllowedValues()) { String s1 = property.getName(t); if (!NAME_PATTERN.matcher(s1).matches()) { throw new IllegalArgumentException("Block: " + block.getClass() + " has property: " + s + " with invalidly named value: " + s1); } } return s; } }
/** Recolour the Minecraft block * @param state The block to be recoloured * @param colour The new colour * @return A new blockstate which is a recoloured version of the original */ static IBlockState applyColour(IBlockState state, Colour colour) { for (IProperty prop : (java.util.Set<IProperty>)state.getProperties().keySet()) { if (prop.getName().equals("color") && prop.getValueClass() == net.minecraft.item.EnumDyeColor.class) { net.minecraft.item.EnumDyeColor current = (net.minecraft.item.EnumDyeColor)state.getValue(prop); if (!current.getName().equalsIgnoreCase(colour.name())) { return state.withProperty(prop, EnumDyeColor.valueOf(colour.name())); } } } return state; }
/** Test whether this block has a colour attribute which matches the list of allowed colours * @param bs blockstate to test * @param allowedColours list of allowed Colour enum values * @return true if the block matches. */ public static boolean blockColourMatches(IBlockState bs, List<Colour> allowedColours) { for (IProperty prop : (java.util.Set<IProperty>) bs.getProperties().keySet()) { if (prop.getName().equals("color") && prop.getValueClass() == net.minecraft.item.EnumDyeColor.class) { // The block in question has a colour, so check it is a specified one: net.minecraft.item.EnumDyeColor current = (net.minecraft.item.EnumDyeColor)bs.getValue(prop); for (Colour col : allowedColours) { if (current.getName().equalsIgnoreCase(col.name())) return true; } } } return false; }
protected ModelResourceLocation getModelResourceLocation(IBlockState state) { Map < IProperty<?>, Comparable<? >> map = Maps. < IProperty<?>, Comparable<? >> newLinkedHashMap(state.getProperties()); String s; if (this.name == null) { s = ((ResourceLocation)Block.REGISTRY.getNameForObject(state.getBlock())).toString(); } else { s = String.format("%s:%s", Block.REGISTRY.getNameForObject(state.getBlock()).getResourceDomain(), this.removeName(this.name, map)); } if (this.suffix != null) { s = s + this.suffix; } for (IProperty<?> iproperty : this.ignored) { map.remove(iproperty); } return new ModelResourceLocation(s, this.getPropertyString(map)); }
/** * Called when a Block is right-clicked with this Item */ public boolean onItemUse(ItemStack stack, EntityPlayer playerIn, World worldIn, BlockPos pos, EnumFacing side, float hitX, float hitY, float hitZ) { if (stack.stackSize == 0) { return false; } else if (!playerIn.canPlayerEdit(pos.offset(side), side, stack)) { return false; } else { Object object = this.singleSlab.getVariant(stack); IBlockState iblockstate = worldIn.getBlockState(pos); if (iblockstate.getBlock() == this.singleSlab) { IProperty iproperty = this.singleSlab.getVariantProperty(); Comparable comparable = iblockstate.getValue(iproperty); BlockSlab.EnumBlockHalf blockslab$enumblockhalf = (BlockSlab.EnumBlockHalf)iblockstate.getValue(BlockSlab.HALF); if ((side == EnumFacing.UP && blockslab$enumblockhalf == BlockSlab.EnumBlockHalf.BOTTOM || side == EnumFacing.DOWN && blockslab$enumblockhalf == BlockSlab.EnumBlockHalf.TOP) && comparable == object) { IBlockState iblockstate1 = this.doubleSlab.getDefaultState().withProperty(iproperty, comparable); if (worldIn.checkNoEntityCollision(this.doubleSlab.getCollisionBoundingBox(worldIn, pos, iblockstate1)) && worldIn.setBlockState(pos, iblockstate1, 3)) { worldIn.playSoundEffect((double)((float)pos.getX() + 0.5F), (double)((float)pos.getY() + 0.5F), (double)((float)pos.getZ() + 0.5F), this.doubleSlab.stepSound.getPlaceSound(), (this.doubleSlab.stepSound.getVolume() + 1.0F) / 2.0F, this.doubleSlab.stepSound.getFrequency() * 0.8F); --stack.stackSize; } return true; } } return this.tryPlace(stack, worldIn, pos.offset(side), object) ? true : super.onItemUse(stack, playerIn, worldIn, pos, side, hitX, hitY, hitZ); } }
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; }
@SuppressWarnings("unchecked") static <T extends Block> StateMetaMapper<T> create(Collection<IProperty<?>> properties) { if (properties.size() == 0) return new EmptyStateMetaMapper<>(); else if (properties.size() == 1) return new SimpleStateMetaMapper(properties.iterator().next()); else return new BitStateMetaMapper<>(properties); }
public void buildPropertyValueTable(Map < Map < IProperty<?>, Comparable<? >> , BlockStateContainer.StateImplementation > map) { if (this.propertyValueTable != null) { throw new IllegalStateException(); } else { Table < IProperty<?>, Comparable<?>, IBlockState > table = HashBasedTable. < IProperty<?>, Comparable<?>, IBlockState > create(); UnmodifiableIterator unmodifiableiterator = this.properties.entrySet().iterator(); while (unmodifiableiterator.hasNext()) { Entry < IProperty<?>, Comparable<? >> entry = (Entry)unmodifiableiterator.next(); IProperty<?> iproperty = (IProperty)entry.getKey(); for (Comparable<?> comparable : iproperty.getAllowedValues()) { if (comparable != entry.getValue()) { table.put(iproperty, comparable, map.get(this.getPropertiesWithValue(iproperty, comparable))); } } } this.propertyValueTable = ImmutableTable. < IProperty<?>, Comparable<?>, IBlockState > copyOf(table); } }
private List < Iterable < Comparable<? >>> getAllowedValues() { List < Iterable < Comparable<? >>> list = Lists. < Iterable < Comparable<? >>> newArrayList(); ImmutableCollection < IProperty<? >> immutablecollection = this.properties.values(); UnmodifiableIterator unmodifiableiterator = immutablecollection.iterator(); while (unmodifiableiterator.hasNext()) { IProperty<?> iproperty = (IProperty)unmodifiableiterator.next(); list.add(((IProperty)iproperty).getAllowedValues()); } return list; }
/** * Rotate the block. For vanilla blocks this rotates around the axis passed in (generally, it should be the "face" that was hit). * Note: for mod blocks, this is up to the block and modder to decide. It is not mandated that it be a rotation around the * face, but could be a rotation to orient *to* that face, or a visiting of possible rotations. * The method should return true if the rotation was successful though. * * @param world The world * @param pos Block position in world * @param axis The axis to rotate around * @return True if the rotation was successful, False if the rotation failed, or is not possible */ public boolean rotateBlock(World world, BlockPos pos, EnumFacing axis) { IBlockState state = world.getBlockState(pos); for (IProperty<?> prop : state.getProperties().keySet()) { if (prop.getName().equals("facing") || prop.getName().equals("rotation")) { world.setBlockState(pos, state.cycleProperty(prop)); return true; } } return false; }
public IProperty<BlockRailBase.EnumRailDirection> getShapeProperty() { return SHAPE; }
protected BlockState createBlockState() { return new BlockState(this, new IProperty[] {POWER}); }
protected BlockState createBlockState() { return new BlockState(this, new IProperty[] {AGE}); }
protected BlockState createBlockState() { return new BlockState(this, new IProperty[] {FACING}); }
/** Extract the type, variation and facing attributes of a blockstate and return them in a new DrawBlock object.<br> * @param state the IBlockState to be examined * @return A DrawBlock object */ public static DrawBlock getDrawBlockFromBlockState(IBlockState state, List<IProperty> extraProperties) { if (state == null) return null; DrawBlock block = new DrawBlock(); Object blockName = Block.blockRegistry.getNameForObject(state.getBlock()); if (blockName instanceof ResourceLocation) { String name = ((ResourceLocation)blockName).getResourcePath(); BlockType type = BlockType.fromValue(name); block.setType(type); } Colour col = null; Variation var = null; Facing face = null; // Add properties: for (IProperty prop : (java.util.Set<IProperty>) state.getProperties().keySet()) { String propVal = state.getValue(prop).toString(); boolean matched = false; // Try colour first: if (col == null) { col = attemptToGetAsColour(propVal); if (col != null) matched = true; } // Then variant: if (!matched && var == null) { var = attemptToGetAsVariant(propVal); if (var != null) matched = true; } // Then facing: if (!matched && face == null) { face = attemptToGetAsFacing(propVal); if (face != null) matched = true; } if (!matched) { if (extraProperties != null) extraProperties.add(prop); } } if (col != null) block.setColour(col); if (var != null) block.setVariant(var); if (face != null) block.setFace(face); return block; }
protected BlockStateContainer createBlockState() { return new BlockStateContainer(this, new IProperty[] {FACING}); }
@Override public Collection<IProperty<?>> getPropertyKeys() { return delegate.getPropertyKeys(); }
@Override public <T extends Comparable<T>> T getValue(IProperty<T> property) { return delegate.getValue(property); }
public IProperty<?> getVariantProperty() { return VARIANT; }
protected BlockState createBlockState() { return new BlockState(this, new IProperty[] {VARIANT, CHECK_DECAY, DECAYABLE}); }
private StateMap(IProperty<?> name, String suffix, List < IProperty<? >> ignored) { this.name = name; this.suffix = suffix; this.ignored = ignored; }
@Override protected BlockStateContainer createBlockState() { return new BlockStateContainer(this, new IProperty[]{HALF}); }
protected BlockStateContainer createBlockState() { return new BlockStateContainer(this, new IProperty[] {BITES}); }
protected BlockState createBlockState() { return new BlockState(this, new IProperty[] {FACING, AGE}); }
public StateMap.Builder withName(IProperty<?> builderPropertyIn) { this.name = builderPropertyIn; return this; }
protected BlockStateContainer createBlockState() { return new BlockStateContainer(this, new IProperty[] {HALF, FACING, OPEN, HINGE, POWERED}); }
protected BlockState createBlockState() { return new BlockState(this, new IProperty[] {FACING, NODROP}); }
public static void regBlock(Block block, int stackSize, IProperty<?>... toIgnore) { blocksWithCustomStateMap.add(block); propertiesToIgnoreCustomStateMap.add(toIgnore); regBlock(block, stackSize); }
@SideOnly(Side.CLIENT) public static void createStateMappers(Block block, IProperty<?>[] toIgnore) { ModelLoader.setCustomStateMapper(block, (new StateMap.Builder().ignore(toIgnore)).build()); }
public static void regSingleBlock(Block block, IProperty<?>... toIgnore) { blocksWithCustomStateMap.add(block); propertiesToIgnoreCustomStateMap.add(toIgnore); HarshenConfigs.BLOCKS.allComponants.add(block); }
protected BlockState createBlockState() { return new BlockState(this, new IProperty[] {HAS_BOTTLE[0], HAS_BOTTLE[1], HAS_BOTTLE[2]}); }