Search in sources :

Example 61 with Vector3

use of micdoodle8.mods.galacticraft.api.vector.Vector3 in project Galacticraft by micdoodle8.

the class RoomBossVenus method addComponentParts.

@Override
public boolean addComponentParts(World worldIn, Random random, StructureBoundingBox chunkBox) {
    StructureBoundingBox box = new StructureBoundingBox(new int[] { Integer.MAX_VALUE, Integer.MAX_VALUE, Integer.MAX_VALUE, Integer.MIN_VALUE, Integer.MIN_VALUE, Integer.MIN_VALUE });
    for (int i = 0; i <= this.sizeX; i++) {
        for (int j = 0; j <= this.sizeY; j++) {
            for (int k = 0; k <= this.sizeZ; k++) {
                double dX = (i - this.sizeX / 2);
                double dZ = (k - this.sizeZ / 2);
                double dXZ = Math.sqrt(dX * dX + dZ * dZ);
                double f = -Math.pow((dXZ * 1.5) / (this.sizeX / 2 - 1), 6) + this.sizeY - 1;
                if (j == 0) {
                    this.setBlockState(worldIn, this.configuration.getBrickBlockFloor(), i, j, k, chunkBox);
                } else if (j < f) {
                    this.setBlockState(worldIn, Blocks.air.getDefaultState(), i, j, k, chunkBox);
                    if (j + 1 >= f && (dXZ > 5) && random.nextInt(12) == 0) {
                        int distFromFloor = random.nextInt(5) + 2;
                        for (int j0 = j; j0 >= distFromFloor + 1; --j0) {
                            BlockTorchWeb.EnumWebType webType;
                            if (j0 == distFromFloor + 1) {
                                webType = BlockTorchWeb.EnumWebType.WEB_1;
                            } else {
                                webType = BlockTorchWeb.EnumWebType.WEB_0;
                            }
                            this.setBlockState(worldIn, VenusBlocks.torchWeb.getDefaultState().withProperty(BlockTorchWeb.WEB_TYPE, webType), i, j0, k, chunkBox);
                        }
                    }
                    if (i < box.minX) {
                        box.minX = i;
                    }
                    if (i > box.maxX) {
                        box.maxX = i;
                    }
                    if (j < box.minY) {
                        box.minY = j;
                    }
                    if (j > box.maxY) {
                        box.maxY = j;
                    }
                    if (k < box.minZ) {
                        box.minZ = k;
                    }
                    if (k > box.maxZ) {
                        box.maxZ = k;
                    }
                } else {
                    boolean placeBlock = true;
                    int start = (this.boundingBox.maxX - this.boundingBox.minX) / 2 - 1;
                    int end = (this.boundingBox.maxX - this.boundingBox.minX) / 2 + 1;
                    if (i > start && i <= end && j < 5 && j > 2) {
                        if ((getDirection() == EnumFacing.SOUTH || (this.exitDirection != null && this.exitDirection == EnumFacing.SOUTH)) && k < 7) {
                            placeBlock = false;
                        }
                        if ((getDirection() == EnumFacing.NORTH || (this.exitDirection != null && this.exitDirection == EnumFacing.NORTH)) && k > this.sizeZ - 7) {
                            placeBlock = false;
                        }
                    }
                    start = (this.boundingBox.maxZ - this.boundingBox.minZ) / 2 - 1;
                    end = (this.boundingBox.maxZ - this.boundingBox.minZ) / 2 + 1;
                    if (k > start && k <= end && j < 5 && j > 2) {
                        if ((getDirection() == EnumFacing.EAST || (this.exitDirection != null && this.exitDirection == EnumFacing.EAST)) && i < 7) {
                            placeBlock = false;
                        }
                        if ((getDirection() == EnumFacing.WEST || (this.exitDirection != null && this.exitDirection == EnumFacing.WEST)) && i > this.sizeX - 7) {
                            placeBlock = false;
                        }
                    }
                    if (placeBlock) {
                        this.setBlockState(worldIn, this.configuration.getBrickBlock(), i, j, k, chunkBox);
                    } else {
                        this.setBlockState(worldIn, Blocks.air.getDefaultState(), i, j, k, chunkBox);
                    }
                }
            }
        }
    }
    int spawnerX = this.sizeX / 2;
    int spawnerY = 1;
    int spawnerZ = this.sizeZ / 2;
    BlockPos blockpos = new BlockPos(this.getXWithOffset(spawnerX, spawnerZ), this.getYWithOffset(spawnerY), this.getZWithOffset(spawnerX, spawnerZ));
    // Is this position inside the chunk currently being generated?
    if (chunkBox.isVecInside(blockpos)) {
        worldIn.setBlockState(blockpos, VenusBlocks.bossSpawner.getDefaultState(), 2);
        TileEntityDungeonSpawner spawner = (TileEntityDungeonSpawner) worldIn.getTileEntity(blockpos);
        if (spawner != null) {
            if (box.getXSize() > 10000 || box.getYSize() > 10000 || box.getZSize() > 10000) {
                GCLog.severe("Failed to set correct boss room size. This is a bug!");
            } else {
                spawner.setRoom(new Vector3(box.minX + this.boundingBox.minX, box.minY + this.boundingBox.minY, box.minZ + this.boundingBox.minZ), new Vector3(box.maxX - box.minX + 1, box.maxY - box.minY + 1, box.maxZ - box.minZ + 1));
                spawner.setChestPos(this.chestPos);
            }
        }
    }
    return true;
}
Also used : StructureBoundingBox(net.minecraft.world.gen.structure.StructureBoundingBox) BlockPos(net.minecraft.util.BlockPos) TileEntityDungeonSpawner(micdoodle8.mods.galacticraft.core.tile.TileEntityDungeonSpawner) Vector3(micdoodle8.mods.galacticraft.api.vector.Vector3)

