Search in sources :

Example 11 with Planet

use of micdoodle8.mods.galacticraft.api.galaxies.Planet in project Galacticraft by micdoodle8.

the class GuiCelestialSelection method mouseClicked.

@Override
protected void mouseClicked(int x, int y, int button) throws IOException {
    super.mouseClicked(x, y, button);
    boolean clickHandled = false;
    final int LHS = GuiCelestialSelection.BORDER_SIZE + GuiCelestialSelection.BORDER_EDGE_SIZE;
    final int RHS = width - LHS;
    final int TOP = LHS;
    if (this.selectedBody != null && x > LHS && x < LHS + 88 && y > TOP && y < TOP + 13) {
        this.unselectCelestialBody();
        return;
    }
    if (!this.mapMode) {
        if (x >= RHS - 95 && x < RHS && y > TOP + 181 + canCreateOffset && y < TOP + 182 + 12 + canCreateOffset) {
            if (this.selectedBody != null) {
                SpaceStationRecipe recipe = WorldUtil.getSpaceStationRecipe(this.selectedBody.getDimensionID());
                if (recipe != null && this.canCreateSpaceStation(this.selectedBody)) {
                    if (recipe.matches(this.mc.thePlayer, false) || this.mc.thePlayer.capabilities.isCreativeMode) {
                        GalacticraftCore.packetPipeline.sendToServer(new PacketSimple(EnumSimplePacket.S_BIND_SPACE_STATION_ID, GCCoreUtil.getDimensionID(this.mc.theWorld), new Object[] { this.selectedBody.getDimensionID() }));
                        // Zoom in on Overworld to show the new SpaceStation if not already zoomed
                        if (!this.isZoomed()) {
                            this.selectionState = EnumSelection.ZOOMED;
                            this.preSelectZoom = this.zoom;
                            this.preSelectPosition = this.position;
                            this.ticksSinceSelection = 0;
                            this.doneZooming = false;
                        }
                        return;
                    }
                    clickHandled = true;
                }
            }
        }
    }
    if (this.mapMode) {
        if (x > RHS - 88 && x < RHS && y > TOP && y < TOP + 13) {
            this.mc.displayGuiScreen(null);
            this.mc.setIngameFocus();
            clickHandled = true;
        }
    }
    if (this.selectedBody != null && !this.mapMode) {
        if (x > RHS - 88 && x < RHS && y > TOP && y < TOP + 13) {
            if (!(this.selectedBody instanceof Satellite) || !this.selectedStationOwner.equals("")) {
                this.teleportToSelectedBody();
            }
            clickHandled = true;
        }
    }
    // Need unscaled mouse coords
    int mouseX = Mouse.getX();
    int mouseY = Mouse.getY() * -1 + Minecraft.getMinecraft().displayHeight - 1;
    if (this.selectedBody instanceof Satellite) {
        if (this.renamingSpaceStation) {
            if (x >= width / 2 - 90 && x <= width / 2 + 90 && y >= this.height / 2 - 38 && y <= this.height / 2 + 38) {
                // Apply
                if (x >= width / 2 - 90 + 17 && x <= width / 2 - 90 + 17 + 72 && y >= this.height / 2 - 38 + 59 && y <= this.height / 2 - 38 + 59 + 12) {
                    String strName = PlayerUtil.getName(this.mc.thePlayer);
                    // Integer spacestationID = this.spaceStationIDs.get(strName);
                    // if (spacestationID == null) spacestationID = this.spaceStationIDs.get(strName.toLowerCase());
                    Satellite selectedSatellite = (Satellite) this.selectedBody;
                    Integer spacestationID = this.spaceStationMap.get(getSatelliteParentID(selectedSatellite)).get(strName).getStationDimensionID();
                    if (spacestationID == null) {
                        spacestationID = this.spaceStationMap.get(getSatelliteParentID(selectedSatellite)).get(strName.toLowerCase()).getStationDimensionID();
                    }
                    if (spacestationID != null) {
                        this.spaceStationMap.get(getSatelliteParentID(selectedSatellite)).get(strName).setStationName(this.renamingString);
                        // this.spaceStationNames.put(strName, this.renamingString);
                        GalacticraftCore.packetPipeline.sendToServer(new PacketSimple(EnumSimplePacket.S_RENAME_SPACE_STATION, GCCoreUtil.getDimensionID(this.mc.theWorld), new Object[] { this.renamingString, spacestationID }));
                    }
                    this.renamingSpaceStation = false;
                }
                // Cancel
                if (x >= width / 2 && x <= width / 2 + 72 && y >= this.height / 2 - 38 + 59 && y <= this.height / 2 - 38 + 59 + 12) {
                    this.renamingSpaceStation = false;
                }
                clickHandled = true;
            }
        } else {
            this.drawTexturedModalRect(width / 2 - 47, TOP, 94, 11, 0, 414, 188, 22, false, false);
            if (x >= width / 2 - 47 && x <= width / 2 - 47 + 94 && y >= TOP && y <= TOP + 11) {
                if (this.selectedStationOwner.length() != 0 && this.selectedStationOwner.equalsIgnoreCase(PlayerUtil.getName(this.mc.thePlayer))) {
                    this.renamingSpaceStation = true;
                    this.renamingString = null;
                    clickHandled = true;
                }
            }
            Satellite selectedSatellite = (Satellite) this.selectedBody;
            int stationListSize = this.spaceStationMap.get(getSatelliteParentID(selectedSatellite)).size();
            int max = Math.min((this.height / 2) / 14, stationListSize);
            int xPos;
            int yPos;
            // Up button
            xPos = RHS - 85;
            yPos = TOP + 45;
            if (x >= xPos && x <= xPos + 61 && y >= yPos && y <= yPos + 4) {
                if (this.spaceStationListOffset > 0) {
                    this.spaceStationListOffset--;
                }
                clickHandled = true;
            }
            // Down button
            xPos = RHS - 85;
            yPos = TOP + 49 + max * 14;
            if (x >= xPos && x <= xPos + 61 && y >= yPos && y <= yPos + 4) {
                if (max + spaceStationListOffset < stationListSize) {
                    this.spaceStationListOffset++;
                }
                clickHandled = true;
            }
            Iterator<Map.Entry<String, StationDataGUI>> it = this.spaceStationMap.get(getSatelliteParentID(selectedSatellite)).entrySet().iterator();
            int i = 0;
            int j = 0;
            while (it.hasNext() && i < max) {
                Map.Entry<String, StationDataGUI> e = it.next();
                if (j >= this.spaceStationListOffset) {
                    int xOffset = 0;
                    if (e.getKey().equalsIgnoreCase(this.selectedStationOwner)) {
                        xOffset -= 5;
                    }
                    xPos = RHS - 95 + xOffset;
                    yPos = TOP + 50 + i * 14;
                    if (x >= xPos && x <= xPos + 93 && y >= yPos && y <= yPos + 12) {
                        this.selectedStationOwner = e.getKey();
                        clickHandled = true;
                    }
                    i++;
                }
                j++;
            }
        }
    }
    int xPos = LHS + 2;
    int yPos = TOP + 10;
    boolean planetZoomedMoon = this.isZoomed() && this.selectedParent instanceof Planet;
    // Top yellow button e.g. Sol
    if (x >= xPos && x <= xPos + 93 && y >= yPos && y <= yPos + 12 && this.selectedParent instanceof CelestialBody) {
        if (this.selectedBody == null) {
            this.preSelectZoom = this.zoom;
            this.preSelectPosition = this.position;
        }
        EnumSelection selectionCountOld = this.selectionState;
        if (this.isSelected()) {
            this.unselectCelestialBody();
        }
        if (selectionCountOld == EnumSelection.ZOOMED) {
            this.selectionState = EnumSelection.SELECTED;
        }
        this.selectedBody = (CelestialBody) this.selectedParent;
        this.ticksSinceSelection = 0;
        this.selectionState = EnumSelection.values()[this.selectionState.ordinal() + 1];
        if (this.isZoomed() && !planetZoomedMoon) {
            this.ticksSinceMenuOpen = 0;
        }
        clickHandled = true;
    }
    yPos += 22;
    // First blue button - normally the Selected Body (but it's the parent planet if this is a moon)
    if (x >= xPos && x <= xPos + 93 && y >= yPos && y <= yPos + 12) {
        if (planetZoomedMoon) {
            if (this.selectedBody == null) {
                this.preSelectZoom = this.zoom;
                this.preSelectPosition = this.position;
            }
            EnumSelection selectionCountOld = this.selectionState;
            if (this.isSelected()) {
                this.unselectCelestialBody();
            }
            if (selectionCountOld == EnumSelection.ZOOMED) {
                this.selectionState = EnumSelection.SELECTED;
            }
            this.selectedBody = (CelestialBody) this.selectedParent;
            this.ticksSinceSelection = 0;
            this.selectionState = EnumSelection.values()[this.selectionState.ordinal() + 1];
        }
        clickHandled = true;
    }
    if (!clickHandled) {
        List<CelestialBody> children = this.getChildren(this.isZoomed() ? this.selectedBody : this.selectedParent);
        yPos = TOP + 50;
        for (CelestialBody child : children) {
            clickHandled = this.testClicked(child, child.equals(this.selectedBody) ? 5 : 0, yPos, x, y, false);
            yPos += 14;
            if (!clickHandled && !this.isZoomed() && child.equals(this.selectedBody)) {
                List<CelestialBody> grandchildren = this.getChildren(child);
                int gOffset = 0;
                for (CelestialBody grandchild : grandchildren) {
                    if (gOffset + 14 > this.animateGrandchildren) {
                        break;
                    }
                    clickHandled = this.testClicked(grandchild, 10, yPos, x, y, true);
                    yPos += 14;
                    gOffset += 14;
                    if (clickHandled)
                        break;
                }
                yPos += this.animateGrandchildren - gOffset;
            }
            if (clickHandled)
                break;
        }
    }
    if (!clickHandled) {
        for (Map.Entry<CelestialBody, Vector3f> e : this.planetPosMap.entrySet()) {
            CelestialBody bodyClicked = e.getKey();
            if (this.selectedBody == null && bodyClicked instanceof IChildBody) {
                continue;
            }
            // Z value holds size on-screen
            float iconSize = e.getValue().z;
            if (mouseX >= e.getValue().x - iconSize && mouseX <= e.getValue().x + iconSize && mouseY >= e.getValue().y - iconSize && mouseY <= e.getValue().y + iconSize) {
                if (this.selectedBody != bodyClicked || !this.isZoomed()) {
                    if (this.isSelected() && this.selectedBody != bodyClicked) {
                        if (!(this.selectedBody instanceof IChildBody && ((IChildBody) this.selectedBody).getParentPlanet() == bodyClicked)) {
                            this.unselectCelestialBody();
                        } else if (this.isZoomed()) {
                            this.selectionState = EnumSelection.SELECTED;
                        }
                    }
                    this.doneZooming = false;
                    this.planetZoom = 0.0F;
                    if (bodyClicked != this.selectedBody) {
                        this.lastSelectedBody = this.selectedBody;
                    }
                    this.selectedBody = bodyClicked;
                    this.ticksSinceSelection = 0;
                    this.selectionState = EnumSelection.values()[this.selectionState.ordinal() + 1];
                    if (this.isZoomed()) {
                        this.ticksSinceMenuOpen = 0;
                    }
                    // Auto select if it's a spacestation and there is only a single entry
                    if (this.selectedBody instanceof Satellite && this.spaceStationMap.get(this.getSatelliteParentID((Satellite) this.selectedBody)).size() == 1) {
                        Iterator<Map.Entry<String, StationDataGUI>> it = this.spaceStationMap.get(this.getSatelliteParentID((Satellite) this.selectedBody)).entrySet().iterator();
                        this.selectedStationOwner = it.next().getKey();
                    }
                    clickHandled = true;
                    break;
                }
            }
        }
    }
    if (!clickHandled) {
        if (this.selectedBody != null) {
            this.unselectCelestialBody();
            this.planetZoom = 0.0F;
        }
        mouseDragging = true;
    }
    Object selectedParent = this.selectedParent;
    if (this.selectedBody instanceof IChildBody) {
        selectedParent = ((IChildBody) this.selectedBody).getParentPlanet();
    } else if (this.selectedBody instanceof Planet) {
        selectedParent = ((Planet) this.selectedBody).getParentSolarSystem();
    } else if (this.selectedBody == null) {
        selectedParent = GalacticraftCore.solarSystemSol;
    }
    if (this.selectedParent != selectedParent) {
        this.selectedParent = selectedParent;
    }
}
Also used : PacketSimple(micdoodle8.mods.galacticraft.core.network.PacketSimple) SpaceStationRecipe(micdoodle8.mods.galacticraft.api.recipe.SpaceStationRecipe) Vector3f(org.lwjgl.util.vector.Vector3f)

