Skip to content

Commit

Permalink
Improved teleportation (#64)
Browse files Browse the repository at this point in the history
* Changed map mode to be an enum instead of boolean

* Added map mode to packet handler

* Added packet to cancel the teleportation so the GUI isnt automatically reopened

* Derp

* No longer put a rocket in the lander when using dimensiontp

* Spotless

* Updated BS

* spotlessApply (#65)

Co-authored-by: Maxim <[email protected]>
Co-authored-by: GitHub GTNH Actions <>

Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com>
  • Loading branch information
minecraft7771 and github-actions[bot] authored Dec 29, 2022
1 parent 000c8ea commit fd9a309
Show file tree
Hide file tree
Showing 9 changed files with 99 additions and 50 deletions.
23 changes: 18 additions & 5 deletions build.gradle
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
//version: 1670690877
//version: 1671313514
/*
DO NOT CHANGE THIS FILE!
Also, you may replace this file at any time if there is an update available.
Expand Down Expand Up @@ -31,7 +31,7 @@ buildscript {
url 'https://maven.minecraftforge.net'
}
maven {
// GTNH ForgeGradle Fork
// GTNH ForgeGradle and ASM Fork
name = "GTNH Maven"
url = "http://jenkins.usrv.eu:8081/nexus/content/groups/public/"
}
Expand All @@ -45,7 +45,9 @@ buildscript {
}
}
dependencies {
classpath 'net.minecraftforge.gradle:ForgeGradle:1.2.11'
//Overwrite the current ASM version to fix shading newer than java 8 applicatations.
classpath 'org.ow2.asm:asm-debug-all-custom:5.0.3'
classpath 'net.minecraftforge.gradle:ForgeGradle:1.2.13'
}
}
plugins {
Expand Down Expand Up @@ -278,7 +280,9 @@ minecraft {
runDir = 'run'

if (replaceGradleTokenInFile) {
replaceIn replaceGradleTokenInFile
for (f in replaceGradleTokenInFile.split(',')) {
replaceIn f
}
if (gradleTokenModId) {
replace gradleTokenModId, modId
}
Expand Down Expand Up @@ -330,6 +334,12 @@ repositories {
name = "GTNH Maven"
url = "http://jenkins.usrv.eu:8081/nexus/content/groups/public/"
}
if (usesMixinDebug.toBoolean()) {
maven {
name = "Fabric Maven"
url = "https://maven.fabricmc.net/"
}
}
}
}

Expand All @@ -339,6 +349,9 @@ dependencies {
annotationProcessor('com.google.guava:guava:24.1.1-jre')
annotationProcessor('com.google.code.gson:gson:2.8.6')
annotationProcessor('com.gtnewhorizon:gtnhmixins:2.1.3:processor')
if (usesMixinDebug.toBoolean()) {
runtimeOnly('org.jetbrains:intellij-fernflower:1.2.1.16')
}
}
if (usesMixins.toBoolean() || forceEnableMixins.toBoolean()) {
compile('com.gtnewhorizon:gtnhmixins:2.1.3')
Expand Down Expand Up @@ -694,7 +707,7 @@ if (modrinthProjectId.size() != 0 && System.getenv("MODRINTH_TOKEN") != null) {
}
}
if (usesMixins.toBoolean()) {
addModrinthDep("required", "version", "gtnhmixins")
addModrinthDep("required", "project", "gtnhmixins")
}
tasks.modrinth.dependsOn(build)
tasks.publish.dependsOn(tasks.modrinth)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
import micdoodle8.mods.galacticraft.api.world.IExitHeight;
import micdoodle8.mods.galacticraft.api.world.IGalacticraftWorldProvider;
import micdoodle8.mods.galacticraft.core.GalacticraftCore;
import micdoodle8.mods.galacticraft.core.client.gui.screen.GuiCelestialSelection;
import micdoodle8.mods.galacticraft.core.entities.player.GCPlayerStats;
import micdoodle8.mods.galacticraft.core.network.PacketSimple;
import micdoodle8.mods.galacticraft.core.network.PacketSimple.EnumSimplePacket;
Expand Down Expand Up @@ -415,7 +416,8 @@ public void onReachAtmosphere() {

this.onTeleport(player);
final GCPlayerStats stats = GCPlayerStats.get(player);
WorldUtil.toCelestialSelection(player, stats, this.getRocketTier());
WorldUtil.toCelestialSelection(
player, stats, this.getRocketTier(), GuiCelestialSelection.MapMode.TRAVEL);
}

// Destroy any rocket which reached the top of the atmosphere and is not
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -169,7 +169,7 @@ private Object getClientGuiElement(int ID, EntityPlayer player, World world, Vec
final EntityClientPlayerMP playerClient = PlayerUtil.getPlayerBaseClientFromPlayer(player, false);

if (ID == GuiIdsCore.GALAXY_MAP) {
return new GuiCelestialSelection(true, null);
return new GuiCelestialSelection(GuiCelestialSelection.MapMode.VIEW, null);
} else if (ID == GuiIdsCore.ROCKET_INVENTORY && player.ridingEntity instanceof EntityTieredRocket) {
return new GuiRocketInventory(
player.inventory,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,23 @@
import org.lwjgl.util.vector.Vector4f;

public class GuiCelestialSelection extends GuiScreen {
public enum MapMode {
TRAVEL,
VIEW,
TELEPORTATION;

public static MapMode fromInteger(int val) {
switch (val) {
case 1:
return VIEW;
case 2:
return TELEPORTATION;
default:
return TRAVEL;
}
}
}

protected enum EnumSelectionState {
PREVIEW,
PROFILE
Expand Down Expand Up @@ -90,7 +107,7 @@ protected enum EnumSelectionState {
protected int selectionCount = 0;
protected int zoomTooltipPos = 0;
protected Object selectedParent = GalacticraftCore.solarSystemSol;
protected final boolean mapMode;
protected final MapMode mapMode;
public List<CelestialBody> possibleBodies;

// Each home planet has a map of owner's names linked with their station data:
Expand All @@ -107,7 +124,7 @@ protected enum EnumSelectionState {
protected int lastMovePosY = -1;
protected boolean errorLogged = false;

public GuiCelestialSelection(boolean mapMode, List<CelestialBody> possibleBodies) {
public GuiCelestialSelection(MapMode mapMode, List<CelestialBody> possibleBodies) {
this.translation.x = 0.0F;
this.translation.y = 0.0F;
this.mapMode = mapMode;
Expand Down Expand Up @@ -345,7 +362,7 @@ protected Vector2f getTranslationAdvanced(float partialTicks) {
@Override
protected void keyTyped(char keyChar, int keyID) {
// Override and do nothing, so it isn't possible to exit the GUI
if (this.mapMode) {
if (this.mapMode == MapMode.VIEW) {
super.keyTyped(keyChar, keyID);
}

Expand Down Expand Up @@ -403,7 +420,9 @@ public boolean isValid(String string) {
}

protected boolean canCreateSpaceStation(CelestialBody atBody) {
if (this.mapMode || !atBody.getAllowSatellite() || ConfigManagerCore.disableSpaceStationCreation) {
if ((this.mapMode == MapMode.VIEW)
|| !atBody.getAllowSatellite()
|| ConfigManagerCore.disableSpaceStationCreation) {
// If we are in map mode or the parent body doesn't allow satellites in general
// or if space stations aren't
// allowed at all,
Expand Down Expand Up @@ -543,7 +562,8 @@ protected boolean teleportToSelectedBody() {
this.mc.gameSettings.thirdPersonView = 0;
}
GalacticraftCore.packetPipeline.sendToServer(new PacketSimple(
PacketSimple.EnumSimplePacket.S_TELEPORT_ENTITY, new Object[] {dimension}));
PacketSimple.EnumSimplePacket.S_TELEPORT_ENTITY,
new Object[] {dimension, this.mapMode == MapMode.TRAVEL}));
// TODO Some type of clientside "in Space" holding screen here while waiting for
// the server to do
// the teleport
Expand Down Expand Up @@ -611,7 +631,7 @@ protected void mouseClicked(int x, int y, int button) {
return;
}

if (!this.mapMode) {
if (this.mapMode != MapMode.VIEW) {
if (x >= this.width - GuiCelestialSelection.BORDER_WIDTH - GuiCelestialSelection.BORDER_EDGE_WIDTH - 95
&& x < this.width - GuiCelestialSelection.BORDER_WIDTH - GuiCelestialSelection.BORDER_EDGE_WIDTH
&& y
Expand Down Expand Up @@ -649,18 +669,20 @@ protected void mouseClicked(int x, int y, int button) {
}
}

if (this.mapMode) {
if (this.mapMode == MapMode.VIEW || (this.mapMode == MapMode.TELEPORTATION && this.selectedBody == null)) {
if (x > this.width - BORDER_WIDTH - BORDER_EDGE_WIDTH - 88
&& x < this.width - BORDER_WIDTH - BORDER_EDGE_WIDTH
&& y > BORDER_WIDTH + BORDER_EDGE_WIDTH
&& y < BORDER_WIDTH + BORDER_EDGE_WIDTH + 13) {
GalacticraftCore.packetPipeline.sendToServer(
new PacketSimple(EnumSimplePacket.S_CANCEL_TELEPORTATION, new Object[] {}));
this.mc.displayGuiScreen(null);
this.mc.setIngameFocus();
clickHandled = true;
}
}

if (this.selectedBody != null && !this.mapMode) {
if (this.selectedBody != null && this.mapMode != MapMode.VIEW) {
if (x > this.width - BORDER_WIDTH - BORDER_EDGE_WIDTH - 88
&& x < this.width - BORDER_WIDTH - BORDER_EDGE_WIDTH
&& y > BORDER_WIDTH + BORDER_EDGE_WIDTH
Expand Down Expand Up @@ -1818,7 +1840,7 @@ public void drawButtons(int mousePosX, int mousePosY) {
}
}

if (this.mapMode) {
if (this.mapMode == MapMode.VIEW || (this.mapMode == MapMode.TELEPORTATION && this.selectedBody == null)) {
this.mc.renderEngine.bindTexture(GuiCelestialSelection.guiMain0);
GL11.glColor4f(1.0F, 0.0F, 0.0F, 1);
this.mc.renderEngine.bindTexture(GuiCelestialSelection.guiMain0);
Expand Down Expand Up @@ -2293,7 +2315,7 @@ public void drawButtons(int mousePosX, int mousePosY) {

this.mc.renderEngine.bindTexture(GuiCelestialSelection.guiMain1);

if (!this.mapMode) {
if (this.mapMode != MapMode.VIEW) {
if (mousePosX
>= this.width
- GuiCelestialSelection.BORDER_WIDTH
Expand Down Expand Up @@ -2365,7 +2387,7 @@ public void drawButtons(int mousePosX, int mousePosY) {
true,
false);

if (!this.mapMode) {
if (this.mapMode != MapMode.VIEW) {
this.drawSplitString(
GCCoreUtil.translate("gui.message.createSS.name")
.toUpperCase(),
Expand Down Expand Up @@ -2527,7 +2549,7 @@ public void drawButtons(int mousePosX, int mousePosY) {
false,
false);

if (!this.mapMode) {
if (this.mapMode != MapMode.VIEW) {
if (!this.selectedBody.getReachable()
|| this.possibleBodies != null && !this.possibleBodies.contains(this.selectedBody)
|| this.selectedBody instanceof Satellite && this.selectedStationOwner.equals("")) {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,19 +1,15 @@
package micdoodle8.mods.galacticraft.core.command;

import micdoodle8.mods.galacticraft.api.entity.IRocketType;
import micdoodle8.mods.galacticraft.core.client.gui.screen.GuiCelestialSelection;
import micdoodle8.mods.galacticraft.core.entities.player.GCPlayerStats;
import micdoodle8.mods.galacticraft.core.items.GCItems;
import micdoodle8.mods.galacticraft.core.util.EnumColor;
import micdoodle8.mods.galacticraft.core.util.GCCoreUtil;
import micdoodle8.mods.galacticraft.core.util.PlayerUtil;
import micdoodle8.mods.galacticraft.core.util.VersionUtil;
import micdoodle8.mods.galacticraft.core.util.WorldUtil;
import net.minecraft.command.CommandBase;
import net.minecraft.command.CommandException;
import net.minecraft.command.ICommandSender;
import net.minecraft.command.WrongUsageException;
import net.minecraft.entity.player.EntityPlayerMP;
import net.minecraft.item.ItemStack;
import net.minecraft.server.MinecraftServer;
import net.minecraft.util.ChunkCoordinates;
import net.minecraft.world.WorldServer;
Expand Down Expand Up @@ -53,26 +49,16 @@ public void processCommand(ICommandSender icommandsender, String[] astring) {
server.worldServerForDimension(server.worldServers[0].provider.dimensionId);
final ChunkCoordinates chunkcoordinates = worldserver.getSpawnPoint();
final GCPlayerStats stats = GCPlayerStats.get(playerBase);
stats.rocketStacks = new ItemStack[2];
stats.rocketType = IRocketType.EnumRocketType.DEFAULT.ordinal();
stats.rocketItem = GCItems.rocketTier1;
stats.fuelLevel = 1000;
stats.coordsTeleportedFromX = chunkcoordinates.posX;
stats.coordsTeleportedFromZ = chunkcoordinates.posZ;

try {
WorldUtil.toCelestialSelection(playerBase, stats, Integer.MAX_VALUE);
WorldUtil.toCelestialSelection(
playerBase, stats, Integer.MAX_VALUE, GuiCelestialSelection.MapMode.TELEPORTATION);
} catch (final Exception e) {
e.printStackTrace();
throw e;
}

VersionUtil.notifyAdmins(
icommandsender,
this,
"commands.dimensionteleport",
EnumColor.GREY + "[" + playerBase.getCommandSenderName(),
"]");
} else {
throw new Exception("Could not find player with name: " + astring[0]);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@
import micdoodle8.mods.galacticraft.core.GalacticraftCore;
import micdoodle8.mods.galacticraft.core.blocks.BlockUnlitTorch;
import micdoodle8.mods.galacticraft.core.blocks.GCBlocks;
import micdoodle8.mods.galacticraft.core.client.gui.screen.GuiCelestialSelection;
import micdoodle8.mods.galacticraft.core.dimension.SpaceRace;
import micdoodle8.mods.galacticraft.core.dimension.SpaceRaceManager;
import micdoodle8.mods.galacticraft.core.dimension.WorldProviderSpaceStation;
Expand Down Expand Up @@ -901,9 +902,9 @@ protected void sendPlanetList(EntityPlayerMP player, GCPlayerStats playerStats)

if (!temp.equals(playerStats.savedPlanetList) || player.ticksExisted % 100 == 0) {
GalacticraftCore.packetPipeline.sendTo(
new PacketSimple(
EnumSimplePacket.C_UPDATE_DIMENSION_LIST,
new Object[] {player.getGameProfile().getName(), temp}),
new PacketSimple(EnumSimplePacket.C_UPDATE_DIMENSION_LIST, new Object[] {
player.getGameProfile().getName(), temp, playerStats.currentMapMode.ordinal()
}),
player);
playerStats.savedPlanetList = temp;
// GCLog.debug("Sending to " + player.getGameProfile().getName() + ": " + temp);
Expand Down Expand Up @@ -1097,7 +1098,8 @@ public void onPlayerUpdate(EntityPlayerMP player) {
GCPlayer.openPlanetSelectionGuiCooldown--;

if (GCPlayer.openPlanetSelectionGuiCooldown == 1 && !GCPlayer.hasOpenedPlanetSelectionGui) {
WorldUtil.toCelestialSelection(player, GCPlayer, GCPlayer.spaceshipTier);
WorldUtil.toCelestialSelection(
player, GCPlayer, GCPlayer.spaceshipTier, GuiCelestialSelection.MapMode.TRAVEL);
GCPlayer.hasOpenedPlanetSelectionGui = true;
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
import micdoodle8.mods.galacticraft.api.recipe.ISchematicPage;
import micdoodle8.mods.galacticraft.api.recipe.SchematicRegistry;
import micdoodle8.mods.galacticraft.core.blocks.GCBlocks;
import micdoodle8.mods.galacticraft.core.client.gui.screen.GuiCelestialSelection;
import micdoodle8.mods.galacticraft.core.command.CommandGCInv;
import micdoodle8.mods.galacticraft.core.inventory.InventoryExtended;
import micdoodle8.mods.galacticraft.core.util.ConfigManagerCore;
Expand Down Expand Up @@ -85,6 +86,7 @@ public class GCPlayerStats implements IExtendedEntityProperties {
public int spaceRaceInviteTeamID;

public boolean usingPlanetSelectionGui;
public GuiCelestialSelection.MapMode currentMapMode;
public String savedPlanetList = "";
public int openPlanetSelectionGuiCooldown;
public boolean hasOpenedPlanetSelectionGui = false;
Expand Down Expand Up @@ -141,6 +143,7 @@ public void saveNBTData(NBTTagCompound nbt) {
nbt.setBoolean("OxygenSetupValid", this.oxygenSetupValid);
nbt.setBoolean("usingParachute2", this.usingParachute);
nbt.setBoolean("usingPlanetSelectionGui", this.usingPlanetSelectionGui);
nbt.setInteger("currentMapMode", this.currentMapMode.ordinal());
nbt.setInteger("teleportCooldown", this.teleportCooldown);
nbt.setDouble("coordsTeleportedFromX", this.coordsTeleportedFromX);
nbt.setDouble("coordsTeleportedFromZ", this.coordsTeleportedFromZ);
Expand Down Expand Up @@ -243,6 +246,7 @@ public void loadNBTData(NBTTagCompound nbt) {

this.usingParachute = nbt.getBoolean("usingParachute2");
this.usingPlanetSelectionGui = nbt.getBoolean("usingPlanetSelectionGui");
this.currentMapMode = GuiCelestialSelection.MapMode.fromInteger(nbt.getInteger("currentMapMode"));
this.teleportCooldown = nbt.getInteger("teleportCooldown");
this.coordsTeleportedFromX = nbt.getDouble("coordsTeleportedFromX");
this.coordsTeleportedFromZ = nbt.getDouble("coordsTeleportedFromZ");
Expand Down
Loading

0 comments on commit fd9a309

Please sign in to comment.