use of net.minecraft.entity.player.InventoryPlayer in project Minestuck by mraof.
the class ClientEditHandler method onTossEvent.
@SubscribeEvent
public void onTossEvent(ItemTossEvent event) {
if (event.getEntity().world.isRemote && event.getPlayer() == ClientProxy.getClientPlayer() && isActive()) {
InventoryPlayer inventory = event.getPlayer().inventory;
ItemStack stack = event.getEntityItem().getItem();
int ordinal = DeployList.getOrdinal(stack);
if (ordinal >= 0) {
if (!ServerEditHandler.isBlockItem(stack.getItem()) && GristHelper.canAfford(MinestuckPlayerData.getClientGrist(), givenItems[ordinal] ? DeployList.getSecondaryCost(stack) : DeployList.getPrimaryCost(stack)))
givenItems[ordinal] = true;
else
event.setCanceled(true);
}
if (event.isCanceled()) {
if (!inventory.getItemStack().isEmpty())
inventory.setItemStack(ItemStack.EMPTY);
else
inventory.setInventorySlotContents(inventory.currentItem, ItemStack.EMPTY);
event.getEntityItem().setDead();
}
}
}
use of net.minecraft.entity.player.InventoryPlayer in project Minestuck by mraof.
the class ServerEditHandler method onTossEvent.
@SubscribeEvent
public void onTossEvent(ItemTossEvent event) {
InventoryPlayer inventory = event.getPlayer().inventory;
if (!event.getEntity().world.isRemote && getData(event.getPlayer()) != null) {
EditData data = getData(event.getPlayer());
ItemStack stack = event.getEntityItem().getItem();
if (DeployList.containsItemStack(stack) && !isBlockItem(stack.getItem())) {
GristSet cost = data.connection.givenItems()[DeployList.getOrdinal(stack)] ? DeployList.getSecondaryCost(stack) : DeployList.getPrimaryCost(stack);
if (GristHelper.canAfford(MinestuckPlayerData.getGristSet(data.connection.getClientIdentifier()), cost)) {
GristHelper.decrease(data.connection.getClientIdentifier(), cost);
MinestuckPlayerTracker.updateGristCache(data.connection.getClientIdentifier());
data.connection.givenItems()[DeployList.getOrdinal(stack)] = true;
if (!data.connection.isMain())
SkaianetHandler.giveItems(data.connection.getClientIdentifier());
} else
event.setCanceled(true);
} else {
event.setCanceled(true);
}
if (event.isCanceled()) {
event.getEntityItem().setDead();
if (!inventory.getItemStack().isEmpty())
inventory.setItemStack(ItemStack.EMPTY);
else
inventory.setInventorySlotContents(inventory.currentItem, ItemStack.EMPTY);
}
}
}
use of net.minecraft.entity.player.InventoryPlayer in project Minestuck by mraof.
the class EntityDecoy method initInventory.
private void initInventory(EntityPlayerMP player) {
inventory = new InventoryPlayer(this.player);
this.player.inventory = inventory;
if (// Custom inventory class
player.inventory.getClass() != InventoryPlayer.class) {
Class<? extends InventoryPlayer> c = player.inventory.getClass();
try {
Constructor<? extends InventoryPlayer> constructor = c.getConstructor(EntityPlayer.class);
inventory = constructor.newInstance(this.player);
this.player.inventory = inventory;
} catch (Exception e) {
throw new IllegalStateException("The custom inventory class \"" + c.getName() + "\" is not supported.");
}
}
inventory.copyInventory(player.inventory);
}
use of net.minecraft.entity.player.InventoryPlayer in project minecolonies by Minecolonies.
the class WindowWareHouseBuilding method updateResourcePane.
/**
* Update one row pad with its resource informations.
*/
private void updateResourcePane() {
final BuildingBuilderResource resource = new BuildingBuilderResource(new ItemStack(Blocks.EMERALD_BLOCK, 1), 1);
final int amountToSet;
final InventoryPlayer inventory = this.mc.player.inventory;
final boolean isCreative = this.mc.player.capabilities.isCreativeMode;
if (isCreative) {
amountToSet = resource.getAmount();
} else {
amountToSet = InventoryUtils.getItemCountInItemHandler(new InvWrapper(inventory), resource.getItem(), resource.getDamageValue());
}
resource.setPlayerAmount(amountToSet);
final Label resourceLabel = findPaneOfTypeByID(RESOURCE_NAME, Label.class);
final Label resourceMissingLabel = findPaneOfTypeByID(RESOURCE_MISSING, Label.class);
final Label neededLabel = findPaneOfTypeByID(RESOURCE_AVAILABLE_NEEDED, Label.class);
final Button addButton = findPaneOfTypeByID(RESOURCE_ADD, Button.class);
BuildingBuilderResource.RessourceAvailability availability = resource.getAvailabilityStatus();
if (!allowMoreStorageUpgrades) {
availability = BuildingBuilderResource.RessourceAvailability.NOT_NEEDED;
}
switch(availability) {
case DONT_HAVE:
addButton.disable();
resourceLabel.setColor(RED, RED);
resourceMissingLabel.setColor(RED, RED);
neededLabel.setColor(RED, RED);
break;
case NEED_MORE:
addButton.enable();
resourceLabel.setColor(RED, RED);
resourceMissingLabel.setColor(RED, RED);
neededLabel.setColor(RED, RED);
break;
case HAVE_ENOUGH:
addButton.enable();
resourceLabel.setColor(DARKGREEN, DARKGREEN);
resourceMissingLabel.setColor(DARKGREEN, DARKGREEN);
neededLabel.setColor(DARKGREEN, DARKGREEN);
break;
case NOT_NEEDED:
default:
addButton.disable();
resourceLabel.setColor(BLACK, BLACK);
resourceMissingLabel.setColor(BLACK, BLACK);
neededLabel.setColor(BLACK, BLACK);
break;
}
// position the addResource Button to the right
resourceLabel.setLabelText(resource.getName());
final int missing = resource.getMissingFromPlayer();
if (missing < 0) {
resourceMissingLabel.setLabelText(Integer.toString(missing));
} else {
resourceMissingLabel.setLabelText("");
}
neededLabel.setLabelText(Integer.toString(resource.getAvailable()) + " / " + Integer.toString(resource.getAmount()));
findPaneOfTypeByID(RESOURCE_QUANTITY_MISSING, Label.class).setLabelText(Integer.toString(resource.getAmount() - resource.getAvailable()));
findPaneOfTypeByID(RESOURCE_ICON, ItemIcon.class).setItem(new ItemStack(resource.getItem(), 1, resource.getDamageValue()));
}
use of net.minecraft.entity.player.InventoryPlayer in project BetterQuesting by Funwayguy.
the class GuiContainerThemed method drawScreen.
/**
* Draws the screen and all the components in it.
*/
public void drawScreen(int mouseX, int mouseY, float partialTicks) {
super.drawScreen(mouseX, mouseY, partialTicks);
int i = this.guiLeft;
int j = this.guiTop;
this.drawGuiContainerBackgroundLayer(partialTicks, mouseX, mouseY);
GlStateManager.disableRescaleNormal();
RenderHelper.disableStandardItemLighting();
GlStateManager.disableLighting();
GlStateManager.disableDepth();
super.drawScreen(mouseX, mouseY, partialTicks);
RenderHelper.enableGUIStandardItemLighting();
GlStateManager.pushMatrix();
GlStateManager.translate((float) i, (float) j, 0.0F);
GlStateManager.color(1.0F, 1.0F, 1.0F, 1.0F);
GlStateManager.enableRescaleNormal();
this.theSlot = null;
OpenGlHelper.setLightmapTextureCoords(OpenGlHelper.lightmapTexUnit, 240.0F, 240.0F);
GlStateManager.color(1.0F, 1.0F, 1.0F, 1.0F);
for (int i1 = 0; i1 < this.inventorySlots.inventorySlots.size(); ++i1) {
Slot slot = (Slot) this.inventorySlots.inventorySlots.get(i1);
if (slot.isEnabled()) {
this.drawSlot(slot);
}
if (this.isMouseOverSlot(slot, mouseX, mouseY) && slot.isEnabled()) {
this.theSlot = slot;
GlStateManager.disableLighting();
GlStateManager.disableDepth();
int j1 = slot.xPos;
int k1 = slot.yPos;
GlStateManager.colorMask(true, true, true, false);
this.drawGradientRect(j1, k1, j1 + 16, k1 + 16, -2130706433, -2130706433);
GlStateManager.colorMask(true, true, true, true);
GlStateManager.enableLighting();
GlStateManager.enableDepth();
}
}
RenderHelper.disableStandardItemLighting();
this.drawGuiContainerForegroundLayer(mouseX, mouseY);
RenderHelper.enableGUIStandardItemLighting();
InventoryPlayer inventoryplayer = this.mc.player.inventory;
ItemStack itemstack = this.draggedStack.isEmpty() ? inventoryplayer.getItemStack() : this.draggedStack;
if (!itemstack.isEmpty()) {
int k2 = this.draggedStack.isEmpty() ? 8 : 16;
String s = null;
if (!this.draggedStack.isEmpty() && this.isRightMouseClick) {
itemstack = itemstack.copy();
itemstack.setCount(MathHelper.ceil((float) itemstack.getCount() / 2.0F));
} else if (this.dragSplitting && this.dragSplittingSlots.size() > 1) {
itemstack = itemstack.copy();
itemstack.setCount(this.dragSplittingRemnant);
if (itemstack.isEmpty()) {
s = "" + TextFormatting.YELLOW + "0";
}
}
this.drawItemStack(itemstack, mouseX - i - 8, mouseY - j - k2, s);
}
if (!this.returningStack.isEmpty()) {
float f = (float) (Minecraft.getSystemTime() - this.returningStackTime) / 100.0F;
if (f >= 1.0F) {
f = 1.0F;
this.returningStack = ItemStack.EMPTY;
}
int l2 = this.returningStackDestSlot.xPos - this.touchUpX;
int i3 = this.returningStackDestSlot.yPos - this.touchUpY;
int l1 = this.touchUpX + (int) ((float) l2 * f);
int i2 = this.touchUpY + (int) ((float) i3 * f);
this.drawItemStack(this.returningStack, l1, i2, (String) null);
}
GlStateManager.popMatrix();
if (inventoryplayer.getItemStack().isEmpty() && this.theSlot != null && this.theSlot.getHasStack()) {
ItemStack itemstack1 = this.theSlot.getStack();
this.renderToolTip(itemstack1, mouseX, mouseY);
}
GlStateManager.enableLighting();
GlStateManager.enableDepth();
RenderHelper.enableStandardItemLighting();
}
Aggregations