Example 12 with Planet

use of micdoodle8.mods.galacticraft.api.galaxies.Planet in project Galacticraft by micdoodle8.

the class GuiCelestialSelection method drawCircles.

public void drawCircles() {
    GL11.glColor4f(1, 1, 1, 1);
    GL11.glLineWidth(3);
    int count = 0;
    final float theta = (float) (2 * Math.PI / 90);
    final float cos = (float) Math.cos(theta);
    final float sin = (float) Math.sin(theta);
    for (Planet planet : GalaxyRegistry.getRegisteredPlanets().values()) {
        if (planet.getParentSolarSystem() != null) {
            Vector3f systemOffset = this.getCelestialBodyPosition(planet.getParentSolarSystem().getMainStar());
            float x = this.getScale(planet);
            float y = 0;
            float alpha = 1.0F;
            if ((this.selectedBody instanceof IChildBody && ((IChildBody) this.selectedBody).getParentPlanet() != planet) || (this.selectedBody instanceof Planet && this.selectedBody != planet && this.isZoomed())) {
                if (this.lastSelectedBody == null && !(this.selectedBody instanceof IChildBody) && !(this.selectedBody instanceof Satellite)) {
                    alpha = 1.0F - Math.min(this.ticksSinceSelection / 25.0F, 1.0F);
                } else {
                    alpha = 0.0F;
                }
            }
            if (alpha != 0) {
                switch(count % 2) {
                    case 0:
                        GL11.glColor4f(0.0F / 1.4F, 0.6F / 1.4F, 1.0F / 1.4F, alpha / 1.4F);
                        break;
                    case 1:
                        GL11.glColor4f(0.3F / 1.4F, 0.8F / 1.4F, 1.0F / 1.4F, alpha / 1.4F);
                        break;
                }
                CelestialBodyRenderEvent.CelestialRingRenderEvent.Pre preEvent = new CelestialBodyRenderEvent.CelestialRingRenderEvent.Pre(planet, systemOffset);
                MinecraftForge.EVENT_BUS.post(preEvent);
                if (!preEvent.isCanceled()) {
                    GL11.glTranslatef(systemOffset.x, systemOffset.y, systemOffset.z);
                    GL11.glBegin(GL11.GL_LINE_LOOP);
                    float temp;
                    for (int i = 0; i < 90; i++) {
                        GL11.glVertex2f(x, y);
                        temp = x;
                        x = cos * x - sin * y;
                        y = sin * temp + cos * y;
                    }
                    GL11.glEnd();
                    GL11.glTranslatef(-systemOffset.x, -systemOffset.y, -systemOffset.z);
                    count++;
                }
                CelestialBodyRenderEvent.CelestialRingRenderEvent.Post postEvent = new CelestialBodyRenderEvent.CelestialRingRenderEvent.Post(planet);
                MinecraftForge.EVENT_BUS.post(postEvent);
            }
        }
    }
    count = 0;
    if (this.selectedBody != null) {
        Vector3f planetPos = this.getCelestialBodyPosition(this.selectedBody);
        if (this.selectedBody instanceof IChildBody) {
            planetPos = this.getCelestialBodyPosition(((IChildBody) this.selectedBody).getParentPlanet());
        } else if (this.selectedBody instanceof Satellite) {
            planetPos = this.getCelestialBodyPosition(((Satellite) this.selectedBody).getParentPlanet());
        }
        GL11.glTranslatef(planetPos.x, planetPos.y, 0);
        for (Moon moon : GalaxyRegistry.getRegisteredMoons().values()) {
            if ((moon.getParentPlanet() == this.selectedBody && this.selectionState != EnumSelection.SELECTED) || moon == this.selectedBody || getSiblings(this.selectedBody).contains(moon)) {
                if (this.drawCircle(moon, count, sin, cos)) {
                    count++;
                }
            }
        }
        for (Satellite satellite : GalaxyRegistry.getRegisteredSatellites().values()) {
            if (this.possibleBodies != null && this.possibleBodies.contains(satellite)) {
                if ((satellite.getParentPlanet() == this.selectedBody && this.selectionState != EnumSelection.SELECTED) && this.ticksSinceSelection > 24 || satellite == this.selectedBody || this.lastSelectedBody instanceof IChildBody) {
                    if (this.drawCircle(satellite, count, sin, cos)) {
                        count++;
                    }
                }
            }
        }
    }
    GL11.glLineWidth(1);
}
Also used : CelestialBodyRenderEvent(micdoodle8.mods.galacticraft.api.event.client.CelestialBodyRenderEvent) Vector3f(org.lwjgl.util.vector.Vector3f)

