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);
}
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);
}
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());
}
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));
}
Aggregations