use of forestry.api.core.ICamouflageItemHandler in project ForestryMC by ForestryMC.
the class ModelCamouflaged method addCamouflageModel.
private void addCamouflageModel(B block, IModelBaker baker, BlockRenderLayer layer, IBlockAccess world, BlockPos pos) {
if (world == null || pos == null) {
TextureAtlasSprite defaultSprite = block.getDefaultSprite();
baker.addBlockModel(pos, defaultSprite, DEFAULT_COLOR_INDEX);
baker.setParticleSprite(defaultSprite);
} else {
ItemStack camouflageStack = block.getCamouflageBlock(world, pos);
if (camouflageStack.isEmpty()) {
camouflageStack = GreenhouseController.createDefaultCamouflageBlock();
}
Block camouflageBlock = Block.getBlockFromItem(camouflageStack.getItem());
ICamouflageItemHandler itemHandler = CamouflageManager.camouflageAccess.getHandler(camouflageStack);
if (itemHandler != null) {
Pair<IBlockState, IBakedModel> modelPair = itemHandler.getModel(camouflageStack);
IBlockState blockState = modelPair.getLeft();
if (camouflageBlock.canRenderInLayer(blockState, layer)) {
IBakedModel bakedModel = modelPair.getRight();
baker.addBakedModel(blockState, bakedModel);
baker.setParticleSprite(bakedModel.getParticleTexture());
}
}
}
}
use of forestry.api.core.ICamouflageItemHandler in project ForestryMC by ForestryMC.
the class WidgetCamouflageSlot method handleMouseClick.
@Override
public void handleMouseClick(int mouseX, int mouseY, int mouseButton) {
super.handleMouseClick(mouseX, mouseY, mouseButton);
if (GuiScreen.isShiftKeyDown()) {
camouflageHandler.setCamouflageBlock(camouflageHandler.getDefaultCamouflageBlock(), true);
} else {
EntityPlayer player = Minecraft.getMinecraft().player;
ItemStack stack = player.inventory.getItemStack();
if (!stack.isEmpty()) {
if (!CamouflageManager.camouflageAccess.isItemBlackListed(stack)) {
for (ICamouflageItemHandler handler : CamouflageManager.camouflageAccess.getItemHandlers()) {
if (handler != null && handler.canHandle(stack)) {
camouflageHandler.setCamouflageBlock(stack.copy(), true);
}
}
}
}
}
}
Aggregations