Search in sources :

Example 1 with Footprint

use of micdoodle8.mods.galacticraft.core.wrappers.Footprint in project Galacticraft by micdoodle8.

the class FootprintRenderer method renderFootprints.

public static void renderFootprints(EntityPlayer player, float partialTicks) {
    GL11.glPushMatrix();
    double interpPosX = player.lastTickPosX + (player.posX - player.lastTickPosX) * partialTicks;
    double interpPosY = player.lastTickPosY + (player.posY - player.lastTickPosY) * partialTicks;
    double interpPosZ = player.lastTickPosZ + (player.posZ - player.lastTickPosZ) * partialTicks;
    FMLClientHandler.instance().getClient().renderEngine.bindTexture(FootprintRenderer.footprintTexture);
    GL11.glColor4f(1.0F, 1.0F, 1.0F, 1.0F);
    GL11.glDepthMask(true);
    GL11.glEnable(GL11.GL_DEPTH_TEST);
    GL11.glEnable(GL11.GL_TEXTURE_2D);
    GL11.glDisable(GL11.GL_CULL_FACE);
    GL11.glEnable(GL11.GL_BLEND);
    OpenGlHelper.glBlendFunc(GL11.GL_SRC_ALPHA, GL11.GL_ONE_MINUS_SRC_ALPHA, 1, 0);
    Tessellator tessellator = Tessellator.getInstance();
    float f7 = 1.0F;
    float f6 = 0.0F;
    float f8 = 0.0F;
    float f9 = 1.0F;
    float f10 = 0.4F;
    GL11.glAlphaFunc(GL11.GL_GREATER, 0.1F);
    for (List<Footprint> footprintList : footprints.values()) {
        for (Footprint footprint : footprintList) {
            if (footprint.dimension == GCCoreUtil.getDimensionID(player.worldObj)) {
                GL11.glPushMatrix();
                float ageScale = footprint.age / (float) Footprint.MAX_AGE;
                WorldRenderer worldRenderer = tessellator.getWorldRenderer();
                worldRenderer.begin(GL11.GL_QUADS, DefaultVertexFormats.POSITION_TEX);
                float f11 = (float) (footprint.position.x - interpPosX);
                float f12 = (float) (footprint.position.y - interpPosY) + 0.001F;
                float f13 = (float) (footprint.position.z - interpPosZ);
                GL11.glTranslatef(f11, f12, f13);
                int brightness = (int) (100 + ageScale * 155);
                // worldRenderer.putBrightness4(brightness, brightness, brightness, brightness);
                GL11.glColor4f(1 - ageScale, 1 - ageScale, 1 - ageScale, 1 - ageScale);
                double footprintScale = 0.5F;
                worldRenderer.pos(Math.sin((45 - footprint.rotation) / Constants.RADIANS_TO_DEGREES_D) * footprintScale, 0, Math.cos((45 - footprint.rotation) / Constants.RADIANS_TO_DEGREES_D) * footprintScale).tex(f7, f9).endVertex();
                worldRenderer.pos(Math.sin((135 - footprint.rotation) / Constants.RADIANS_TO_DEGREES_D) * footprintScale, 0, Math.cos((135 - footprint.rotation) / Constants.RADIANS_TO_DEGREES_D) * footprintScale).tex(f7, f8).endVertex();
                worldRenderer.pos(Math.sin((225 - footprint.rotation) / Constants.RADIANS_TO_DEGREES_D) * footprintScale, 0, Math.cos((225 - footprint.rotation) / Constants.RADIANS_TO_DEGREES_D) * footprintScale).tex(f6, f8).endVertex();
                worldRenderer.pos(Math.sin((315 - footprint.rotation) / Constants.RADIANS_TO_DEGREES_D) * footprintScale, 0, Math.cos((315 - footprint.rotation) / Constants.RADIANS_TO_DEGREES_D) * footprintScale).tex(f6, f9).endVertex();
                tessellator.draw();
                GL11.glPopMatrix();
            }
        }
    }
    GL11.glDisable(GL11.GL_BLEND);
    GL11.glEnable(GL11.GL_CULL_FACE);
    GL11.glPopMatrix();
}
Also used : Footprint(micdoodle8.mods.galacticraft.core.wrappers.Footprint) Tessellator(net.minecraft.client.renderer.Tessellator) WorldRenderer(net.minecraft.client.renderer.WorldRenderer) Footprint(micdoodle8.mods.galacticraft.core.wrappers.Footprint)

