mirror of
https://github.com/GTNewHorizons/Chisel.git
synced 2026-11-25 14:44:35 +00:00
[ci skip] spotlessApply with the new settings
This commit is contained in:
1 parent
a314fccd1b
commit
8f026dad8f
161 files changed
+14073
-12846
No files matched your search
@@ -1,8 +1,5 @@
|
||||
package team.chisel.inventory;
|
||||
|
||||
import team.chisel.block.tileentity.TileEntityAutoChisel;
|
||||
import team.chisel.network.PacketHandler;
|
||||
import team.chisel.network.message.MessageAutoChisel;
|
||||
import net.minecraft.entity.player.EntityPlayer;
|
||||
import net.minecraft.entity.player.InventoryPlayer;
|
||||
import net.minecraft.inventory.Container;
|
||||
@@ -10,191 +7,203 @@ import net.minecraft.inventory.IInventory;
|
||||
import net.minecraft.inventory.Slot;
|
||||
import net.minecraft.item.ItemStack;
|
||||
|
||||
import team.chisel.block.tileentity.TileEntityAutoChisel;
|
||||
import team.chisel.network.PacketHandler;
|
||||
import team.chisel.network.message.MessageAutoChisel;
|
||||
|
||||
public class ContainerAutoChisel extends Container {
|
||||
|
||||
public TileEntityAutoChisel autoChisel;
|
||||
public EntityPlayer player;
|
||||
public TileEntityAutoChisel autoChisel;
|
||||
public EntityPlayer player;
|
||||
|
||||
public ContainerAutoChisel(InventoryPlayer player, TileEntityAutoChisel tileEntityAutoChisel) {
|
||||
public ContainerAutoChisel(InventoryPlayer player, TileEntityAutoChisel tileEntityAutoChisel) {
|
||||
|
||||
this.player = player.player;
|
||||
autoChisel = tileEntityAutoChisel;
|
||||
this.player = player.player;
|
||||
autoChisel = tileEntityAutoChisel;
|
||||
|
||||
addSlot(tileEntityAutoChisel, 0, 53, 15);
|
||||
addSlot(tileEntityAutoChisel, 1, 78, 52);
|
||||
addSlot(tileEntityAutoChisel, 2, 103, 15);
|
||||
addSlot(tileEntityAutoChisel, 3, 8, 62);
|
||||
addSlot(tileEntityAutoChisel, 4, 152, 5);
|
||||
addSlot(tileEntityAutoChisel, 5, 152, 25);
|
||||
addSlot(tileEntityAutoChisel, 6, 152, 45);
|
||||
addSlot(tileEntityAutoChisel, 7, 152, 65);
|
||||
addSlot(tileEntityAutoChisel, 0, 53, 15);
|
||||
addSlot(tileEntityAutoChisel, 1, 78, 52);
|
||||
addSlot(tileEntityAutoChisel, 2, 103, 15);
|
||||
addSlot(tileEntityAutoChisel, 3, 8, 62);
|
||||
addSlot(tileEntityAutoChisel, 4, 152, 5);
|
||||
addSlot(tileEntityAutoChisel, 5, 152, 25);
|
||||
addSlot(tileEntityAutoChisel, 6, 152, 45);
|
||||
addSlot(tileEntityAutoChisel, 7, 152, 65);
|
||||
|
||||
bindPlayerInventory(player);
|
||||
}
|
||||
bindPlayerInventory(player);
|
||||
}
|
||||
|
||||
private void addSlot(IInventory inv, final int id, int x, int y) {
|
||||
addSlotToContainer(new Slot(inv, id, x, y) {
|
||||
private void addSlot(IInventory inv, final int id, int x, int y) {
|
||||
addSlotToContainer(new Slot(inv, id, x, y) {
|
||||
|
||||
@Override
|
||||
public boolean isItemValid(ItemStack arg0) {
|
||||
return inventory.isItemValidForSlot(id, arg0);
|
||||
}
|
||||
});
|
||||
}
|
||||
@Override
|
||||
public boolean isItemValid(ItemStack arg0) {
|
||||
return inventory.isItemValidForSlot(id, arg0);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
protected void bindPlayerInventory(InventoryPlayer invPlayer) {
|
||||
for (int row = 0; row < 3; row++) {
|
||||
for (int column = 0; column < 9; column++) {
|
||||
addSlotToContainer(new Slot(invPlayer, column + row * 9 + 9, 8 + column * 18, 84 + row * 18));
|
||||
}
|
||||
}
|
||||
protected void bindPlayerInventory(InventoryPlayer invPlayer) {
|
||||
for (int row = 0; row < 3; row++) {
|
||||
for (int column = 0; column < 9; column++) {
|
||||
addSlotToContainer(new Slot(invPlayer, column + row * 9 + 9, 8 + column * 18, 84 + row * 18));
|
||||
}
|
||||
}
|
||||
|
||||
for (int slotNumber = 0; slotNumber < 9; slotNumber++) {
|
||||
addSlotToContainer(new Slot(invPlayer, slotNumber, 8 + slotNumber * 18, 142));
|
||||
}
|
||||
}
|
||||
for (int slotNumber = 0; slotNumber < 9; slotNumber++) {
|
||||
addSlotToContainer(new Slot(invPlayer, slotNumber, 8 + slotNumber * 18, 142));
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean canInteractWith(EntityPlayer player) {
|
||||
return autoChisel.isUseableByPlayer(player);
|
||||
}
|
||||
@Override
|
||||
public boolean canInteractWith(EntityPlayer player) {
|
||||
return autoChisel.isUseableByPlayer(player);
|
||||
}
|
||||
|
||||
@Override
|
||||
public ItemStack transferStackInSlot(EntityPlayer player, int slotNumber) {
|
||||
ItemStack itemStack = null;
|
||||
Slot slot = (Slot) this.inventorySlots.get(slotNumber);
|
||||
@Override
|
||||
public ItemStack transferStackInSlot(EntityPlayer player, int slotNumber) {
|
||||
ItemStack itemStack = null;
|
||||
Slot slot = (Slot) this.inventorySlots.get(slotNumber);
|
||||
|
||||
if (slot != null && slot.getHasStack()) {
|
||||
ItemStack itemStack1 = slot.getStack();
|
||||
itemStack = itemStack1.copy();
|
||||
if (slot != null && slot.getHasStack()) {
|
||||
ItemStack itemStack1 = slot.getStack();
|
||||
itemStack = itemStack1.copy();
|
||||
|
||||
// if we are in the auto chisel
|
||||
if (slotNumber <= 7) {
|
||||
if (!this.mergeItemStack(itemStack1, 8, 42, false)) {
|
||||
return null;
|
||||
}
|
||||
// otherwise just put it in one of the machine slots
|
||||
} else if (!this.mergeItemStack(itemStack1, 0, 8, false)) {
|
||||
return null;
|
||||
}
|
||||
// if we are in the auto chisel
|
||||
if (slotNumber <= 7) {
|
||||
if (!this.mergeItemStack(itemStack1, 8, 42, false)) {
|
||||
return null;
|
||||
}
|
||||
// otherwise just put it in one of the machine slots
|
||||
} else if (!this.mergeItemStack(itemStack1, 0, 8, false)) {
|
||||
return null;
|
||||
}
|
||||
|
||||
if (itemStack1.stackSize == 0) {
|
||||
slot.putStack(null);
|
||||
} else {
|
||||
slot.onSlotChanged();
|
||||
}
|
||||
if (itemStack1.stackSize == 0) {
|
||||
slot.putStack(null);
|
||||
} else {
|
||||
slot.onSlotChanged();
|
||||
}
|
||||
|
||||
if (itemStack1.stackSize == itemStack.stackSize) {
|
||||
return null;
|
||||
}
|
||||
if (itemStack1.stackSize == itemStack.stackSize) {
|
||||
return null;
|
||||
}
|
||||
|
||||
slot.onPickupFromSlot(player, itemStack1);
|
||||
}
|
||||
slot.onPickupFromSlot(player, itemStack1);
|
||||
}
|
||||
|
||||
return itemStack;
|
||||
}
|
||||
return itemStack;
|
||||
}
|
||||
|
||||
@Override
|
||||
public ItemStack slotClick(int slotId, int p_75144_2_, int p_75144_3_, EntityPlayer player) {
|
||||
if (slotId >= 0 && slotId < this.inventorySlots.size()) {
|
||||
Slot slot = (Slot) this.inventorySlots.get(slotId);
|
||||
ItemStack stack = slot.getStack();
|
||||
ItemStack ret = super.slotClick(slotId, p_75144_2_, p_75144_3_, player);
|
||||
@Override
|
||||
public ItemStack slotClick(int slotId, int p_75144_2_, int p_75144_3_, EntityPlayer player) {
|
||||
if (slotId >= 0 && slotId < this.inventorySlots.size()) {
|
||||
Slot slot = (Slot) this.inventorySlots.get(slotId);
|
||||
ItemStack stack = slot.getStack();
|
||||
ItemStack ret = super.slotClick(slotId, p_75144_2_, p_75144_3_, player);
|
||||
|
||||
if (!player.worldObj.isRemote && slot.slotNumber == TileEntityAutoChisel.BASE && !ItemStack.areItemStacksEqual(stack, slot.getStack())) {
|
||||
int chiseled = stack == null ? 0 : slot.getStack() == null ? stack.stackSize : stack.stackSize - slot.getStack().stackSize;
|
||||
PacketHandler.INSTANCE.sendToDimension(new MessageAutoChisel(autoChisel, chiseled, false, false), player.worldObj.provider.dimensionId);
|
||||
}
|
||||
if (!player.worldObj.isRemote && slot.slotNumber == TileEntityAutoChisel.BASE
|
||||
&& !ItemStack.areItemStacksEqual(stack, slot.getStack())) {
|
||||
int chiseled = stack == null ? 0
|
||||
: slot.getStack() == null ? stack.stackSize : stack.stackSize - slot.getStack().stackSize;
|
||||
PacketHandler.INSTANCE.sendToDimension(
|
||||
new MessageAutoChisel(autoChisel, chiseled, false, false),
|
||||
player.worldObj.provider.dimensionId);
|
||||
}
|
||||
|
||||
return ret;
|
||||
}
|
||||
return super.slotClick(slotId, p_75144_2_, p_75144_3_, player);
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
return super.slotClick(slotId, p_75144_2_, p_75144_3_, player);
|
||||
}
|
||||
|
||||
/**
|
||||
* Added validation of slot input
|
||||
*
|
||||
* @author CrazyPants
|
||||
*/
|
||||
@Override
|
||||
protected boolean mergeItemStack(ItemStack par1ItemStack, int fromIndex, int toIndex, boolean reversOrder) {
|
||||
/**
|
||||
* Added validation of slot input
|
||||
*
|
||||
* @author CrazyPants
|
||||
*/
|
||||
@Override
|
||||
protected boolean mergeItemStack(ItemStack par1ItemStack, int fromIndex, int toIndex, boolean reversOrder) {
|
||||
|
||||
boolean result = false;
|
||||
int checkIndex = fromIndex;
|
||||
boolean result = false;
|
||||
int checkIndex = fromIndex;
|
||||
|
||||
if (reversOrder) {
|
||||
checkIndex = toIndex - 1;
|
||||
}
|
||||
if (reversOrder) {
|
||||
checkIndex = toIndex - 1;
|
||||
}
|
||||
|
||||
Slot slot;
|
||||
ItemStack itemstack1;
|
||||
Slot slot;
|
||||
ItemStack itemstack1;
|
||||
|
||||
if (par1ItemStack.isStackable()) {
|
||||
if (par1ItemStack.isStackable()) {
|
||||
|
||||
while (par1ItemStack.stackSize > 0 && (!reversOrder && checkIndex < toIndex || reversOrder && checkIndex >= fromIndex)) {
|
||||
slot = (Slot) this.inventorySlots.get(checkIndex);
|
||||
itemstack1 = slot.getStack();
|
||||
while (par1ItemStack.stackSize > 0
|
||||
&& (!reversOrder && checkIndex < toIndex || reversOrder && checkIndex >= fromIndex)) {
|
||||
slot = (Slot) this.inventorySlots.get(checkIndex);
|
||||
itemstack1 = slot.getStack();
|
||||
|
||||
if (itemstack1 != null && itemstack1.getItem() == par1ItemStack.getItem() && (!par1ItemStack.getHasSubtypes() || par1ItemStack.getItemDamage() == itemstack1.getItemDamage())
|
||||
&& ItemStack.areItemStackTagsEqual(par1ItemStack, itemstack1) && slot.isItemValid(par1ItemStack)) {
|
||||
if (itemstack1 != null && itemstack1.getItem() == par1ItemStack.getItem()
|
||||
&& (!par1ItemStack.getHasSubtypes()
|
||||
|| par1ItemStack.getItemDamage() == itemstack1.getItemDamage())
|
||||
&& ItemStack.areItemStackTagsEqual(par1ItemStack, itemstack1)
|
||||
&& slot.isItemValid(par1ItemStack)) {
|
||||
|
||||
int mergedSize = itemstack1.stackSize + par1ItemStack.stackSize;
|
||||
int maxStackSize = Math.min(par1ItemStack.getMaxStackSize(), slot.getSlotStackLimit());
|
||||
if (mergedSize <= maxStackSize) {
|
||||
par1ItemStack.stackSize = 0;
|
||||
itemstack1.stackSize = mergedSize;
|
||||
slot.onSlotChanged();
|
||||
result = true;
|
||||
} else if (itemstack1.stackSize < maxStackSize) {
|
||||
par1ItemStack.stackSize -= maxStackSize - itemstack1.stackSize;
|
||||
itemstack1.stackSize = maxStackSize;
|
||||
slot.onSlotChanged();
|
||||
result = true;
|
||||
}
|
||||
}
|
||||
int mergedSize = itemstack1.stackSize + par1ItemStack.stackSize;
|
||||
int maxStackSize = Math.min(par1ItemStack.getMaxStackSize(), slot.getSlotStackLimit());
|
||||
if (mergedSize <= maxStackSize) {
|
||||
par1ItemStack.stackSize = 0;
|
||||
itemstack1.stackSize = mergedSize;
|
||||
slot.onSlotChanged();
|
||||
result = true;
|
||||
} else if (itemstack1.stackSize < maxStackSize) {
|
||||
par1ItemStack.stackSize -= maxStackSize - itemstack1.stackSize;
|
||||
itemstack1.stackSize = maxStackSize;
|
||||
slot.onSlotChanged();
|
||||
result = true;
|
||||
}
|
||||
}
|
||||
|
||||
if (reversOrder) {
|
||||
--checkIndex;
|
||||
} else {
|
||||
++checkIndex;
|
||||
}
|
||||
}
|
||||
}
|
||||
if (reversOrder) {
|
||||
--checkIndex;
|
||||
} else {
|
||||
++checkIndex;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (par1ItemStack.stackSize > 0) {
|
||||
if (reversOrder) {
|
||||
checkIndex = toIndex - 1;
|
||||
} else {
|
||||
checkIndex = fromIndex;
|
||||
}
|
||||
if (par1ItemStack.stackSize > 0) {
|
||||
if (reversOrder) {
|
||||
checkIndex = toIndex - 1;
|
||||
} else {
|
||||
checkIndex = fromIndex;
|
||||
}
|
||||
|
||||
while (!reversOrder && checkIndex < toIndex || reversOrder && checkIndex >= fromIndex) {
|
||||
slot = (Slot) this.inventorySlots.get(checkIndex);
|
||||
itemstack1 = slot.getStack();
|
||||
while (!reversOrder && checkIndex < toIndex || reversOrder && checkIndex >= fromIndex) {
|
||||
slot = (Slot) this.inventorySlots.get(checkIndex);
|
||||
itemstack1 = slot.getStack();
|
||||
|
||||
if (itemstack1 == null && slot.isItemValid(par1ItemStack)) {
|
||||
ItemStack in = par1ItemStack.copy();
|
||||
in.stackSize = Math.min(in.stackSize, slot.getSlotStackLimit());
|
||||
if (itemstack1 == null && slot.isItemValid(par1ItemStack)) {
|
||||
ItemStack in = par1ItemStack.copy();
|
||||
in.stackSize = Math.min(in.stackSize, slot.getSlotStackLimit());
|
||||
|
||||
slot.putStack(in);
|
||||
slot.onSlotChanged();
|
||||
if (in.stackSize >= par1ItemStack.stackSize) {
|
||||
par1ItemStack.stackSize = 0;
|
||||
} else {
|
||||
par1ItemStack.stackSize -= in.stackSize;
|
||||
}
|
||||
result = true;
|
||||
break;
|
||||
}
|
||||
slot.putStack(in);
|
||||
slot.onSlotChanged();
|
||||
if (in.stackSize >= par1ItemStack.stackSize) {
|
||||
par1ItemStack.stackSize = 0;
|
||||
} else {
|
||||
par1ItemStack.stackSize -= in.stackSize;
|
||||
}
|
||||
result = true;
|
||||
break;
|
||||
}
|
||||
|
||||
if (reversOrder) {
|
||||
--checkIndex;
|
||||
} else {
|
||||
++checkIndex;
|
||||
}
|
||||
}
|
||||
}
|
||||
if (reversOrder) {
|
||||
--checkIndex;
|
||||
} else {
|
||||
++checkIndex;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
return result;
|
||||
}
|
||||
}
|
||||
@@ -1,156 +1,170 @@
|
||||
package team.chisel.inventory;
|
||||
|
||||
import com.cricketcraft.chisel.api.carving.ICarvingRegistry;
|
||||
import net.minecraft.entity.player.EntityPlayer;
|
||||
import net.minecraft.entity.player.InventoryPlayer;
|
||||
import net.minecraft.inventory.Container;
|
||||
import net.minecraft.inventory.Slot;
|
||||
import net.minecraft.item.Item;
|
||||
import net.minecraft.item.ItemStack;
|
||||
|
||||
import team.chisel.carving.Carving;
|
||||
import team.chisel.item.chisel.ItemChisel;
|
||||
import team.chisel.utils.General;
|
||||
|
||||
import com.cricketcraft.chisel.api.carving.ICarvingRegistry;
|
||||
|
||||
public class ContainerChisel extends Container {
|
||||
|
||||
public final InventoryChiselSelection inventory;
|
||||
public InventoryPlayer playerInventory;
|
||||
int chiselSlot;
|
||||
public ItemStack chisel;
|
||||
public boolean finished;
|
||||
public ICarvingRegistry carving;
|
||||
public final InventoryChiselSelection inventory;
|
||||
public InventoryPlayer playerInventory;
|
||||
int chiselSlot;
|
||||
public ItemStack chisel;
|
||||
public boolean finished;
|
||||
public ICarvingRegistry carving;
|
||||
|
||||
public ContainerChisel(InventoryPlayer inventoryplayer, InventoryChiselSelection inv) {
|
||||
inventory = inv;
|
||||
playerInventory = inventoryplayer;
|
||||
chiselSlot = playerInventory.currentItem;
|
||||
inv.container = this;
|
||||
public ContainerChisel(InventoryPlayer inventoryplayer, InventoryChiselSelection inv) {
|
||||
inventory = inv;
|
||||
playerInventory = inventoryplayer;
|
||||
chiselSlot = playerInventory.currentItem;
|
||||
inv.container = this;
|
||||
|
||||
int top = 8, left = 62;
|
||||
int top = 8, left = 62;
|
||||
|
||||
// selection slots
|
||||
for (int i = 0; i < InventoryChiselSelection.normalSlots; i++) {
|
||||
addSlotToContainer(new SlotChiselSelection(this, inventory, inventory, i, left + ((i % 10) * 18), top + ((i / 10) * 18)));
|
||||
}
|
||||
// selection slots
|
||||
for (int i = 0; i < InventoryChiselSelection.normalSlots; i++) {
|
||||
addSlotToContainer(
|
||||
new SlotChiselSelection(
|
||||
this,
|
||||
inventory,
|
||||
inventory,
|
||||
i,
|
||||
left + ((i % 10) * 18),
|
||||
top + ((i / 10) * 18)));
|
||||
}
|
||||
|
||||
// main slot
|
||||
addSlotToContainer(new SlotChiselInput(this, inventory, InventoryChiselSelection.normalSlots, 24, 24));
|
||||
// main slot
|
||||
addSlotToContainer(new SlotChiselInput(this, inventory, InventoryChiselSelection.normalSlots, 24, 24));
|
||||
|
||||
top += 112;
|
||||
left += 9;
|
||||
// main inv
|
||||
for (int i = 0; i < 27; i++) {
|
||||
addSlotToContainer(new Slot(inventoryplayer, i + 9, left + ((i % 9) * 18), top + (i / 9) * 18));
|
||||
}
|
||||
top += 112;
|
||||
left += 9;
|
||||
// main inv
|
||||
for (int i = 0; i < 27; i++) {
|
||||
addSlotToContainer(new Slot(inventoryplayer, i + 9, left + ((i % 9) * 18), top + (i / 9) * 18));
|
||||
}
|
||||
|
||||
top += 58;
|
||||
for (int i = 0; i < 9; i++) {
|
||||
addSlotToContainer(new Slot(inventoryplayer, i, left + ((i % 9) * 18), top + (i / 9) * 18));
|
||||
}
|
||||
top += 58;
|
||||
for (int i = 0; i < 9; i++) {
|
||||
addSlotToContainer(new Slot(inventoryplayer, i, left + ((i % 9) * 18), top + (i / 9) * 18));
|
||||
}
|
||||
|
||||
chisel = inventoryplayer.getCurrentItem();
|
||||
if (chisel != null && chisel.stackTagCompound != null) {
|
||||
ItemStack stack = ItemStack.loadItemStackFromNBT(chisel.stackTagCompound.getCompoundTag("chiselTarget"));
|
||||
inventory.setInventorySlotContents(InventoryChiselSelection.normalSlots, stack);
|
||||
}
|
||||
chisel = inventoryplayer.getCurrentItem();
|
||||
if (chisel != null && chisel.stackTagCompound != null) {
|
||||
ItemStack stack = ItemStack.loadItemStackFromNBT(chisel.stackTagCompound.getCompoundTag("chiselTarget"));
|
||||
inventory.setInventorySlotContents(InventoryChiselSelection.normalSlots, stack);
|
||||
}
|
||||
|
||||
Item item = General.getItem(chisel);
|
||||
carving = item instanceof ItemChisel ? ItemChisel.carving : Carving.chisel;
|
||||
Item item = General.getItem(chisel);
|
||||
carving = item instanceof ItemChisel ? ItemChisel.carving : Carving.chisel;
|
||||
|
||||
inventory.updateItems();
|
||||
}
|
||||
inventory.updateItems();
|
||||
}
|
||||
|
||||
@Override
|
||||
public ItemStack slotClick(int par1, int par2, int par3, EntityPlayer par4EntityPlayer) {
|
||||
// we need to subtract away all the other slots
|
||||
int clickedSlot = par1 - inventory.getSizeInventory() - 27;
|
||||
@Override
|
||||
public ItemStack slotClick(int par1, int par2, int par3, EntityPlayer par4EntityPlayer) {
|
||||
// we need to subtract away all the other slots
|
||||
int clickedSlot = par1 - inventory.getSizeInventory() - 27;
|
||||
|
||||
// if the player has clicked on the chisel or is trying to use a number key to force an itemstack into the slot the chisel is in
|
||||
if (clickedSlot == chiselSlot || (par3 == 2 && par2 == chiselSlot))
|
||||
return null;
|
||||
// if the player has clicked on the chisel or is trying to use a number key to force an itemstack into the slot
|
||||
// the chisel is in
|
||||
if (clickedSlot == chiselSlot || (par3 == 2 && par2 == chiselSlot)) return null;
|
||||
|
||||
return super.slotClick(par1, par2, par3, par4EntityPlayer);
|
||||
}
|
||||
return super.slotClick(par1, par2, par3, par4EntityPlayer);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onContainerClosed(EntityPlayer entityplayer) {
|
||||
inventory.clearItems();
|
||||
super.onContainerClosed(entityplayer);
|
||||
}
|
||||
@Override
|
||||
public void onContainerClosed(EntityPlayer entityplayer) {
|
||||
inventory.clearItems();
|
||||
super.onContainerClosed(entityplayer);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean canInteractWith(EntityPlayer entityplayer) {
|
||||
return inventory.isUseableByPlayer(entityplayer);
|
||||
}
|
||||
@Override
|
||||
public boolean canInteractWith(EntityPlayer entityplayer) {
|
||||
return inventory.isUseableByPlayer(entityplayer);
|
||||
}
|
||||
|
||||
@Override
|
||||
public ItemStack transferStackInSlot(EntityPlayer entity, int slotIdx) {
|
||||
ItemStack itemstack = null;
|
||||
Slot slot = (Slot) this.inventorySlots.get(slotIdx);
|
||||
@Override
|
||||
public ItemStack transferStackInSlot(EntityPlayer entity, int slotIdx) {
|
||||
ItemStack itemstack = null;
|
||||
Slot slot = (Slot) this.inventorySlots.get(slotIdx);
|
||||
|
||||
if (slot != null && slot.getHasStack()) {
|
||||
ItemStack itemstack1 = slot.getStack();
|
||||
itemstack = itemstack1.copy();
|
||||
if (slot != null && slot.getHasStack()) {
|
||||
ItemStack itemstack1 = slot.getStack();
|
||||
itemstack = itemstack1.copy();
|
||||
|
||||
if (slotIdx > InventoryChiselSelection.normalSlots) {
|
||||
if (!this.mergeItemStack(itemstack1, InventoryChiselSelection.normalSlots, InventoryChiselSelection.normalSlots + 1, false)) {
|
||||
return null;
|
||||
}
|
||||
} else {
|
||||
entity.inventory.setItemStack(itemstack1.copy());
|
||||
slot.onPickupFromSlot(entity, itemstack1);
|
||||
itemstack1 = entity.inventory.getItemStack();
|
||||
entity.inventory.setItemStack(null);
|
||||
if (slotIdx > InventoryChiselSelection.normalSlots) {
|
||||
if (!this.mergeItemStack(
|
||||
itemstack1,
|
||||
InventoryChiselSelection.normalSlots,
|
||||
InventoryChiselSelection.normalSlots + 1,
|
||||
false)) {
|
||||
return null;
|
||||
}
|
||||
} else {
|
||||
entity.inventory.setItemStack(itemstack1.copy());
|
||||
slot.onPickupFromSlot(entity, itemstack1);
|
||||
itemstack1 = entity.inventory.getItemStack();
|
||||
entity.inventory.setItemStack(null);
|
||||
|
||||
if (!this.mergeItemStack(itemstack1, InventoryChiselSelection.normalSlots + 1, InventoryChiselSelection.normalSlots + 1 + 36, false)) {
|
||||
if (!this.mergeItemStack(
|
||||
itemstack1,
|
||||
InventoryChiselSelection.normalSlots + 1,
|
||||
InventoryChiselSelection.normalSlots + 1 + 36,
|
||||
false)) {
|
||||
entity.inventory.setItemStack(itemstack1);
|
||||
return null;
|
||||
}
|
||||
}
|
||||
slot.onSlotChange(itemstack1, itemstack);
|
||||
return null;
|
||||
}
|
||||
}
|
||||
slot.onSlotChange(itemstack1, itemstack);
|
||||
|
||||
if (itemstack1.stackSize == 0) {
|
||||
slot.putStack(null);
|
||||
} else {
|
||||
slot.putStack(itemstack1);
|
||||
slot.onSlotChanged();
|
||||
}
|
||||
if (itemstack1.stackSize == itemstack.stackSize) {
|
||||
return null;
|
||||
}
|
||||
if (slotIdx >= InventoryChiselSelection.normalSlots) {
|
||||
slot.onPickupFromSlot(entity, itemstack1);
|
||||
}
|
||||
if (itemstack1.stackSize == 0) {
|
||||
slot.putStack(null);
|
||||
return null;
|
||||
}
|
||||
}
|
||||
return itemstack;
|
||||
}
|
||||
if (itemstack1.stackSize == 0) {
|
||||
slot.putStack(null);
|
||||
} else {
|
||||
slot.putStack(itemstack1);
|
||||
slot.onSlotChanged();
|
||||
}
|
||||
if (itemstack1.stackSize == itemstack.stackSize) {
|
||||
return null;
|
||||
}
|
||||
if (slotIdx >= InventoryChiselSelection.normalSlots) {
|
||||
slot.onPickupFromSlot(entity, itemstack1);
|
||||
}
|
||||
if (itemstack1.stackSize == 0) {
|
||||
slot.putStack(null);
|
||||
return null;
|
||||
}
|
||||
}
|
||||
return itemstack;
|
||||
}
|
||||
|
||||
/**
|
||||
* Added validation of slot input
|
||||
* Only Chiselable allowed
|
||||
*
|
||||
* @author Léa Gris
|
||||
*/
|
||||
@Override
|
||||
protected boolean mergeItemStack(ItemStack par1ItemStack, int fromIndex, int toIndex, boolean reversOrder) {
|
||||
return ((Slot) this.inventorySlots.get(reversOrder ? toIndex - 1 : fromIndex)).isItemValid(par1ItemStack)
|
||||
&& super.mergeItemStack(par1ItemStack, fromIndex, toIndex, reversOrder);
|
||||
}
|
||||
/**
|
||||
* Added validation of slot input Only Chiselable allowed
|
||||
*
|
||||
* @author Léa Gris
|
||||
*/
|
||||
@Override
|
||||
protected boolean mergeItemStack(ItemStack par1ItemStack, int fromIndex, int toIndex, boolean reversOrder) {
|
||||
return ((Slot) this.inventorySlots.get(reversOrder ? toIndex - 1 : fromIndex)).isItemValid(par1ItemStack)
|
||||
&& super.mergeItemStack(par1ItemStack, fromIndex, toIndex, reversOrder);
|
||||
}
|
||||
|
||||
public void onChiselSlotChanged() {
|
||||
ItemStack stack = playerInventory.mainInventory[chiselSlot];
|
||||
if (stack == null || !stack.isItemEqual(chisel))
|
||||
finished = true;
|
||||
public void onChiselSlotChanged() {
|
||||
ItemStack stack = playerInventory.mainInventory[chiselSlot];
|
||||
if (stack == null || !stack.isItemEqual(chisel)) finished = true;
|
||||
|
||||
if (finished)
|
||||
return;
|
||||
if (finished) return;
|
||||
|
||||
General.setChiselTarget(chisel, inventory.getStackInSpecialSlot());
|
||||
General.setChiselTarget(chisel, inventory.getStackInSpecialSlot());
|
||||
|
||||
playerInventory.mainInventory[chiselSlot] = chisel;
|
||||
}
|
||||
playerInventory.mainInventory[chiselSlot] = chisel;
|
||||
}
|
||||
}
|
||||
@@ -5,81 +5,80 @@ import net.minecraft.inventory.Container;
|
||||
import net.minecraft.inventory.IInventory;
|
||||
import net.minecraft.inventory.Slot;
|
||||
import net.minecraft.item.ItemStack;
|
||||
|
||||
import team.chisel.block.tileentity.TileEntityPresent;
|
||||
|
||||
public class ContainerPresent extends Container {
|
||||
|
||||
private IInventory lower;
|
||||
private int rows;
|
||||
private IInventory lower;
|
||||
private int rows;
|
||||
private boolean isContainerValid = true;
|
||||
public ContainerPresent(IInventory player, IInventory chest) {
|
||||
lower = chest;
|
||||
rows = chest.getSizeInventory() / 9;
|
||||
chest.openInventory();
|
||||
int a = (rows - 4) * 18;
|
||||
|
||||
for (int d = 0; d < rows; d++) {
|
||||
for (int e = 0; e < 9; e++) {
|
||||
addSlotToContainer(new Slot(chest, e + d * 9, 8 + e * 18, 18 + d * 18));
|
||||
}
|
||||
}
|
||||
public ContainerPresent(IInventory player, IInventory chest) {
|
||||
lower = chest;
|
||||
rows = chest.getSizeInventory() / 9;
|
||||
chest.openInventory();
|
||||
int a = (rows - 4) * 18;
|
||||
|
||||
for (int d = 0; d < 3; d++) {
|
||||
for (int e = 0; e < 9; e++) {
|
||||
addSlotToContainer(new Slot(player, e + d * 9 + 9, 8 + e * 18, 103 + d * 18 + a));
|
||||
}
|
||||
}
|
||||
for (int d = 0; d < rows; d++) {
|
||||
for (int e = 0; e < 9; e++) {
|
||||
addSlotToContainer(new Slot(chest, e + d * 9, 8 + e * 18, 18 + d * 18));
|
||||
}
|
||||
}
|
||||
|
||||
for (int d = 0; d < 9; d++) {
|
||||
addSlotToContainer(new Slot(player, d, 8 + d * 18, 161 + a));
|
||||
}
|
||||
}
|
||||
for (int d = 0; d < 3; d++) {
|
||||
for (int e = 0; e < 9; e++) {
|
||||
addSlotToContainer(new Slot(player, e + d * 9 + 9, 8 + e * 18, 103 + d * 18 + a));
|
||||
}
|
||||
}
|
||||
|
||||
public IInventory getLowerPresentInventory() {
|
||||
return lower;
|
||||
}
|
||||
for (int d = 0; d < 9; d++) {
|
||||
addSlotToContainer(new Slot(player, d, 8 + d * 18, 161 + a));
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public ItemStack transferStackInSlot(EntityPlayer p_82846_1_, int p_82846_2_) {
|
||||
|
||||
ItemStack itemstack = null;
|
||||
Slot slot = (Slot) this.inventorySlots.get(p_82846_2_);
|
||||
|
||||
if (slot != null && slot.getHasStack()) {
|
||||
ItemStack itemstack1 = slot.getStack();
|
||||
itemstack = itemstack1.copy();
|
||||
|
||||
if (p_82846_2_ < rows * 9) {
|
||||
if (!this.mergeItemStack(itemstack1, rows * 9, inventorySlots.size(), true)) {
|
||||
return null;
|
||||
}
|
||||
} else if (!this.mergeItemStack(itemstack1, 0, rows * 9, false)) {
|
||||
return null;
|
||||
}
|
||||
|
||||
if (itemstack1.stackSize == 0) {
|
||||
slot.putStack((ItemStack) null);
|
||||
} else {
|
||||
slot.onSlotChanged();
|
||||
}
|
||||
}
|
||||
|
||||
return itemstack;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean canInteractWith(EntityPlayer p_75145_1_) {
|
||||
return isContainerValid;
|
||||
}
|
||||
public IInventory getLowerPresentInventory() {
|
||||
return lower;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void detectAndSendChanges()
|
||||
{
|
||||
TileEntityPresent te = (TileEntityPresent)lower;
|
||||
if( te != null && te.hasWorldObj() && !te.getWorldObj().isRemote)
|
||||
{
|
||||
if (te.getWorldObj().getTileEntity(te.xCoord, te.yCoord, te.zCoord) != te)
|
||||
isContainerValid = false;
|
||||
public ItemStack transferStackInSlot(EntityPlayer p_82846_1_, int p_82846_2_) {
|
||||
|
||||
ItemStack itemstack = null;
|
||||
Slot slot = (Slot) this.inventorySlots.get(p_82846_2_);
|
||||
|
||||
if (slot != null && slot.getHasStack()) {
|
||||
ItemStack itemstack1 = slot.getStack();
|
||||
itemstack = itemstack1.copy();
|
||||
|
||||
if (p_82846_2_ < rows * 9) {
|
||||
if (!this.mergeItemStack(itemstack1, rows * 9, inventorySlots.size(), true)) {
|
||||
return null;
|
||||
}
|
||||
} else if (!this.mergeItemStack(itemstack1, 0, rows * 9, false)) {
|
||||
return null;
|
||||
}
|
||||
|
||||
if (itemstack1.stackSize == 0) {
|
||||
slot.putStack((ItemStack) null);
|
||||
} else {
|
||||
slot.onSlotChanged();
|
||||
}
|
||||
}
|
||||
|
||||
return itemstack;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean canInteractWith(EntityPlayer p_75145_1_) {
|
||||
return isContainerValid;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void detectAndSendChanges() {
|
||||
TileEntityPresent te = (TileEntityPresent) lower;
|
||||
if (te != null && te.hasWorldObj() && !te.getWorldObj().isRemote) {
|
||||
if (te.getWorldObj().getTileEntity(te.xCoord, te.yCoord, te.zCoord) != te) isContainerValid = false;
|
||||
}
|
||||
super.detectAndSendChanges();
|
||||
}
|
||||
|
||||
@@ -2,10 +2,6 @@ package team.chisel.inventory;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import com.cricketcraft.chisel.api.IChiselItem;
|
||||
|
||||
import team.chisel.item.chisel.ItemChisel;
|
||||
import team.chisel.utils.General;
|
||||
import net.minecraft.block.Block;
|
||||
import net.minecraft.entity.player.EntityPlayer;
|
||||
import net.minecraft.inventory.IInventory;
|
||||
@@ -13,182 +9,182 @@ import net.minecraft.item.Item;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.item.ItemTool;
|
||||
|
||||
import team.chisel.item.chisel.ItemChisel;
|
||||
import team.chisel.utils.General;
|
||||
|
||||
import com.cricketcraft.chisel.api.IChiselItem;
|
||||
|
||||
public class InventoryChiselSelection implements IInventory {
|
||||
|
||||
ItemStack chisel;
|
||||
public final static int normalSlots = 60;
|
||||
ContainerChisel container;
|
||||
ItemStack[] inventory;
|
||||
private int currentScroll = 0;
|
||||
private int maxScroll = 0;
|
||||
ItemStack chisel;
|
||||
public final static int normalSlots = 60;
|
||||
ContainerChisel container;
|
||||
ItemStack[] inventory;
|
||||
private int currentScroll = 0;
|
||||
private int maxScroll = 0;
|
||||
|
||||
public InventoryChiselSelection(ItemStack c) {
|
||||
super();
|
||||
public InventoryChiselSelection(ItemStack c) {
|
||||
super();
|
||||
|
||||
inventory = new ItemStack[normalSlots + 1];
|
||||
chisel = c;
|
||||
}
|
||||
inventory = new ItemStack[normalSlots + 1];
|
||||
chisel = c;
|
||||
}
|
||||
|
||||
public void setCurrentScroll(int currentScroll) {
|
||||
if (this.currentScroll != currentScroll) {
|
||||
this.currentScroll = currentScroll;
|
||||
updateItems();
|
||||
}
|
||||
}
|
||||
public void setCurrentScroll(int currentScroll) {
|
||||
if (this.currentScroll != currentScroll) {
|
||||
this.currentScroll = currentScroll;
|
||||
updateItems();
|
||||
}
|
||||
}
|
||||
|
||||
public int getCurrentScroll() {
|
||||
return currentScroll;
|
||||
}
|
||||
public int getCurrentScroll() {
|
||||
return currentScroll;
|
||||
}
|
||||
|
||||
public int getMaxScroll() {
|
||||
return maxScroll;
|
||||
}
|
||||
public int getMaxScroll() {
|
||||
return maxScroll;
|
||||
}
|
||||
|
||||
public void onInventoryUpdate(int slot) {
|
||||
public void onInventoryUpdate(int slot) {
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getSizeInventory() {
|
||||
return normalSlots + 1;
|
||||
}
|
||||
@Override
|
||||
public int getSizeInventory() {
|
||||
return normalSlots + 1;
|
||||
}
|
||||
|
||||
@Override
|
||||
public ItemStack getStackInSlot(int var1) {
|
||||
return inventory[var1];
|
||||
}
|
||||
@Override
|
||||
public ItemStack getStackInSlot(int var1) {
|
||||
return inventory[var1];
|
||||
}
|
||||
|
||||
public void updateInventoryState(int slot) {
|
||||
onInventoryUpdate(slot);
|
||||
}
|
||||
public void updateInventoryState(int slot) {
|
||||
onInventoryUpdate(slot);
|
||||
}
|
||||
|
||||
@Override
|
||||
public ItemStack decrStackSize(int slot, int amount) {
|
||||
if (this.inventory[slot] != null) {
|
||||
ItemStack stack;
|
||||
if (this.inventory[slot].stackSize <= amount) {
|
||||
stack = this.inventory[slot];
|
||||
this.inventory[slot] = null;
|
||||
updateInventoryState(slot);
|
||||
return stack;
|
||||
} else {
|
||||
stack = this.inventory[slot].splitStack(amount);
|
||||
@Override
|
||||
public ItemStack decrStackSize(int slot, int amount) {
|
||||
if (this.inventory[slot] != null) {
|
||||
ItemStack stack;
|
||||
if (this.inventory[slot].stackSize <= amount) {
|
||||
stack = this.inventory[slot];
|
||||
this.inventory[slot] = null;
|
||||
updateInventoryState(slot);
|
||||
return stack;
|
||||
} else {
|
||||
stack = this.inventory[slot].splitStack(amount);
|
||||
|
||||
if (this.inventory[slot].stackSize == 0)
|
||||
this.inventory[slot] = null;
|
||||
if (this.inventory[slot].stackSize == 0) this.inventory[slot] = null;
|
||||
|
||||
updateInventoryState(slot);
|
||||
updateInventoryState(slot);
|
||||
|
||||
return stack;
|
||||
}
|
||||
} else
|
||||
return null;
|
||||
}
|
||||
return stack;
|
||||
}
|
||||
} else return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getInventoryName() {
|
||||
return "container.chisel";
|
||||
}
|
||||
@Override
|
||||
public String getInventoryName() {
|
||||
return "container.chisel";
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean hasCustomInventoryName() {
|
||||
return false;
|
||||
}
|
||||
@Override
|
||||
public boolean hasCustomInventoryName() {
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getInventoryStackLimit() {
|
||||
return 64;
|
||||
}
|
||||
@Override
|
||||
public int getInventoryStackLimit() {
|
||||
return 64;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void markDirty() {
|
||||
@Override
|
||||
public void markDirty() {
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isUseableByPlayer(EntityPlayer entityplayer) {
|
||||
return true;
|
||||
}
|
||||
@Override
|
||||
public boolean isUseableByPlayer(EntityPlayer entityplayer) {
|
||||
return true;
|
||||
}
|
||||
|
||||
public void clearItems() {
|
||||
for (int i = 0; i < normalSlots; i++) {
|
||||
inventory[i] = null;
|
||||
}
|
||||
maxScroll = 0;
|
||||
}
|
||||
public void clearItems() {
|
||||
for (int i = 0; i < normalSlots; i++) {
|
||||
inventory[i] = null;
|
||||
}
|
||||
maxScroll = 0;
|
||||
}
|
||||
|
||||
public ItemStack getStackInSpecialSlot() {
|
||||
return inventory[normalSlots];
|
||||
}
|
||||
public ItemStack getStackInSpecialSlot() {
|
||||
return inventory[normalSlots];
|
||||
}
|
||||
|
||||
public void updateItems() {
|
||||
ItemStack chiseledItem = inventory[normalSlots];
|
||||
clearItems();
|
||||
public void updateItems() {
|
||||
ItemStack chiseledItem = inventory[normalSlots];
|
||||
clearItems();
|
||||
|
||||
if (chiseledItem == null) {
|
||||
container.onChiselSlotChanged();
|
||||
return;
|
||||
}
|
||||
if (chiseledItem == null) {
|
||||
container.onChiselSlotChanged();
|
||||
return;
|
||||
}
|
||||
|
||||
Item item = chiseledItem.getItem();
|
||||
if (item == null)
|
||||
return;
|
||||
Item item = chiseledItem.getItem();
|
||||
if (item == null) return;
|
||||
|
||||
if (Block.getBlockFromItem(item) == null)
|
||||
return;
|
||||
if (Block.getBlockFromItem(item) == null) return;
|
||||
|
||||
if (!((IChiselItem) chisel.getItem()).canChisel(container.playerInventory.player.worldObj, chisel, General.getVariation(chiseledItem)))
|
||||
return;
|
||||
if (!((IChiselItem) chisel.getItem())
|
||||
.canChisel(container.playerInventory.player.worldObj, chisel, General.getVariation(chiseledItem)))
|
||||
return;
|
||||
|
||||
List<ItemStack> list = container.carving.getItemsForChiseling(chiseledItem);
|
||||
maxScroll = list.size();
|
||||
int activeVariations = 0;
|
||||
while (activeVariations < normalSlots && activeVariations + currentScroll < list.size()) {
|
||||
if (Block.blockRegistry.getNameForObject(Block.getBlockFromItem(list.get(activeVariations + currentScroll).getItem())) != null) {
|
||||
inventory[activeVariations] = list.get(activeVariations + currentScroll);
|
||||
activeVariations++;
|
||||
}
|
||||
}
|
||||
List<ItemStack> list = container.carving.getItemsForChiseling(chiseledItem);
|
||||
maxScroll = list.size();
|
||||
int activeVariations = 0;
|
||||
while (activeVariations < normalSlots && activeVariations + currentScroll < list.size()) {
|
||||
if (Block.blockRegistry.getNameForObject(
|
||||
Block.getBlockFromItem(list.get(activeVariations + currentScroll).getItem())) != null) {
|
||||
inventory[activeVariations] = list.get(activeVariations + currentScroll);
|
||||
activeVariations++;
|
||||
}
|
||||
}
|
||||
|
||||
container.onChiselSlotChanged();
|
||||
}
|
||||
container.onChiselSlotChanged();
|
||||
}
|
||||
|
||||
@Override
|
||||
public ItemStack getStackInSlotOnClosing(int slot) {
|
||||
ItemStack stack = getStackInSlot(slot);
|
||||
@Override
|
||||
public ItemStack getStackInSlotOnClosing(int slot) {
|
||||
ItemStack stack = getStackInSlot(slot);
|
||||
|
||||
if (stack == null)
|
||||
return null;
|
||||
inventory[slot] = null;
|
||||
if (stack == null) return null;
|
||||
inventory[slot] = null;
|
||||
|
||||
updateInventoryState(slot);
|
||||
return stack;
|
||||
}
|
||||
updateInventoryState(slot);
|
||||
return stack;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setInventorySlotContents(int slot, ItemStack stack) {
|
||||
// we do not want external chisel variant updates
|
||||
if (slot == normalSlots) {
|
||||
inventory[slot] = stack;
|
||||
updateInventoryState(slot);
|
||||
}
|
||||
}
|
||||
@Override
|
||||
public void setInventorySlotContents(int slot, ItemStack stack) {
|
||||
// we do not want external chisel variant updates
|
||||
if (slot == normalSlots) {
|
||||
inventory[slot] = stack;
|
||||
updateInventoryState(slot);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void openInventory() {
|
||||
}
|
||||
@Override
|
||||
public void openInventory() {}
|
||||
|
||||
@Override
|
||||
public void closeInventory() {
|
||||
}
|
||||
@Override
|
||||
public void closeInventory() {}
|
||||
|
||||
@Override
|
||||
public boolean isItemValidForSlot(int i, ItemStack stack) {
|
||||
// Really didn't think people would chisel a shovel
|
||||
if (stack.getItem() instanceof ItemTool) {
|
||||
return false;
|
||||
}
|
||||
@Override
|
||||
public boolean isItemValidForSlot(int i, ItemStack stack) {
|
||||
// Really didn't think people would chisel a shovel
|
||||
if (stack.getItem() instanceof ItemTool) {
|
||||
return false;
|
||||
}
|
||||
|
||||
return !(stack != null && (stack.getItem() instanceof ItemChisel)) && i == normalSlots;
|
||||
}
|
||||
return !(stack != null && (stack.getItem() instanceof ItemChisel)) && i == normalSlots;
|
||||
}
|
||||
}
|
||||
@@ -6,34 +6,32 @@ import net.minecraft.item.ItemStack;
|
||||
|
||||
public class SlotChiselInput extends Slot {
|
||||
|
||||
public SlotChiselInput(ContainerChisel container, InventoryChiselSelection inv, int i, int j, int k) {
|
||||
super(inv, i, j, k);
|
||||
selInventory = inv;
|
||||
this.container = container;
|
||||
}
|
||||
public SlotChiselInput(ContainerChisel container, InventoryChiselSelection inv, int i, int j, int k) {
|
||||
super(inv, i, j, k);
|
||||
selInventory = inv;
|
||||
this.container = container;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isItemValid(ItemStack itemstack) {
|
||||
return !container.finished
|
||||
&& !container.carving.getItemsForChiseling(itemstack).isEmpty()
|
||||
&& super.isItemValid(itemstack);
|
||||
}
|
||||
@Override
|
||||
public boolean isItemValid(ItemStack itemstack) {
|
||||
return !container.finished && !container.carving.getItemsForChiseling(itemstack).isEmpty()
|
||||
&& super.isItemValid(itemstack);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean canTakeStack(EntityPlayer par1EntityPlayer) {
|
||||
return !container.finished && super.canTakeStack(par1EntityPlayer);
|
||||
}
|
||||
@Override
|
||||
public boolean canTakeStack(EntityPlayer par1EntityPlayer) {
|
||||
return !container.finished && super.canTakeStack(par1EntityPlayer);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onSlotChanged() {
|
||||
if (container.finished)
|
||||
return;
|
||||
@Override
|
||||
public void onSlotChanged() {
|
||||
if (container.finished) return;
|
||||
|
||||
super.onSlotChanged();
|
||||
selInventory.setCurrentScroll(0);
|
||||
selInventory.updateItems();
|
||||
}
|
||||
super.onSlotChanged();
|
||||
selInventory.setCurrentScroll(0);
|
||||
selInventory.updateItems();
|
||||
}
|
||||
|
||||
ContainerChisel container;
|
||||
InventoryChiselSelection selInventory;
|
||||
ContainerChisel container;
|
||||
InventoryChiselSelection selInventory;
|
||||
}
|
||||
@@ -7,33 +7,33 @@ import net.minecraft.item.ItemStack;
|
||||
|
||||
public class SlotChiselPlayer extends Slot {
|
||||
|
||||
public SlotChiselPlayer(ContainerChisel container, InventoryPlayer inv, int i, int j, int k) {
|
||||
super(inv, i, j, k);
|
||||
public SlotChiselPlayer(ContainerChisel container, InventoryPlayer inv, int i, int j, int k) {
|
||||
super(inv, i, j, k);
|
||||
|
||||
this.container = container;
|
||||
selInventory = inv;
|
||||
}
|
||||
this.container = container;
|
||||
selInventory = inv;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isItemValid(ItemStack par1ItemStack) {
|
||||
return false;
|
||||
}
|
||||
@Override
|
||||
public boolean isItemValid(ItemStack par1ItemStack) {
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onPickupFromSlot(EntityPlayer player, ItemStack itemstack) {
|
||||
container.finished = true;
|
||||
}
|
||||
@Override
|
||||
public void onPickupFromSlot(EntityPlayer player, ItemStack itemstack) {
|
||||
container.finished = true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean getHasStack() {
|
||||
return false;
|
||||
}
|
||||
@Override
|
||||
public boolean getHasStack() {
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public ItemStack decrStackSize(int i) {
|
||||
return null;
|
||||
}
|
||||
@Override
|
||||
public ItemStack decrStackSize(int i) {
|
||||
return null;
|
||||
}
|
||||
|
||||
ContainerChisel container;
|
||||
InventoryPlayer selInventory;
|
||||
ContainerChisel container;
|
||||
InventoryPlayer selInventory;
|
||||
}
|
||||
@@ -1,75 +1,85 @@
|
||||
package team.chisel.inventory;
|
||||
|
||||
import com.cricketcraft.chisel.api.IChiselItem;
|
||||
import com.cricketcraft.chisel.api.Statistics;
|
||||
|
||||
import team.chisel.carving.Carving;
|
||||
import team.chisel.utils.General;
|
||||
import team.chisel.utils.GeneralClient;
|
||||
import net.minecraft.entity.player.EntityPlayer;
|
||||
import net.minecraft.inventory.IInventory;
|
||||
import net.minecraft.inventory.Slot;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.util.MathHelper;
|
||||
|
||||
import team.chisel.carving.Carving;
|
||||
import team.chisel.utils.General;
|
||||
import team.chisel.utils.GeneralClient;
|
||||
|
||||
import com.cricketcraft.chisel.api.IChiselItem;
|
||||
import com.cricketcraft.chisel.api.Statistics;
|
||||
|
||||
public class SlotChiselSelection extends Slot {
|
||||
|
||||
private final ContainerChisel container;
|
||||
private final InventoryChiselSelection selInventory;
|
||||
private final ContainerChisel container;
|
||||
private final InventoryChiselSelection selInventory;
|
||||
|
||||
public SlotChiselSelection(ContainerChisel container, InventoryChiselSelection inv, IInventory iinventory, int i, int j, int k) {
|
||||
super(iinventory, i, j, k);
|
||||
public SlotChiselSelection(ContainerChisel container, InventoryChiselSelection inv, IInventory iinventory, int i,
|
||||
int j, int k) {
|
||||
super(iinventory, i, j, k);
|
||||
|
||||
this.container = container;
|
||||
selInventory = inv;
|
||||
}
|
||||
this.container = container;
|
||||
selInventory = inv;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isItemValid(ItemStack itemstack) {
|
||||
return false;
|
||||
}
|
||||
@Override
|
||||
public boolean isItemValid(ItemStack itemstack) {
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean canTakeStack(EntityPlayer par1EntityPlayer) {
|
||||
if (container.finished)
|
||||
return false;
|
||||
@Override
|
||||
public boolean canTakeStack(EntityPlayer par1EntityPlayer) {
|
||||
if (container.finished) return false;
|
||||
|
||||
return par1EntityPlayer.inventory.getItemStack() == null;
|
||||
}
|
||||
return par1EntityPlayer.inventory.getItemStack() == null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onPickupFromSlot(EntityPlayer player, ItemStack itemstack) {
|
||||
ItemStack heldStack = player.inventory.getItemStack();
|
||||
ItemStack crafted = selInventory.inventory[InventoryChiselSelection.normalSlots];
|
||||
@Override
|
||||
public void onPickupFromSlot(EntityPlayer player, ItemStack itemstack) {
|
||||
ItemStack heldStack = player.inventory.getItemStack();
|
||||
ItemStack crafted = selInventory.inventory[InventoryChiselSelection.normalSlots];
|
||||
|
||||
if (heldStack == null) {
|
||||
selInventory.decrStackSize(InventoryChiselSelection.normalSlots, 1);
|
||||
} else {
|
||||
putStack(itemstack.copy());
|
||||
if (heldStack == null) {
|
||||
selInventory.decrStackSize(InventoryChiselSelection.normalSlots, 1);
|
||||
} else {
|
||||
putStack(itemstack.copy());
|
||||
|
||||
player.inventory.setItemStack(null);
|
||||
player.inventory.setItemStack(null);
|
||||
|
||||
if (selInventory.inventory[InventoryChiselSelection.normalSlots] == null)
|
||||
return;
|
||||
if (selInventory.inventory[InventoryChiselSelection.normalSlots] == null) return;
|
||||
|
||||
player.inventory.setItemStack(new ItemStack(itemstack.getItem(), selInventory.inventory[InventoryChiselSelection.normalSlots].stackSize, itemstack.getItemDamage()));
|
||||
selInventory.setInventorySlotContents(InventoryChiselSelection.normalSlots, null);
|
||||
}
|
||||
player.inventory.setItemStack(
|
||||
new ItemStack(
|
||||
itemstack.getItem(),
|
||||
selInventory.inventory[InventoryChiselSelection.normalSlots].stackSize,
|
||||
itemstack.getItemDamage()));
|
||||
selInventory.setInventorySlotContents(InventoryChiselSelection.normalSlots, null);
|
||||
}
|
||||
|
||||
selInventory.updateItems();
|
||||
selInventory.updateItems();
|
||||
|
||||
if (((IChiselItem) container.chisel.getItem()).onChisel(player.worldObj, container.chisel, General.getVariation(crafted))) {
|
||||
container.chisel.damageItem(1, player);
|
||||
if (container.chisel.stackSize <= 0) {
|
||||
player.inventory.mainInventory[player.inventory.currentItem] = null;
|
||||
}
|
||||
}
|
||||
if (((IChiselItem) container.chisel.getItem())
|
||||
.onChisel(player.worldObj, container.chisel, General.getVariation(crafted))) {
|
||||
container.chisel.damageItem(1, player);
|
||||
if (container.chisel.stackSize <= 0) {
|
||||
player.inventory.mainInventory[player.inventory.currentItem] = null;
|
||||
}
|
||||
}
|
||||
|
||||
if (player.worldObj.isRemote) {
|
||||
String sound = Carving.chisel.getVariationSound(crafted.getItem(), crafted.getItemDamage());
|
||||
GeneralClient.playChiselSound(player.worldObj, MathHelper.floor_double(player.posX), MathHelper.floor_double(player.posY), MathHelper.floor_double(player.posZ), sound);
|
||||
} else {
|
||||
container.playerInventory.player.addStat(Statistics.blocksChiseled, crafted.stackSize);
|
||||
}
|
||||
}
|
||||
if (player.worldObj.isRemote) {
|
||||
String sound = Carving.chisel.getVariationSound(crafted.getItem(), crafted.getItemDamage());
|
||||
GeneralClient.playChiselSound(
|
||||
player.worldObj,
|
||||
MathHelper.floor_double(player.posX),
|
||||
MathHelper.floor_double(player.posY),
|
||||
MathHelper.floor_double(player.posZ),
|
||||
sound);
|
||||
} else {
|
||||
container.playerInventory.player.addStat(Statistics.blocksChiseled, crafted.stackSize);
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user