Search in sources :

Example 31 with InventoryPlayer

use of net.minecraft.entity.player.InventoryPlayer in project BetterStorage by copygirl.

the class SlotArmorBackpack method isItemValid.

@Override
public boolean isItemValid(ItemStack stack) {
    if (stack == null)
        return false;
    EntityPlayer player = ((InventoryPlayer) inventory).player;
    Item item = stack.getItem();
    if ((item instanceof ItemBackpack) && !ItemBackpack.canEquipBackpack(player))
        return false;
    return item.isValidArmor(stack, armorType, player);
}
Also used : InventoryPlayer(net.minecraft.entity.player.InventoryPlayer) Item(net.minecraft.item.Item) EntityPlayer(net.minecraft.entity.player.EntityPlayer) ItemBackpack(net.mcft.copy.betterstorage.item.ItemBackpack)

Example 32 with InventoryPlayer

use of net.minecraft.entity.player.InventoryPlayer in project pnc-repressurized by TeamPneumatic.

the class TileEntityChargingStation method update.

@Override
public void update() {
    disCharging = false;
    charging = false;
    List<IPressurizable> chargingItems = new ArrayList<>();
    List<ItemStack> chargedStacks = new ArrayList<>();
    if (getChargingItem().getItem() instanceof IPressurizable) {
        chargingItems.add((IPressurizable) getChargingItem().getItem());
        chargedStacks.add(getChargingItem());
    }
    if (this.getUpgrades(EnumUpgrade.DISPENSER) > 0) {
        // creating a new word, 'entities padding'.
        List<Entity> entitiesPadding = getWorld().getEntitiesWithinAABB(Entity.class, new AxisAlignedBB(getPos().getX(), getPos().getY(), getPos().getZ(), getPos().getX() + 1, getPos().getY() + 2, getPos().getZ() + 1));
        for (Entity entity : entitiesPadding) {
            if (entity instanceof IPressurizable) {
                chargingItems.add((IPressurizable) entity);
                chargedStacks.add(ItemStack.EMPTY);
            } else if (entity instanceof EntityItem) {
                ItemStack entityStack = ((EntityItem) entity).getItem();
                if (entityStack.getItem() instanceof IPressurizable) {
                    chargingItems.add((IPressurizable) entityStack.getItem());
                    chargedStacks.add(entityStack);
                }
            } else if (entity instanceof EntityPlayer) {
                InventoryPlayer inv = ((EntityPlayer) entity).inventory;
                for (int i = 0; i < inv.getSizeInventory(); i++) {
                    ItemStack stack = inv.getStackInSlot(i);
                    if (stack.getItem() instanceof IPressurizable) {
                        chargingItems.add((IPressurizable) stack.getItem());
                        chargedStacks.add(stack);
                    }
                }
            }
        }
    }
    int speedMultiplier = (int) getSpeedMultiplierFromUpgrades();
    for (int i = 0; i < PneumaticValues.CHARGING_STATION_CHARGE_RATE * speedMultiplier; i++) {
        boolean charged = false;
        for (int j = 0; j < chargingItems.size(); j++) {
            IPressurizable chargingItem = chargingItems.get(j);
            ItemStack chargedItem = chargedStacks.get(j);
            if (chargingItem.getPressure(chargedItem) > getPressure() + 0.01F && chargingItem.getPressure(chargedItem) > 0F) {
                if (!getWorld().isRemote) {
                    chargingItem.addAir(chargedItem, -1);
                    addAir(1);
                }
                disCharging = true;
                renderAirProgress -= ANIMATION_AIR_SPEED;
                if (renderAirProgress < 0.0F) {
                    renderAirProgress += 1F;
                }
                charged = true;
            } else if (chargingItem.getPressure(chargedItem) < getPressure() - 0.01F && chargingItem.getPressure(chargedItem) < chargingItem.maxPressure(chargedItem)) {
                // if there is pressure, and the item isn't fully charged yet..
                if (!getWorld().isRemote) {
                    chargingItem.addAir(chargedItem, 1);
                    addAir(-1);
                }
                charging = true;
                renderAirProgress += ANIMATION_AIR_SPEED;
                if (renderAirProgress > 1.0F) {
                    renderAirProgress -= 1F;
                }
                charged = true;
            }
        }
        if (!charged)
            break;
    }
    if (!getWorld().isRemote && oldRedstoneStatus != shouldEmitRedstone()) {
        oldRedstoneStatus = shouldEmitRedstone();
        updateNeighbours();
    }
    super.update();
    if (!getWorld().isRemote) {
        List<Pair<EnumFacing, IAirHandler>> teList = getAirHandler(null).getConnectedPneumatics();
        if (teList.size() == 0)
            getAirHandler(null).airLeak(getRotation());
    }
}
Also used : AxisAlignedBB(net.minecraft.util.math.AxisAlignedBB) IPressurizable(me.desht.pneumaticcraft.api.item.IPressurizable) Entity(net.minecraft.entity.Entity) ArrayList(java.util.ArrayList) InventoryPlayer(net.minecraft.entity.player.InventoryPlayer) EntityPlayer(net.minecraft.entity.player.EntityPlayer) ItemStack(net.minecraft.item.ItemStack) EntityItem(net.minecraft.entity.item.EntityItem) Pair(org.apache.commons.lang3.tuple.Pair)

