Search in sources :

Example 51 with IProperty

use of net.minecraft.block.properties.IProperty in project ForestryMC by ForestryMC.

the class MachineStateMapper method putStateModelLocations.

@Override
public Map<IBlockState, ModelResourceLocation> putStateModelLocations(Block block) {
    if (!(type.getMachineProperties() instanceof IMachinePropertiesTesr)) {
        for (EnumFacing facing : EnumFacing.values()) {
            if (facing == EnumFacing.DOWN || facing == EnumFacing.UP) {
                continue;
            }
            IBlockState state = block.getDefaultState().withProperty(BlockBase.FACING, facing);
            LinkedHashMap<IProperty<?>, Comparable<?>> linkedhashmap = Maps.newLinkedHashMap(state.getProperties());
            ResourceLocation blockLocation = Block.REGISTRY.getNameForObject(block);
            String s = String.format("%s:%s", blockLocation.getResourceDomain(), blockLocation.getResourcePath());
            mapStateModelLocations.put(state, new ModelResourceLocation(s, getPropertyString(linkedhashmap)));
        }
    }
    return this.mapStateModelLocations;
}
Also used : IBlockState(net.minecraft.block.state.IBlockState) IMachinePropertiesTesr(forestry.core.blocks.IMachinePropertiesTesr) IProperty(net.minecraft.block.properties.IProperty) EnumFacing(net.minecraft.util.EnumFacing) ModelResourceLocation(net.minecraft.client.renderer.block.model.ModelResourceLocation) ResourceLocation(net.minecraft.util.ResourceLocation) ModelResourceLocation(net.minecraft.client.renderer.block.model.ModelResourceLocation)

Example 52 with IProperty

use of net.minecraft.block.properties.IProperty in project ForestryMC by ForestryMC.

the class PluginImmersiveEngineering method postInit.

@Override
public void postInit() {
    IFarmRegistry farmRegistry = ForestryAPI.farmRegistry;
    ItemStack hempSeed = getItemStack("seed");
    Block hempCrop = getBlock("hemp");
    if (hempCrop != null) {
        int seedAmount = ForestryAPI.activeMode.getIntegerSetting("squeezer.liquid.seed");
        Stream<IProperty<?>> propertyStream = hempCrop.getBlockState().getProperties().stream();
        IProperty age = propertyStream.filter(p -> p.getName().equals("type")).findAny().orElseGet(null);
        if (hempSeed != null && hempCrop != Blocks.AIR && age != null) {
            Optional bottom0 = age.parseValue("bottom0");
            Optional bottom4 = age.parseValue("bottom4");
            Optional top0 = age.parseValue("top0");
            if (bottom0.isPresent() && top0.isPresent()) {
                IBlockState defaultState = hempCrop.getDefaultState();
                IBlockState planted = defaultState.withProperty(age, (Comparable) bottom0.get());
                IBlockState mature = defaultState.withProperty(age, (Comparable) bottom4.get());
                IBlockState topMature = defaultState.withProperty(age, (Comparable) top0.get());
                farmRegistry.registerFarmables("farmWheat", new FarmableDoubleCrop(hempSeed, planted, mature, topMature, false));
                farmRegistry.registerFarmables("farmOrchard", new FarmableDoubleCrop(hempSeed, planted, mature, topMature, true));
                RecipeManagers.squeezerManager.addRecipe(10, hempSeed, Fluids.SEED_OIL.getFluid(seedAmount));
            }
        }
    }
    Fluid ethanol = FluidRegistry.getFluid("ethanol");
    if (ethanol != null) {
        GeneratorFuel ethanolFuel = new GeneratorFuel(new FluidStack(ethanol, 1), (int) (32 * ForestryAPI.activeMode.getFloatSetting("fuel.ethanol.generator")), 4);
        FuelManager.generatorFuel.put(ethanol, ethanolFuel);
    }
}
Also used : GeneratorFuel(forestry.api.fuels.GeneratorFuel) IBlockState(net.minecraft.block.state.IBlockState) Optional(com.google.common.base.Optional) FarmableDoubleCrop(forestry.farming.logic.farmables.FarmableDoubleCrop) IProperty(net.minecraft.block.properties.IProperty) FluidStack(net.minecraftforge.fluids.FluidStack) Fluid(net.minecraftforge.fluids.Fluid) Block(net.minecraft.block.Block) IFarmRegistry(forestry.api.farming.IFarmRegistry) ItemStack(net.minecraft.item.ItemStack)

