Search in sources :

Example 1 with BlockStemCrop

use of com.eerussianguy.firmalife.blocks.BlockStemCrop in project firmalife by eerussianguy.

the class VanillaStemStateMapper method getVanillaAge.

// tfc data says facing=[dir] and stage=[0..maxStage]
// vanilla can render a vertical stalk wih facing=up and age=[0..7]
// or a bent stalk with facing=[dir] and no other parameters.
// visually, we want stage=maxStage to render a bent stalk
// and we want stage=0 to render age=0, and we want stage=maxStage-1 to render age=7
// for all other stages we can interpolate
// this returns the vanilla age from 0 to 7, or -1 if fully grown
public static int getVanillaAge(IBlockState state) {
    BlockStemCrop block = (BlockStemCrop) state.getBlock();
    PropertyInteger stage = block.getStageProperty();
    int growthStage = state.getValue(stage);
    int maxStage = block.getCrop().getMaxStage();
    if (growthStage == maxStage)
        return -1;
    float fractionGrown = ((float) growthStage) / ((float) (maxStage - 1));
    return (int) (fractionGrown * 7.0f);
}
Also used : PropertyInteger(net.minecraft.block.properties.PropertyInteger) BlockStemCrop(com.eerussianguy.firmalife.blocks.BlockStemCrop)

Example 2 with BlockStemCrop

use of com.eerussianguy.firmalife.blocks.BlockStemCrop in project firmalife by eerussianguy.

the class ClientRegisterEventsFL method registerColorHandlerBlocks.

@SubscribeEvent
@SideOnly(Side.CLIENT)
public static void registerColorHandlerBlocks(ColorHandlerEvent.Block event) {
    BlockColors blockColors = event.getBlockColors();
    IBlockColor foliageColor = GrassColorHandler::computeGrassColor;
    blockColors.registerBlockColorHandler(foliageColor, BlocksFL.getAllFruitLeaves().toArray(new Block[0]));
    blockColors.registerBlockColorHandler(foliageColor, BlocksFL.getAllBonsai().toArray(new Block[0]));
    // use vanilla stem coloring for stemcrops
    for (BlockStemCrop block : BlocksFL.getAllCropBlocks()) {
        blockColors.registerBlockColorHandler((state, world, pos, tintIndex) -> {
            int vanillaAge = VanillaStemStateMapper.getVanillaAge(state);
            if (vanillaAge == -1)
                // for fully grown, we color it like stage 7
                vanillaAge = 7;
            return blockColors.colorMultiplier(Blocks.MELON_STEM.getDefaultState().withProperty(BlockStem.AGE, vanillaAge), world, pos, tintIndex);
        }, block);
    }
    for (BlockCropDead block : BlocksFL.getAllDeadCrops()) {
        blockColors.registerBlockColorHandler((state, world, os, tintIndex) -> 0xCC7400, block);
    }
    blockColors.registerBlockColorHandler(foliageColor, BlocksFL.CINNAMON_LEAVES);
}
Also used : IBlockColor(net.minecraft.client.renderer.color.IBlockColor) BlockStemCrop(com.eerussianguy.firmalife.blocks.BlockStemCrop) ItemBlock(net.minecraft.item.ItemBlock) BlockCropDead(net.dries007.tfc.objects.blocks.agriculture.BlockCropDead) BlockColors(net.minecraft.client.renderer.color.BlockColors) SubscribeEvent(net.minecraftforge.fml.common.eventhandler.SubscribeEvent) SideOnly(net.minecraftforge.fml.relauncher.SideOnly)

Example 3 with BlockStemCrop

use of com.eerussianguy.firmalife.blocks.BlockStemCrop in project firmalife by eerussianguy.

the class ClientRegisterEventsFL method registerModels.