Example 33 with InventoryPlayer

use of net.minecraft.entity.player.InventoryPlayer in project pnc-repressurized by TeamPneumatic.

the class TileEntityProgrammableController method initializeFakePlayer.

private void initializeFakePlayer() {
    fakePlayer = new DroneFakePlayer((WorldServer) getWorld(), new GameProfile(getOwnerUUID(), ownerName), this);
    fakePlayer.connection = new NetHandlerPlayServer(FMLCommonHandler.instance().getMinecraftServerInstance(), new NetworkManager(EnumPacketDirection.SERVERBOUND), fakePlayer);
    fakePlayer.inventory = new InventoryPlayer(fakePlayer) {

        private ItemStack oldStack = ItemStack.EMPTY;

        @Override
        public int getSizeInventory() {
            return getDroneSlots();
        }

        @Override
        public void setInventorySlotContents(int slot, ItemStack stack) {
            super.setInventorySlotContents(slot, stack);
            if (slot == 0) {
                for (EntityEquipmentSlot ee : EntityEquipmentSlot.values()) {
                    if (!oldStack.isEmpty()) {
                        getFakePlayer().getAttributeMap().removeAttributeModifiers(oldStack.getAttributeModifiers(ee));
                    }
                    if (!stack.isEmpty()) {
                        getFakePlayer().getAttributeMap().applyAttributeModifiers(stack.getAttributeModifiers(ee));
                    }
                }
                oldStack = stack;
            }
        }
    };
}
Also used : InventoryPlayer(net.minecraft.entity.player.InventoryPlayer) EntityEquipmentSlot(net.minecraft.inventory.EntityEquipmentSlot) GameProfile(com.mojang.authlib.GameProfile) WorldServer(net.minecraft.world.WorldServer) DroneFakePlayer(me.desht.pneumaticcraft.common.entity.living.EntityDrone.DroneFakePlayer) NetworkManager(net.minecraft.network.NetworkManager) ItemStack(net.minecraft.item.ItemStack) NetHandlerPlayServer(net.minecraft.network.NetHandlerPlayServer)

Example 34 with InventoryPlayer

use of net.minecraft.entity.player.InventoryPlayer in project pnc-repressurized by TeamPneumatic.

the class ContainerPneumaticBase method slotClickPhantom.

