Search in sources :

Example 1 with NSC3A

use of club.nsdn.nyasamarailway.entity.nsc.NSC3A in project NyaSamaRailway by NSDN.

the class ItemNSC3A method onItemUse.

@Override
public boolean onItemUse(ItemStack itemStack, EntityPlayer player, World world, int x, int y, int z, int side, float px, float py, float pz) {
    if (BlockRailBase.func_150051_a(world.getBlock(x, y, z))) {
        if (!world.isRemote) {
            NSC3A cart = new NSC3A(world, (double) x + 0.5, (double) y + 0.5, (double) z + 0.5);
            if (itemStack.hasDisplayName()) {
                cart.setMinecartName(itemStack.getDisplayName());
            }
            ItemStack stack;
            for (int i = 0; i < 9; i++) {
                stack = player.inventory.mainInventory[i];
                if (stack == null)
                    continue;
                if (stack.getItem() == null)
                    continue;
                if (stack.getItem() instanceof NGTablet) {
                    NBTTagList list = Util.getTagListFromNGT(stack);
                    if (list != null) {
                        String[][] code = NSASM.getCode(list);
                        new ExtInfoCore(code) {

                            @Override
                            public World getWorld() {
                                return world;
                            }

                            @Override
                            public double getX() {
                                return x;
                            }

                            @Override
                            public double getY() {
                                return y;
                            }

                            @Override
                            public double getZ() {
                                return z;
                            }

                            @Override
                            public EntityPlayer getPlayer() {
                                return player;
                            }

                            @Override
                            public IExtendedInfoCart getCart() {
                                return cart;
                            }
                        }.run();
                    }
                }
            }
            world.spawnEntityInWorld(cart);
        }
        --itemStack.stackSize;
        return true;
    } else {
        return false;
    }
}
Also used : NBTTagList(net.minecraft.nbt.NBTTagList) EntityPlayer(net.minecraft.entity.player.EntityPlayer) IExtendedInfoCart(club.nsdn.nyasamarailway.entity.IExtendedInfoCart) ItemStack(net.minecraft.item.ItemStack) World(net.minecraft.world.World) NSC3A(club.nsdn.nyasamarailway.entity.nsc.NSC3A) NGTablet(club.nsdn.nyasamatelecom.api.tool.NGTablet) ExtInfoCore(club.nsdn.nyasamarailway.util.ExtInfoCore)

Aggregations

IExtendedInfoCart (club.nsdn.nyasamarailway.entity.IExtendedInfoCart)1 NSC3A (club.nsdn.nyasamarailway.entity.nsc.NSC3A)1 ExtInfoCore (club.nsdn.nyasamarailway.util.ExtInfoCore)1 NGTablet (club.nsdn.nyasamatelecom.api.tool.NGTablet)1 EntityPlayer (net.minecraft.entity.player.EntityPlayer)1 ItemStack (net.minecraft.item.ItemStack)1 NBTTagList (net.minecraft.nbt.NBTTagList)1 World (net.minecraft.world.World)1