@SubscribeEvent
public static void registerModels(ModelRegistryEvent event) {
    // Setting the model resource location for items
    for (Item i : ItemsFL.getAllEasyItems()) ModelLoader.setCustomModelResourceLocation(i, 0, new ModelResourceLocation(i.getRegistryName().toString()));
    for (ItemFruitDoor i : ItemsFL.getAllFruitDoors()) ModelLoader.setCustomModelResourceLocation(i, 0, new ModelResourceLocation(i.getRegistryName().toString()));
    for (ItemBlock ib : BlocksFL.getAllIBs()) ModelLoader.setCustomModelResourceLocation(ib, 0, new ModelResourceLocation(ib.getRegistryName().toString(), "normal"));
    for (BlockFruitTreeLeaves leaves : BlocksFL.getAllFruitLeaves()) ModelLoader.setCustomStateMapper(leaves, new StateMap.Builder().ignore(BlockFruitTreeLeaves.DECAYABLE).ignore(BlockFruitTreeLeaves.HARVESTABLE).build());
    ModelLoader.setCustomStateMapper(BlocksFL.SPOUT, new StateMap.Builder().ignore(StatePropertiesFL.WATERED).ignore(StatePropertiesFL.NEEDS_SOURCE).build());
    ModelLoader.setCustomStateMapper(BlocksFL.SPRINKLER, new StateMap.Builder().ignore(StatePropertiesFL.WATERED).ignore(StatePropertiesFL.NEEDS_SOURCE).build());
    ModelLoader.setCustomStateMapper(BlocksFL.TURNTABLE, new StateMap.Builder().ignore(StatePropertiesFL.CLAY).build());
    ModelLoader.setCustomModelResourceLocation(ItemsFL.CHEESECLOTH, 0, new ModelResourceLocation(ItemsFL.CHEESECLOTH.getRegistryName(), "inventory"));
    ModelLoader.setCustomModelResourceLocation(ItemsFL.CRACKED_COCONUT, 0, new ModelResourceLocation(ItemsFL.CRACKED_COCONUT.getRegistryName(), "inventory"));
    ModelLoader.setCustomModelResourceLocation(ItemsFL.ITEM_CINNAMON_SAPLING, 0, new ModelResourceLocation(ItemsFL.ITEM_CINNAMON_SAPLING.getRegistryName().toString()));
    ModelLoader.setCustomModelResourceLocation(ItemsFL.ITEM_QUAD_PLANTER, 0, new ModelResourceLocation(ItemsFL.ITEM_QUAD_PLANTER.getRegistryName().toString(), "inventory"));
    ModelLoader.setCustomModelResourceLocation(ItemsFL.ITEM_LARGE_PLANTER, 0, new ModelResourceLocation(ItemsFL.ITEM_LARGE_PLANTER.getRegistryName().toString(), "inventory"));
    // Mallet mold
    ItemMetalMalletMold item = ItemsFL.malletMold;
    ModelBakery.registerItemVariants(item, new ModelResourceLocation(item.getRegistryName().toString()));
    ModelBakery.registerItemVariants(item, TFCRegistries.METALS.getValuesCollection().stream().filter(Metal.ItemType.PROPICK_HEAD::hasMold).map(x -> new ModelResourceLocation(FirmaLife.MOD_ID + ":" + x.getRegistryName().getPath() + "_" + item.getRegistryName().getPath())).toArray(ModelResourceLocation[]::new));
    ModelLoader.setCustomMeshDefinition(item, new ItemMeshDefinition() {

        private final ModelResourceLocation FALLBACK = new ModelResourceLocation(item.getRegistryName().toString());

        @Override
        @Nonnull
        public ModelResourceLocation getModelLocation(@Nonnull ItemStack stack) {
            IFluidHandler cap = stack.getCapability(CapabilityFluidHandler.FLUID_HANDLER_CAPABILITY, null);
            if (cap instanceof IMoldHandler) {
                Metal metal = ((IMoldHandler) cap).getMetal();
                if (metal != null) {
                    return new ModelResourceLocation(FirmaLife.MOD_ID + ":" + metal.getRegistryName().getPath() + "_" + stack.getItem().getRegistryName().getPath());
                }
            }
            return FALLBACK;
        }
    });
    // use vanilla stem rendering for StemCrops
    for (BlockStemCrop block : BlocksFL.getAllCropBlocks()) ModelLoader.setCustomStateMapper(block, new VanillaStemStateMapper());
    for (BlockFruitDoor door : BlocksFL.getAllFruitDoors()) ModelLoader.setCustomStateMapper(door, new StateMap.Builder().ignore(BlockDoor.POWERED).build());
    for (BlockFruitFenceGate gate : BlocksFL.getAllFruitFenceGates()) ModelLoader.setCustomStateMapper(gate, new StateMap.Builder().ignore(BlockFenceGate.POWERED).build());
    ModelLoader.setCustomStateMapper(BlocksFL.CINNAMON_LOG, new StateMap.Builder().ignore(StatePropertiesFL.CAN_GROW).build());
    ModelLoader.setCustomStateMapper(BlocksFL.CINNAMON_LEAVES, new StateMap.Builder().ignore(BlockLeaves.DECAYABLE).build());
    ModelLoader.setCustomStateMapper(BlocksFL.CINNAMON_SAPLING, new StateMap.Builder().ignore(BlockSaplingTFC.STAGE).build());
    for (Block block : BlocksFL.getAllFluidBlocks()) ModelLoader.setCustomStateMapper(block, new StateMap.Builder().ignore(BlockFluidBase.LEVEL).build());
    ModelLoader.setCustomStateMapper(BlocksFL.GREENHOUSE_DOOR, new StateMap.Builder().ignore(BlockDoor.POWERED).build());
    ModelLoader.setCustomStateMapper(BlocksFL.CINNAMON_LOG, new StateMap.Builder().ignore(StatePropertiesFL.CAN_GROW).build());
    ModelLoader.setCustomStateMapper(BlocksFL.CINNAMON_LEAVES, new StateMap.Builder().ignore(BlockLeaves.DECAYABLE).build());
    ModelLoader.setCustomStateMapper(BlocksFL.CINNAMON_SAPLING, new StateMap.Builder().ignore(BlockSaplingTFC.STAGE).build());
    ModelLoader.setCustomStateMapper(BlocksFL.QUAD_PLANTER, new QuadPlanterStateMapper());
    ModelLoader.setCustomStateMapper(BlocksFL.LARGE_PLANTER, new LargePlanterStateMapper());
    ClientRegistry.bindTileEntitySpecialRenderer(TEOven.class, new TESROven());
    ClientRegistry.bindTileEntitySpecialRenderer(TEString.class, new TESRString());
    ClientRegistry.bindTileEntitySpecialRenderer(TELeafMat.class, new TESRLeafMat());
    ClientRegistry.bindTileEntitySpecialRenderer(TETurntable.class, new TESRTurntable());
}
Also used : StateMap(net.minecraft.client.renderer.block.statemap.StateMap) ModelResourceLocation(net.minecraft.client.renderer.block.model.ModelResourceLocation) Metal(net.dries007.tfc.api.types.Metal) ItemMetalMalletMold(com.eerussianguy.firmalife.items.ItemMetalMalletMold) IFluidHandler(net.minecraftforge.fluids.capability.IFluidHandler) Item(net.minecraft.item.Item) Nonnull(javax.annotation.Nonnull) IMoldHandler(net.dries007.tfc.api.capability.IMoldHandler) BlockFruitFenceGate(com.eerussianguy.firmalife.blocks.BlockFruitFenceGate) ItemBlock(net.minecraft.item.ItemBlock) ItemFruitDoor(com.eerussianguy.firmalife.items.ItemFruitDoor) ItemMeshDefinition(net.minecraft.client.renderer.ItemMeshDefinition) BlockFruitDoor(com.eerussianguy.firmalife.blocks.BlockFruitDoor) BlockFruitTreeLeaves(net.dries007.tfc.objects.blocks.agriculture.BlockFruitTreeLeaves) BlockStemCrop(com.eerussianguy.firmalife.blocks.BlockStemCrop) ItemBlock(net.minecraft.item.ItemBlock) ItemStack(net.minecraft.item.ItemStack) SubscribeEvent(net.minecraftforge.fml.common.eventhandler.SubscribeEvent)

