Лайтинг

318
12
Ребятки, помогите.. Как заспавнить "энтити" света?
Сделал я что то типа фонаря. Получил корды блока на которые навожу. Суть такая.  Нажимая кнопку R включается фонарь и в онАпдейте чекается ли он врублен и после этого надо спавнить луч света на этих кордах.. Ну и код что бы он исчезал как то...

Спасибо заранее....
 
Сущность - только через мод DynamicLights. Он хорош, сам использую в качестве библиотеки. Вряд ли динамические источники света получится сделать лучше, чем там, не переписывая половину майнкрафта :D
 
Код:
public static ArrayList<Vector3i> blockLightOverrides = new ArrayList<Vector3i>();
    public static int lightOverrideRefreshRate = 5;
public void clientTickStart(Minecraft mc) {
        if (FlansMod.ticker % lightOverrideRefreshRate == 0 && mc.theWorld != null) {
            //Check graphics setting and adjust refresh rate
            lightOverrideRefreshRate = mc.gameSettings.fancyGraphics ? 3 : 5;

            //Reset old light values
            for (Vector3i v : blockLightOverrides) {
                mc.theWorld.updateLightByType(EnumSkyBlock.Block, v.x, v.y, v.z);
            }
            //Clear the list
            blockLightOverrides.clear();

            //Find all flashlights
            for (Object obj : mc.theWorld.playerEntities) {
                EntityPlayer player = (EntityPlayer) obj;
                ItemStack currentHeldItem = player.getCurrentEquippedItem();
                if (currentHeldItem != null && currentHeldItem.getItem() instanceof Flashlight) {
                    ItemStack i = currentHeldItem;
                    if (i.getTagCompound().getBoolean("on")) {
                        for (int kfc = 0; kfc < 2; kfc++) {
                            MovingObjectPosition mop = player.rayTrace(CraftZ.flashRange / 2F * (kfc + 1), 1F);
                            if (mop != null) {
                                int x = mop.blockX;
                                int y = mop.blockY;
                                int z = mop.blockZ;
                                int side = mop.sideHit;
                                switch (side) {
                                    case 0:
                                        y--;
                                        break;
                                    case 1:
                                        y++;
                                        break;
                                    case 2:
                                        z--;
                                        break;
                                    case 3:
                                        z++;
                                        break;
                                    case 4:
                                        x--;
                                        break;
                                    case 5:
                                        x++;
                                        break;
                                }
                                blockLightOverrides.add(new Vector3i(x, y, z));
                                mc.theWorld.setLightValue(EnumSkyBlock.Block, x, y, z, 12);
                                mc.theWorld.updateLightByType(EnumSkyBlock.Block, x, y + 1, z);
                                mc.theWorld.updateLightByType(EnumSkyBlock.Block, x, y - 1, z);
                                mc.theWorld.updateLightByType(EnumSkyBlock.Block, x + 1, y, z);
                                mc.theWorld.updateLightByType(EnumSkyBlock.Block, x - 1, y, z);
                                mc.theWorld.updateLightByType(EnumSkyBlock.Block, x, y, z + 1);
                                mc.theWorld.updateLightByType(EnumSkyBlock.Block, x, y, z - 1);
                            }
                        }
                    }
 
Код:
public static ArrayList<Vector3i> blockLightOverrides = new ArrayList<Vector3i>();
    public static int lightOverrideRefreshRate = 5;
public void clientTickStart(Minecraft mc) {
        if (FlansMod.ticker % lightOverrideRefreshRate == 0 && mc.theWorld != null) {
            //Check graphics setting and adjust refresh rate
            lightOverrideRefreshRate = mc.gameSettings.fancyGraphics ? 3 : 5;

            //Reset old light values
            for (Vector3i v : blockLightOverrides) {
                mc.theWorld.updateLightByType(EnumSkyBlock.Block, v.x, v.y, v.z);
            }
            //Clear the list
            blockLightOverrides.clear();

            //Find all flashlights
            for (Object obj : mc.theWorld.playerEntities) {
                EntityPlayer player = (EntityPlayer) obj;
                ItemStack currentHeldItem = player.getCurrentEquippedItem();
                if (currentHeldItem != null && currentHeldItem.getItem() instanceof Flashlight) {
                    ItemStack i = currentHeldItem;
                    if (i.getTagCompound().getBoolean("on")) {
                        for (int kfc = 0; kfc < 2; kfc++) {
                            MovingObjectPosition mop = player.rayTrace(CraftZ.flashRange / 2F * (kfc + 1), 1F);
                            if (mop != null) {
                                int x = mop.blockX;
                                int y = mop.blockY;
                                int z = mop.blockZ;
                                int side = mop.sideHit;
                                switch (side) {
                                    case 0:
                                        y--;
                                        break;
                                    case 1:
                                        y++;
                                        break;
                                    case 2:
                                        z--;
                                        break;
                                    case 3:
                                        z++;
                                        break;
                                    case 4:
                                        x--;
                                        break;
                                    case 5:
                                        x++;
                                        break;
                                }
                                blockLightOverrides.add(new Vector3i(x, y, z));
                                mc.theWorld.setLightValue(EnumSkyBlock.Block, x, y, z, 12);
                                mc.theWorld.updateLightByType(EnumSkyBlock.Block, x, y + 1, z);
                                mc.theWorld.updateLightByType(EnumSkyBlock.Block, x, y - 1, z);
                                mc.theWorld.updateLightByType(EnumSkyBlock.Block, x + 1, y, z);
                                mc.theWorld.updateLightByType(EnumSkyBlock.Block, x - 1, y, z);
                                mc.theWorld.updateLightByType(EnumSkyBlock.Block, x, y, z + 1);
                                mc.theWorld.updateLightByType(EnumSkyBlock.Block, x, y, z - 1);
                            }
                        }
                    }
                }
                if (currentHeldItem != null && currentHeldItem.getItem() instanceof ItemGun) {
                    GunType type = ((ItemGun) currentHeldItem.getItem()).type;
                    AttachmentType grip = type.getGrip(currentHeldItem);
                    if (grip != null && grip.flashlight) {
                        for (int i = 0; i < 2; i++) {
                            MovingObjectPosition ray = player.rayTrace(grip.flashlightRange / 2F * (i + 1), 1F);
                            if (ray != null) {
                                int x = ray.blockX;
                                int y = ray.blockY;
                                int z = ray.blockZ;
                                int side = ray.sideHit;
                                switch (side) {
                                    case 0:
                                        y--;
                                        break;
                                    case 1:
                                        y++;
                                        break;
                                    case 2:
                                        z--;
                                        break;
                                    case 3:
                                        z++;
                                        break;
                                    case 4:
                                        x--;
                                        break;
                                    case 5:
                                        x++;
                                        break;
                                }
                                blockLightOverrides.add(new Vector3i(x, y, z));
                                mc.theWorld.setLightValue(EnumSkyBlock.Block, x, y, z, 12);
                                mc.theWorld.updateLightByType(EnumSkyBlock.Block, x, y + 1, z);
                                mc.theWorld.updateLightByType(EnumSkyBlock.Block, x, y - 1, z);
                                mc.theWorld.updateLightByType(EnumSkyBlock.Block, x + 1, y, z);
                                mc.theWorld.updateLightByType(EnumSkyBlock.Block, x - 1, y, z);
                                mc.theWorld.updateLightByType(EnumSkyBlock.Block, x, y, z + 1);
                                mc.theWorld.updateLightByType(EnumSkyBlock.Block, x, y, z - 1);
                            }
                        }
                    }
                }
            }

            for (Object obj : mc.theWorld.loadedEntityList) {
                if (obj instanceof EntityBullet) {
                    EntityBullet bullet = (EntityBullet) obj;
                    if (!bullet.isDead && bullet.type.hasLight) {
                        int x = MathHelper.floor_double(bullet.posX);
                        int y = MathHelper.floor_double(bullet.posY);
                        int z = MathHelper.floor_double(bullet.posZ);
                        blockLightOverrides.add(new Vector3i(x, y, z));
                        mc.theWorld.setLightValue(EnumSkyBlock.Block, x, y, z, 15);
                        mc.theWorld.updateLightByType(EnumSkyBlock.Block, x, y + 1, z);
                        mc.theWorld.updateLightByType(EnumSkyBlock.Block, x, y - 1, z);
                        mc.theWorld.updateLightByType(EnumSkyBlock.Block, x + 1, y, z);
                        mc.theWorld.updateLightByType(EnumSkyBlock.Block, x - 1, y, z);
                        mc.theWorld.updateLightByType(EnumSkyBlock.Block, x, y, z + 1);
                        mc.theWorld.updateLightByType(EnumSkyBlock.Block, x, y, z - 1);
                    }
                } else if (obj instanceof EntityMecha) {
                    EntityMecha mecha = (EntityMecha) obj;
                    int x = MathHelper.floor_double(mecha.posX);
                    int y = MathHelper.floor_double(mecha.posY);
                    int z = MathHelper.floor_double(mecha.posZ);
                    if (mecha.lightLevel() > 0) {
                        blockLightOverrides.add(new Vector3i(x, y, z));
                        mc.theWorld.setLightValue(EnumSkyBlock.Block, x, y, z, Math.max(mc.theWorld.getBlockLightValue(x, y, z), mecha.lightLevel()));
                        mc.theWorld.updateLightByType(EnumSkyBlock.Block, x + 1, y, z);
                        mc.theWorld.updateLightByType(EnumSkyBlock.Block, x - 1, y + 1, z);
                        mc.theWorld.updateLightByType(EnumSkyBlock.Block, x, y + 1, z);
                        mc.theWorld.updateLightByType(EnumSkyBlock.Block, x, y - 1, z);
                        mc.theWorld.updateLightByType(EnumSkyBlock.Block, x, y, z + 1);
                        mc.theWorld.updateLightByType(EnumSkyBlock.Block, x, y, z - 1);
                    }
                    if (mecha.forceDark()) {
                        for (int i = -3; i <= 3; i++) {
                            for (int j = -3; j <= 3; j++) {
                                for (int k = -3; k <= 3; k++) {
                                    int xd = i + x;
                                    int yd = j + y;
                                    int zd = k + z;
                                    blockLightOverrides.add(new Vector3i(xd, yd, zd));
                                    mc.theWorld.setLightValue(EnumSkyBlock.Sky, xd, yd, zd, Math.abs(i) + Math.abs(j) + Math.abs(k));
                                }
                            }
                        }
                    }
                }
            }
        }
    }
[merge_posts_bbcode]Добавлено: 26.06.2015 00:01:44[/merge_posts_bbcode]
Код:
public static ArrayList<Vector3i> blockLightOverrides = new ArrayList<Vector3i>();
    public static int lightOverrideRefreshRate = 5;
public void clientTickStart(Minecraft mc) {
        if (FlansMod.ticker % lightOverrideRefreshRate == 0 && mc.theWorld != null) {
            //Check graphics setting and adjust refresh rate
            lightOverrideRefreshRate = mc.gameSettings.fancyGraphics ? 3 : 5;

            //Reset old light values
            for (Vector3i v : blockLightOverrides) {
                mc.theWorld.updateLightByType(EnumSkyBlock.Block, v.x, v.y, v.z);
            }
            //Clear the list
            blockLightOverrides.clear();

            //Find all flashlights
            for (Object obj : mc.theWorld.playerEntities) {
                EntityPlayer player = (EntityPlayer) obj;
                ItemStack currentHeldItem = player.getCurrentEquippedItem();
                if (currentHeldItem != null && currentHeldItem.getItem() instanceof Flashlight) {
                    ItemStack i = currentHeldItem;
                    if (i.getTagCompound().getBoolean("on")) {
                        for (int kfc = 0; kfc < 2; kfc++) {
                            MovingObjectPosition mop = player.rayTrace(CraftZ.flashRange / 2F * (kfc + 1), 1F);
                            if (mop != null) {
                                int x = mop.blockX;
                                int y = mop.blockY;
                                int z = mop.blockZ;
                                int side = mop.sideHit;
                                switch (side) {
                                    case 0:
                                        y--;
                                        break;
                                    case 1:
                                        y++;
                                        break;
                                    case 2:
                                        z--;
                                        break;
                                    case 3:
                                        z++;
                                        break;
                                    case 4:
                                        x--;
                                        break;
                                    case 5:
                                        x++;
                                        break;
                                }
                                blockLightOverrides.add(new Vector3i(x, y, z));
                                mc.theWorld.setLightValue(EnumSkyBlock.Block, x, y, z, 12);
                                mc.theWorld.updateLightByType(EnumSkyBlock.Block, x, y + 1, z);
                                mc.theWorld.updateLightByType(EnumSkyBlock.Block, x, y - 1, z);
                                mc.theWorld.updateLightByType(EnumSkyBlock.Block, x + 1, y, z);
                                mc.theWorld.updateLightByType(EnumSkyBlock.Block, x - 1, y, z);
                                mc.theWorld.updateLightByType(EnumSkyBlock.Block, x, y, z + 1);
                                mc.theWorld.updateLightByType(EnumSkyBlock.Block, x, y, z - 1);
                            }
                        }
                    }
                }
                if (currentHeldItem != null && currentHeldItem.getItem() instanceof ItemGun) {
                    GunType type = ((ItemGun) currentHeldItem.getItem()).type;
                    AttachmentType grip = type.getGrip(currentHeldItem);
                    if (grip != null && grip.flashlight) {
                        for (int i = 0; i < 2; i++) {
                            MovingObjectPosition ray = player.rayTrace(grip.flashlightRange / 2F * (i + 1), 1F);
                            if (ray != null) {
                                int x = ray.blockX;
                                int y = ray.blockY;
                                int z = ray.blockZ;
                                int side = ray.sideHit;
                                switch (side) {
                                    case 0:
                                        y--;
                                        break;
                                    case 1:
                                        y++;
                                        break;
                                    case 2:
                                        z--;
                                        break;
                                    case 3:
                                        z++;
                                        break;
                                    case 4:
                                        x--;
                                        break;
                                    case 5:
                                        x++;
                                        break;
                                }
                                blockLightOverrides.add(new Vector3i(x, y, z));
                                mc.theWorld.setLightValue(EnumSkyBlock.Block, x, y, z, 12);
                                mc.theWorld.updateLightByType(EnumSkyBlock.Block, x, y + 1, z);
                                mc.theWorld.updateLightByType(EnumSkyBlock.Block, x, y - 1, z);
                                mc.theWorld.updateLightByType(EnumSkyBlock.Block, x + 1, y, z);
                                mc.theWorld.updateLightByType(EnumSkyBlock.Block, x - 1, y, z);
                                mc.theWorld.updateLightByType(EnumSkyBlock.Block, x, y, z + 1);
                                mc.theWorld.updateLightByType(EnumSkyBlock.Block, x, y, z - 1);
                            }
                        }
                    }
                }
            }

            for (Object obj : mc.theWorld.loadedEntityList) {
                if (obj instanceof EntityBullet) {
                    EntityBullet bullet = (EntityBullet) obj;
                    if (!bullet.isDead && bullet.type.hasLight) {
                        int x = MathHelper.floor_double(bullet.posX);
                        int y = MathHelper.floor_double(bullet.posY);
                        int z = MathHelper.floor_double(bullet.posZ);
                        blockLightOverrides.add(new Vector3i(x, y, z));
                        mc.theWorld.setLightValue(EnumSkyBlock.Block, x, y, z, 15);
                        mc.theWorld.updateLightByType(EnumSkyBlock.Block, x, y + 1, z);
                        mc.theWorld.updateLightByType(EnumSkyBlock.Block, x, y - 1, z);
                        mc.theWorld.updateLightByType(EnumSkyBlock.Block, x + 1, y, z);
                        mc.theWorld.updateLightByType(EnumSkyBlock.Block, x - 1, y, z);
                        mc.theWorld.updateLightByType(EnumSkyBlock.Block, x, y, z + 1);
                        mc.theWorld.updateLightByType(EnumSkyBlock.Block, x, y, z - 1);
                    }
                } else if (obj instanceof EntityMecha) {
                    EntityMecha mecha = (EntityMecha) obj;
                    int x = MathHelper.floor_double(mecha.posX);
                    int y = MathHelper.floor_double(mecha.posY);
                    int z = MathHelper.floor_double(mecha.posZ);
                    if (mecha.lightLevel() > 0) {
                        blockLightOverrides.add(new Vector3i(x, y, z));
                        mc.theWorld.setLightValue(EnumSkyBlock.Block, x, y, z, Math.max(mc.theWorld.getBlockLightValue(x, y, z), mecha.lightLevel()));
                        mc.theWorld.updateLightByType(EnumSkyBlock.Block, x + 1, y, z);
                        mc.theWorld.updateLightByType(EnumSkyBlock.Block, x - 1, y + 1, z);
                        mc.theWorld.updateLightByType(EnumSkyBlock.Block, x, y + 1, z);
                        mc.theWorld.updateLightByType(EnumSkyBlock.Block, x, y - 1, z);
                        mc.theWorld.updateLightByType(EnumSkyBlock.Block, x, y, z + 1);
                        mc.theWorld.updateLightByType(EnumSkyBlock.Block, x, y, z - 1);
                    }
                    if (mecha.forceDark()) {
                        for (int i = -3; i <= 3; i++) {
                            for (int j = -3; j <= 3; j++) {
                                for (int k = -3; k <= 3; k++) {
                                    int xd = i + x;
                                    int yd = j + y;
                                    int zd = k + z;
                                    blockLightOverrides.add(new Vector3i(xd, yd, zd));
                                    mc.theWorld.setLightValue(EnumSkyBlock.Sky, xd, yd, zd, Math.abs(i) + Math.abs(j) + Math.abs(k));
                                }
                            }
                        }
                    }
                }
            }
        }
    }
 
Назад
Сверху