import li.cil.oc.api.detail.ItemInfo; //导入依赖的package包/类
@Override
public boolean onItemUse(ItemStack stack, EntityPlayer player, World world, int x, int y, int z, int side, float hitX, float hitY, float hitZ) {
if(stack != null && stack.getItem() instanceof ItemPackage && player.isSneaking() && !world.isRemote) {
NBTTagCompound tag = stack.getTagCompound();
if(tag == null || !tag.hasKey("t")) {
player.addChatMessage(new ChatComponentTranslation("chat.cheatycomputers.invalid"));
return true;
}
int tier = tag.getInteger("t");
final int caseX, caseY, caseZ;
if(world.getBlock(x, y, z).isReplaceable(world, x, y, z)) {
caseX = x;
caseY = y;
caseZ = z;
} else {
ForgeDirection dir = ForgeDirection.getOrientation(side);
caseX = x + dir.offsetX;
caseY = y + dir.offsetY;
caseZ = z + dir.offsetZ;
}
if(!world.getBlock(caseX, caseY, caseZ).isReplaceable(world, caseX, caseY, caseZ)) {
player.addChatMessage(new ChatComponentTranslation("chat.cheatycomputers.obstructed"));
return true;
}
Block block = ScalaProxy.getCase(tier).block();
world.setBlock(caseX, caseY, caseZ, block);
world.playSoundEffect((double) ((float) caseX + 0.5F), (double) ((float) caseY + 0.5F), (double) ((float) caseZ + 0.5F), block.stepSound.func_150496_b(), (block.stepSound.getVolume() + 1.0F) / 2.0F, block.stepSound.getPitch() * 0.8F);
TileEntity tile = world.getTileEntity(caseX, caseY, caseZ);
if(tile instanceof Rotatable) {
ScalaProxy.setFacing(((Rotatable) tile), player);
}
Network.joinOrCreateNetwork(world.getTileEntity(caseX, caseY, caseZ));
InventorySlots.InventorySlot[] slots = InventorySlots.computer()[tier];
for(InventorySlots.InventorySlot slot : slots) {
//NBTTagList list = tag.getTagList(slot.slot(), NBT.TAG_COMPOUND);
NBTTagList list = tag.getTagList(slot.slot(), NBT.TAG_STRING);
int count = ScalaProxy.countSlots(slots, slot.slot());
for(int i = 0; i < count; i++) {
//NBTTagCompound data = list.getCompoundTagAt(i);
//ItemStack toAdd = ItemStack.loadItemStackFromNBT(data);
ItemInfo info = Items.get(list.getStringTagAt(i));
if(info != null) {
ItemStack toAdd = info.createItemStack(1);
if(toAdd != null) {
ScalaProxy.insertIntoInventoryAt(toAdd.copy(), new BlockPosition(caseX, caseY, caseZ, Option.apply(world)));
//InventoryUtils.insertIntoInventoryAt(toAdd.copy(),
// new BlockPosition(x, y, z, Option.apply(world)), Option.<ForgeDirection>empty(), 64, false);
}
}
}
}
if(!player.capabilities.isCreativeMode) {
player.inventory.decrStackSize(player.inventory.currentItem, 1);
}
return true;
}
return super.onItemUse(stack, player, world, x, y, z, side, hitX, hitY, hitZ);
}
请发表评论