Added Clipboard
This commit is contained in:
parent
9c6d2e83b3
commit
3c39a54cb6
|
@ -5,12 +5,16 @@ import cpw.mods.fml.common.SidedProxy;
|
||||||
import cpw.mods.fml.common.event.FMLInitializationEvent;
|
import cpw.mods.fml.common.event.FMLInitializationEvent;
|
||||||
import cpw.mods.fml.common.event.FMLPostInitializationEvent;
|
import cpw.mods.fml.common.event.FMLPostInitializationEvent;
|
||||||
import cpw.mods.fml.common.event.FMLPreInitializationEvent;
|
import cpw.mods.fml.common.event.FMLPreInitializationEvent;
|
||||||
|
import cpw.mods.fml.common.network.NetworkRegistry;
|
||||||
|
import cpw.mods.fml.common.network.simpleimpl.SimpleNetworkWrapper;
|
||||||
import cpw.mods.fml.common.registry.EntityRegistry;
|
import cpw.mods.fml.common.registry.EntityRegistry;
|
||||||
|
import cpw.mods.fml.relauncher.Side;
|
||||||
import ley.modding.dartcraft.block.DartBlocks;
|
import ley.modding.dartcraft.block.DartBlocks;
|
||||||
import ley.modding.dartcraft.entity.*;
|
import ley.modding.dartcraft.entity.*;
|
||||||
import ley.modding.dartcraft.event.EventHandler;
|
import ley.modding.dartcraft.event.EventHandler;
|
||||||
import ley.modding.dartcraft.internal.Registry;
|
import ley.modding.dartcraft.internal.Registry;
|
||||||
import ley.modding.dartcraft.item.DartItems;
|
import ley.modding.dartcraft.item.DartItems;
|
||||||
|
import ley.modding.dartcraft.network.PacketClipButton;
|
||||||
import ley.modding.dartcraft.proxy.CommonProxy;
|
import ley.modding.dartcraft.proxy.CommonProxy;
|
||||||
import ley.modding.dartcraft.tab.DartcraftTab;
|
import ley.modding.dartcraft.tab.DartcraftTab;
|
||||||
import ley.modding.tileralib.api.IRegistry;
|
import ley.modding.tileralib.api.IRegistry;
|
||||||
|
@ -29,11 +33,15 @@ public class Dartcraft {
|
||||||
@SidedProxy(serverSide = "ley.modding.dartcraft.proxy.CommonProxy", clientSide = "ley.modding.dartcraft.proxy.ClientProxy")
|
@SidedProxy(serverSide = "ley.modding.dartcraft.proxy.CommonProxy", clientSide = "ley.modding.dartcraft.proxy.ClientProxy")
|
||||||
public static CommonProxy proxy;
|
public static CommonProxy proxy;
|
||||||
|
|
||||||
|
public static SimpleNetworkWrapper channel;
|
||||||
|
|
||||||
public static CreativeTabs tab = new DartcraftTab();
|
public static CreativeTabs tab = new DartcraftTab();
|
||||||
|
|
||||||
@Mod.EventHandler
|
@Mod.EventHandler
|
||||||
public void preInit(FMLPreInitializationEvent e) {
|
public void preInit(FMLPreInitializationEvent e) {
|
||||||
MinecraftForge.EVENT_BUS.register(new EventHandler());
|
MinecraftForge.EVENT_BUS.register(new EventHandler());
|
||||||
|
channel = NetworkRegistry.INSTANCE.newSimpleChannel("Dartcraft");
|
||||||
|
channel.registerMessage(PacketClipButton.Handler.class, PacketClipButton.class, 0, Side.SERVER);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Mod.EventHandler
|
@Mod.EventHandler
|
||||||
|
|
|
@ -0,0 +1,393 @@
|
||||||
|
package ley.modding.dartcraft.client.gui;
|
||||||
|
|
||||||
|
|
||||||
|
import ley.modding.dartcraft.Dartcraft;
|
||||||
|
import ley.modding.dartcraft.item.ItemClipboard;
|
||||||
|
import ley.modding.dartcraft.util.ItemCraftingInventory;
|
||||||
|
import net.minecraft.entity.Entity;
|
||||||
|
import net.minecraft.entity.player.EntityPlayer;
|
||||||
|
import net.minecraft.inventory.*;
|
||||||
|
import net.minecraft.item.ItemStack;
|
||||||
|
import net.minecraft.item.crafting.CraftingManager;
|
||||||
|
import net.minecraft.nbt.NBTTagCompound;
|
||||||
|
import net.minecraftforge.oredict.OreDictionary;
|
||||||
|
|
||||||
|
import java.util.ArrayList;
|
||||||
|
|
||||||
|
public class ContainerClipboard extends Container {
|
||||||
|
public ItemCraftingInventory contents;
|
||||||
|
|
||||||
|
public InventoryCraftResult craftResult = new InventoryCraftResult();
|
||||||
|
|
||||||
|
public ItemStack originStack;
|
||||||
|
|
||||||
|
public IInventory playerInv;
|
||||||
|
|
||||||
|
public EntityPlayer user;
|
||||||
|
|
||||||
|
private boolean hasInitialized;
|
||||||
|
|
||||||
|
private boolean useInventory;
|
||||||
|
|
||||||
|
private ItemStack[] neiBuffer;
|
||||||
|
|
||||||
|
public ContainerClipboard(EntityPlayer player, ItemCraftingInventory inv) {
|
||||||
|
if (player == null)
|
||||||
|
return;
|
||||||
|
if (inv == null || inv.parent == null) {
|
||||||
|
player.closeScreen();
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
this.hasInitialized = false;
|
||||||
|
this.contents = inv;
|
||||||
|
this.user = player;
|
||||||
|
this.playerInv = (IInventory)player.inventory;
|
||||||
|
this.contents.setCraftingListener(this);
|
||||||
|
this.neiBuffer = new ItemStack[9];
|
||||||
|
int i;
|
||||||
|
for (i = 0; i < 3; i++) {
|
||||||
|
for (int j = 0; j < 3; j++)
|
||||||
|
addSlotToContainer(new ClipSlot((IInventory)this.contents, i * 3 + j, 25 + j * 18, 12 + i * 18));
|
||||||
|
}
|
||||||
|
addSlotToContainer((Slot)new ClipSlotCrafting(this.user, (IInventory)this.contents, (IInventory)this.craftResult, 0, 113, 30));
|
||||||
|
for (i = 0; i < 3; i++) {
|
||||||
|
for (int j = 0; j < 9; j++)
|
||||||
|
addSlotToContainer(new Slot(this.playerInv, 9 + i * 9 + j, 8 + 18 * j, 75 + 18 * i));
|
||||||
|
}
|
||||||
|
for (i = 0; i < 9; i++)
|
||||||
|
addSlotToContainer(new Slot(this.playerInv, i, 8 + 18 * i, 133));
|
||||||
|
this.hasInitialized = true;
|
||||||
|
onCraftMatrixChanged((IInventory)this.contents);
|
||||||
|
this.originStack = inv.parent;
|
||||||
|
if (this.originStack == null || !(this.originStack.getItem() instanceof ItemClipboard))
|
||||||
|
player.closeScreen();
|
||||||
|
this.useInventory = this.originStack.getTagCompound().getBoolean("useInventory");
|
||||||
|
canStayOpen(player);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void onCraftMatrixChanged(IInventory inv) {
|
||||||
|
if (!this.hasInitialized)
|
||||||
|
return;
|
||||||
|
this.craftResult.setInventorySlotContents(0, CraftingManager.getInstance().findMatchingRecipe((InventoryCrafting) this.contents, ((Entity)this.user).worldObj));
|
||||||
|
}
|
||||||
|
|
||||||
|
public ItemStack slotClick(int slot, int button, int par3, EntityPlayer player) {
|
||||||
|
save();
|
||||||
|
if (slot < getInventory().size())
|
||||||
|
return super.slotClick(slot, button, par3, player);
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void save() {
|
||||||
|
if (this.user == null)
|
||||||
|
return;
|
||||||
|
ItemStack parent = this.contents.findParent(this.user);
|
||||||
|
if (parent != null) {
|
||||||
|
this.contents.onGuiSaved(this.user);
|
||||||
|
} else {
|
||||||
|
this.user.closeScreen();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public boolean canStayOpen(EntityPlayer player) {
|
||||||
|
return (this.contents.findParent(player) != null);
|
||||||
|
}
|
||||||
|
|
||||||
|
public ItemStack transferStackInSlot(EntityPlayer player, int index) {
|
||||||
|
ItemStack returnStack = null;
|
||||||
|
Slot slot = (Slot) this.inventorySlots.get(index);
|
||||||
|
if (slot != null && slot.getHasStack()) {
|
||||||
|
ItemStack stack = slot.getStack();
|
||||||
|
returnStack = stack.copy();
|
||||||
|
if (index >= 0 && index < 9)
|
||||||
|
if (!mergeItemStack(stack, 10, 46, true))
|
||||||
|
return null;
|
||||||
|
if (index == 9) {
|
||||||
|
int maxCraftable = this.craftResult.getStackInSlot(0).getMaxStackSize() / (this.craftResult.getStackInSlot(0)).stackSize;
|
||||||
|
int i;
|
||||||
|
for (i = 0; i < 9; i++) {
|
||||||
|
ItemStack tempStack = this.contents.getStackInSlot(i);
|
||||||
|
if (tempStack != null && tempStack.stackSize < maxCraftable)
|
||||||
|
maxCraftable = tempStack.stackSize;
|
||||||
|
}
|
||||||
|
for (i = 0; i < maxCraftable; i++) {
|
||||||
|
if (!mergeItemStack(stack.copy(), 10, 46, true))
|
||||||
|
return null;
|
||||||
|
try {
|
||||||
|
slot.onSlotChanged();
|
||||||
|
slot.onPickupFromSlot(player, stack);
|
||||||
|
} catch (Exception e) {}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (index > 9 && index < 46) {
|
||||||
|
if (!isItemValidForSlot(stack))
|
||||||
|
return null;
|
||||||
|
if (!mergeItemStack(stack, 0, 9, false))
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
if (stack.stackSize == 0) {
|
||||||
|
slot.putStack((ItemStack)null);
|
||||||
|
} else {
|
||||||
|
slot.onSlotChanged();
|
||||||
|
}
|
||||||
|
if (stack.stackSize == returnStack.stackSize)
|
||||||
|
return null;
|
||||||
|
slot.onPickupFromSlot(player, stack);
|
||||||
|
}
|
||||||
|
return returnStack;
|
||||||
|
}
|
||||||
|
|
||||||
|
private boolean isItemValidForSlot(ItemStack stack) {
|
||||||
|
boolean isValid = !(stack.getItem() instanceof ItemClipboard);
|
||||||
|
return isValid;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void onContainerClosed(EntityPlayer player) {
|
||||||
|
super.onContainerClosed(player);
|
||||||
|
if (!Dartcraft.proxy.isSimulating(((Entity)player).worldObj))
|
||||||
|
return;
|
||||||
|
this.contents.onGuiSaved(player);
|
||||||
|
}
|
||||||
|
|
||||||
|
protected void retrySlotClick(int par1, int par2, boolean par3, EntityPlayer par4EntityPlayer) {}
|
||||||
|
|
||||||
|
public void grabItems(ItemStack[] items) {
|
||||||
|
if (items == null || items.length != 9 || this.contents == null)
|
||||||
|
return;
|
||||||
|
clearMatrix();
|
||||||
|
int i;
|
||||||
|
for (i = 0; i < this.contents.getSizeInventory(); i++) {
|
||||||
|
ItemStack tempStack = this.contents.getStackInSlot(i);
|
||||||
|
if (tempStack != null)
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
for (i = 0; i < 9; i++) {
|
||||||
|
if (items[i] != null) {
|
||||||
|
boolean found = false;
|
||||||
|
int j;
|
||||||
|
for (j = 0; j < this.user.inventory.mainInventory.length; j++) {
|
||||||
|
if (isItemEquivalent(items[i], this.user.inventory.mainInventory[j])) {
|
||||||
|
this.contents.setInventorySlotContents(i, this.user.inventory.mainInventory[j].copy());
|
||||||
|
this.user.inventory.mainInventory[j] = null;
|
||||||
|
found = true;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (!found)
|
||||||
|
for (j = 0; j < this.contents.getSizeInventory(); j++) {
|
||||||
|
if (j >= i)
|
||||||
|
break;
|
||||||
|
if (isItemEquivalent(items[i], this.contents.getStackInSlot(j)))
|
||||||
|
if ((this.contents.getStackInSlot(j)).stackSize > 1) {
|
||||||
|
this.contents.setInventorySlotContents(i, this.contents.getStackInSlot(j).copy());
|
||||||
|
(this.contents.getStackInSlot(i)).stackSize = 1;
|
||||||
|
(this.contents.getStackInSlot(j)).stackSize--;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
balanceItems();
|
||||||
|
}
|
||||||
|
|
||||||
|
public void balanceItems() {
|
||||||
|
ArrayList<ItemStack> checked = new ArrayList<ItemStack>();
|
||||||
|
for (int i = 0; i < 9; i++) {
|
||||||
|
ItemStack contentAt = this.contents.getStackInSlot(i);
|
||||||
|
if (contentAt != null && contentAt.getMaxStackSize() > 1 &&
|
||||||
|
!containsItem(checked, contentAt)) {
|
||||||
|
checked.add(contentAt.copy());
|
||||||
|
int total = 0;
|
||||||
|
int stacks = 0;
|
||||||
|
for (int j = 0; j < 9; j++) {
|
||||||
|
ItemStack tempStack = this.contents.getStackInSlot(j);
|
||||||
|
if (tempStack != null && areStacksSameItem(tempStack, contentAt)) {
|
||||||
|
total += (this.contents.getStackInSlot(j)).stackSize;
|
||||||
|
stacks++;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
int newAmt = total / stacks;
|
||||||
|
int remainder = total % stacks;
|
||||||
|
for (int k = 0; k < 9; k++) {
|
||||||
|
ItemStack tempStack = this.contents.getStackInSlot(k);
|
||||||
|
if (tempStack != null && areStacksSameItem(tempStack, contentAt)) {
|
||||||
|
tempStack.stackSize = newAmt;
|
||||||
|
if (remainder > 0) {
|
||||||
|
tempStack.stackSize++;
|
||||||
|
remainder--;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public void doDistribute() {
|
||||||
|
ItemStack firstStack = null;
|
||||||
|
ItemStack secondStack = null;
|
||||||
|
int[] iterator = { 0, 1, 2, 5, 8, 7, 6, 3 };
|
||||||
|
int freeSlots = 0;
|
||||||
|
for (int i : iterator) {
|
||||||
|
if (this.contents.getStackInSlot(i) != null && (this.contents.getStackInSlot(i)).stackSize > 1 && this.contents
|
||||||
|
.getStackInSlot(i).getMaxStackSize() > 1)
|
||||||
|
if (firstStack == null) {
|
||||||
|
firstStack = this.contents.getStackInSlot(i);
|
||||||
|
} else if (secondStack == null) {
|
||||||
|
secondStack = this.contents.getStackInSlot(i);
|
||||||
|
}
|
||||||
|
if (this.contents.getStackInSlot(i) == null)
|
||||||
|
freeSlots++;
|
||||||
|
}
|
||||||
|
if (freeSlots == 9)
|
||||||
|
return;
|
||||||
|
boolean turn = true;
|
||||||
|
boolean hasChanged = false;
|
||||||
|
if (freeSlots > 0 && firstStack != null)
|
||||||
|
for (int i : iterator) {
|
||||||
|
if (this.contents.getStackInSlot(i) == null)
|
||||||
|
if (turn) {
|
||||||
|
if (firstStack.stackSize > 1) {
|
||||||
|
this.contents.setInventorySlotContents(i, new ItemStack(firstStack.getItem(), 1, firstStack
|
||||||
|
.getItemDamage()));
|
||||||
|
if (firstStack.hasTagCompound())
|
||||||
|
this.contents.getStackInSlot(i).setTagCompound((NBTTagCompound) firstStack
|
||||||
|
.getTagCompound().copy());
|
||||||
|
firstStack.stackSize--;
|
||||||
|
hasChanged = true;
|
||||||
|
} else if (secondStack != null && secondStack.stackSize > 1) {
|
||||||
|
this.contents.setInventorySlotContents(i, new ItemStack(secondStack.getItem(), 1, secondStack
|
||||||
|
.getItemDamage()));
|
||||||
|
if (secondStack.hasTagCompound())
|
||||||
|
this.contents.getStackInSlot(i).setTagCompound((NBTTagCompound)secondStack
|
||||||
|
.getTagCompound().copy());
|
||||||
|
secondStack.stackSize--;
|
||||||
|
hasChanged = true;
|
||||||
|
}
|
||||||
|
turn = (secondStack == null);
|
||||||
|
} else {
|
||||||
|
if (secondStack.stackSize > 1) {
|
||||||
|
this.contents.setInventorySlotContents(i, new ItemStack(secondStack.getItem(), 1, secondStack
|
||||||
|
.getItemDamage()));
|
||||||
|
if (secondStack.hasTagCompound())
|
||||||
|
this.contents.getStackInSlot(i).setTagCompound((NBTTagCompound)secondStack
|
||||||
|
.getTagCompound().copy());
|
||||||
|
secondStack.stackSize--;
|
||||||
|
hasChanged = true;
|
||||||
|
} else if (firstStack != null && firstStack.stackSize > 1) {
|
||||||
|
this.contents.setInventorySlotContents(i, new ItemStack(firstStack.getItem(), 1, firstStack
|
||||||
|
.getItemDamage()));
|
||||||
|
if (firstStack.hasTagCompound())
|
||||||
|
this.contents.getStackInSlot(i).setTagCompound((NBTTagCompound)firstStack
|
||||||
|
.getTagCompound().copy());
|
||||||
|
firstStack.stackSize--;
|
||||||
|
hasChanged = true;
|
||||||
|
}
|
||||||
|
turn = true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (freeSlots == 0 || !hasChanged) {
|
||||||
|
ArrayList<ItemStack> buffer = new ArrayList<ItemStack>();
|
||||||
|
for (int i : iterator)
|
||||||
|
buffer.add(this.contents.getStackInSlot(i));
|
||||||
|
int index = 0;
|
||||||
|
for (int i : new int[] { 1, 2, 5, 8, 7, 6, 3, 0 }) {
|
||||||
|
this.contents.setInventorySlotContents(i, buffer.get(index));
|
||||||
|
index++;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
balanceItems();
|
||||||
|
}
|
||||||
|
|
||||||
|
private boolean containsItem(ArrayList<ItemStack> list, ItemStack stack) {
|
||||||
|
for (ItemStack check : list) {
|
||||||
|
if (areStacksSameItem(check, stack))
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
private boolean areStacksSameItem(ItemStack stack1, ItemStack stack2) {
|
||||||
|
if (stack1 == null || stack2 == null)
|
||||||
|
return (stack1 == null && stack2 == null);
|
||||||
|
return (stack1.getItem() == stack2.getItem() && stack1.getItemDamage() == stack2
|
||||||
|
.getItemDamage() && ((stack1.hasTagCompound() && stack2.hasTagCompound() &&
|
||||||
|
ItemStack.areItemStackTagsEqual(stack1, stack2)) || (
|
||||||
|
!stack1.hasTagCompound() && !stack2.hasTagCompound())));
|
||||||
|
}
|
||||||
|
|
||||||
|
public void clearMatrix() {
|
||||||
|
if (!canStayOpen(this.user)) {
|
||||||
|
this.user.closeScreen();
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
for (int i = 0; i < 9; i++)
|
||||||
|
transferStackInSlot(this.user, i);
|
||||||
|
}
|
||||||
|
|
||||||
|
public boolean getUseInventory() {
|
||||||
|
return this.useInventory;
|
||||||
|
}
|
||||||
|
|
||||||
|
public boolean canInteractWith(EntityPlayer var1) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
private class ClipSlot extends Slot {
|
||||||
|
int index = 0;
|
||||||
|
|
||||||
|
public ClipSlot(IInventory inv, int index, int x, int y) {
|
||||||
|
super(inv, index, x, y);
|
||||||
|
this.index = index;
|
||||||
|
}
|
||||||
|
|
||||||
|
public boolean isItemValid(ItemStack stack) {
|
||||||
|
if (stack != null)
|
||||||
|
return ContainerClipboard.this.isItemValidForSlot(stack);
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
public boolean canTakeStack(EntityPlayer player) {
|
||||||
|
if (!getHasStack())
|
||||||
|
return true;
|
||||||
|
if (!ContainerClipboard.this.canStayOpen(player))
|
||||||
|
return false;
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void onSlotChanged() {
|
||||||
|
super.onSlotChanged();
|
||||||
|
if (getHasStack() && (getStack()).stackSize <= 0)
|
||||||
|
this.inventory.setInventorySlotContents(this.index, (ItemStack)null);
|
||||||
|
ContainerClipboard.this.save();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private class ClipSlotCrafting extends SlotCrafting {
|
||||||
|
public ClipSlotCrafting(EntityPlayer player, IInventory inv, IInventory inv2, int slot, int x, int y) {
|
||||||
|
super(player, inv, inv2, slot, x, y);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void onSlotChanged() {
|
||||||
|
super.onSlotChanged();
|
||||||
|
ContainerClipboard.this.save();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public static boolean isItemEquivalent(ItemStack first, ItemStack second) {
|
||||||
|
if (OreDictionary.itemMatches(first, second, false))
|
||||||
|
return true;
|
||||||
|
if (first == null || second == null)
|
||||||
|
return false;
|
||||||
|
int firstID = OreDictionary.getOreID(first);
|
||||||
|
if (firstID > 0) {
|
||||||
|
ArrayList<ItemStack> firstOres = OreDictionary.getOres(Integer.valueOf(firstID));
|
||||||
|
if (firstOres != null && firstOres.size() > 0)
|
||||||
|
for (ItemStack tempStack : firstOres) {
|
||||||
|
if (OreDictionary.itemMatches(tempStack, second, false))
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
137
src/main/java/ley/modding/dartcraft/client/gui/GuiClipboard.java
Normal file
137
src/main/java/ley/modding/dartcraft/client/gui/GuiClipboard.java
Normal file
|
@ -0,0 +1,137 @@
|
||||||
|
package ley.modding.dartcraft.client.gui;
|
||||||
|
|
||||||
|
import ley.modding.dartcraft.Dartcraft;
|
||||||
|
import ley.modding.dartcraft.network.DartPacket;
|
||||||
|
import ley.modding.dartcraft.network.PacketClipButton;
|
||||||
|
import net.minecraft.client.gui.GuiScreen;
|
||||||
|
import net.minecraft.client.gui.inventory.GuiContainer;
|
||||||
|
import net.minecraft.client.renderer.entity.RenderItem;
|
||||||
|
import net.minecraft.entity.player.EntityPlayer;
|
||||||
|
import net.minecraft.item.ItemStack;
|
||||||
|
import org.lwjgl.opengl.GL11;
|
||||||
|
|
||||||
|
import java.awt.*;
|
||||||
|
|
||||||
|
public class GuiClipboard extends GuiContainer {
|
||||||
|
public static RenderItem itemRenderer = new RenderItem();
|
||||||
|
|
||||||
|
private int posX;
|
||||||
|
|
||||||
|
private int posY;
|
||||||
|
|
||||||
|
private final int DELAY = 8;
|
||||||
|
|
||||||
|
private ContainerClipboard container;
|
||||||
|
|
||||||
|
private EntityPlayer player;
|
||||||
|
|
||||||
|
private Rectangle distBounds;
|
||||||
|
|
||||||
|
private Rectangle balanceBounds;
|
||||||
|
|
||||||
|
private Rectangle clearBounds;
|
||||||
|
|
||||||
|
private int distRender;
|
||||||
|
|
||||||
|
private int clearRender;
|
||||||
|
|
||||||
|
private int balanceRender;
|
||||||
|
|
||||||
|
private boolean useInventory;
|
||||||
|
|
||||||
|
public GuiClipboard(ContainerClipboard cont) {
|
||||||
|
super(cont);
|
||||||
|
this.container = cont;
|
||||||
|
this.player = cont.user;
|
||||||
|
this.xSize = 176;
|
||||||
|
this.ySize = 156;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void initGui() {
|
||||||
|
super.initGui();
|
||||||
|
this.balanceBounds = new Rectangle(this.guiLeft + 88, this.guiTop + 11, 11, 11);
|
||||||
|
this.distBounds = new Rectangle(this.guiLeft + 81, this.guiTop + 52, 11, 11);
|
||||||
|
this.clearBounds = new Rectangle(this.guiLeft + 95, this.guiTop + 52, 11, 11);
|
||||||
|
this.distRender = this.clearRender = this.balanceRender = 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void updateScreen() {
|
||||||
|
super.updateScreen();
|
||||||
|
if (this.container == null || !this.container.canStayOpen(this.container.user))
|
||||||
|
this.player.closeScreen();
|
||||||
|
}
|
||||||
|
|
||||||
|
protected void mouseClicked(int x, int y, int button) {
|
||||||
|
super.mouseClicked(x, y, button);
|
||||||
|
if (button != 0)
|
||||||
|
return;
|
||||||
|
Point pos = new Point(x, y);
|
||||||
|
if (this.balanceBounds.contains(pos)) {
|
||||||
|
getClass();
|
||||||
|
this.balanceRender = 8;
|
||||||
|
Dartcraft.proxy.sendPacketToServer((DartPacket) new PacketClipButton((EntityPlayer)((GuiScreen)this).mc.thePlayer, 0));
|
||||||
|
this.container.balanceItems();
|
||||||
|
}
|
||||||
|
if (this.distBounds.contains(pos)) {
|
||||||
|
getClass();
|
||||||
|
this.distRender = 8;
|
||||||
|
Dartcraft.proxy.sendPacketToServer((DartPacket)new PacketClipButton((EntityPlayer)((GuiScreen)this).mc.thePlayer, 1));
|
||||||
|
this.container.doDistribute();
|
||||||
|
}
|
||||||
|
if (this.clearBounds.contains(pos)) {
|
||||||
|
getClass();
|
||||||
|
this.clearRender = 8;
|
||||||
|
Dartcraft.proxy.sendPacketToServer((DartPacket)new PacketClipButton((EntityPlayer)((GuiScreen)this).mc.thePlayer, 2));
|
||||||
|
this.container.clearMatrix();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
protected void drawGuiContainerBackgroundLayer(float var1, int var2, int var3) {
|
||||||
|
GL11.glColor4f(1.0F, 1.0F, 1.0F, 1.0F);
|
||||||
|
Dartcraft.proxy.bindTexture("clipGui.png");
|
||||||
|
drawTexturedModalRect(this.guiLeft, this.guiTop, 0, 0, this.xSize, this.ySize);
|
||||||
|
if (this.distRender > 0) {
|
||||||
|
drawTexturedModalRect(this.distBounds.x, this.distBounds.y, 176, 11, 11, 11);
|
||||||
|
this.distRender--;
|
||||||
|
}
|
||||||
|
if (this.balanceRender > 0) {
|
||||||
|
drawTexturedModalRect(this.balanceBounds.x, this.balanceBounds.y, 176, 0, 11, 11);
|
||||||
|
this.balanceRender--;
|
||||||
|
}
|
||||||
|
if (this.clearRender > 0) {
|
||||||
|
drawTexturedModalRect(this.clearBounds.x, this.clearBounds.y, 176, 22, 11, 11);
|
||||||
|
this.clearRender--;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
protected void drawGuiContainerForegroundLayer(int par1, int par2) {
|
||||||
|
GL11.glColor4f(1.0F, 1.0F, 1.0F, 1.0F);
|
||||||
|
fontRendererObj.drawString("Clipboard", 105, 11, 4210752);
|
||||||
|
}
|
||||||
|
|
||||||
|
private void drawSlot(ItemStack stack, int x, int y) {
|
||||||
|
this.zLevel = 50.0F;
|
||||||
|
itemRenderer.renderWithColor = false;
|
||||||
|
float value = 0.8F;
|
||||||
|
GL11.glColor4f(value, value, value, 0.65F);
|
||||||
|
GL11.glEnable(3042);
|
||||||
|
GL11.glDisable(2896);
|
||||||
|
itemRenderer.renderItemIntoGUI(this.fontRendererObj, ((GuiScreen)this).mc.renderEngine, stack, x, y, false);
|
||||||
|
GL11.glDisable(3042);
|
||||||
|
GL11.glColor4f(1.0F, 1.0F, 1.0F, 1.0F);
|
||||||
|
this.zLevel = 0.0F;
|
||||||
|
}
|
||||||
|
|
||||||
|
public boolean handleDragNDrop(GuiContainer gui, int x, int y, ItemStack stack, int button) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
public boolean hideItemPanelSlot(GuiContainer gui, int x, int y, int w, int h) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
public Iterable<Integer> getItemSpawnSlots(GuiContainer gui, ItemStack item) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
|
@ -0,0 +1,63 @@
|
||||||
|
package ley.modding.dartcraft.client.gui;
|
||||||
|
|
||||||
|
import cpw.mods.fml.common.network.IGuiHandler;
|
||||||
|
import ley.modding.dartcraft.item.ItemClipboard;
|
||||||
|
import ley.modding.dartcraft.util.EntityUtils;
|
||||||
|
import ley.modding.dartcraft.util.ItemCraftingInventory;
|
||||||
|
import net.minecraft.entity.Entity;
|
||||||
|
import net.minecraft.entity.player.EntityPlayer;
|
||||||
|
import net.minecraft.item.ItemStack;
|
||||||
|
import net.minecraft.nbt.NBTTagCompound;
|
||||||
|
import net.minecraft.world.World;
|
||||||
|
|
||||||
|
public class GuiHandler implements IGuiHandler {
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Object getServerGuiElement(int ID, EntityPlayer player, World world, int x, int y, int z) {
|
||||||
|
ItemStack clipStack;
|
||||||
|
switch (ID) {
|
||||||
|
case 0:
|
||||||
|
clipStack = getClipboard(player);
|
||||||
|
if (clipStack != null)
|
||||||
|
return new ContainerClipboard(player, new ItemCraftingInventory(9, clipStack));
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Object getClientGuiElement(int ID, EntityPlayer player, World world, int x, int y, int z) {
|
||||||
|
ItemStack clipStack;
|
||||||
|
switch (ID) {
|
||||||
|
case 0:
|
||||||
|
clipStack = getClipboard(player);
|
||||||
|
if (clipStack != null)
|
||||||
|
return new GuiClipboard(new ContainerClipboard(player, new ItemCraftingInventory(9, clipStack)));
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
private ItemStack getClipboard(EntityPlayer player) {
|
||||||
|
NBTTagCompound dartTag = EntityUtils.getModComp((Entity) player);
|
||||||
|
int location = -1;
|
||||||
|
if (dartTag != null)
|
||||||
|
for (int i = 0; i < 9; i++) {
|
||||||
|
ItemStack tempStack = player.inventory.mainInventory[i];
|
||||||
|
if (tempStack != null && tempStack.getItem() instanceof ItemClipboard && tempStack
|
||||||
|
.getTagCompound().getInteger("ID") == dartTag.getInteger("toOpen"))
|
||||||
|
if (location == -1) {
|
||||||
|
location = i;
|
||||||
|
} else {
|
||||||
|
player.inventory.mainInventory[i].getTagCompound().removeTag("ID");
|
||||||
|
dartTag.removeTag("toOpen");
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
dartTag.removeTag("toOpen");
|
||||||
|
if (location > -1)
|
||||||
|
return player.inventory.mainInventory[location];
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
|
@ -18,6 +18,7 @@ public class DartItems {
|
||||||
public static Item forcemitts;
|
public static Item forcemitts;
|
||||||
public static Item forceflask;
|
public static Item forceflask;
|
||||||
public static Item entitybottle;
|
public static Item entitybottle;
|
||||||
|
public static Item clipboard;
|
||||||
|
|
||||||
//Useless Items
|
//Useless Items
|
||||||
public static Item fortune;
|
public static Item fortune;
|
||||||
|
@ -44,6 +45,7 @@ public class DartItems {
|
||||||
DartItems.claw = reg.registerItem(new BaseItem("claw"));
|
DartItems.claw = reg.registerItem(new BaseItem("claw"));
|
||||||
DartItems.goldenpower = reg.registerItem(new BaseItem("goldenpower"));
|
DartItems.goldenpower = reg.registerItem(new BaseItem("goldenpower"));
|
||||||
DartItems.resource = reg.registerItem(new BaseItem("resource"));
|
DartItems.resource = reg.registerItem(new BaseItem("resource"));
|
||||||
|
DartItems.clipboard = reg.registerItem(new ItemClipboard());
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
56
src/main/java/ley/modding/dartcraft/item/ItemClipboard.java
Normal file
56
src/main/java/ley/modding/dartcraft/item/ItemClipboard.java
Normal file
|
@ -0,0 +1,56 @@
|
||||||
|
package ley.modding.dartcraft.item;
|
||||||
|
|
||||||
|
import ley.modding.dartcraft.Dartcraft;
|
||||||
|
import ley.modding.dartcraft.proxy.CommonProxy;
|
||||||
|
import ley.modding.dartcraft.util.EntityUtils;
|
||||||
|
import ley.modding.dartcraft.util.Util;
|
||||||
|
import net.minecraft.entity.Entity;
|
||||||
|
import net.minecraft.entity.player.EntityPlayer;
|
||||||
|
import net.minecraft.item.Item;
|
||||||
|
import net.minecraft.item.ItemStack;
|
||||||
|
import net.minecraft.nbt.NBTBase;
|
||||||
|
import net.minecraft.nbt.NBTTagCompound;
|
||||||
|
import net.minecraft.nbt.NBTTagList;
|
||||||
|
import net.minecraft.world.World;
|
||||||
|
|
||||||
|
|
||||||
|
public class ItemClipboard extends Item {
|
||||||
|
|
||||||
|
public ItemClipboard() {
|
||||||
|
Util.configureItem(this, "clipboard");
|
||||||
|
setMaxStackSize(1);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void onUpdate(ItemStack stack, World world, Entity entity, int par4, boolean par5) {
|
||||||
|
if (stack == null)
|
||||||
|
return;
|
||||||
|
if (!stack.hasTagCompound())
|
||||||
|
initCompound(stack);
|
||||||
|
if (!stack.getTagCompound().hasKey("ID"))
|
||||||
|
stack.getTagCompound().setInteger("ID", CommonProxy.rand.nextInt());
|
||||||
|
}
|
||||||
|
|
||||||
|
private void initCompound(ItemStack stack) {
|
||||||
|
NBTTagCompound comp = new NBTTagCompound();
|
||||||
|
comp.setBoolean("useInventory", false);
|
||||||
|
NBTTagList contents = new NBTTagList();
|
||||||
|
for (int i = 0; i < 9; i++) {
|
||||||
|
NBTTagCompound itemComp = new NBTTagCompound();
|
||||||
|
itemComp.setByte("Slot", (byte)i);
|
||||||
|
contents.appendTag((NBTBase) itemComp);
|
||||||
|
}
|
||||||
|
comp.setTag("contents", (NBTBase)contents);
|
||||||
|
stack.setTagCompound(comp);
|
||||||
|
}
|
||||||
|
|
||||||
|
public ItemStack onItemRightClick(ItemStack stack, World world, EntityPlayer player) {
|
||||||
|
if (stack.hasTagCompound()) {
|
||||||
|
NBTTagCompound dartTag = EntityUtils.getModComp((Entity)player);
|
||||||
|
dartTag.setInteger("toOpen", stack.getTagCompound().getInteger("ID"));
|
||||||
|
if (Dartcraft.proxy.isSimulating(world))
|
||||||
|
player.openGui(Dartcraft.instance, 0, world, (int)((Entity)player).posX, (int)((Entity)player).posY, (int)((Entity)player).posZ);
|
||||||
|
}
|
||||||
|
return stack;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
69
src/main/java/ley/modding/dartcraft/network/DartPacket.java
Normal file
69
src/main/java/ley/modding/dartcraft/network/DartPacket.java
Normal file
|
@ -0,0 +1,69 @@
|
||||||
|
package ley.modding.dartcraft.network;
|
||||||
|
|
||||||
|
import cpw.mods.fml.common.network.NetworkRegistry;
|
||||||
|
import cpw.mods.fml.common.network.simpleimpl.IMessage;
|
||||||
|
import io.netty.buffer.ByteBuf;
|
||||||
|
|
||||||
|
public abstract class DartPacket implements IMessage {
|
||||||
|
protected String receiver;
|
||||||
|
|
||||||
|
protected int dimensionID;
|
||||||
|
|
||||||
|
protected NetworkRegistry.TargetPoint point;
|
||||||
|
|
||||||
|
public abstract boolean getToClient();
|
||||||
|
|
||||||
|
public abstract boolean isDimPacket();
|
||||||
|
|
||||||
|
public int getDimID() {
|
||||||
|
return this.dimensionID;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getReceiver() {
|
||||||
|
return this.receiver;
|
||||||
|
}
|
||||||
|
|
||||||
|
public NetworkRegistry.TargetPoint getLocation() {
|
||||||
|
return this.point;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void fromBytes(ByteBuf buf) {
|
||||||
|
try {
|
||||||
|
if (isDimPacket())
|
||||||
|
this.dimensionID = buf.readByte();
|
||||||
|
int nameSize = buf.readByte();
|
||||||
|
if (nameSize > 0) {
|
||||||
|
this.receiver = "";
|
||||||
|
for (int i = 0; i < nameSize; i++)
|
||||||
|
this.receiver += buf.readChar();
|
||||||
|
}
|
||||||
|
if (buf.readBoolean())
|
||||||
|
this
|
||||||
|
.point = new NetworkRegistry.TargetPoint(buf.readInt(), buf.readDouble(), buf.readDouble(), buf.readDouble(), buf.readDouble());
|
||||||
|
} catch (Exception e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public void toBytes(ByteBuf buf) {
|
||||||
|
if (this.receiver == null)
|
||||||
|
this.receiver = "";
|
||||||
|
try {
|
||||||
|
if (isDimPacket())
|
||||||
|
buf.writeByte(this.dimensionID);
|
||||||
|
buf.writeByte((this.receiver != null) ? this.receiver.length() : 0);
|
||||||
|
for (int i = 0; i < this.receiver.length(); i++)
|
||||||
|
buf.writeChar(this.receiver.charAt(i));
|
||||||
|
buf.writeBoolean((this.point != null));
|
||||||
|
if (this.point != null) {
|
||||||
|
buf.writeInt(this.point.dimension);
|
||||||
|
buf.writeDouble(this.point.x);
|
||||||
|
buf.writeDouble(this.point.y);
|
||||||
|
buf.writeDouble(this.point.z);
|
||||||
|
buf.writeDouble(this.point.range);
|
||||||
|
}
|
||||||
|
} catch (Exception e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
|
@ -0,0 +1,60 @@
|
||||||
|
package ley.modding.dartcraft.network;
|
||||||
|
|
||||||
|
import cpw.mods.fml.common.network.simpleimpl.IMessage;
|
||||||
|
import cpw.mods.fml.common.network.simpleimpl.IMessageHandler;
|
||||||
|
import cpw.mods.fml.common.network.simpleimpl.MessageContext;
|
||||||
|
import io.netty.buffer.ByteBuf;
|
||||||
|
import ley.modding.dartcraft.client.gui.ContainerClipboard;
|
||||||
|
import ley.modding.dartcraft.util.EntityUtils;
|
||||||
|
import net.minecraft.entity.player.EntityPlayer;
|
||||||
|
|
||||||
|
public class PacketClipButton extends DartPacket implements IMessage {
|
||||||
|
protected int button;
|
||||||
|
|
||||||
|
public PacketClipButton() {}
|
||||||
|
|
||||||
|
public PacketClipButton(EntityPlayer player, int button) {
|
||||||
|
this.button = button;
|
||||||
|
this.receiver = player.getCommandSenderName();
|
||||||
|
}
|
||||||
|
|
||||||
|
public boolean getToClient() {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
public boolean isDimPacket() {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void fromBytes(ByteBuf buf) {
|
||||||
|
super.fromBytes(buf);
|
||||||
|
this.button = buf.readByte();
|
||||||
|
}
|
||||||
|
|
||||||
|
public void toBytes(ByteBuf buf) {
|
||||||
|
super.toBytes(buf);
|
||||||
|
buf.writeByte(this.button);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static class Handler implements IMessageHandler<PacketClipButton, IMessage> {
|
||||||
|
public IMessage onMessage(PacketClipButton packet, MessageContext ctx) {
|
||||||
|
EntityPlayer player = EntityUtils.getPlayerByName(packet.getReceiver());
|
||||||
|
if (player != null) {
|
||||||
|
ContainerClipboard clipboard = (player.openContainer != null && player.openContainer instanceof ContainerClipboard) ? (ContainerClipboard)player.openContainer : null;
|
||||||
|
if (clipboard != null)
|
||||||
|
switch (packet.button) {
|
||||||
|
case 0:
|
||||||
|
clipboard.balanceItems();
|
||||||
|
break;
|
||||||
|
case 1:
|
||||||
|
clipboard.doDistribute();
|
||||||
|
break;
|
||||||
|
case 2:
|
||||||
|
clipboard.clearMatrix();
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
|
@ -1,6 +1,7 @@
|
||||||
package ley.modding.dartcraft.proxy;
|
package ley.modding.dartcraft.proxy;
|
||||||
|
|
||||||
import cpw.mods.fml.client.registry.RenderingRegistry;
|
import cpw.mods.fml.client.registry.RenderingRegistry;
|
||||||
|
import cpw.mods.fml.common.network.simpleimpl.IMessage;
|
||||||
import ley.modding.dartcraft.Config;
|
import ley.modding.dartcraft.Config;
|
||||||
import ley.modding.dartcraft.Dartcraft;
|
import ley.modding.dartcraft.Dartcraft;
|
||||||
import ley.modding.dartcraft.client.renderer.block.PowerOreRenderer;
|
import ley.modding.dartcraft.client.renderer.block.PowerOreRenderer;
|
||||||
|
@ -9,6 +10,7 @@ import ley.modding.dartcraft.client.renderer.entity.RenderEntityBottle;
|
||||||
import ley.modding.dartcraft.client.renderer.item.RenderItemForceFlask;
|
import ley.modding.dartcraft.client.renderer.item.RenderItemForceFlask;
|
||||||
import ley.modding.dartcraft.entity.*;
|
import ley.modding.dartcraft.entity.*;
|
||||||
import ley.modding.dartcraft.item.DartItems;
|
import ley.modding.dartcraft.item.DartItems;
|
||||||
|
import ley.modding.dartcraft.network.DartPacket;
|
||||||
import net.minecraft.client.model.ModelChicken;
|
import net.minecraft.client.model.ModelChicken;
|
||||||
import net.minecraft.client.model.ModelCow;
|
import net.minecraft.client.model.ModelCow;
|
||||||
import net.minecraft.client.model.ModelPig;
|
import net.minecraft.client.model.ModelPig;
|
||||||
|
@ -41,4 +43,12 @@ public class ClientProxy extends CommonProxy {
|
||||||
RenderingRegistry.registerBlockHandler(new PowerOreRenderer());
|
RenderingRegistry.registerBlockHandler(new PowerOreRenderer());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void sendPacketToServer(DartPacket packet) {
|
||||||
|
try {
|
||||||
|
Dartcraft.channel.sendToServer((IMessage)packet);
|
||||||
|
} catch (Exception e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,6 +1,10 @@
|
||||||
package ley.modding.dartcraft.proxy;
|
package ley.modding.dartcraft.proxy;
|
||||||
|
|
||||||
import cpw.mods.fml.client.FMLClientHandler;
|
import cpw.mods.fml.client.FMLClientHandler;
|
||||||
|
import cpw.mods.fml.common.network.NetworkRegistry;
|
||||||
|
import ley.modding.dartcraft.Dartcraft;
|
||||||
|
import ley.modding.dartcraft.client.gui.GuiHandler;
|
||||||
|
import ley.modding.dartcraft.network.DartPacket;
|
||||||
import ley.modding.dartcraft.util.ForceUpgradeManager;
|
import ley.modding.dartcraft.util.ForceUpgradeManager;
|
||||||
import net.minecraft.client.Minecraft;
|
import net.minecraft.client.Minecraft;
|
||||||
import net.minecraft.entity.player.EntityPlayer;
|
import net.minecraft.entity.player.EntityPlayer;
|
||||||
|
@ -30,6 +34,9 @@ public class CommonProxy {
|
||||||
|
|
||||||
public void init() {
|
public void init() {
|
||||||
ForceUpgradeManager.load();
|
ForceUpgradeManager.load();
|
||||||
|
NetworkRegistry.INSTANCE.registerGuiHandler(Dartcraft.instance, new GuiHandler());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void sendPacketToServer(DartPacket packet) {}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -5,9 +5,12 @@ import ley.modding.dartcraft.item.DartItems;
|
||||||
import ley.modding.dartcraft.proxy.CommonProxy;
|
import ley.modding.dartcraft.proxy.CommonProxy;
|
||||||
import net.minecraft.entity.Entity;
|
import net.minecraft.entity.Entity;
|
||||||
import net.minecraft.entity.EntityList;
|
import net.minecraft.entity.EntityList;
|
||||||
|
import net.minecraft.entity.player.EntityPlayer;
|
||||||
import net.minecraft.item.ItemStack;
|
import net.minecraft.item.ItemStack;
|
||||||
import net.minecraft.nbt.*;
|
import net.minecraft.nbt.*;
|
||||||
|
import net.minecraft.server.MinecraftServer;
|
||||||
import net.minecraft.world.World;
|
import net.minecraft.world.World;
|
||||||
|
import net.minecraft.world.WorldServer;
|
||||||
|
|
||||||
import java.lang.reflect.Constructor;
|
import java.lang.reflect.Constructor;
|
||||||
|
|
||||||
|
@ -80,5 +83,21 @@ public class EntityUtils {
|
||||||
return CommonProxy.rand.nextFloat() * 0.25F + 0.85F;
|
return CommonProxy.rand.nextFloat() * 0.25F + 0.85F;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static EntityPlayer getPlayerByName(String username) {
|
||||||
|
EntityPlayer player = null;
|
||||||
|
try {
|
||||||
|
WorldServer[] worlds = (MinecraftServer.getServer()).worldServers;
|
||||||
|
for (int i = 0; i < worlds.length; i++) {
|
||||||
|
WorldServer world = worlds[i];
|
||||||
|
if (world != null)
|
||||||
|
player = world.getPlayerEntityByName(username);
|
||||||
|
if (player != null)
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
} catch (Exception e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
}
|
||||||
|
return player;
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -0,0 +1,176 @@
|
||||||
|
package ley.modding.dartcraft.util;
|
||||||
|
|
||||||
|
import net.minecraft.entity.player.EntityPlayer;
|
||||||
|
import net.minecraft.inventory.Container;
|
||||||
|
import net.minecraft.inventory.IInventory;
|
||||||
|
import net.minecraft.inventory.InventoryCrafting;
|
||||||
|
import net.minecraft.item.ItemStack;
|
||||||
|
import net.minecraft.nbt.NBTBase;
|
||||||
|
import net.minecraft.nbt.NBTTagCompound;
|
||||||
|
import net.minecraft.nbt.NBTTagList;
|
||||||
|
|
||||||
|
public class ItemCraftingInventory extends InventoryCrafting implements IInventory {
|
||||||
|
public boolean isItemInventory = false;
|
||||||
|
|
||||||
|
public ItemStack parent;
|
||||||
|
|
||||||
|
protected ItemStack[] contents;
|
||||||
|
|
||||||
|
private Container eventHandler;
|
||||||
|
|
||||||
|
public ItemCraftingInventory(int size) {
|
||||||
|
super(null, 3, 3);
|
||||||
|
this.contents = new ItemStack[size];
|
||||||
|
}
|
||||||
|
|
||||||
|
public ItemCraftingInventory(int size, ItemStack stack) {
|
||||||
|
this(size);
|
||||||
|
this.parent = stack;
|
||||||
|
this.isItemInventory = true;
|
||||||
|
if (stack != null && stack.hasTagCompound())
|
||||||
|
readFromNBT(stack.getTagCompound());
|
||||||
|
}
|
||||||
|
|
||||||
|
public void onGuiSaved(EntityPlayer player) {
|
||||||
|
this.parent = findParent(player);
|
||||||
|
if (this.parent != null)
|
||||||
|
save();
|
||||||
|
}
|
||||||
|
|
||||||
|
public ItemStack findParent(EntityPlayer player) {
|
||||||
|
if (this.parent == null)
|
||||||
|
return null;
|
||||||
|
NBTTagCompound comp = this.parent.getTagCompound();
|
||||||
|
if (comp == null)
|
||||||
|
return null;
|
||||||
|
int id = comp.getInteger("ID");
|
||||||
|
for (int i = 0; i < player.inventory.getSizeInventory(); i++) {
|
||||||
|
if (player.inventory.getStackInSlot(i) != null) {
|
||||||
|
NBTTagCompound playerComp = player.inventory.getStackInSlot(i).getTagCompound();
|
||||||
|
if (playerComp != null)
|
||||||
|
if (id == playerComp.getInteger("ID"))
|
||||||
|
return player.inventory.getStackInSlot(i);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (player.inventory.getItemStack() != null) {
|
||||||
|
NBTTagCompound playerComp = player.inventory.getItemStack().getTagCompound();
|
||||||
|
if (playerComp != null && id == playerComp.getInteger("ID"))
|
||||||
|
return player.inventory.getItemStack();
|
||||||
|
}
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
public boolean matchesID(int secondID) {
|
||||||
|
if (this.parent == null)
|
||||||
|
return false;
|
||||||
|
NBTTagCompound comp = this.parent.getTagCompound();
|
||||||
|
if (comp == null)
|
||||||
|
return false;
|
||||||
|
int id = comp.getInteger("ID");
|
||||||
|
return (id == secondID);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void save() {
|
||||||
|
NBTTagCompound comp = this.parent.getTagCompound();
|
||||||
|
if (comp == null)
|
||||||
|
comp = new NBTTagCompound();
|
||||||
|
writeToNBT(comp);
|
||||||
|
this.parent.setTagCompound(comp);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void readFromNBT(NBTTagCompound comp) {
|
||||||
|
if (comp == null)
|
||||||
|
return;
|
||||||
|
if (comp.hasKey("contents")) {
|
||||||
|
NBTTagList contentList = (NBTTagList)comp.getTag("contents");
|
||||||
|
this.contents = new ItemStack[getSizeInventory()];
|
||||||
|
for (int i = 0; i < contentList.tagCount(); i++) {
|
||||||
|
NBTTagCompound tempComp = contentList.getCompoundTagAt(i);
|
||||||
|
byte slotByte = tempComp.getByte("Slot");
|
||||||
|
if (slotByte >= 0 && slotByte < this.contents.length)
|
||||||
|
this.contents[slotByte] = ItemStack.loadItemStackFromNBT(tempComp);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public void writeToNBT(NBTTagCompound comp) {
|
||||||
|
NBTTagList contentList = new NBTTagList();
|
||||||
|
for (int i = 0; i < this.contents.length; i++) {
|
||||||
|
if (this.contents[i] != null) {
|
||||||
|
NBTTagCompound tempComp = new NBTTagCompound();
|
||||||
|
tempComp.setByte("Slot", (byte)i);
|
||||||
|
this.contents[i].writeToNBT(tempComp);
|
||||||
|
contentList.appendTag((NBTBase)tempComp);
|
||||||
|
}
|
||||||
|
comp.setTag("contents", (NBTBase) contentList);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setCraftingListener(Container container) {
|
||||||
|
this.eventHandler = container;
|
||||||
|
}
|
||||||
|
|
||||||
|
public ItemStack decrStackSize(int i, int j) {
|
||||||
|
if (this.contents == null || this.contents.length <= i || i < 0 || this.contents[i] == null)
|
||||||
|
return null;
|
||||||
|
if ((this.contents[i]).stackSize <= j) {
|
||||||
|
ItemStack itemStack = this.contents[i];
|
||||||
|
this.contents[i] = null;
|
||||||
|
onInventoryChanged();
|
||||||
|
return itemStack;
|
||||||
|
}
|
||||||
|
ItemStack product = this.contents[i].splitStack(j);
|
||||||
|
if ((this.contents[i]).stackSize == 0)
|
||||||
|
this.contents[i] = null;
|
||||||
|
onInventoryChanged();
|
||||||
|
return product;
|
||||||
|
}
|
||||||
|
|
||||||
|
public ItemStack getStackInSlotOnClosing(int slot) {
|
||||||
|
if (this.contents == null || this.contents.length <= slot || slot < 0 || this.contents[slot] == null)
|
||||||
|
return null;
|
||||||
|
ItemStack returnVal = this.contents[slot];
|
||||||
|
this.contents[slot] = null;
|
||||||
|
onInventoryChanged();
|
||||||
|
return returnVal;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setInventorySlotContents(int index, ItemStack stack) {
|
||||||
|
if (this.contents == null || this.contents.length <= index || index < 0)
|
||||||
|
return;
|
||||||
|
this.contents[index] = stack;
|
||||||
|
onInventoryChanged();
|
||||||
|
}
|
||||||
|
|
||||||
|
public ItemStack getStackInSlot(int index) {
|
||||||
|
if (this.contents != null && this.contents.length > index)
|
||||||
|
return this.contents[index];
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
public int getSizeInventory() {
|
||||||
|
return (this.contents != null) ? this.contents.length : 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getInventoryName() {
|
||||||
|
return "inventory.clipboard";
|
||||||
|
}
|
||||||
|
|
||||||
|
public int getInventoryStackLimit() {
|
||||||
|
return 64;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void onInventoryChanged() {
|
||||||
|
if (this.eventHandler != null)
|
||||||
|
this.eventHandler.onCraftMatrixChanged(this);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void openInventory() {}
|
||||||
|
|
||||||
|
public void closeInventory() {}
|
||||||
|
|
||||||
|
public boolean isUseableByPlayer(EntityPlayer player) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
BIN
src/main/resources/assets/dartcraft/clipGui.png
Normal file
BIN
src/main/resources/assets/dartcraft/clipGui.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 10 KiB |
|
@ -11,6 +11,7 @@ item.forceflask_potion_force.name=Liquid Force Flask
|
||||||
item.forceflask_potion_green.name=Green Liquid Flask
|
item.forceflask_potion_green.name=Green Liquid Flask
|
||||||
item.forceflask_potion_blue.name=Blue Liquid Flask
|
item.forceflask_potion_blue.name=Blue Liquid Flask
|
||||||
item.forceflask_potion_red.name=Red Liquid Flask
|
item.forceflask_potion_red.name=Red Liquid Flask
|
||||||
|
item.clipboard.name=Clipboard
|
||||||
tile.powerore.name=Power Ore
|
tile.powerore.name=Power Ore
|
||||||
tile.forcelog.name=Force Log
|
tile.forcelog.name=Force Log
|
||||||
tile.forceleaves.name=Force Leaves
|
tile.forceleaves.name=Force Leaves
|
||||||
|
|
BIN
src/main/resources/assets/dartcraft/textures/items/clipboard.png
Normal file
BIN
src/main/resources/assets/dartcraft/textures/items/clipboard.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 2.9 KiB |
Loading…
Reference in a new issue