Example 13 with Planet

use of micdoodle8.mods.galacticraft.api.galaxies.Planet in project MorePlanets by SteveKunG.

the class CelestialRegisterHelper method createSpaceStation.

public static Satellite createSpaceStation(String name, Planet planet, float phaseShift, float distance, float orbitTime, float size, int tier) {
    Satellite satellite = new Satellite(name).setParentBody(planet);
    satellite.setPhaseShift(phaseShift);
    satellite.setRelativeDistanceFromCenter(new ScalableDistance(distance, distance));
    satellite.setRelativeOrbitTime(orbitTime);
    satellite.setRelativeSize(size);
    satellite.setTierRequired(tier);
    satellite.setBodyIcon(new ResourceLocation("moreplanets:textures/gui/celestialbodies/" + name + ".png"));
    return satellite;
}
Also used : ScalableDistance(micdoodle8.mods.galacticraft.api.galaxies.CelestialBody.ScalableDistance) ResourceLocation(net.minecraft.util.ResourceLocation)

Example 14 with Planet

use of micdoodle8.mods.galacticraft.api.galaxies.Planet in project Galacticraft by micdoodle8.

the class SpaceStationWorldData method getStationData.

/**
 * Retrieve a space station data entry, creating if necessary (with provided data)
 */
public static SpaceStationWorldData getStationData(World world, int stationID, int homeID, int providerIdDynamic, int providerIdStatic, EntityPlayer owner) {
    int providerType = DimensionManager.getProviderType(stationID);
    boolean foundMatch = false;
    // being called on an incorrect
    for (Satellite satellite : GalaxyRegistry.getRegisteredSatellites().values()) {
        if (satellite.getDimensionIdStatic() == providerType || satellite.getDimensionID() == providerType) {
            foundMatch = true;
            break;
        }
    }
    if (!foundMatch) {
        return null;
    } else {
        final String stationIdentifier = SpaceStationWorldData.getSpaceStationID(stationID);
        SpaceStationWorldData stationData = (SpaceStationWorldData) world.loadItemData(SpaceStationWorldData.class, Constants.GCDATAFOLDER + stationIdentifier);
        if (stationData == null) {
            stationData = new SpaceStationWorldData(stationIdentifier);
            world.setItemData(Constants.GCDATAFOLDER + stationIdentifier, stationData);
            stationData.dataCompound = new NBTTagCompound();
            if (owner != null) {
                stationData.owner = PlayerUtil.getName(owner).replace(".", "");
            }
            stationData.spaceStationName = "Station: " + stationData.owner;
            if (owner != null) {
                stationData.allowedPlayers.add(PlayerUtil.getName(owner));
            }
            if (homeID == -1) {
                throw new RuntimeException("Space station being created on bad home planet ID!");
            } else {
                stationData.homePlanet = homeID;
            }
            if (providerIdDynamic == -1 || providerIdStatic == -1) {
                throw new RuntimeException("Space station being created on bad provider IDs!");
            } else {
                stationData.dimensionIdDynamic = providerIdDynamic;
                stationData.dimensionIdStatic = providerIdStatic;
            }
            stationData.markDirty();
        }
        if (stationData.getSpaceStationName().replace(" ", "").isEmpty()) {
            stationData.setSpaceStationName("Station: " + stationData.owner);
            stationData.markDirty();
        }
        return stationData;
    }
}
Also used : NBTTagCompound(net.minecraft.nbt.NBTTagCompound) Satellite(micdoodle8.mods.galacticraft.api.galaxies.Satellite)