Example 4 with BlockStemCrop

use of com.eerussianguy.firmalife.blocks.BlockStemCrop in project firmalife by eerussianguy.

the class VanillaStemStateMapper method getModelResourceLocation.

@Override
public ModelResourceLocation getModelResourceLocation(IBlockState state) {
    BlockStemCrop block = (BlockStemCrop) state.getBlock();
    // use the vanilla melon stem blockstates json
    String s = Block.REGISTRY.getNameForObject(Blocks.MELON_STEM).toString();
    Map<IProperty<?>, Comparable<?>> map = Maps.newLinkedHashMap(state.getProperties());
    // always skip the wild parameter, since it doesn't affect rendering
    map.remove(WILD);
    int vanillaAge = getVanillaAge(state);
    map.remove(block.getStageProperty());
    // spoof a vanilla melon's blockstate
    if (vanillaAge >= 0) {
        map.put(BlockStem.AGE, vanillaAge);
        // needed to get correct insertion order
        map.remove(BlockStemCrop.FACING);
        map.put(BlockStemCrop.FACING, EnumFacing.UP);
    } else if (map.get(BlockStemCrop.FACING) == EnumFacing.UP) {
        // this should never happen in reality but it is a possible blockstate
        // so we have to include something here so that we don't get
        // missing variant errors
        map.put(BlockStemCrop.FACING, EnumFacing.NORTH);
    }
    return new ModelResourceLocation(s, getPropertyString(map));
}
Also used : BlockStemCrop(com.eerussianguy.firmalife.blocks.BlockStemCrop) IProperty(net.minecraft.block.properties.IProperty) ModelResourceLocation(net.minecraft.client.renderer.block.model.ModelResourceLocation)

