use of net.minecraft.entity.player.InventoryPlayer in project malmo by Microsoft.
the class PlaceCommandsImplementation method onExecute.
@Override
protected boolean onExecute(String verb, String parameter, MissionInit missionInit) {
EntityPlayerSP player = Minecraft.getMinecraft().player;
if (player == null)
return false;
if (!verb.equalsIgnoreCase("place"))
return false;
Item item = Item.getByNameOrId(parameter);
Block block = Block.getBlockFromItem(item);
if (item == null || item.getRegistryName() == null || block.getRegistryName() == null)
return false;
InventoryPlayer inv = player.inventory;
boolean blockInInventory = false;
ItemStack stackInInventory = null;
int stackIndex = -1;
for (int i = 0; !blockInInventory && i < inv.getSizeInventory(); i++) {
Item stack = inv.getStackInSlot(i).getItem();
if (stack.getRegistryName() != null && stack.getRegistryName().equals(item.getRegistryName())) {
stackInInventory = inv.getStackInSlot(i);
stackIndex = i;
blockInInventory = true;
}
}
// We don't have that item in our inventories
if (!blockInInventory)
return false;
RayTraceResult mop = Minecraft.getMinecraft().objectMouseOver;
if (mop.typeOfHit == RayTraceResult.Type.BLOCK) {
BlockPos pos = mop.getBlockPos().add(mop.sideHit.getDirectionVec());
// Can we place this block here?
AxisAlignedBB axisalignedbb = block.getDefaultState().getCollisionBoundingBox(player.world, pos);
if (axisalignedbb == null || player.world.checkNoEntityCollision(axisalignedbb.offset(pos), null)) {
MalmoMod.network.sendToServer(new DiscreteMovementCommandsImplementation.UseActionMessage(mop.getBlockPos(), new ItemStack(block), mop.sideHit, false, mop.hitVec));
if (stackInInventory.getCount() == 1)
inv.setInventorySlotContents(stackIndex, new ItemStack(Block.getBlockById(0)));
else
stackInInventory.setCount(stackInInventory.getCount() - 1);
}
}
return true;
}
use of net.minecraft.entity.player.InventoryPlayer in project MorePlanets by SteveKunG.
the class BlockInfectedVines method onEntityCollision.
@Override
public void onEntityCollision(World world, BlockPos pos, IBlockState state, Entity entity) {
if (entity instanceof EntityLivingBase) {
EntityLivingBase living = (EntityLivingBase) entity;
if (living instanceof EntityPlayer) {
EntityPlayer player = (EntityPlayer) entity;
InventoryPlayer inventory = player.inventory;
for (int i = 0; i < 4; i++) {
if (inventory.armorInventory.get(i).isEmpty() || !(inventory.armorInventory.get(i).getItem() instanceof ItemArmor)) {
if (!player.capabilities.isCreativeMode) {
player.attackEntityFrom(DamageSourceMP.INFECTED_GAS, (int) (4.0D * 0.1D + 1.0D));
player.addPotionEffect(new PotionEffect(MobEffects.POISON, 50, 1));
}
}
}
}
if (!(living instanceof EntityPlayer) && !(entity instanceof ISpaceMob && ((ISpaceMob) entity).getMobType() == EnumMobType.NIBIRU)) {
living.attackEntityFrom(DamageSourceMP.INFECTED_GAS, (int) (4.0D * 0.1D + 1.0D));
living.addPotionEffect(new PotionEffect(MobEffects.POISON, 50, 1));
}
}
}
use of net.minecraft.entity.player.InventoryPlayer in project GregTech by GregTechCE.
the class ElectricStats method onUpdate.
@Override
public void onUpdate(ItemStack itemStack, Entity entity) {
IElectricItem electricItem = itemStack.getCapability(GregtechCapabilities.CAPABILITY_ELECTRIC_ITEM, null);
if (!entity.world.isRemote && entity instanceof EntityPlayer && electricItem != null && electricItem.canProvideChargeExternally() && isInDishargeMode(itemStack) && electricItem.getCharge() > 0L) {
EntityPlayer entityPlayer = (EntityPlayer) entity;
InventoryPlayer inventoryPlayer = entityPlayer.inventory;
long transferLimit = electricItem.getTransferLimit();
for (int i = 0; i < inventoryPlayer.getSizeInventory(); i++) {
ItemStack itemInSlot = inventoryPlayer.getStackInSlot(i);
IElectricItem slotElectricItem = itemInSlot.getCapability(GregtechCapabilities.CAPABILITY_ELECTRIC_ITEM, null);
if (slotElectricItem != null && !slotElectricItem.canProvideChargeExternally()) {
long chargedAmount = chargeElectricItem(transferLimit, electricItem, slotElectricItem);
if (chargedAmount > 0L) {
transferLimit -= chargedAmount;
if (transferLimit == 0L)
break;
}
}
}
}
}
use of net.minecraft.entity.player.InventoryPlayer in project GregTech by GregTechCE.
the class ItemListSlotWidget method setCreativeHeldItem.
private void setCreativeHeldItem(ItemStack itemStack) {
InventoryPlayer inventory = gui.entityPlayer.inventory;
if (!itemStack.isEmpty() && inventory.getItemStack().isEmpty()) {
itemStack.setCount(itemStack.getMaxStackSize());
inventory.setItemStack(itemStack);
}
}
use of net.minecraft.entity.player.InventoryPlayer in project GregTech by GregTechCE.
the class ItemListSlotWidget method extractItemStack.
private void extractItemStack(ItemStackKey itemStackKey, int amount, boolean isClient) {
InventoryPlayer inventory = gui.entityPlayer.inventory;
if (inventory.getItemStack().isEmpty()) {
if (!isClient) {
// on server, we try to extract from the network
IItemList itemList = gridWidget.getItemList();
int amountExtracted = itemList.extractItem(itemStackKey, amount, false);
if (amountExtracted > 0) {
ItemStack resultStack = itemStackKey.getItemStack();
resultStack.setCount(amountExtracted);
inventory.setItemStack(resultStack);
}
uiAccess.sendHeldItemUpdate();
} else {
// on client we assume we can extract as much items as user wishes
ItemStack itemStack = itemStackKey.getItemStack();
itemStack.setCount(amount);
inventory.setItemStack(itemStack);
}
}
}
Aggregations