Example 15 with Planet

use of micdoodle8.mods.galacticraft.api.galaxies.Planet in project Galacticraft by micdoodle8.

the class GalacticraftCore method registerCoreGameScreens.

private static void registerCoreGameScreens() {
    if (GCCoreUtil.getEffectiveSide() == Side.CLIENT) {
        IGameScreen rendererBasic = new GameScreenBasic();
        IGameScreen rendererCelest = new GameScreenCelestial();
        // Type 0 - blank
        GalacticraftRegistry.registerScreen(rendererBasic);
        // Type 1 - local satellite view
        GalacticraftRegistry.registerScreen(rendererBasic);
        // Type 2 - solar system
        GalacticraftRegistry.registerScreen(rendererCelest);
        // Type 3 - local planet
        GalacticraftRegistry.registerScreen(rendererCelest);
        // Type 4 - render test
        GalacticraftRegistry.registerScreen(rendererCelest);
    } else {
        GalacticraftRegistry.registerScreensServer(5);
    }
}
Also used : IGameScreen(micdoodle8.mods.galacticraft.api.client.IGameScreen) GameScreenCelestial(micdoodle8.mods.galacticraft.core.client.screen.GameScreenCelestial) GameScreenBasic(micdoodle8.mods.galacticraft.core.client.screen.GameScreenBasic)

