summaryrefslogtreecommitdiff
path: root/src/main/java/jp/plusplus/fbs/pottery/usable/container
diff options
context:
space:
mode:
authorBenjamin Culkin <scorpress@gmail.com>2024-08-24 08:16:37 -0400
committerBenjamin Culkin <scorpress@gmail.com>2024-08-24 08:16:37 -0400
commit70c1354a4a96698758a88c032866288f79de6f5a (patch)
treeeca51294e84b90a4cb3230bc2c7900469e784184 /src/main/java/jp/plusplus/fbs/pottery/usable/container
Initial commitHEADtrunk
Diffstat (limited to 'src/main/java/jp/plusplus/fbs/pottery/usable/container')
-rw-r--r--src/main/java/jp/plusplus/fbs/pottery/usable/container/ContainerPotteryUsableBase.classbin0 -> 3277 bytes
-rw-r--r--src/main/java/jp/plusplus/fbs/pottery/usable/container/ContainerPotteryUsableBase.java95
-rw-r--r--src/main/java/jp/plusplus/fbs/pottery/usable/container/GuiPotteryUsableBase.classbin0 -> 2489 bytes
-rw-r--r--src/main/java/jp/plusplus/fbs/pottery/usable/container/GuiPotteryUsableBase.java40
-rw-r--r--src/main/java/jp/plusplus/fbs/pottery/usable/container/InventoryPotteryUsable$1.classbin0 -> 943 bytes
-rw-r--r--src/main/java/jp/plusplus/fbs/pottery/usable/container/InventoryPotteryUsable.classbin0 -> 6183 bytes
-rw-r--r--src/main/java/jp/plusplus/fbs/pottery/usable/container/InventoryPotteryUsable.java175
-rw-r--r--src/main/java/jp/plusplus/fbs/pottery/usable/container/SlotPotteryUsable.classbin0 -> 1521 bytes
-rw-r--r--src/main/java/jp/plusplus/fbs/pottery/usable/container/SlotPotteryUsable.java27
9 files changed, 337 insertions, 0 deletions
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
--- /dev/null
+++ b/src/main/java/jp/plusplus/fbs/pottery/usable/container/ContainerPotteryUsableBase.class
Binary files 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
--- /dev/null
+++ b/src/main/java/jp/plusplus/fbs/pottery/usable/container/GuiPotteryUsableBase.class
Binary files 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
--- /dev/null
+++ b/src/main/java/jp/plusplus/fbs/pottery/usable/container/InventoryPotteryUsable$1.class
Binary files 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
--- /dev/null
+++ b/src/main/java/jp/plusplus/fbs/pottery/usable/container/InventoryPotteryUsable.class
Binary files 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<inventorySize;i++){
+ itemStacks[i]=potteryEffect.onInventoryOpening(player, potteryStack, i, itemStacks[i]);
+ }
+ }
+
+ @Override
+ public void closeInventory() {
+ //インベントリが閉じるときのの処理
+ for(int i=0;i<inventorySize;i++){
+ itemStacks[i]=potteryEffect.onInventoryClosing(player, potteryStack, i, itemStacks[i]);
+ }
+
+ NBTTagList tagList = new NBTTagList();
+ for (int i = 0; i < itemStacks.length; i++) {
+ if (itemStacks[i] != null) {
+ NBTTagCompound compound = new NBTTagCompound();
+ compound.setByte("Slot", (byte) i);
+ itemStacks[i].writeToNBT(compound);
+ tagList.appendTag(compound);
+ }
+ }
+ ItemStack result = new ItemStack(potteryStack.getItem(), 1, potteryStack.getItemDamage());
+ result.setTagCompound((NBTTagCompound)potteryStack.getTagCompound().copy());
+ result.getTagCompound().setTag(PotteryBase.ITEM_STACKS, tagList);
+
+ player.inventory.mainInventory[potteryStackIndex] = result;
+ }
+
+ @Override
+ public boolean isItemValidForSlot(int p_94041_1_, ItemStack p_94041_2_) {
+ return potteryEffect.isItemValid(player, potteryStack, p_94041_1_, p_94041_2_);
+ }
+}
diff --git a/src/main/java/jp/plusplus/fbs/pottery/usable/container/SlotPotteryUsable.class b/src/main/java/jp/plusplus/fbs/pottery/usable/container/SlotPotteryUsable.class
new file mode 100644
index 0000000..afebc3b
--- /dev/null
+++ b/src/main/java/jp/plusplus/fbs/pottery/usable/container/SlotPotteryUsable.class
Binary files differ
diff --git a/src/main/java/jp/plusplus/fbs/pottery/usable/container/SlotPotteryUsable.java b/src/main/java/jp/plusplus/fbs/pottery/usable/container/SlotPotteryUsable.java
new file mode 100644
index 0000000..099e65b
--- /dev/null
+++ b/src/main/java/jp/plusplus/fbs/pottery/usable/container/SlotPotteryUsable.java
@@ -0,0 +1,27 @@
+package jp.plusplus.fbs.pottery.usable.container;
+
+import net.minecraft.entity.player.EntityPlayer;
+import net.minecraft.inventory.IInventory;
+import net.minecraft.inventory.Slot;
+import net.minecraft.item.ItemStack;
+
+/**
+ * Created by plusplus_F on 2016/03/30.
+ */
+public class SlotPotteryUsable extends Slot {
+ protected InventoryPotteryUsable inventoryPottery;
+ public SlotPotteryUsable(InventoryPotteryUsable iInventory, int index, int x, int y) {
+ super(iInventory, index, x, y);
+ inventoryPottery=iInventory;
+ }
+
+ @Override
+ public boolean isItemValid(ItemStack itemStack) {
+ return inventoryPottery.potteryEffect.isItemValid(inventoryPottery.player, inventoryPottery.potteryStack, getSlotIndex(), itemStack);
+ }
+
+ @Override
+ public boolean canTakeStack(EntityPlayer player) {
+ return inventoryPottery.potteryEffect.canTakeStack(player, inventoryPottery.potteryStack, getSlotIndex(), getStack());
+ }
+}