Java 类net.minecraft.item.ItemFirework 实例源码

项目:Production-Line    文件:MixinTileEntityFurnace.java   
@Inject(method = "update", at = @At("RETURN"))
private void onUpdate(CallbackInfo callbackInfo) {
    if (!this.world.isRemote) {
        if (this.isBurning()) {
            ItemStack itemStack = this.furnaceItemStacks[0];
            if (itemStack != null) {
                if (itemStack.getItem() instanceof ItemBlock) {
                    Block block = ((ItemBlock) itemStack.getItem()).block;
                    if (block.getMaterial(block.getStateFromMeta(itemStack.getMetadata())) == Material.TNT) {
                        this.doExplosion();
                    }
                } else if (itemStack.getItem() == Items.GUNPOWDER) {
                    this.doExplosion();
                } else if (itemStack.getItem() instanceof ItemFirework || itemStack.getItem()
                        instanceof ItemFireworkCharge) {
                    this.doExplosion();
                }
            }
        }
    }
}
项目:BaseClient    文件:AutoTaunt.java   
@EventTarget
private void onTick(TickEvent event) {
    int i = 0;
    while (i < 8) {
        Item item;
        if (this.mc.thePlayer.inventory.mainInventory[i] != null && ((item = this.mc.thePlayer.inventory.mainInventory[i].getItem()) instanceof ItemRedstone || Item.getIdFromItem((Item)item) == 353 || item instanceof ItemFirework)) {
            this.mc.thePlayer.sendQueue.addToSendQueue((Packet)new C09PacketHeldItemChange(i));
            this.mc.thePlayer.sendQueue.addToSendQueue((Packet)new C08PacketPlayerBlockPlacement(this.mc.thePlayer.inventory.mainInventory[i]));
            this.mc.thePlayer.sendQueue.addToSendQueue((Packet)new C09PacketHeldItemChange(this.mc.thePlayer.inventory.currentItem));
        }
        ++i;
    }
}
项目:morecommands    文件:CommandFirework.java   
@Override
public String execute(CommandSender sender, String[] params) throws CommandException {
    Entity entity = params.length > 2 ? null : 
        isSenderOfEntityType(sender.getMinecraftISender(), Entity.class) ? 
        getSenderAsEntity(sender.getMinecraftISender(), Entity.class) : null;
    BlockPos spawn = null;

    if (params.length > 2)
        spawn = getCoordFromParams(sender.getMinecraftISender(), params, 0);
    else
        spawn = entity == null ? sender.getPosition() : EntityUtils.traceBlock(entity, 128.0D);

    if (spawn == null) 
        throw new CommandException("command.firework.notFound", sender);

    Random rand = new Random();
    RecipeFireworks recipe = (RecipeFireworks) CraftingManager.REGISTRY.getObject(new ResourceLocation("fireworks"));

    if (recipe != null) {
        InventoryCrafting inv = new InventoryCrafting(new Container()
        {
            public boolean canInteractWith(EntityPlayer playerIn) {return false;}
        }, 3, 3);

        ItemStack dye;
        ItemStack output;

        do {
            for (int i = 0; i < inv.getSizeInventory(); ++i) inv.setInventorySlotContents(i, null);

            dye = new ItemStack(Items.DYE, 1, rand.nextInt(MAX_DYE_TYPES));

            inv.setInventorySlotContents(0, dye);
            inv.setInventorySlotContents(1, new ItemStack(Items.GUNPOWDER));

            if (rand.nextBoolean())
                inv.setInventorySlotContents(2, new ItemStack(shapeModifiers.get(rand.nextInt(shapeModifiers.size()))));

            if (rand.nextBoolean())
                inv.setInventorySlotContents(3, new ItemStack(effectModifiers.get(rand.nextInt(effectModifiers.size()))));
        }
        while (!recipe.matches(inv, sender.getMinecraftISender().getEntityWorld()));

        output = recipe.getRecipeOutput();

        if (output.getItem() instanceof ItemFireworkCharge) {
            do {
                for (int i = 0; i < inv.getSizeInventory(); ++i) inv.setInventorySlotContents(i, null);

                inv.setInventorySlotContents(0, output);
                inv.setInventorySlotContents(1, new ItemStack(Items.PAPER));

                int gunpowder = rand.nextInt(MAX_GUNPOWDER);
                for (int i = 0; i < gunpowder; i++) inv.setInventorySlotContents(2 + i, new ItemStack(Items.GUNPOWDER));
            }
            while (!recipe.matches(inv, sender.getMinecraftISender().getEntityWorld()));

            output = recipe.getRecipeOutput();

            if (output.getItem() instanceof ItemFirework) {
                ItemFirework firework = (ItemFirework) output.getItem();

                EntityFireworkRocket rocket = new EntityFireworkRocket(sender.getWorld(), spawn.getX(), spawn.getY(), spawn.getZ(), output);;
                sender.getWorld().spawnEntity(rocket);
            }
        }
    }

    return null;
}
项目:Pay2Spawn    文件:NbtRequestMessage.java   
@Override
public IMessage onMessage(NbtRequestMessage message, MessageContext ctx)
{
    if (ctx.side.isClient())
    {
        switch (message.type)
        {
            case ENTITY:
                callbackCustomEntityType.callback(message.response);
                break;
            case FIREWORK:
                callbackFireworksType.callback(message.response);
                break;
            case ITEM:
                callbackItemType.callback(message.response);
                break;
            case BLOCK:
                callbackBlockType.callback(message.response);
                break;
        }
    }
    else
    {
        switch (message.type)
        {
            case ENTITY:
                NBTTagCompound nbt = new NBTTagCompound();
                Entity entity = ctx.getServerHandler().playerEntity.worldObj.getEntityByID(message.entityId);
                entity.writeToNBT(nbt);
                entity.writeToNBTOptional(nbt);
                nbt.setString("id", EntityList.getEntityString(entity));
                return new NbtRequestMessage(message.type, JsonNBTHelper.parseNBT(nbt).toString());
            case FIREWORK:
                ItemStack itemStack = ctx.getServerHandler().playerEntity.getHeldItem();
                if (itemStack != null && itemStack.getItem() instanceof ItemFirework)
                {
                    return new NbtRequestMessage(message.type, JsonNBTHelper.parseNBT(ctx.getServerHandler().playerEntity.getHeldItem().writeToNBT(new NBTTagCompound())).toString());
                }
                else
                {
                    Helper.sendChatToPlayer(ctx.getServerHandler().playerEntity, "You are not holding an ItemFirework...", EnumChatFormatting.RED);
                }
                break;
            case ITEM:
                if (ctx.getServerHandler().playerEntity.getHeldItem() != null)
                {
                    return new NbtRequestMessage(message.type, JsonNBTHelper.parseNBT(ctx.getServerHandler().playerEntity.getHeldItem().writeToNBT(new NBTTagCompound())).toString());
                }
                else
                {
                    Helper.sendChatToPlayer(ctx.getServerHandler().playerEntity, "You are not holding an item...", EnumChatFormatting.RED);
                }
                break;
            case BLOCK:
                NBTTagCompound compound = new NBTTagCompound();
                World world = DimensionManager.getWorld(message.dim);
                compound.setInteger(StructureType.BLOCKID_KEY, Block.getIdFromBlock(world.getBlock(message.x, message.y, message.z)));
                compound.setInteger(StructureType.META_KEY, world.getBlockMetadata(message.x, message.y, message.z));
                TileEntity tileEntity = world.getTileEntity(message.x, message.y, message.z);
                if (tileEntity != null)
                {
                    NBTTagCompound te = new NBTTagCompound();
                    tileEntity.writeToNBT(te);
                    compound.setTag(StructureType.TEDATA_KEY, te);
                }
                return new NbtRequestMessage(message.type, JsonNBTHelper.parseNBT(compound).toString());
        }
    }
    return null;
}