Aggregations

ItemStack (net.minecraft.item.ItemStack)7 ResourceLocation (net.minecraft.util.ResourceLocation)7 IGalacticraftWorldProvider (micdoodle8.mods.galacticraft.api.world.IGalacticraftWorldProvider)6 Planet (micdoodle8.mods.galacticraft.api.galaxies.Planet)4 AtmosphereInfo (micdoodle8.mods.galacticraft.api.world.AtmosphereInfo)4 Vector3f (org.lwjgl.util.vector.Vector3f)4 ScalableDistance (micdoodle8.mods.galacticraft.api.galaxies.CelestialBody.ScalableDistance)3 BlockVec3 (micdoodle8.mods.galacticraft.api.vector.BlockVec3)3 EntityPlayerMP (net.minecraft.entity.player.EntityPlayerMP)3 CelestialBodyRenderEvent (micdoodle8.mods.galacticraft.api.event.client.CelestialBodyRenderEvent)2 SpaceStationRecipe (micdoodle8.mods.galacticraft.api.recipe.SpaceStationRecipe)2 Vector3 (micdoodle8.mods.galacticraft.api.vector.Vector3)2 Entity (net.minecraft.entity.Entity)2 EntityLivingBase (net.minecraft.entity.EntityLivingBase)2 NBTTagCompound (net.minecraft.nbt.NBTTagCompound)2 PotionEffect (net.minecraft.potion.PotionEffect)2 WorldProvider (net.minecraft.world.WorldProvider)2 WorldServer (net.minecraft.world.WorldServer)2 SpawnListEntry (net.minecraft.world.biome.BiomeGenBase.SpawnListEntry)2 SubscribeEvent (net.minecraftforge.fml.common.eventhandler.SubscribeEvent)2