Example 2 with Footprint

use of micdoodle8.mods.galacticraft.core.wrappers.Footprint in project Galacticraft by micdoodle8.

the class FootprintRenderer method setFootprints.

public static void setFootprints(long chunkKey, List<Footprint> prints) {
    List<Footprint> footprintList = footprints.get(chunkKey);
    if (footprintList == null) {
        footprintList = new ArrayList<Footprint>();
    }
    Iterator<Footprint> i = footprintList.iterator();
    while (i.hasNext()) {
        Footprint print = i.next();
        if (!print.owner.equals(FMLClientHandler.instance().getClient().thePlayer.getName())) {
            i.remove();
        }
    }
    footprintList.addAll(prints);
    footprints.put(chunkKey, footprintList);
}
Also used : Footprint(micdoodle8.mods.galacticraft.core.wrappers.Footprint)

Example 3 with Footprint

use of micdoodle8.mods.galacticraft.core.wrappers.Footprint in project Galacticraft by micdoodle8.

the class BlockBasicMoon method breakBlock.

@Override
public void breakBlock(World worldIn, BlockPos pos, IBlockState state) {
    super.breakBlock(worldIn, pos, state);
    EnumBlockBasicMoon type = ((EnumBlockBasicMoon) state.getValue(BASIC_TYPE_MOON));
    if (!worldIn.isRemote && type == EnumBlockBasicMoon.MOON_TURF) {
        Map<Long, List<Footprint>> footprintChunkMap = TickHandlerServer.serverFootprintMap.get(GCCoreUtil.getDimensionID(worldIn));
        if (footprintChunkMap != null) {
            long chunkKey = ChunkCoordIntPair.chunkXZ2Int(pos.getX() >> 4, pos.getZ() >> 4);
            List<Footprint> footprintList = footprintChunkMap.get(chunkKey);
            if (footprintList != null && !footprintList.isEmpty()) {
                List<Footprint> toRemove = new ArrayList<Footprint>();
                for (Footprint footprint : footprintList) {
                    if (footprint.position.x > pos.getX() && footprint.position.x < pos.getX() + 1 && footprint.position.z > pos.getZ() && footprint.position.z < pos.getZ() + 1) {
                        toRemove.add(footprint);
                    }
                }
                if (!toRemove.isEmpty()) {
                    footprintList.removeAll(toRemove);
                }
            }
        }
        TickHandlerServer.footprintBlockChanges.add(new BlockVec3Dim(pos, GCCoreUtil.getDimensionID(worldIn)));
    }
}
Also used : Footprint(micdoodle8.mods.galacticraft.core.wrappers.Footprint) ArrayList(java.util.ArrayList) ArrayList(java.util.ArrayList) List(java.util.List) BlockVec3Dim(micdoodle8.mods.galacticraft.api.vector.BlockVec3Dim)

Example 4 with Footprint

use of micdoodle8.mods.galacticraft.core.wrappers.Footprint in project Galacticraft by micdoodle8.

the class PlayerClient method updateFeet.