@Nonnull
private ItemStack slotClickPhantom(Slot slot, int dragType, ClickType clickType, EntityPlayer player) {
    ItemStack stack = ItemStack.EMPTY;
    if (clickType == ClickType.CLONE && dragType == 2) {
        // middle-click: clear slot
        if (((IPhantomSlot) slot).canAdjust()) {
            slot.putStack(ItemStack.EMPTY);
        }
    } else if ((clickType == ClickType.PICKUP || clickType == ClickType.QUICK_MOVE) && (dragType == 0 || dragType == 1)) {
        // left or right-click...
        InventoryPlayer playerInv = player.inventory;
        slot.onSlotChanged();
        ItemStack stackSlot = slot.getStack();
        ItemStack stackHeld = playerInv.getItemStack();
        stack = stackSlot.copy();
        if (stackSlot.isEmpty()) {
            if (!stackHeld.isEmpty() && slot.isItemValid(stackHeld)) {
                fillPhantomSlot(slot, stackHeld, clickType, dragType);
            }
        } else if (stackHeld.isEmpty()) {
            adjustPhantomSlot(slot, clickType, dragType);
            slot.onTake(player, playerInv.getItemStack());
        } else if (slot.isItemValid(stackHeld)) {
            if (canStacksMerge(stackSlot, stackHeld)) {
                adjustPhantomSlot(slot, clickType, dragType);
            } else {
                fillPhantomSlot(slot, stackHeld, clickType, dragType);
            }
        }
    }
    return stack;
}
Also used : InventoryPlayer(net.minecraft.entity.player.InventoryPlayer) ItemStack(net.minecraft.item.ItemStack) Nonnull(javax.annotation.Nonnull)

Example 35 with InventoryPlayer

use of net.minecraft.entity.player.InventoryPlayer in project RFToolsDimensions by McJty.

the class RfToolsDimensionManager method checkValidPhasedFieldGenerator.

public static boolean checkValidPhasedFieldGenerator(EntityPlayer player, boolean consume, int tickCost) {
    InventoryPlayer inventory = player.inventory;
    for (int i = 0; i < inventory.getHotbarSize(); i++) {
        ItemStack slot = inventory.getStackInSlot(i);
        if (slot != null && slot.getItem() == ModItems.phasedFieldGeneratorItem) {
            PhasedFieldGeneratorItem pfg = (PhasedFieldGeneratorItem) slot.getItem();
            int energyStored = pfg.getEnergyStored(slot);
            int toConsume;
            if (GeneralConfiguration.enableDynamicPhaseCost) {
                toConsume = (int) (DimensionTickEvent.MAXTICKS * tickCost * GeneralConfiguration.dynamicPhaseCostAmount);
            } else {
                toConsume = DimensionTickEvent.MAXTICKS * PowerConfiguration.PHASEDFIELD_CONSUMEPERTICK;
            }
            if (energyStored >= toConsume) {
                if (consume) {
                    pfg.extractEnergy(slot, toConsume, false);
                }
                return true;
            }
        }
    }
    return false;
}
Also used : InventoryPlayer(net.minecraft.entity.player.InventoryPlayer) ItemStack(net.minecraft.item.ItemStack) PhasedFieldGeneratorItem(mcjty.rftoolsdim.items.PhasedFieldGeneratorItem)

Aggregations

InventoryPlayer (net.minecraft.entity.player.InventoryPlayer)81 ItemStack (net.minecraft.item.ItemStack)56 Slot (net.minecraft.inventory.Slot)15 EntityPlayer (net.minecraft.entity.player.EntityPlayer)14 EntityPlayerMP (net.minecraft.entity.player.EntityPlayerMP)8 Item (net.minecraft.item.Item)6 SubscribeEvent (net.minecraftforge.fml.common.eventhandler.SubscribeEvent)6 ArrayList (java.util.ArrayList)5 Nonnull (javax.annotation.Nonnull)4 IFuzzySlot (logisticspipes.interfaces.IFuzzySlot)4 Button (com.minecolonies.blockout.controls.Button)3 EntityItem (net.minecraft.entity.item.EntityItem)3 AxisAlignedBB (net.minecraft.util.math.AxisAlignedBB)3 IPhantomSlot (buildcraft.lib.gui.slot.IPhantomSlot)2 TileProjectTable (com.bluepowermod.tile.tier1.TileProjectTable)2 ItemIcon (com.minecolonies.blockout.controls.ItemIcon)2 Label (com.minecolonies.blockout.controls.Label)2 BuildingBuilderResource (com.minecolonies.coremod.colony.buildings.utils.BuildingBuilderResource)2 GameProfile (com.mojang.authlib.GameProfile)2 LinkedList (java.util.LinkedList)2