-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
a862b52
commit f9dd64c
Showing
16 changed files
with
287 additions
and
222 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
83 changes: 83 additions & 0 deletions
83
src/main/java/org/teacon/signmeup/config/waypoints/Waypoint.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,83 @@ | ||
package org.teacon.signmeup.config.waypoints; | ||
|
||
import io.netty.buffer.ByteBuf; | ||
import net.minecraft.network.codec.ByteBufCodecs; | ||
import net.minecraft.network.codec.StreamCodec; | ||
import org.jetbrains.annotations.NotNull; | ||
|
||
import java.util.Map; | ||
import java.util.Objects; | ||
import java.util.concurrent.ConcurrentHashMap; | ||
|
||
public class Waypoint { | ||
public static final Map<String, Waypoint> INSTANCES = new ConcurrentHashMap<>(); | ||
|
||
public static final StreamCodec<ByteBuf, Waypoint> CODEC = new StreamCodec<>() { | ||
@Override | ||
public @NotNull Waypoint decode(@NotNull ByteBuf buffer) { | ||
return new Waypoint( | ||
ByteBufCodecs.STRING_UTF8.decode(buffer), | ||
ByteBufCodecs.STRING_UTF8.decode(buffer), | ||
ByteBufCodecs.VAR_INT.decode(buffer), | ||
ByteBufCodecs.VAR_INT.decode(buffer), | ||
ByteBufCodecs.VAR_INT.decode(buffer), | ||
ByteBufCodecs.FLOAT.decode(buffer), | ||
ByteBufCodecs.FLOAT.decode(buffer) | ||
); | ||
} | ||
|
||
@Override | ||
public void encode(@NotNull ByteBuf buffer, @NotNull Waypoint value) { | ||
ByteBufCodecs.STRING_UTF8.encode(buffer, value.name); | ||
ByteBufCodecs.STRING_UTF8.encode(buffer, value.description); | ||
ByteBufCodecs.VAR_INT.encode(buffer, value.x); | ||
ByteBufCodecs.VAR_INT.encode(buffer, value.y); | ||
ByteBufCodecs.VAR_INT.encode(buffer, value.z); | ||
ByteBufCodecs.FLOAT.encode(buffer, value.rx); | ||
ByteBufCodecs.FLOAT.encode(buffer, value.ry); | ||
} | ||
}; | ||
|
||
public static void load() { | ||
for (Waypoint waypoint : WaypointSavedData.load()) { | ||
INSTANCES.put(waypoint.name, waypoint); | ||
} | ||
} | ||
|
||
public static void save() { | ||
WaypointSavedData.save(INSTANCES.values()); | ||
} | ||
|
||
public final String name, description; | ||
public final int x, y, z; | ||
|
||
public final float rx, ry; | ||
|
||
public Waypoint(String name, String description, int x, int y, int z, float rx, float ry) { | ||
this.name = name; | ||
this.description = description; | ||
this.x = x; | ||
this.y = y; | ||
this.z = z; | ||
this.rx = rx; | ||
this.ry = ry; | ||
} | ||
|
||
@Override | ||
public boolean equals(Object obj) { | ||
if (obj instanceof Waypoint that) { | ||
return Objects.equals(that.name, name); | ||
} | ||
return false; | ||
} | ||
|
||
@Override | ||
public int hashCode() { | ||
return name.hashCode(); | ||
} | ||
|
||
@Override | ||
public String toString() { | ||
return "[WayPoint name=" + name + ", description=" + description + ", <" + x + ", " + y + ", " + z + ">, rotation=<" + rx + ", " + ry + ">]"; | ||
} | ||
} |
15 changes: 15 additions & 0 deletions
15
src/main/java/org/teacon/signmeup/config/waypoints/WaypointClientEvents.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
package org.teacon.signmeup.config.waypoints; | ||
|
||
import net.neoforged.api.distmarker.Dist; | ||
import net.neoforged.bus.api.SubscribeEvent; | ||
import net.neoforged.fml.common.EventBusSubscriber; | ||
import net.neoforged.neoforge.client.event.ClientPlayerNetworkEvent; | ||
import org.teacon.signmeup.SignMeUp; | ||
|
||
@EventBusSubscriber(value = Dist.CLIENT, modid = SignMeUp.MODID, bus = EventBusSubscriber.Bus.GAME) | ||
public class WaypointClientEvents { | ||
@SubscribeEvent | ||
public static void onPlayerLoggedOut(ClientPlayerNetworkEvent.LoggingOut event) { | ||
Waypoint.INSTANCES.clear(); | ||
} | ||
} |
Oops, something went wrong.