Example 62 with Vector3

use of micdoodle8.mods.galacticraft.api.vector.Vector3 in project Galacticraft by micdoodle8.

the class TileEntityDungeonSpawner method update.

@Override
public void update() {
    super.update();
    if (this.roomCoords == null) {
        return;
    }
    if (!this.worldObj.isRemote) {
        if (this.range15 == null) {
            final Vector3 thisVec = new Vector3(this);
            this.range15 = AxisAlignedBB.fromBounds(thisVec.x - 15, thisVec.y - 15, thisVec.z - 15, thisVec.x + 15, thisVec.y + 15, thisVec.z + 15);
            this.rangeBounds = AxisAlignedBB.fromBounds(this.roomCoords.intX(), this.roomCoords.intY(), this.roomCoords.intZ(), this.roomCoords.intX() + this.roomSize.intX(), this.roomCoords.intY() + this.roomSize.intY(), this.roomCoords.intZ() + this.roomSize.intZ());
            this.rangeBoundsPlus3 = this.rangeBounds.expand(3, 3, 3);
        }
        if (// 15 minutes
        this.lastKillTime > 0 && MinecraftServer.getCurrentTimeMillis() - lastKillTime > 900000) {
            this.lastKillTime = 0;
            this.isBossDefeated = false;
        // After 15 minutes a new boss is able to be spawned
        }
        final List<E> l = this.worldObj.getEntitiesWithinAABB(bossClass, this.range15);
        for (final Entity e : l) {
            if (!e.isDead) {
                this.boss = (IBoss) e;
                this.spawned = true;
                this.isBossDefeated = false;
                this.boss.onBossSpawned(this);
            }
        }
        List<EntityMob> entitiesWithin = this.worldObj.getEntitiesWithinAABB(EntityMob.class, this.rangeBoundsPlus3);
        for (Entity mob : entitiesWithin) {
            if (this.getDisabledCreatures().contains(mob.getClass())) {
                mob.setDead();
            }
        }
        List<EntityPlayer> playersWithin = this.worldObj.getEntitiesWithinAABB(EntityPlayer.class, this.rangeBounds);
        this.playerInRange = !playersWithin.isEmpty();
        if (this.playerInRange) {
            if (!this.lastPlayerInRange && !this.spawned) {
                // Try to create a boss entity
                if (this.boss == null && !this.isBossDefeated) {
                    try {
                        Constructor<?> c = this.bossClass.getConstructor(new Class[] { World.class });
                        this.boss = (IBoss) c.newInstance(new Object[] { this.worldObj });
                        ((Entity) this.boss).setPosition(this.getPos().getX() + 0.5, this.getPos().getY() + 1.0, this.getPos().getZ() + 0.5);
                    } catch (Exception e) {
                        e.printStackTrace();
                    }
                }
                // Now spawn the boss
                if (this.boss != null) {
                    if (this.boss instanceof EntityLiving) {
                        EntityLiving bossLiving = (EntityLiving) this.boss;
                        bossLiving.onInitialSpawn(this.worldObj.getDifficultyForLocation(new BlockPos(bossLiving)), null);
                        this.worldObj.spawnEntityInWorld(bossLiving);
                        this.playSpawnSound(bossLiving);
                        this.spawned = true;
                    }
                }
            }
        }
        this.lastPlayerInRange = this.playerInRange;
    }
}
Also used : EntityMob(net.minecraft.entity.monster.EntityMob) Entity(net.minecraft.entity.Entity) EntityLiving(net.minecraft.entity.EntityLiving) EntityPlayer(net.minecraft.entity.player.EntityPlayer) Vector3(micdoodle8.mods.galacticraft.api.vector.Vector3) BlockPos(net.minecraft.util.BlockPos)