Example 53 with IProperty

use of net.minecraft.block.properties.IProperty in project GregTech by GregTechCE.

the class MetaBlocks method registerItemModelWithOverride.

@SideOnly(Side.CLIENT)
private static void registerItemModelWithOverride(Block block, Map<IProperty<?>, Comparable<?>> stateOverrides) {
    for (IBlockState state : block.getBlockState().getValidStates()) {
        HashMap<IProperty<?>, Comparable<?>> stringProperties = new HashMap<>(state.getProperties());
        stringProperties.putAll(stateOverrides);
        // noinspection ConstantConditions
        ModelLoader.setCustomModelResourceLocation(Item.getItemFromBlock(block), block.getMetaFromState(state), new ModelResourceLocation(block.getRegistryName(), statePropertiesToString(stringProperties)));
    }
}
Also used : IBlockState(net.minecraft.block.state.IBlockState) IProperty(net.minecraft.block.properties.IProperty) ModelResourceLocation(net.minecraft.client.renderer.block.model.ModelResourceLocation) SideOnly(net.minecraftforge.fml.relauncher.SideOnly)

Example 54 with IProperty

use of net.minecraft.block.properties.IProperty in project GregTech by GregTechCE.

the class PredicateConfigUtils method parseBlockStatePropertyPredicate.

private static Predicate<IBlockState> parseBlockStatePropertyPredicate(JsonObject object) {
    Block block = OreConfigUtils.getBlockByName(object.get("block").getAsString());
    Map<IProperty<?>, List<Object>> allowedValues = new HashMap<>();
    for (IProperty<?> property : block.getBlockState().getProperties()) {
        JsonElement valueElement = object.get(property.getName());
        if (valueElement == null) {
            continue;
        }
        if (valueElement.isJsonPrimitive()) {
            JsonElement singleValue = valueElement;
            valueElement = new JsonArray();
            valueElement.getAsJsonArray().add(singleValue);
        }
        if (valueElement.isJsonArray()) {
            ArrayList<Object> allValues = new ArrayList<>();
            JsonArray valuesArray = valueElement.getAsJsonArray();
            boolean isBlacklist = false;
            for (JsonElement allowedValue : valuesArray) {
                String elementValue = allowedValue.getAsString();
                if (elementValue.startsWith("!")) {
                    elementValue = elementValue.substring(1);
                    isBlacklist = true;
                }
                Optional<?> parsedValue = property.parseValue(elementValue);
                if (!parsedValue.isPresent()) {
                    throw new IllegalArgumentException("Couldn't parse property " + property.getName() + " value " + valueElement);
                }
                allValues.add(parsedValue.get());
            }
            if (isBlacklist) {
                ArrayList<Object> blacklistValues = allValues;
                allValues = new ArrayList<>(property.getAllowedValues());
                allValues.removeAll(blacklistValues);
            }
            allowedValues.put(property, allValues);
        }
    }
    return blockState -> {
        for (IProperty<?> property : blockState.getPropertyKeys()) {
            if (!allowedValues.containsKey(property))
                // do not check unspecified properties
                continue;
            Object propertyValue = blockState.getValue(property);
            if (!allowedValues.get(property).contains(propertyValue))
                return false;
        }
        return true;
    };
}
Also used : JsonObject(com.google.gson.JsonObject) WorldBlockPredicate(gregtech.api.util.WorldBlockPredicate) Predicate(java.util.function.Predicate) HashMap(java.util.HashMap) StoneType(gregtech.api.unification.ore.StoneType) ArrayList(java.util.ArrayList) JsonElement(com.google.gson.JsonElement) IBlockState(net.minecraft.block.state.IBlockState) JsonArray(com.google.gson.JsonArray) List(java.util.List) IProperty(net.minecraft.block.properties.IProperty) Block(net.minecraft.block.Block) Optional(com.google.common.base.Optional) Map(java.util.Map) JsonPrimitive(com.google.gson.JsonPrimitive) HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) JsonArray(com.google.gson.JsonArray) IProperty(net.minecraft.block.properties.IProperty) JsonElement(com.google.gson.JsonElement) Block(net.minecraft.block.Block) ArrayList(java.util.ArrayList) List(java.util.List) JsonObject(com.google.gson.JsonObject)

