make the specimen slot work and some small improvements

This commit is contained in:
Raoul Van den Berge
2015-12-18 12:31:37 +01:00
parent 9cd5f2487c
commit 4d5af85215
8 changed files with 74 additions and 26 deletions

View File

@@ -2,7 +2,7 @@ package storagecraft.container;
import net.minecraft.entity.player.EntityPlayer;
import storagecraft.SCItems;
import storagecraft.inventory.slot.SlotItemFilter;
import storagecraft.container.slot.SlotItemFilter;
import storagecraft.tile.TileDrive;
public class ContainerDrive extends ContainerSC {

View File

@@ -1,7 +1,7 @@
package storagecraft.container;
import net.minecraft.entity.player.EntityPlayer;
import storagecraft.inventory.slot.SlotSpecimen;
import storagecraft.container.slot.SlotSpecimen;
import storagecraft.tile.TileImporter;
public class ContainerImporter extends ContainerSC {

View File

@@ -4,6 +4,7 @@ import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.inventory.Container;
import net.minecraft.inventory.Slot;
import net.minecraft.item.ItemStack;
import storagecraft.container.slot.SlotSpecimen;
public class ContainerSC extends Container {
private EntityPlayer player;
@@ -34,6 +35,23 @@ public class ContainerSC extends Container {
}
}
@Override
public ItemStack slotClick(int id, int clickedButton, int mode, EntityPlayer player) {
Slot slot = id >= 0 ? getSlot(id) : null;
if (slot instanceof SlotSpecimen) {
if (clickedButton == 2) {
slot.putStack(null);
} else {
slot.putStack(player.inventory.getItemStack() == null ? null : player.inventory.getItemStack().copy());
}
return player.inventory.getItemStack();
}
return super.slotClick(id, clickedButton, mode, player);
}
@Override
public ItemStack transferStackInSlot(EntityPlayer player, int slotIndex) {
return null;

View File

@@ -0,0 +1,21 @@
package storagecraft.container.slot;
import net.minecraft.inventory.IInventory;
import net.minecraft.inventory.Slot;
import net.minecraft.item.Item;
import net.minecraft.item.ItemStack;
public class SlotItemFilter extends Slot {
private Item item;
public SlotItemFilter(IInventory inventory, int id, int x, int y, Item item) {
super(inventory, id, x, y);
this.item = item;
}
@Override
public boolean isItemValid(ItemStack item) {
return item.getItem() == this.item;
}
}

View File

@@ -0,0 +1,31 @@
package storagecraft.container.slot;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.inventory.IInventory;
import net.minecraft.inventory.Slot;
import net.minecraft.item.ItemStack;
public class SlotSpecimen extends Slot {
public SlotSpecimen(IInventory inventory, int id, int x, int y) {
super(inventory, id, x, y);
}
@Override
public boolean canTakeStack(EntityPlayer player) {
return false;
}
@Override
public boolean isItemValid(ItemStack stack) {
return true;
}
@Override
public void putStack(ItemStack stack) {
if (stack != null) {
stack.stackSize = 1;
}
super.putStack(stack);
}
}