下面列出了怎么用net.minecraft.inventory.SlotCrafting的API类实例代码及写法,或者点击链接到github查看源代码。
public GTContainerWorktable(InventoryPlayer player, GTTileWorktable tile) {
super(tile);
this.block = tile;
this.world = player.player.getEntityWorld();
this.player = player.player;
// crafting output slot
this.addSlotToContainer(new SlotCrafting(this.player, craftMatrix, craftResult, 0, 136, 46));// slot 0
// crafting slots
for (int i = 0; i < 3; ++i) {
for (int j = 0; j < 3; ++j) {
this.addSlotToContainer(new Slot(craftMatrix, (j + i * 3), 82 + j * 18, 28 + i * 18));
}
}
// main inventory
int k;
for (k = 0; k < 4; ++k) {
for (int l = 0; l < 4; ++l) {
this.addSlotToContainer(new SlotBase(tile, (k + l * 4) + 1, 8 + l * 18, 8 + k * 18));
}
}
// tool slots
for (k = 0; k < 5; k++) {
this.addSlotToContainer(new SlotCustom(tile, k + 17, 82 + (k * 18), 8, toolFilter));
}
// park slot
this.addSlotToContainer(new SlotBase(tile, 22, 154, 46));
this.addComponent(new GTGuiCompWorktable(tile, this));
this.addPlayerInventory(player, 0, 0);
readTileCraftingList();
this.block.inUse = true;
this.block.setActive(true);
}
public CraftingGuiInventoryContainer(EntityPlayer basePlayer) {
this.addSlotToContainer(new SlotCrafting(basePlayer, this.craftMatrix, this.craftResult, 0, -2000, -2000));
for (int i = 0; i < 4; ++i) {
this.addSlotToContainer(new Slot(this.craftMatrix, i, -2000, -2000));
}
for (int i = 0; i < 4; ++i) {
final int k = i;
this.addSlotToContainer(new Slot(basePlayer.inventory, basePlayer.inventory.getSizeInventory() - 1 - i, 8, 8 + i * 18) {
@Override
public int getSlotStackLimit() {
return 1;
}
@Override
public boolean isItemValid(ItemStack p_75214_1_) {
if (p_75214_1_ == null) {
return false;
}
return p_75214_1_.getItem().isValidArmor(p_75214_1_, k, Wrapper.INSTANCE.player());
}
@Override
public IIcon getBackgroundIconIndex() {
return ItemArmor.func_94602_b(k);
}
});
}
for (int i = 0; i < 3; ++i) {
for (int j = 0; j < 9; ++j) {
this.addSlotToContainer(new Slot(basePlayer.inventory, j + (i + 1) * 9, 8 + j * 18, 84 + i * 18));
}
}
for (int i = 0; i < 9; ++i) {
this.addSlotToContainer(new Slot(basePlayer.inventory, i, 8 + i * 18, 142));
}
this.onCraftMatrixChanged(this.craftMatrix);
}
public ContainerPlayerExpandedCrafting(InventoryPlayer playerInventory, boolean localWorld, EntityPlayer player)
{
super(playerInventory, localWorld, player);
craftMatrix = new InventoryCrafting(this, 3, 3);
/*this.inventorySlots.remove(1);
this.inventorySlots.remove(1);
this.inventorySlots.remove(1);
this.inventorySlots.remove(1);*/
this.addSlotToContainer(new SlotCrafting(playerInventory.player, this.craftMatrix, this.craftResult, 0, 154, 28));
for (int i = 0; i < 3; ++i)
{
for (int j = 0; j < 3; ++j)
{
this.addSlotToContainer(new Slot(this.craftMatrix, j + i * 3, 98 + j * 18, 18 + i * 18));
}
}
for (int i = 0; i < 5; i++)
{
this.inventorySlots.get(i).xDisplayPosition = -999;
this.inventorySlots.get(i).yDisplayPosition = -999;
}
}
private MCCraftingGrid(InventoryCrafting inventory) {
this.inventory = inventory;
width = height = (int) Math.sqrt(inventory.getSizeInventory());
items = new nova.core.item.Item[width * height];
original = new ItemStack[items.length];
itemCount = 0;
update();
Container container = ReflectionUtil.getCraftingContainer(inventory);
if (container != null) {
@SuppressWarnings("unchecked")
List<Slot> slots = container.inventorySlots;
EntityPlayer playerOrig = null;
Optional<Player> player = Optional.empty();
for (Slot slot : slots) {
if (slot instanceof SlotCrafting) {
playerOrig = ReflectionUtil.getCraftingSlotPlayer((SlotCrafting) slot);
player = WrapUtility.getNovaPlayer(playerOrig);
if (player.isPresent()) {
break;
}
}
}
this.playerOrig = playerOrig;
this.player = player;
} else {
playerOrig = null;
player = Optional.empty();
}
}
public static EntityPlayer getCraftingSlotPlayer(SlotCrafting slot) {
try {
return (EntityPlayer) SLOTCRAFTING_PLAYER.get(slot);
} catch (IllegalAccessException | NullPointerException ex) {
Game.logger().error("could not get inventory eventhandler");
return null;
}
}
private MCCraftingGrid(InventoryCrafting inventory) {
this.inventory = inventory;
width = height = (int) Math.sqrt(inventory.getSizeInventory());
items = new nova.core.item.Item[width * height];
original = new ItemStack[items.length];
itemCount = 0;
update();
Container container = ReflectionUtil.getCraftingContainer(inventory);
if (container != null) {
@SuppressWarnings("unchecked")
List<Slot> slots = container.inventorySlots;
EntityPlayer playerOrig = null;
Optional<Player> player = Optional.empty();
for (Slot slot : slots) {
if (slot instanceof SlotCrafting) {
playerOrig = ReflectionUtil.getCraftingSlotPlayer((SlotCrafting) slot);
player = WrapUtility.getNovaPlayer(playerOrig);
if (player.isPresent()) {
break;
}
}
}
this.playerOrig = playerOrig;
this.player = player;
} else {
playerOrig = null;
player = Optional.empty();
}
}
public static EntityPlayer getCraftingSlotPlayer(SlotCrafting slot) {
try {
return (EntityPlayer) SLOTCRAFTING_PLAYER.get(slot);
} catch (IllegalAccessException ex) {
Game.logger().error("could not get inventory eventhandler");
return null;
}
}
private MCCraftingGrid(InventoryCrafting inventory) {
this.inventory = inventory;
width = height = (int) Math.sqrt(inventory.getSizeInventory());
items = new nova.core.item.Item[width * height];
original = new net.minecraft.item.ItemStack[items.length];
itemCount = 0;
update();
Container container = ReflectionUtil.getCraftingContainer(inventory);
if (container != null) {
@SuppressWarnings("unchecked")
List<Slot> slots = container.inventorySlots;
EntityPlayer playerOrig = null;
Optional<Player> player = Optional.empty();
for (Slot slot : slots) {
if (slot instanceof SlotCrafting) {
playerOrig = ReflectionUtil.getCraftingSlotPlayer((SlotCrafting) slot);
player = WrapUtility.getNovaPlayer(playerOrig);
if (player.isPresent()) {
break;
}
}
}
this.playerOrig = playerOrig;
this.player = player;
} else {
playerOrig = null;
player = Optional.empty();
}
}
public static EntityPlayer getCraftingSlotPlayer(SlotCrafting slot) {
try {
return (EntityPlayer) SLOTCRAFTING_PLAYER.get(slot);
} catch (IllegalAccessException ex) {
Game.logger().error("could not get inventory eventhandler");
return null;
}
}
@Override
public boolean handleSlotClick(GuiContainer gui, int slotIndex, int button, Slot slot, int modifier, boolean eventconsumed) {
if (eventconsumed ||
!NEIClientConfig.isEnabled() ||
isSpreading(gui))
return eventconsumed;
if (deleteMode && slotIndex >= 0 && slot != null) {
if (NEIClientUtils.shiftKey() && button == 0) {
ItemStack itemstack1 = slot.getStack();
if (itemstack1 != null)
NEIClientUtils.deleteItemsOfType(itemstack1);
} else if (button == 1)
NEIClientUtils.decreaseSlotStack(slot.slotNumber);
else
NEIClientUtils.deleteSlotStack(slot.slotNumber);
return true;
}
if (button == 1 && slot instanceof SlotCrafting)//right click
{
for (int i1 = 0; i1 < 64; i1++)//click this slot 64 times
manager.handleSlotClick(slot.slotNumber, button, 0);
return true;
}
if (NEIClientUtils.controlKey()
&& slot != null && slot.getStack() != null
&& slot.isItemValid(slot.getStack())) {
NEIClientUtils.cheatItem(slot.getStack(), button, 1);
return true;
}
if(GuiInfo.hasCustomSlots(gui))
return false;
if (slotIndex >= 0 && NEIClientUtils.shiftKey() && NEIClientUtils.getHeldItem() != null && !slot.getHasStack()) {
ItemStack held = NEIClientUtils.getHeldItem();
manager.handleSlotClick(slot.slotNumber, button, 0);
if (slot.isItemValid(held) && !ItemInfo.fastTransferExemptions.contains(slot.getClass()))
fastTransferManager.performMassTransfer(gui, pickedUpFromSlot, slotIndex, held);
return true;
}
if (slotIndex == -999 && NEIClientUtils.shiftKey() && button == 0) {
fastTransferManager.throwAll(gui, pickedUpFromSlot);
return true;
}
return false;
}