@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; }
public EnumFacing getOrientation() { IBlockState state = world.getBlockState(getPos()); if(state.getPropertyKeys().contains(BotaniaStateProps.FACING)) return state.getValue(BotaniaStateProps.FACING); return EnumFacing.WEST; // fallback }
@Override public Collection<IProperty<?>> getPropertyKeys() { return normalState.getPropertyKeys(); }
public static Collection<IProperty<?>> getPropertyKeys(IBlockState state) { return state.getPropertyKeys(); }
@Override public @Nonnull Collection<IProperty<?>> getPropertyKeys() { return state.getPropertyKeys(); }
@SuppressWarnings({ "rawtypes", "unchecked" }) public static <T extends Comparable<T>> IProperty<T> getProperty(final IBlockState blockState, final String name) { for (final IProperty prop : blockState.getPropertyKeys()) { if (prop.getName().equals(name)) { return prop; } } return null; }
@Override protected IBakedModel getModel(List<IBakedModel> list, @Nullable IBlockState state) { if (state != null && state.getPropertyKeys().contains(TIER)) { return list.get(state.getValue(TIER) - 1); } return list.get(0); }
IBlockAccess world = MinecraftForgeClient.getRegionRenderCache(te.getWorld(), pos); IBlockState state = world.getBlockState(pos); if(state.getPropertyKeys().contains(Properties.StaticProperty))
@Override public int getMetaFromState(IBlockState state) { if (state.getPropertyKeys().contains(property)) return (state.getValue(property)).ordinal(); else return 0; }
IBlockAccess world = MinecraftForgeClient.getRegionRenderCache( te.getWorld(), pos ); IBlockState state = world.getBlockState( pos ); if( state.getPropertyKeys().contains( Properties.StaticProperty ) )
private static EnumFacing getStateFacing(IBlockState state) { Collection<IProperty<?>> props = state.getPropertyKeys(); for(IProperty prop : props) if(prop.getName().equals("facing")) { Object obj = state.getValue(prop); if(obj instanceof EnumFacing) return (EnumFacing) obj; } return null; }
@Nullable public static <T extends Comparable<T>> IProperty<T> getProperty(Block block, String propertyName, Class<T> valueClass) { for (IProperty<?> property : block.getDefaultState().getPropertyKeys()) { if (property.getName().equals(propertyName)) { if (property.getValueClass().isAssignableFrom(valueClass)) { //noinspection unchecked return (IProperty<T>) property; } } } return null; } }
private IBlockState convert(BlockData data) { Block block = Block.getBlockFromName(data.block); if (block == null) { return Blocks.AIR.getDefaultState(); } IBlockState state; if (data.state == null || data.state.isEmpty()) { state = block.getStateFromMeta(data.meta); } else { state = block.getDefaultState(); for (Map.Entry<String, String> entry : data.state.entrySet()) { Optional<IProperty<?>> property = state.getPropertyKeys().stream().filter(iProperty -> entry.getKey().equals(iProperty.getName())).findFirst(); if (property.isPresent()) { state = setProperty(state, property.get(), entry.getValue()); } } } return state; }
private int getStrength(IBlockAccess world, BlockPos pos) { IBlockState state = world.getBlockState(pos); if(state.getBlock().isFullBlock(state)) return 3; if(state.getPropertyKeys().contains(SIZE)) return state.getValue(SIZE).strength; return 0; }
public static boolean shouldMoveTE(boolean te, IBlockState state) { if(!ModuleLoader.isFeatureEnabled(PistonsMoveTEs.class)) return te; // Jukeboxes that are playing can't be moved so the music can be stopped if(state.getPropertyKeys().contains(BlockJukebox.HAS_RECORD) && state.getValue(BlockJukebox.HAS_RECORD)) return true; ResourceLocation res = Block.REGISTRY.getNameForObject(state.getBlock()); return PistonsMoveTEs.movementBlacklist.contains(res.toString()) || PistonsMoveTEs.movementBlacklist.contains(res.getResourceDomain()); }
@SuppressWarnings({ "rawtypes", "unchecked" }) private static boolean putMatchingProperty(final Map<IProperty, Comparable> map, final IBlockState blockState, final String name, final String value, final boolean strict) throws LocalizedException { for (final IProperty property : blockState.getPropertyKeys()) { if (property.getName().equalsIgnoreCase(name)) { final Collection<Comparable> allowedValues = property.getAllowedValues(); for (final Comparable allowedValue : allowedValues) { if (String.valueOf(allowedValue).equalsIgnoreCase(value)) { map.put(property, allowedValue); return true; } } } } if (strict) { throw new LocalizedException(Names.Messages.INVALID_PROPERTY_FOR_BLOCK, name + "=" + value, Block.REGISTRY.getNameForObject(blockState.getBlock())); } return false; }
@Override public boolean apply(@Nullable IBlockState input) { IBlockState defaultState = input.getBlock().getDefaultState(); for (IProperty<?> property : defaultState.getPropertyKeys()) { String propName = property.getName(); if (properties.containsKey(propName)) { String reqValueStr = properties.get(propName); Comparable<?> reqValue = BlockStateUtils.getPropertyValueByName(input, property, reqValueStr); if (!reqValueStr.equals("*") && (reqValue == null || input.getValue(property) != reqValue)) { return false; } } // If missing key for this property, allow it to have any value } return true; }
public static IBlockState rotate(@Nonnull IBlockState paintSource) { // TODO: Need to handle cases like stairs that have 'upper' and 'lower' so they are included in the rotation // cycle for (IProperty<?> prop : paintSource.getPropertyKeys()) { if (prop instanceof PropertyDirection) { return paintSource.cycleProperty(prop); } else if (prop == BlockSlab.HALF) { return paintSource.cycleProperty(prop); } } if (paintSource.getBlock() instanceof BlockLog) { return paintSource.cycleProperty(BlockLog.LOG_AXIS); } return paintSource; }
public static void onPistonUpdate(TileEntityPiston piston) { if(!ModuleLoader.isFeatureEnabled(PistonsPushPullItems.class) || piston.getWorld().isRemote) return; IBlockState state = piston.getPistonState(); boolean pulling = state.getBlock() != Blocks.PISTON_HEAD; boolean sticky = state.getBlock() == Blocks.STICKY_PISTON || (state.getPropertyKeys().contains(BlockPistonExtension.TYPE) && state.getValue(BlockPistonExtension.TYPE) == EnumPistonType.STICKY); if(pulling != sticky) return; EnumFacing face = piston.getFacing(); AxisAlignedBB aabb = new AxisAlignedBB(piston.getPos().offset(face, pulling ? 2 : 1)); List<EntityItem> items = piston.getWorld().getEntitiesWithinAABB(EntityItem.class, aabb); for(EntityItem entity : items) onEntityHandled(entity, face, sticky); }
@Override public void resetTask() { if(closeDoor) { IBlockState state = entity.world.getBlockState(doorPosition).getActualState(entity.world, doorPosition); if(!state.getPropertyKeys().contains(BlockDoor.OPEN)) return; EnumFacing direction = state.getValue(BlockDoor.FACING); boolean isOpen = state.getValue(BlockDoor.OPEN); BlockDoor.EnumHingePosition isMirrored = state.getValue(BlockDoor.HINGE); BlockPos mirrorPos = doorPosition.offset(isMirrored == BlockDoor.EnumHingePosition.RIGHT ? direction.rotateYCCW() : direction.rotateY()); BlockPos doorPos = state.getValue(BlockDoor.HALF) == BlockDoor.EnumDoorHalf.LOWER ? mirrorPos : mirrorPos.down(); IBlockState other = entity.world.getBlockState(doorPos).getActualState(entity.world, doorPos); if(state.getMaterial() != Material.IRON && other.getBlock() == doorBlock && other.getValue(BlockDoor.FACING) == direction && other.getValue(BlockDoor.OPEN) == isOpen && other.getValue(BlockDoor.HINGE) != isMirrored) { IBlockState newState = other.cycleProperty(BlockDoor.OPEN); entity.world.setBlockState(doorPos, newState, 10); } doorBlock.toggleDoor(entity.world, doorPosition, false); } }