From 70c1354a4a96698758a88c032866288f79de6f5a Mon Sep 17 00:00:00 2001 From: Benjamin Culkin Date: Sat, 24 Aug 2024 08:16:37 -0400 Subject: Initial commit --- .../container/ContainerPotteryUsableBase.class | Bin 0 -> 3277 bytes .../container/ContainerPotteryUsableBase.java | 95 +++++++++++ .../usable/container/GuiPotteryUsableBase.class | Bin 0 -> 2489 bytes .../usable/container/GuiPotteryUsableBase.java | 40 +++++ .../container/InventoryPotteryUsable$1.class | Bin 0 -> 943 bytes .../usable/container/InventoryPotteryUsable.class | Bin 0 -> 6183 bytes .../usable/container/InventoryPotteryUsable.java | 175 +++++++++++++++++++++ .../usable/container/SlotPotteryUsable.class | Bin 0 -> 1521 bytes .../usable/container/SlotPotteryUsable.java | 27 ++++ 9 files changed, 337 insertions(+) create mode 100644 src/main/java/jp/plusplus/fbs/pottery/usable/container/ContainerPotteryUsableBase.class create mode 100644 src/main/java/jp/plusplus/fbs/pottery/usable/container/ContainerPotteryUsableBase.java create mode 100644 src/main/java/jp/plusplus/fbs/pottery/usable/container/GuiPotteryUsableBase.class create mode 100644 src/main/java/jp/plusplus/fbs/pottery/usable/container/GuiPotteryUsableBase.java create mode 100644 src/main/java/jp/plusplus/fbs/pottery/usable/container/InventoryPotteryUsable$1.class create mode 100644 src/main/java/jp/plusplus/fbs/pottery/usable/container/InventoryPotteryUsable.class create mode 100644 src/main/java/jp/plusplus/fbs/pottery/usable/container/InventoryPotteryUsable.java create mode 100644 src/main/java/jp/plusplus/fbs/pottery/usable/container/SlotPotteryUsable.class create mode 100644 src/main/java/jp/plusplus/fbs/pottery/usable/container/SlotPotteryUsable.java (limited to 'src/main/java/jp/plusplus/fbs/pottery/usable/container') diff --git a/src/main/java/jp/plusplus/fbs/pottery/usable/container/ContainerPotteryUsableBase.class b/src/main/java/jp/plusplus/fbs/pottery/usable/container/ContainerPotteryUsableBase.class new file mode 100644 index 0000000..425e8ea Binary files /dev/null and b/src/main/java/jp/plusplus/fbs/pottery/usable/container/ContainerPotteryUsableBase.class differ diff --git a/src/main/java/jp/plusplus/fbs/pottery/usable/container/ContainerPotteryUsableBase.java b/src/main/java/jp/plusplus/fbs/pottery/usable/container/ContainerPotteryUsableBase.java new file mode 100644 index 0000000..0c679c5 --- /dev/null +++ b/src/main/java/jp/plusplus/fbs/pottery/usable/container/ContainerPotteryUsableBase.java @@ -0,0 +1,95 @@ +package jp.plusplus.fbs.pottery.usable.container; + +import jp.plusplus.fbs.container.slot.SlotShowOnly; +import jp.plusplus.fbs.item.ItemCore; +import net.minecraft.entity.player.EntityPlayer; +import net.minecraft.entity.player.InventoryPlayer; +import net.minecraft.inventory.Container; +import net.minecraft.inventory.ContainerChest; +import net.minecraft.inventory.Slot; +import net.minecraft.item.ItemStack; + +/** + * Created by plusplus_F on 2016/03/30. + */ +public class ContainerPotteryUsableBase extends Container { + public ItemStack currentItem; + public EntityPlayer player; + public InventoryPotteryUsable inventory; + public int inventoryRows; + + public ContainerPotteryUsableBase(EntityPlayer player) { + this.player = player; + currentItem = player.getCurrentEquippedItem(); + inventory = new InventoryPotteryUsable(player); + + //壺のスロット + inventoryRows = (inventory.getSizeInventory() + 8) / 9; + for (int i = 0; i < inventory.getSizeInventory(); i++) { + addSlotToContainer(new SlotPotteryUsable(inventory, i, 8 + (i % 9) * 18, 18 + (i / 9) * 18)); + } + + //player slots + int y = (inventoryRows - 4) * 18; + for (int j = 0; j < 3; ++j) { + for (int k = 0; k < 9; ++k) { + this.addSlotToContainer(new Slot(player.inventory, k + j * 9 + 9, 8 + k * 18, 103 + j * 18 + y)); + } + } + for (int j = 0; j < 9; ++j) { + if (j == inventory.potteryStackIndex) this.addSlotToContainer(new SlotShowOnly(player.inventory, j, 8 + j * 18, 161 + y)); + else this.addSlotToContainer(new Slot(player.inventory, j, 8 + j * 18, 161 + y)); + } + + inventory.openInventory(); + } + + public void onContainerClosed(EntityPlayer p_75134_1_) { + super.onContainerClosed(p_75134_1_); + inventory.closeInventory(); + } + + @Override + public boolean canInteractWith(EntityPlayer p_75145_1_) { + return true; + } + + @Override + public ItemStack transferStackInSlot(EntityPlayer player1, int slotIndex) { + ItemStack itemstack = null; + Slot slot = (Slot) this.inventorySlots.get(slotIndex); + + if (slot != null && slot.getHasStack()) { + ItemStack itemstack1 = slot.getStack(); + itemstack = itemstack1.copy(); + + if(slot.getStack()==null || slotIndex==inventory.potteryStackIndex){ + //スロットがNULLだったり開いてる壺なら何もしない + return null; + } + else if (slotIndex < this.inventory.getSizeInventory()) { + //壺のインベントリ内であれば他所に移す + if (!this.mergeItemStack(itemstack1, this.inventory.getSizeInventory(), this.inventorySlots.size(), true)) { + return null; + } + } + else if(!inventory.isItemValidForSlot(slotIndex, itemstack)){ + //プレイヤーのインベントリにあり、それが壺のインベントリに適さない場合何もしない + return null; + } + else if (!this.mergeItemStack(itemstack1, 0, this.inventory.getSizeInventory(), false)) { + //壺のインベントリに移せるか試してる + return null; + } + + //アイテムの消去と更新処理 + if (itemstack1.stackSize == 0) { + slot.putStack((ItemStack) null); + } else { + slot.onSlotChanged(); + } + } + + return itemstack; + } +} diff --git a/src/main/java/jp/plusplus/fbs/pottery/usable/container/GuiPotteryUsableBase.class b/src/main/java/jp/plusplus/fbs/pottery/usable/container/GuiPotteryUsableBase.class new file mode 100644 index 0000000..23856fb Binary files /dev/null and b/src/main/java/jp/plusplus/fbs/pottery/usable/container/GuiPotteryUsableBase.class differ diff --git a/src/main/java/jp/plusplus/fbs/pottery/usable/container/GuiPotteryUsableBase.java b/src/main/java/jp/plusplus/fbs/pottery/usable/container/GuiPotteryUsableBase.java new file mode 100644 index 0000000..b3c9967 --- /dev/null +++ b/src/main/java/jp/plusplus/fbs/pottery/usable/container/GuiPotteryUsableBase.java @@ -0,0 +1,40 @@ +package jp.plusplus.fbs.pottery.usable.container; + +import net.minecraft.client.gui.inventory.GuiChest; +import net.minecraft.client.gui.inventory.GuiContainer; +import net.minecraft.client.resources.I18n; +import net.minecraft.inventory.Container; +import net.minecraft.util.ResourceLocation; +import org.lwjgl.opengl.GL11; + +/** + * Created by plusplus_F on 2016/03/30. + */ +public class GuiPotteryUsableBase extends GuiContainer { + private static final ResourceLocation field_147017_u = new ResourceLocation("textures/gui/container/generic_54.png"); + private ContainerPotteryUsableBase container; + + public GuiPotteryUsableBase(ContainerPotteryUsableBase p_i1072_1_) { + super(p_i1072_1_); + this.container=p_i1072_1_; + this.allowUserInput = false; + short short1 = 222; + int i = short1 - 108; + this.ySize = i + container.inventoryRows * 18; + } + + @Override + protected void drawGuiContainerForegroundLayer(int p_146979_1_, int p_146979_2_) { + this.fontRendererObj.drawString(container.inventory.getInventoryName(), 8, 6, 4210752); + } + + @Override + protected void drawGuiContainerBackgroundLayer(float p_146976_1_, int p_146976_2_, int p_146976_3_) { + GL11.glColor4f(1.0F, 1.0F, 1.0F, 1.0F); + this.mc.getTextureManager().bindTexture(field_147017_u); + int k = (this.width - this.xSize) / 2; + int l = (this.height - this.ySize) / 2; + this.drawTexturedModalRect(k, l, 0, 0, this.xSize, container.inventoryRows * 18 + 17); + this.drawTexturedModalRect(k, l + container.inventoryRows * 18 + 17, 0, 126, this.xSize, 96); + } +} diff --git a/src/main/java/jp/plusplus/fbs/pottery/usable/container/InventoryPotteryUsable$1.class b/src/main/java/jp/plusplus/fbs/pottery/usable/container/InventoryPotteryUsable$1.class new file mode 100644 index 0000000..18ad90d Binary files /dev/null and b/src/main/java/jp/plusplus/fbs/pottery/usable/container/InventoryPotteryUsable$1.class differ diff --git a/src/main/java/jp/plusplus/fbs/pottery/usable/container/InventoryPotteryUsable.class b/src/main/java/jp/plusplus/fbs/pottery/usable/container/InventoryPotteryUsable.class new file mode 100644 index 0000000..7f289ed Binary files /dev/null and b/src/main/java/jp/plusplus/fbs/pottery/usable/container/InventoryPotteryUsable.class differ diff --git a/src/main/java/jp/plusplus/fbs/pottery/usable/container/InventoryPotteryUsable.java b/src/main/java/jp/plusplus/fbs/pottery/usable/container/InventoryPotteryUsable.java new file mode 100644 index 0000000..ec5ef32 --- /dev/null +++ b/src/main/java/jp/plusplus/fbs/pottery/usable/container/InventoryPotteryUsable.java @@ -0,0 +1,175 @@ +package jp.plusplus.fbs.pottery.usable.container; + +import jp.plusplus.fbs.api.IPottery; +import jp.plusplus.fbs.pottery.ItemBlockPottery; +import jp.plusplus.fbs.pottery.PotteryRegistry; +import jp.plusplus.fbs.pottery.usable.PotteryBase; +import net.minecraft.entity.player.EntityPlayer; +import net.minecraft.inventory.IInventory; +import net.minecraft.item.ItemBlock; +import net.minecraft.item.ItemStack; +import net.minecraft.nbt.NBTTagCompound; +import net.minecraft.nbt.NBTTagList; + +/** + * Created by plusplus_F on 2016/03/30. + * インベントリ持ち魔法の壺のインベントリ + */ +public class InventoryPotteryUsable implements IInventory{ + public EntityPlayer player; + public ItemStack potteryStack; + public int potteryStackIndex; + public PotteryBase potteryEffect; + public IPottery pottery; + + protected ItemStack[] itemStacks; + protected int inventorySize; + + public InventoryPotteryUsable(EntityPlayer player){ + this.player=player; + this.potteryStack=player.getCurrentEquippedItem(); + this.potteryStackIndex=player.inventory.currentItem; + this.potteryEffect= PotteryRegistry.getPotteryEffect(ItemBlockPottery.getId(potteryStack)); + this.pottery=(IPottery)((ItemBlock)potteryStack.getItem()).field_150939_a; + + switch (pottery.getSize(potteryStack.getTagCompound())){ + case MEDIUM: inventorySize=9*2; break; + case LARGE: inventorySize=9*3; break; + default: inventorySize=9*1; break; + } + itemStacks=new ItemStack[inventorySize]; + } + + @Override + public int getSizeInventory() { + return inventorySize; + } + + @Override + public ItemStack getStackInSlot(int p_70301_1_) { + return itemStacks[p_70301_1_]; + } + + @Override + public ItemStack decrStackSize(int i, int size) { + if (this.itemStacks[i] != null) { + ItemStack itemstack; + + if (this.itemStacks[i].stackSize <= size) { + itemstack = this.itemStacks[i]; + this.itemStacks[i] = null; + this.markDirty(); + return itemstack; + } else { + itemstack = this.itemStacks[i].splitStack(size); + + if (this.itemStacks[i].stackSize == 0) { + this.itemStacks[i] = null; + } + + this.markDirty(); + return itemstack; + } + } + return null; + } + + @Override + public ItemStack getStackInSlotOnClosing(int i) { + if (this.itemStacks[i] != null) { + ItemStack itemstack = this.itemStacks[i]; + this.itemStacks[i] = null; + return itemstack; + } + return null; + } + + @Override + public void setInventorySlotContents(int i, ItemStack item) { + this.itemStacks[i] = item; + + if (item != null && item.stackSize > this.getInventoryStackLimit()) { + item.stackSize = this.getInventoryStackLimit(); + } + + this.markDirty(); + } + + @Override + public String getInventoryName() { + return potteryStack.getDisplayName(); + } + + @Override + public boolean hasCustomInventoryName() { + return false; + } + + @Override + public int getInventoryStackLimit() { + return 64; + } + + @Override + public void markDirty() { + + } + + @Override + public boolean isUseableByPlayer(EntityPlayer p_70300_1_) { + return true; + } + + @Override + public void openInventory() { + if (!potteryStack.hasTagCompound()) { + potteryStack.setTagCompound(new NBTTagCompound()); + potteryStack.getTagCompound().setTag(PotteryBase.ITEM_STACKS, new NBTTagList()); + } + else if(!potteryStack.getTagCompound().hasKey(PotteryBase.ITEM_STACKS)){ + potteryStack.getTagCompound().setTag(PotteryBase.ITEM_STACKS, new NBTTagList()); + } + + NBTTagList tags = (NBTTagList) potteryStack.getTagCompound().getTag(PotteryBase.ITEM_STACKS); + for (int i = 0; i < tags.tagCount(); i++) { + NBTTagCompound tagCompound = tags.getCompoundTagAt(i); + int slot = tagCompound.getByte("Slot"); + if (slot >= 0 && slot < itemStacks.length) { + itemStacks[slot] = ItemStack.loadItemStackFromNBT(tagCompound); + } + } + + //インベントリが開くときの処理 + for(int i=0;i