Search in sources :

Example 1 with IAirType

use of net.tropicraft.core.common.item.scuba.api.IAirType in project Tropicraft by Tropicraft.

the class ItemScubaTank method initCapabilities.

@Override
public ICapabilityProvider initCapabilities(ItemStack stack, NBTTagCompound nbt) {
    return ScubaCapabilities.getProvider(ScubaCapabilities.getTankCapability(), () -> {
        IScubaTank ret = new IScubaTank.ScubaTank() {

            @Override
            public void setPressure(float pressure) {
                super.setPressure(pressure);
                stack.setTagCompound(serializeNBT());
            }

            @Override
            public void setAirType(IAirType type) {
                super.setAirType(type);
                stack.setTagCompound(serializeNBT());
            }
        };
        if (stack.hasTagCompound()) {
            ret.deserializeNBT(stack.getTagCompound());
        }
        return ret;
    });
}
Also used : IScubaTank(net.tropicraft.core.common.item.scuba.api.IScubaTank) IScubaTank(net.tropicraft.core.common.item.scuba.api.IScubaTank) IAirType(net.tropicraft.core.common.item.scuba.api.IAirType)

Example 2 with IAirType

use of net.tropicraft.core.common.item.scuba.api.IAirType in project Tropicraft by Tropicraft.

the class ItemScubaTank method getSubItems.

/**
 * returns a list of items with the same ID, but different meta (eg: dye returns 16 items)
 */
@Override
@SideOnly(Side.CLIENT)
public void getSubItems(CreativeTabs tab, NonNullList<ItemStack> list) {
    if (!isInCreativeTab(tab))
        return;
    ItemStack stack = new ItemStack(this);
    IScubaTank tank = stack.getCapability(ScubaCapabilities.getTankCapability(), null);
    for (IAirType airType : AirTypeRegistry.INSTANCE.getTypes()) {
        tank.setPressure(0);
        tank.setAirType(airType);
        list.add(stack.copy());
        tank.setPressure(airType.getMaxCapacity());
        list.add(stack.copy());
    }
}
Also used : ItemStack(net.minecraft.item.ItemStack) IScubaTank(net.tropicraft.core.common.item.scuba.api.IScubaTank) IAirType(net.tropicraft.core.common.item.scuba.api.IAirType) SideOnly(net.minecraftforge.fml.relauncher.SideOnly)

Example 3 with IAirType

use of net.tropicraft.core.common.item.scuba.api.IAirType in project Tropicraft by Tropicraft.

the class ItemScubaChestplateGear method onScubaTick.

@Override
public void onScubaTick(World world, EntityPlayer player, ItemStack itemstack) {
    if (player.capabilities.isCreativeMode)
        return;
    if (!world.isRemote && world.getTotalWorldTime() % UPDATE_RATE == 0) {
        ItemStack helmetStack = player.getItemStackFromSlot(EntityEquipmentSlot.HEAD);
        // Ensure the player doesn't drown if they have the proper tanks / air in tanks
        if (!itemstack.isEmpty() && !helmetStack.isEmpty() && helmetStack.getItem() instanceof ItemScubaHelmet) {
            IScubaGear gear = itemstack.getCapability(ScubaCapabilities.getGearCapability(), null);
            IScubaTank tankToEmpty = gear.getFirstNonEmptyTank();
            if (tankToEmpty != null) {
                float air = tankToEmpty.getPressure();
                if (air > 0) {
                    IAirType airType = tankToEmpty.getAirType();
                    tankToEmpty.setPressure(Math.max(0, air - airType.getUsageRate()));
                    gear.markDirty();
                    player.setAir(300);
                }
            }
        }
    }
}
Also used : IScubaGear(net.tropicraft.core.common.item.scuba.api.IScubaGear) ItemStack(net.minecraft.item.ItemStack) IScubaTank(net.tropicraft.core.common.item.scuba.api.IScubaTank) IAirType(net.tropicraft.core.common.item.scuba.api.IAirType)

Example 4 with IAirType

use of net.tropicraft.core.common.item.scuba.api.IAirType in project Tropicraft by Tropicraft.

the class ItemScubaTank method addInformation.

/**
 * allows items to add custom lines of information to the mouseover description
 */
@SideOnly(Side.CLIENT)
@Override
public void addInformation(ItemStack itemstack, @Nullable World world, List<String> list, ITooltipFlag flag) {
    IScubaTank cap = itemstack.getCapability(ScubaCapabilities.getTankCapability(), null);
    IAirType airType = cap.getAirType();
    list.add(TextFormatting.BLUE + I18n.format("tropicraft.gui.air.type", TextFormatting.GRAY + airType.getDisplayName()));
    list.add(TextFormatting.BLUE + I18n.format("tropicraft.gui.air.capacity", TextFormatting.GRAY.toString() + airType.getMaxCapacity()));
    list.add(TextFormatting.BLUE + I18n.format("tropicraft.gui.air.remaining", TextFormatting.GRAY.toString() + cap.getPressure()));
    list.add(TextFormatting.BLUE + I18n.format("tropicraft.gui.air.efficiency", TextFormatting.GRAY + efficiencyFmt.format(airType.getUsageRate() * 20)));
}
Also used : IScubaTank(net.tropicraft.core.common.item.scuba.api.IScubaTank) IAirType(net.tropicraft.core.common.item.scuba.api.IAirType) SideOnly(net.minecraftforge.fml.relauncher.SideOnly)

Aggregations

IAirType (net.tropicraft.core.common.item.scuba.api.IAirType)4 IScubaTank (net.tropicraft.core.common.item.scuba.api.IScubaTank)4 ItemStack (net.minecraft.item.ItemStack)2 SideOnly (net.minecraftforge.fml.relauncher.SideOnly)2 IScubaGear (net.tropicraft.core.common.item.scuba.api.IScubaGear)1