Example 63 with Vector3

use of micdoodle8.mods.galacticraft.api.vector.Vector3 in project Galacticraft by micdoodle8.

the class TileEntityDungeonSpawner method readFromNBT.

@Override
public void readFromNBT(NBTTagCompound nbt) {
    super.readFromNBT(nbt);
    this.playerInRange = this.lastPlayerInRange = nbt.getBoolean("playerInRange");
    this.isBossDefeated = nbt.getBoolean("defeated");
    try {
        this.bossClass = (Class<E>) Class.forName(nbt.getString("bossClass"));
    } catch (Exception e) {
        e.printStackTrace();
    }
    this.roomCoords = new Vector3();
    this.roomCoords.x = nbt.getDouble("roomCoordsX");
    this.roomCoords.y = nbt.getDouble("roomCoordsY");
    this.roomCoords.z = nbt.getDouble("roomCoordsZ");
    this.roomSize = new Vector3();
    this.roomSize.x = nbt.getDouble("roomSizeX");
    this.roomSize.y = nbt.getDouble("roomSizeY");
    this.roomSize.z = nbt.getDouble("roomSizeZ");
    if (nbt.hasKey("lastKillTime")) {
        this.lastKillTime = nbt.getLong("lastKillTime");
    } else if (nbt.hasKey("lastKillTimeNew")) {
        long savedTime = nbt.getLong("lastKillTimeNew");
        this.lastKillTime = savedTime == 0 ? 0 : savedTime + MinecraftServer.getCurrentTimeMillis();
    }
    if (nbt.hasKey("chestPosNull") && !nbt.getBoolean("chestPosNull")) {
        this.chestPos = new BlockPos(nbt.getInteger("chestX"), nbt.getInteger("chestY"), nbt.getInteger("chestZ"));
    }
}
Also used : Vector3(micdoodle8.mods.galacticraft.api.vector.Vector3) BlockPos(net.minecraft.util.BlockPos)

Example 64 with Vector3

use of micdoodle8.mods.galacticraft.api.vector.Vector3 in project Galacticraft by micdoodle8.

the class WorldUtil method teleportEntitySimple.

public static Entity teleportEntitySimple(World worldNew, int dimID, EntityPlayerMP player, Vector3 spawnPos) {
    if (player.ridingEntity != null) {
        player.ridingEntity.setDead();
        player.mountEntity(null);
    }
    World worldOld = player.worldObj;
    int oldDimID = GCCoreUtil.getDimensionID(worldOld);
    boolean dimChange = worldOld != worldNew;
    // Make sure the entity is added to the correct chunk in the OLD world so that it will be properly removed later if it needs to be unloaded from that world
    worldOld.updateEntityWithOptionalForce(player, false);
    if (dimChange) {
        player.dimension = dimID;
        if (ConfigManagerCore.enableDebug) {
            GCLog.info("DEBUG: Sending respawn packet to player for dim " + dimID);
        }
        player.playerNetServerHandler.sendPacket(new S07PacketRespawn(dimID, player.worldObj.getDifficulty(), player.worldObj.getWorldInfo().getTerrainType(), player.theItemInWorldManager.getGameType()));
        if (worldNew.provider instanceof WorldProviderSpaceStation) {
            if (WorldUtil.registeredSpaceStations.containsKey(dimID)) // TODO This has never been effective before due to the earlier bug - what does it actually do?
            {
                NBTTagCompound var2 = new NBTTagCompound();
                SpaceStationWorldData.getStationData(worldNew, dimID, player).writeToNBT(var2);
                GalacticraftCore.packetPipeline.sendTo(new PacketSimple(EnumSimplePacket.C_UPDATE_SPACESTATION_DATA, GCCoreUtil.getDimensionID(player.worldObj), new Object[] { dimID, var2 }), player);
            }
        }
        removeEntityFromWorld(worldOld, player, true);
        forceMoveEntityToPos(player, (WorldServer) worldNew, spawnPos, true);
        GCLog.info("Server attempting to transfer player " + PlayerUtil.getName(player) + " to dimension " + GCCoreUtil.getDimensionID(worldNew));
        player.mcServer.getConfigurationManager().preparePlayer(player, (WorldServer) worldOld);
        player.theItemInWorldManager.setWorld((WorldServer) worldNew);
        player.mcServer.getConfigurationManager().updateTimeAndWeatherForPlayer(player, (WorldServer) worldNew);
        player.mcServer.getConfigurationManager().syncPlayerInventory(player);
        for (Object o : player.getActivePotionEffects()) {
            PotionEffect var10 = (PotionEffect) o;
            player.playerNetServerHandler.sendPacket(new S1DPacketEntityEffect(player.getEntityId(), var10));
        }
        player.playerNetServerHandler.sendPacket(new S1FPacketSetExperience(player.experience, player.experienceTotal, player.experienceLevel));
        FMLCommonHandler.instance().firePlayerChangedDimensionEvent((EntityPlayerMP) player, oldDimID, dimID);
    } else {
        forceMoveEntityToPos(player, (WorldServer) worldNew, spawnPos, false);
        GCLog.info("Server attempting to transfer player " + PlayerUtil.getName(player) + " within same dimension " + GCCoreUtil.getDimensionID(worldNew));
    }
    player.capabilities.isFlying = false;
    GalacticraftCore.packetPipeline.sendTo(new PacketSimple(EnumSimplePacket.C_RESET_THIRD_PERSON, GCCoreUtil.getDimensionID(player.worldObj), new Object[] {}), player);
    // Update PlayerStatsGC
    GCPlayerStats stats = GCPlayerStats.get(player);
    GCPlayerHandler.setUsingParachute(player, stats, false);
    return player;
}
Also used : S07PacketRespawn(net.minecraft.network.play.server.S07PacketRespawn) PotionEffect(net.minecraft.potion.PotionEffect) WorldProviderSpaceStation(micdoodle8.mods.galacticraft.core.dimension.WorldProviderSpaceStation) S1FPacketSetExperience(net.minecraft.network.play.server.S1FPacketSetExperience) NBTTagCompound(net.minecraft.nbt.NBTTagCompound) S1DPacketEntityEffect(net.minecraft.network.play.server.S1DPacketEntityEffect) GCPlayerStats(micdoodle8.mods.galacticraft.core.entities.player.GCPlayerStats) PacketSimple(micdoodle8.mods.galacticraft.core.network.PacketSimple)