private void updateFeet(EntityPlayerSP player, double motionX, double motionZ) {
    GCPlayerStatsClient stats = GCPlayerStatsClient.get(player);
    double motionSqrd = motionX * motionX + motionZ * motionZ;
    // If the player is on the moon, not airbourne and not riding anything
    if (motionSqrd > 0.001 && player.worldObj != null && player.worldObj.provider instanceof WorldProviderMoon && player.ridingEntity == null && !player.capabilities.isFlying) {
        int iPosX = MathHelper.floor_double(player.posX);
        int iPosY = MathHelper.floor_double(player.posY - 0.05);
        int iPosZ = MathHelper.floor_double(player.posZ);
        BlockPos pos1 = new BlockPos(iPosX, iPosY, iPosZ);
        IBlockState state = player.worldObj.getBlockState(pos1);
        // If the block below is the moon block
        if (state.getBlock() == GCBlocks.blockMoon) {
            // And is the correct metadata (moon turf)
            if (state.getValue(BlockBasicMoon.BASIC_TYPE_MOON) == BlockBasicMoon.EnumBlockBasicMoon.MOON_TURF) {
                // If it has been long enough since the last step
                if (stats.getDistanceSinceLastStep() > 0.35) {
                    Vector3 pos = new Vector3(player);
                    // Set the footprint position to the block below and add random number to stop z-fighting
                    pos.y = MathHelper.floor_double(player.posY) + player.getRNG().nextFloat() / 100.0F;
                    // Adjust footprint to left or right depending on step count
                    switch(stats.getLastStep()) {
                        case 0:
                            pos.translate(new Vector3(Math.sin(Math.toRadians(-player.rotationYaw + 90)) * 0.25, 0, Math.cos(Math.toRadians(-player.rotationYaw + 90)) * 0.25));
                            break;
                        case 1:
                            pos.translate(new Vector3(Math.sin(Math.toRadians(-player.rotationYaw - 90)) * 0.25, 0, Math.cos(Math.toRadians(-player.rotationYaw - 90)) * 0.25));
                            break;
                    }
                    pos = WorldUtil.getFootprintPosition(player.worldObj, player.rotationYaw - 180, pos, new BlockVec3(player));
                    long chunkKey = ChunkCoordIntPair.chunkXZ2Int(pos.intX() >> 4, pos.intZ() >> 4);
                    FootprintRenderer.addFootprint(chunkKey, GCCoreUtil.getDimensionID(player.worldObj), pos, player.rotationYaw, player.getName());
                    // Increment and cap step counter at 1
                    stats.setLastStep((stats.getLastStep() + 1) % 2);
                    stats.setDistanceSinceLastStep(0);
                } else {
                    stats.setDistanceSinceLastStep(stats.getDistanceSinceLastStep() + motionSqrd);
                }
            }
        }
    }
}
Also used : IBlockState(net.minecraft.block.state.IBlockState) WorldProviderMoon(micdoodle8.mods.galacticraft.core.dimension.WorldProviderMoon) Vector3(micdoodle8.mods.galacticraft.api.vector.Vector3) BlockVec3(micdoodle8.mods.galacticraft.api.vector.BlockVec3)

Example 5 with Footprint

use of micdoodle8.mods.galacticraft.core.wrappers.Footprint in project Galacticraft by micdoodle8.

the class TickHandlerServer method onServerTick.