Example 55 with IProperty

use of net.minecraft.block.properties.IProperty in project malmo by Microsoft.

the class MovingTargetDecoratorImplementation method isValid.

private boolean isValid(World world, BlockPos pos) {
    // In bounds?
    if (!blockInBounds(pos, this.arenaBounds))
        return false;
    // Already in path?
    if (this.path.contains(pos))
        return false;
    // Does there need to be air above the target?
    if (this.targetParams.isRequiresAirAbove() && !world.isAirBlock(pos.up()))
        return false;
    // Check the current block is "permeable"...
    IBlockState block = world.getBlockState(pos);
    List<IProperty> extraProperties = new ArrayList<IProperty>();
    DrawBlock db = MinecraftTypeHelper.getDrawBlockFromBlockState(block, extraProperties);
    boolean typesMatch = this.targetParams.getPermeableBlocks().getType().isEmpty();
    for (BlockType bt : this.targetParams.getPermeableBlocks().getType()) {
        if (db.getType() == bt) {
            typesMatch = true;
            break;
        }
    }
    if (!typesMatch)
        return false;
    if (db.getColour() != null) {
        boolean coloursMatch = this.targetParams.getPermeableBlocks().getColour().isEmpty();
        for (Colour col : this.targetParams.getPermeableBlocks().getColour()) {
            if (db.getColour() == col) {
                coloursMatch = true;
                break;
            }
        }
        if (!coloursMatch)
            return false;
    }
    if (db.getVariant() != null) {
        boolean variantsMatch = this.targetParams.getPermeableBlocks().getVariant().isEmpty();
        for (Variation var : this.targetParams.getPermeableBlocks().getVariant()) {
            if (db.getVariant() == var) {
                variantsMatch = true;
                break;
            }
        }
        if (!variantsMatch)
            return false;
    }
    return true;
}
Also used : IBlockState(net.minecraft.block.state.IBlockState) IProperty(net.minecraft.block.properties.IProperty) BlockType(com.microsoft.Malmo.Schemas.BlockType) ArrayList(java.util.ArrayList) DrawBlock(com.microsoft.Malmo.Schemas.DrawBlock) Variation(com.microsoft.Malmo.Schemas.Variation) Colour(com.microsoft.Malmo.Schemas.Colour)

Aggregations

IProperty (net.minecraft.block.properties.IProperty)72 IBlockState (net.minecraft.block.state.IBlockState)39 Block (net.minecraft.block.Block)20 ResourceLocation (net.minecraft.util.ResourceLocation)14 ModelResourceLocation (net.minecraft.client.renderer.block.model.ModelResourceLocation)11 ItemStack (net.minecraft.item.ItemStack)10 EnumFacing (net.minecraft.util.EnumFacing)10 Map (java.util.Map)9 SideOnly (net.minecraftforge.fml.relauncher.SideOnly)9 ArrayList (java.util.ArrayList)8 BlockStateContainer (net.minecraft.block.state.BlockStateContainer)8 TileEntity (net.minecraft.tileentity.TileEntity)7 BlockPos (net.minecraft.util.math.BlockPos)7 JsonObject (com.google.gson.JsonObject)6 DrawBlock (com.microsoft.Malmo.Schemas.DrawBlock)5 ExtendedBlockState (net.minecraftforge.common.property.ExtendedBlockState)5 JsonArray (com.google.gson.JsonArray)4 JsonElement (com.google.gson.JsonElement)4 List (java.util.List)4 Collectors (java.util.stream.Collectors)4