Search in sources :

Example 1 with NGTablet

use of club.nsdn.nyasamatelecom.api.tool.NGTablet in project NyaSamaRailway by NSDN.

the class ItemNSPCT9 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) {
            NSPCT9 cart = new NSPCT9(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) NSPCT9(club.nsdn.nyasamarailway.entity.cart.NSPCT9) ItemStack(net.minecraft.item.ItemStack) World(net.minecraft.world.World) NGTablet(club.nsdn.nyasamatelecom.api.tool.NGTablet) ExtInfoCore(club.nsdn.nyasamarailway.util.ExtInfoCore)

Example 2 with NGTablet

use of club.nsdn.nyasamatelecom.api.tool.NGTablet in project NyaSamaRailway by NSDN.

the class ItemNSPCT9M 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) {
            NSPCT9M cart = new NSPCT9M(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) NGTablet(club.nsdn.nyasamatelecom.api.tool.NGTablet) NSPCT9M(club.nsdn.nyasamarailway.entity.loco.NSPCT9M) ExtInfoCore(club.nsdn.nyasamarailway.util.ExtInfoCore)

Aggregations

IExtendedInfoCart (club.nsdn.nyasamarailway.entity.IExtendedInfoCart)2 ExtInfoCore (club.nsdn.nyasamarailway.util.ExtInfoCore)2 NGTablet (club.nsdn.nyasamatelecom.api.tool.NGTablet)2 EntityPlayer (net.minecraft.entity.player.EntityPlayer)2 ItemStack (net.minecraft.item.ItemStack)2 NBTTagList (net.minecraft.nbt.NBTTagList)2 World (net.minecraft.world.World)2 NSPCT9 (club.nsdn.nyasamarailway.entity.cart.NSPCT9)1 NSPCT9M (club.nsdn.nyasamarailway.entity.loco.NSPCT9M)1