@SubscribeEvent
public void onServerTick(ServerTickEvent event) {
    MinecraftServer server = FMLCommonHandler.instance().getMinecraftServerInstance();
    // Prevent issues when clients switch to LAN servers
    if (server == null) {
        return;
    }
    if (event.phase == Phase.START) {
        if (timerHoustonCommand > 0) {
            if (--timerHoustonCommand == 0) {
                CommandGCHouston.reset();
            }
        }
        for (ScheduledDimensionChange change : TickHandlerServer.scheduledDimensionChanges) {
            try {
                GCPlayerStats stats = GCPlayerStats.get(change.getPlayer());
                final WorldProvider provider = WorldUtil.getProviderForNameServer(change.getDimensionName());
                if (provider != null) {
                    final Integer dim = GCCoreUtil.getDimensionID(provider);
                    GCLog.info("Found matching world (" + dim.toString() + ") for name: " + change.getDimensionName());
                    if (change.getPlayer().worldObj instanceof WorldServer) {
                        final WorldServer world = (WorldServer) change.getPlayer().worldObj;
                        WorldUtil.transferEntityToDimension(change.getPlayer(), dim, world);
                    }
                } else {
                    GCLog.severe("World not found when attempting to transfer entity to dimension: " + change.getDimensionName());
                }
                stats.setTeleportCooldown(10);
                GalacticraftCore.packetPipeline.sendTo(new PacketSimple(EnumSimplePacket.C_CLOSE_GUI, GCCoreUtil.getDimensionID(change.getPlayer().worldObj), new Object[] {}), change.getPlayer());
            } catch (Exception e) {
                GCLog.severe("Error occurred when attempting to transfer entity to dimension: " + change.getDimensionName());
                e.printStackTrace();
            }
        }
        TickHandlerServer.scheduledDimensionChanges.clear();
        if (MapUtil.calculatingMap.get()) {
            MapUtil.BiomeMapNextTick_MultiThreaded();
        } else if (!MapUtil.doneOverworldTexture) {
            MapUtil.makeOverworldTexture();
        }
        if (TickHandlerServer.spaceRaceData == null) {
            World world = server.worldServerForDimension(0);
            TickHandlerServer.spaceRaceData = (WorldDataSpaceRaces) world.getMapStorage().loadData(WorldDataSpaceRaces.class, WorldDataSpaceRaces.saveDataID);
            if (TickHandlerServer.spaceRaceData == null) {
                TickHandlerServer.spaceRaceData = new WorldDataSpaceRaces(WorldDataSpaceRaces.saveDataID);
                world.getMapStorage().setData(WorldDataSpaceRaces.saveDataID, TickHandlerServer.spaceRaceData);
            }
        }
        SpaceRaceManager.tick();
        TileEntityOxygenSealer.onServerTick();
        if (TickHandlerServer.tickCount % 33 == 0) {
            WorldServer[] worlds = server.worldServers;
            for (int i = worlds.length - 1; i >= 0; i--) {
                WorldServer world = worlds[i];
                TileEntityPainter.onServerTick(world);
            }
        }
        if (TickHandlerServer.tickCount % 100 == 0) {
            WorldServer[] worlds = server.worldServers;
            for (int i = 0; i < worlds.length; i++) {
                WorldServer world = worlds[i];
                ChunkProviderServer chunkProviderServer = world.theChunkProviderServer;
                Map<Long, List<Footprint>> footprintMap = TickHandlerServer.serverFootprintMap.get(GCCoreUtil.getDimensionID(world));
                if (footprintMap != null) {
                    boolean mapChanged = false;
                    if (chunkProviderServer != null) {
                        Iterator iterator = chunkProviderServer.loadedChunks.iterator();
                        while (iterator.hasNext()) {
                            Chunk chunk = (Chunk) iterator.next();
                            long chunkKey = ChunkCoordIntPair.chunkXZ2Int(chunk.xPosition, chunk.zPosition);
                            List<Footprint> footprints = footprintMap.get(chunkKey);
                            if (footprints != null) {
                                List<Footprint> toRemove = new ArrayList<Footprint>();
                                for (int j = 0; j < footprints.size(); j++) {
                                    footprints.get(j).age += 100;
                                    if (footprints.get(j).age >= Footprint.MAX_AGE) {
                                        toRemove.add(footprints.get(j));
                                    }
                                }
                                if (!toRemove.isEmpty()) {
                                    footprints.removeAll(toRemove);
                                }
                                footprintMap.put(chunkKey, footprints);
                                mapChanged = true;
                                GalacticraftCore.packetPipeline.sendToDimension(new PacketSimple(EnumSimplePacket.C_UPDATE_FOOTPRINT_LIST, GCCoreUtil.getDimensionID(worlds[i]), new Object[] { chunkKey, footprints.toArray(new Footprint[footprints.size()]) }), GCCoreUtil.getDimensionID(worlds[i]));
                            }
                        }
                    }
                    if (mapChanged) {
                        TickHandlerServer.serverFootprintMap.put(GCCoreUtil.getDimensionID(world), footprintMap);
                    }
                }
            }
        }
        if (!footprintBlockChanges.isEmpty()) {
            for (BlockVec3Dim targetPoint : footprintBlockChanges) {
                WorldServer[] worlds = server.worldServers;
                for (int i = 0; i < worlds.length; i++) {
                    WorldServer world = worlds[i];
                    if (GCCoreUtil.getDimensionID(world) == targetPoint.dim) {
                        long chunkKey = ChunkCoordIntPair.chunkXZ2Int((int) targetPoint.x >> 4, (int) targetPoint.z >> 4);
                        GalacticraftCore.packetPipeline.sendToAllAround(new PacketSimple(EnumSimplePacket.C_FOOTPRINTS_REMOVED, GCCoreUtil.getDimensionID(world), new Object[] { chunkKey, new BlockVec3(targetPoint.x, targetPoint.y, targetPoint.z) }), new NetworkRegistry.TargetPoint(targetPoint.dim, targetPoint.x, targetPoint.y, targetPoint.z, 50));
                    // Map<Long, List<Footprint>> footprintMap = TickHandlerServer.serverFootprintMap.get(world.provider.dimensionId);
                    // 
                    // if (footprintMap != null && !footprintMap.isEmpty())
                    // {
                    // List<Footprint> footprints = footprintMap.get(chunkKey);
                    // if (footprints != null)
                    // GalacticraftCore.packetPipeline.sendToAllAround(new PacketSimple(EnumSimplePacket.C_UPDATE_FOOTPRINT_LIST, new Object[] { chunkKey, footprints.toArray(new Footprint[footprints.size()]) }), new NetworkRegistry.TargetPoint(targetPoint.dim, targetPoint.x, targetPoint.y, targetPoint.z, 50));
                    // }
                    }
                }
            }
            footprintBlockChanges.clear();
        }
        if (tickCount % 20 == 0) {
            if (!playersRequestingMapData.isEmpty()) {
                File baseFolder = new File(DimensionManager.getCurrentSaveRootDirectory(), "galacticraft/overworldMap");
                if (!baseFolder.exists() && !baseFolder.mkdirs()) {
                    GCLog.severe("Base folder(s) could not be created: " + baseFolder.getAbsolutePath());
                } else {
                    ArrayList<EntityPlayerMP> copy = new ArrayList<EntityPlayerMP>(playersRequestingMapData);
                    BufferedImage reusable = new BufferedImage(400, 400, BufferedImage.TYPE_INT_RGB);
                    for (EntityPlayerMP playerMP : copy) {
                        GCPlayerStats stats = GCPlayerStats.get(playerMP);
                        MapUtil.makeVanillaMap(playerMP.dimension, (int) Math.floor(stats.getCoordsTeleportedFromZ()) >> 4, (int) Math.floor(stats.getCoordsTeleportedFromZ()) >> 4, baseFolder, reusable);
                    }
                    playersRequestingMapData.removeAll(copy);
                }
            }
        }
        TickHandlerServer.tickCount++;
        EnergyNetwork.tickCount++;
    } else if (event.phase == Phase.END) {
        for (FluidNetwork network : new ArrayList<>(fluidNetworks)) {
            if (!network.pipes.isEmpty()) {
                network.tickEnd();
            } else {
                fluidNetworks.remove(network);
            }
        }
        int maxPasses = 10;
        while (!TickHandlerServer.networkTicks.isEmpty()) {
            LinkedList<EnergyNetwork> pass = new LinkedList<>();
            pass.addAll(TickHandlerServer.networkTicks);
            TickHandlerServer.networkTicks.clear();
            for (EnergyNetwork grid : pass) {
                grid.tickEnd();
            }
            if (--maxPasses <= 0) {
                break;
            }
        }
        maxPasses = 10;
        while (!TickHandlerServer.oxygenTransmitterUpdates.isEmpty()) {
            LinkedList<TileEntityFluidTransmitter> pass = new LinkedList<>();
            pass.addAll(TickHandlerServer.oxygenTransmitterUpdates);
            TickHandlerServer.oxygenTransmitterUpdates.clear();
            for (TileEntityFluidTransmitter newTile : pass) {
                if (!newTile.isInvalid()) {
                    newTile.refresh();
                }
            }
            if (--maxPasses <= 0) {
                break;
            }
        }
        maxPasses = 10;
        while (!TickHandlerServer.energyTransmitterUpdates.isEmpty()) {
            LinkedList<TileBaseConductor> pass = new LinkedList<>();
            pass.addAll(TickHandlerServer.energyTransmitterUpdates);
            TickHandlerServer.energyTransmitterUpdates.clear();
            for (TileBaseConductor newTile : pass) {
                if (!newTile.isInvalid()) {
                    newTile.refresh();
                }
            }
            if (--maxPasses <= 0) {
                break;
            }
        }
    }
}
Also used : EnergyNetwork(micdoodle8.mods.galacticraft.core.energy.grid.EnergyNetwork) TileBaseConductor(micdoodle8.mods.galacticraft.core.energy.tile.TileBaseConductor) GCPlayerStats(micdoodle8.mods.galacticraft.core.entities.player.GCPlayerStats) CopyOnWriteArrayList(java.util.concurrent.CopyOnWriteArrayList) PacketSimple(micdoodle8.mods.galacticraft.core.network.PacketSimple) WorldServer(net.minecraft.world.WorldServer) World(net.minecraft.world.World) BlockVec3Dim(micdoodle8.mods.galacticraft.api.vector.BlockVec3Dim) BufferedImage(java.awt.image.BufferedImage) ScheduledDimensionChange(micdoodle8.mods.galacticraft.core.wrappers.ScheduledDimensionChange) NetworkRegistry(net.minecraftforge.fml.common.network.NetworkRegistry) WorldProvider(net.minecraft.world.WorldProvider) ChunkProviderServer(net.minecraft.world.gen.ChunkProviderServer) CopyOnWriteArrayList(java.util.concurrent.CopyOnWriteArrayList) WorldDataSpaceRaces(micdoodle8.mods.galacticraft.core.dimension.WorldDataSpaceRaces) BlockVec3(micdoodle8.mods.galacticraft.api.vector.BlockVec3) Footprint(micdoodle8.mods.galacticraft.core.wrappers.Footprint) FluidNetwork(micdoodle8.mods.galacticraft.core.fluid.FluidNetwork) Chunk(net.minecraft.world.chunk.Chunk) Footprint(micdoodle8.mods.galacticraft.core.wrappers.Footprint) MinecraftServer(net.minecraft.server.MinecraftServer) EntityPlayerMP(net.minecraft.entity.player.EntityPlayerMP) File(java.io.File) TileEntityFluidTransmitter(micdoodle8.mods.galacticraft.core.tile.TileEntityFluidTransmitter) SubscribeEvent(net.minecraftforge.fml.common.eventhandler.SubscribeEvent)