Aggregations

BlockStemCrop (com.eerussianguy.firmalife.blocks.BlockStemCrop)4 ModelResourceLocation (net.minecraft.client.renderer.block.model.ModelResourceLocation)2 ItemBlock (net.minecraft.item.ItemBlock)2 SubscribeEvent (net.minecraftforge.fml.common.eventhandler.SubscribeEvent)2 BlockFruitDoor (com.eerussianguy.firmalife.blocks.BlockFruitDoor)1 BlockFruitFenceGate (com.eerussianguy.firmalife.blocks.BlockFruitFenceGate)1 ItemFruitDoor (com.eerussianguy.firmalife.items.ItemFruitDoor)1 ItemMetalMalletMold (com.eerussianguy.firmalife.items.ItemMetalMalletMold)1 Nonnull (javax.annotation.Nonnull)1 IMoldHandler (net.dries007.tfc.api.capability.IMoldHandler)1 Metal (net.dries007.tfc.api.types.Metal)1 BlockCropDead (net.dries007.tfc.objects.blocks.agriculture.BlockCropDead)1 BlockFruitTreeLeaves (net.dries007.tfc.objects.blocks.agriculture.BlockFruitTreeLeaves)1 IProperty (net.minecraft.block.properties.IProperty)1 PropertyInteger (net.minecraft.block.properties.PropertyInteger)1 ItemMeshDefinition (net.minecraft.client.renderer.ItemMeshDefinition)1 StateMap (net.minecraft.client.renderer.block.statemap.StateMap)1 BlockColors (net.minecraft.client.renderer.color.BlockColors)1 IBlockColor (net.minecraft.client.renderer.color.IBlockColor)1 Item (net.minecraft.item.Item)1