Search in sources :

Example 1 with TELeafMat

use of com.eerussianguy.firmalife.te.TELeafMat in project firmalife by eerussianguy.

the class BlockLeafMat method onBlockActivated.

@Override
public boolean onBlockActivated(World world, BlockPos pos, IBlockState state, EntityPlayer player, EnumHand hand, EnumFacing side, float hitX, float hitY, float hitZ) {
    if (!world.isRemote) {
        ItemStack held = player.getHeldItem(hand);
        if (held.hasCapability(CapabilityItemHandler.ITEM_HANDLER_CAPABILITY, null))
            return false;
        TELeafMat te = Helpers.getTE(world, pos, TELeafMat.class);
        if (te != null) {
            IItemHandler inventory = te.getCapability(CapabilityItemHandler.ITEM_HANDLER_CAPABILITY, null);
            if (inventory != null) {
                ItemStack tryStack = new ItemStack(held.getItem(), 1);
                if (DryingRecipe.get(tryStack) != null && inventory.getStackInSlot(0).isEmpty()) {
                    ItemStack leftover = inventory.insertItem(0, held.splitStack(1), false);
                    ItemHandlerHelper.giveItemToPlayer(player, leftover);
                    te.start();
                    te.markForSync();
                    return true;
                }
                if (held.isEmpty() && player.isSneaking()) {
                    ItemStack takeStack = inventory.extractItem(0, 1, false);
                    Helpers.spawnItemStack(world, pos, takeStack);
                    te.deleteSlot();
                    te.clear();
                    te.markForSync();
                }
            }
        }
    }
    return true;
}
Also used : IItemHandler(net.minecraftforge.items.IItemHandler) ItemStack(net.minecraft.item.ItemStack) TELeafMat(com.eerussianguy.firmalife.te.TELeafMat)

Example 2 with TELeafMat

use of com.eerussianguy.firmalife.te.TELeafMat in project firmalife by eerussianguy.

the class BlockLeafMat method breakBlock.

@Override
public void breakBlock(World world, BlockPos pos, IBlockState state) {
    TELeafMat te = Helpers.getTE(world, pos, TELeafMat.class);
    if (te != null) {
        te.onBreakBlock(world, pos, state);
    }
    super.breakBlock(world, pos, state);
}
Also used : TELeafMat(com.eerussianguy.firmalife.te.TELeafMat)

Example 3 with TELeafMat

use of com.eerussianguy.firmalife.te.TELeafMat in project firmalife by eerussianguy.

the class LeafMatProvider method getTooltip.

@Nonnull
@Override
public List<String> getTooltip(World world, @Nonnull BlockPos pos, @Nonnull NBTTagCompound nbt) {
    List<String> currentTooltip = new ArrayList<>();
    TileEntity te = world.getTileEntity(pos);
    if (te instanceof TELeafMat) {
        TELeafMat leafMat = (TELeafMat) te;
        ItemStack mainSlot = leafMat.getCapability(CapabilityItemHandler.ITEM_HANDLER_CAPABILITY, null).getStackInSlot(0);
        DryingRecipe recipe = DryingRecipe.get(mainSlot);
        if (!mainSlot.isEmpty() && recipe != null) {
            long remainingTicks = leafMat.getTicksRemaining();
            switch(ConfigTFC.Client.TOOLTIP.timeTooltipMode) {
                case NONE:
                    break;
                case TICKS:
                    currentTooltip.add(new TextComponentTranslation("waila.tfc.devices.ticks_remaining", remainingTicks).getFormattedText());
                case MINECRAFT_HOURS:
                    long remainingHours = Math.round(remainingTicks / (float) ICalendar.TICKS_IN_HOUR);
                    currentTooltip.add(new TextComponentTranslation("waila.tfc.devices.hours_remaining", remainingHours).getFormattedText());
                    break;
                case REAL_MINUTES:
                    long remainingMinutes = Math.round(remainingTicks / 1200.0f);
                    currentTooltip.add(new TextComponentTranslation("waila.tfc.devices.minutes_remaining", remainingMinutes).getFormattedText());
                    break;
            }
            currentTooltip.add(new TextComponentTranslation(recipe.getOutputItem(mainSlot).getTranslationKey() + ".name").getFormattedText());
        }
    }
    return currentTooltip;
}
Also used : TileEntity(net.minecraft.tileentity.TileEntity) TextComponentTranslation(net.minecraft.util.text.TextComponentTranslation) ArrayList(java.util.ArrayList) DryingRecipe(com.eerussianguy.firmalife.recipe.DryingRecipe) ItemStack(net.minecraft.item.ItemStack) TELeafMat(com.eerussianguy.firmalife.te.TELeafMat) Nonnull(javax.annotation.Nonnull)

Aggregations

TELeafMat (com.eerussianguy.firmalife.te.TELeafMat)3 ItemStack (net.minecraft.item.ItemStack)2 DryingRecipe (com.eerussianguy.firmalife.recipe.DryingRecipe)1 ArrayList (java.util.ArrayList)1 Nonnull (javax.annotation.Nonnull)1 TileEntity (net.minecraft.tileentity.TileEntity)1 TextComponentTranslation (net.minecraft.util.text.TextComponentTranslation)1 IItemHandler (net.minecraftforge.items.IItemHandler)1