Aggregations

Footprint (micdoodle8.mods.galacticraft.core.wrappers.Footprint)10 BlockVec3 (micdoodle8.mods.galacticraft.api.vector.BlockVec3)7 Vector3 (micdoodle8.mods.galacticraft.api.vector.Vector3)6 BlockPos (net.minecraft.util.BlockPos)5 FlagData (micdoodle8.mods.galacticraft.core.wrappers.FlagData)3 IBlockState (net.minecraft.block.state.IBlockState)3 IOException (java.io.IOException)2 ArrayList (java.util.ArrayList)2 UUID (java.util.UUID)2 GuiCelestialSelection (micdoodle8.mods.galacticraft.core.client.gui.screen.GuiCelestialSelection)2 WorldProviderSpaceStation (micdoodle8.mods.galacticraft.core.dimension.WorldProviderSpaceStation)2 EnergyStorage (micdoodle8.mods.galacticraft.core.energy.tile.EnergyStorage)2 TileBaseConductor (micdoodle8.mods.galacticraft.core.energy.tile.TileBaseConductor)2 FluidNetwork (micdoodle8.mods.galacticraft.core.fluid.FluidNetwork)2 PacketSimple (micdoodle8.mods.galacticraft.core.network.PacketSimple)2 Block (net.minecraft.block.Block)2 Minecraft (net.minecraft.client.Minecraft)2 EntityPlayerSP (net.minecraft.client.entity.EntityPlayerSP)2 WorldClient (net.minecraft.client.multiplayer.WorldClient)2 Entity (net.minecraft.entity.Entity)2