Example 65 with Vector3

use of micdoodle8.mods.galacticraft.api.vector.Vector3 in project Galacticraft by micdoodle8.

the class BlockFallenMeteor method colorMultiplier.

@Override
public int colorMultiplier(IBlockAccess worldIn, BlockPos pos, int renderPass) {
    TileEntity tile = worldIn.getTileEntity(pos);
    if (tile instanceof TileEntityFallenMeteor) {
        TileEntityFallenMeteor meteor = (TileEntityFallenMeteor) tile;
        Vector3 col = new Vector3(198, 108, 58);
        col.translate(200 - meteor.getScaledHeatLevel() * 200);
        col.x = Math.min(255, col.x);
        col.y = Math.min(255, col.y);
        col.z = Math.min(255, col.z);
        return ColorUtil.to32BitColor(255, (byte) col.x, (byte) col.y, (byte) col.z);
    }
    return super.colorMultiplier(worldIn, pos, renderPass);
}
Also used : TileEntity(net.minecraft.tileentity.TileEntity) TileEntityFallenMeteor(micdoodle8.mods.galacticraft.core.tile.TileEntityFallenMeteor) Vector3(micdoodle8.mods.galacticraft.api.vector.Vector3)

Aggregations

Vector3 (micdoodle8.mods.galacticraft.api.vector.Vector3)74 BlockPos (net.minecraft.util.BlockPos)13 Entity (net.minecraft.entity.Entity)12 TileEntity (net.minecraft.tileentity.TileEntity)11 BlockVec3 (micdoodle8.mods.galacticraft.api.vector.BlockVec3)8 GCPlayerStats (micdoodle8.mods.galacticraft.core.entities.player.GCPlayerStats)8 EntityPlayer (net.minecraft.entity.player.EntityPlayer)8 Footprint (micdoodle8.mods.galacticraft.core.wrappers.Footprint)6 IBlockState (net.minecraft.block.state.IBlockState)6 EntityLivingBase (net.minecraft.entity.EntityLivingBase)6 EntityPlayerMP (net.minecraft.entity.player.EntityPlayerMP)6 ItemStack (net.minecraft.item.ItemStack)6 IGalacticraftWorldProvider (micdoodle8.mods.galacticraft.api.world.IGalacticraftWorldProvider)5 NBTTagCompound (net.minecraft.nbt.NBTTagCompound)5 SideOnly (net.minecraftforge.fml.relauncher.SideOnly)5 WorldProviderSpaceStation (micdoodle8.mods.galacticraft.core.dimension.WorldProviderSpaceStation)4 PacketSimple (micdoodle8.mods.galacticraft.core.network.PacketSimple)4 FlagData (micdoodle8.mods.galacticraft.core.wrappers.FlagData)4 WorldServer (net.minecraft.world.WorldServer)4 GameProfile (com.mojang.authlib.GameProfile)3