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