Skip to content

Commit

Permalink
Fix MarkerApi not usable on server
Browse files Browse the repository at this point in the history
  • Loading branch information
tyra314 committed Jan 26, 2021
1 parent e40d5ab commit 7ddbc86
Show file tree
Hide file tree
Showing 8 changed files with 27 additions and 25 deletions.
8 changes: 4 additions & 4 deletions src/main/java/hunternif/mc/impl/atlas/api/MarkerAPI.java
Original file line number Diff line number Diff line change
Expand Up @@ -36,14 +36,14 @@ public interface MarkerAPI {
* the player hasn't yet discovered that area.
* @param atlasID the ID of the atlas you want to put marker in. Equal
* to ItemStack damage for ItemAtlas.
* @param markerType name of your custom marker type.
* @param marker name of your custom marker type.
* @param label text label to be displayed on mouseover.
* @param x block coordinate
* @param z block coordinate
* @return returns the marker. null if failed or client
*/
@Nullable
Marker putMarker(@Nonnull World world, boolean visibleAhead, int atlasID, MarkerType markerType, Text label, int x, int z);
Marker putMarker(@Nonnull World world, boolean visibleAhead, int atlasID, Identifier marker, Text label, int x, int z);

/**
* Put a marker in all atlases in the world at specified block coordinates.
Expand All @@ -52,14 +52,14 @@ public interface MarkerAPI {
* @param world
* @param visibleAhead whether the marker should appear visible even if
* the player hasn't yet discovered that area.
* @param markerType name of your custom marker type.
* @param marker name of your custom marker type.
* @param label text label to be displayed on mouseover.
* @param x block coordinate
* @param z block coordinate
* @return returns the marker. null if failed or client
*/
@Nullable
Marker putGlobalMarker(@Nonnull World world, boolean visibleAhead, MarkerType markerType, Text label, int x, int z);
Marker putGlobalMarker(@Nonnull World world, boolean visibleAhead, Identifier marker, Text label, int x, int z);

/**
* Delete a marker from an atlas.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,14 +29,14 @@ public void registerMarker(Identifier identifier, MarkerType markerType) {

@Nullable
@Override
public Marker putMarker(@Nonnull World world, boolean visibleAhead, int atlasID, MarkerType markerType, Text label, int x, int z) {
new AddMarkerC2SPacket(atlasID, MarkerType.REGISTRY.getId(markerType), x, z, visibleAhead, label).send();
public Marker putMarker(@Nonnull World world, boolean visibleAhead, int atlasID, Identifier marker, Text label, int x, int z) {
new AddMarkerC2SPacket(atlasID, marker, x, z, visibleAhead, label).send();
return null;
}

@Nullable
@Override
public Marker putGlobalMarker(@Nonnull World world, boolean visibleAhead, MarkerType markerType, Text label, int x, int z) {
public Marker putGlobalMarker(@Nonnull World world, boolean visibleAhead, Identifier marker, Text label, int x, int z) {
AntiqueAtlasMod.LOG.warn("Client tried to add a global marker");

return null;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,24 +26,24 @@ public class MarkerApiImpl implements MarkerAPI {

@Nullable
@Override
public Marker putMarker(@Nonnull World world, boolean visibleAhead, int atlasID, MarkerType markerType, Text label, int x, int z) {
return doPutMarker(world, visibleAhead, atlasID, markerType, label, x, z);
public Marker putMarker(@Nonnull World world, boolean visibleAhead, int atlasID, Identifier marker, Text label, int x, int z) {
return doPutMarker(world, visibleAhead, atlasID, marker, label, x, z);
}

@Nullable
@Override
public Marker putGlobalMarker(@Nonnull World world, boolean visibleAhead, MarkerType markerType, Text label, int x, int z) {
return doPutMarker(world, visibleAhead, GLOBAL, markerType, label, x, z);
public Marker putGlobalMarker(@Nonnull World world, boolean visibleAhead, Identifier marker, Text label, int x, int z) {
return doPutMarker(world, visibleAhead, GLOBAL, marker, label, x, z);
}

private Marker doPutMarker(World world, boolean visibleAhead, int atlasID, MarkerType markerType, Text label, int x, int z) {
private Marker doPutMarker(World world, boolean visibleAhead, int atlasID, Identifier markerId, Text label, int x, int z) {
Marker marker = null;
if (!world.isClient && world.getServer() != null) {
MarkersData data = atlasID == GLOBAL
? AntiqueAtlasMod.globalMarkersData.getData()
: AntiqueAtlasMod.markersData.getMarkersData(atlasID, world);

marker = data.createAndSaveMarker(MarkerType.REGISTRY.getId(markerType), world.getRegistryKey(), x, z, visibleAhead, label);
marker = data.createAndSaveMarker(markerId, world.getRegistryKey(), x, z, visibleAhead, label);
new MarkersS2CPacket(atlasID, world.getRegistryKey(), Collections.singleton(marker)).send((ServerWorld) world);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
import hunternif.mc.impl.atlas.client.gui.core.GuiComponent;
import hunternif.mc.impl.atlas.client.gui.core.GuiScrollingContainer;
import hunternif.mc.impl.atlas.client.gui.core.ToggleGroup;
import hunternif.mc.impl.atlas.marker.Marker;
import hunternif.mc.impl.atlas.registry.MarkerType;
import hunternif.mc.impl.atlas.util.Log;
import net.fabricmc.api.EnvType;
Expand Down Expand Up @@ -79,7 +80,7 @@ protected void init() {
super.init();

addButton(btnDone = new ButtonWidget(this.width / 2 - BUTTON_WIDTH - BUTTON_SPACING / 2, this.height / 2 + 40, BUTTON_WIDTH, 20, new TranslatableText("gui.done"), (button) -> {
MarkerRegistry.API.putMarker(world, true, atlasID, selectedType, new LiteralText(textField.getText()), markerX, markerZ);
MarkerRegistry.API.putMarker(world, true, atlasID, MarkerType.REGISTRY.getId(selectedType), new LiteralText(textField.getText()), markerX, markerZ);
Log.info("Put marker in Atlas #%d \"%s\" at (%d, %d)", atlasID, textField.getText(), markerX, markerZ);

ClientPlayerEntity player = MinecraftClient.getInstance().player;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ public class DeathWatcher {
public static void onPlayerDeath(PlayerEntity player) {
if (AntiqueAtlasMod.CONFIG.autoDeathMarker) {
for (int atlasID : AtlasAPI.getPlayerAtlases(player)) {
AtlasAPI.markers.putMarker(player.getEntityWorld(), true, atlasID, MarkerType.REGISTRY.get(new Identifier("antiqueatlas:tomb")),
AtlasAPI.markers.putMarker(player.getEntityWorld(), true, atlasID, new Identifier("antiqueatlas:tomb"),
new TranslatableText("gui.antiqueatlas.marker.tomb", player.getName()),
(int) player.getX(), (int) player.getZ());
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,14 +37,14 @@ public void onWorldLoad(WorldEvent.Load event) {
event.getWorld().a(this);
}
}
@SubscribeEvent
public void onWorldUnload(WorldEvent.Unload event) {
if (!event.getWorld().G) {
event.getWorld().b(this);
}
}
@Override
public void a(Entity entity) {
if (entity instanceof PlayerEntity) {
Expand All @@ -64,7 +64,7 @@ public void a(Entity entity) {
}
}
}
@Override
public void b(Entity entity) {
if (entity instanceof PlayerEntity) {
Expand All @@ -81,7 +81,7 @@ public void b(Entity entity) {
}
}
} */

/** Put the Portal marker at the player's current coordinates into all
* atlases that he is carrying, if the same marker is not already there. */
private void addPortalMarkerIfNone(PlayerEntity player) {
Expand Down Expand Up @@ -130,9 +130,9 @@ private void addPortalMarkerIfNone(PlayerEntity player, World world, int atlasID
}

// Marker not found, place new one:
AtlasAPI.markers.putMarker(world, false, atlasID,netherPortalType, new TranslatableText("gui.antiqueatlas.marker.netherPortal"), x, z);
AtlasAPI.markers.putMarker(world, false, atlasID, MarkerType.REGISTRY.getId(netherPortalType), new TranslatableText("gui.antiqueatlas.marker.netherPortal"), x, z);
}

private static boolean isEntityInPortal(Entity entity) {
return ((EntityHooksAA) entity).antiqueAtlas_isInPortal();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
import net.minecraft.item.map.MapIcon;
import net.minecraft.item.map.MapState;
import net.minecraft.text.TranslatableText;
import net.minecraft.util.Identifier;

public class CartographyTableHooks {
public static void onTakeItem(PlayerEntity player, ItemStack map, ItemStack atlas) {
Expand All @@ -25,17 +26,17 @@ public static void onTakeItem(PlayerEntity player, ItemStack map, ItemStack atla
int z = (int) ((int) (icon.getZ() - 0.5f) / 2f) * i + mapState.zCenter;

if (icon.getType() == MapIcon.Type.RED_X) {
MarkerType type = MarkerType.REGISTRY.get(AntiqueAtlasMod.id("red_x_small"));
Identifier type = AntiqueAtlasMod.id("red_x_small");
if (!player.getEntityWorld().isClient()) {
Markers.API.putMarker(player.getEntityWorld(), true, AtlasItem.getAtlasID(atlas), type, new TranslatableText("gui.antiqueatlas.marker.treasure"), x, z);
}
} else if (icon.getType() == MapIcon.Type.MONUMENT) {
MarkerType type = MarkerType.REGISTRY.get(AntiqueAtlasMod.id("tower"));
Identifier type = AntiqueAtlasMod.id("tower");
if (!player.getEntityWorld().isClient()) {
Markers.API.putMarker(player.getEntityWorld(), true, AtlasItem.getAtlasID(atlas), type, new TranslatableText("gui.antiqueatlas.marker.monument"), x, z);
}
} else if (icon.getType() == MapIcon.Type.MANSION) {
MarkerType type = MarkerType.REGISTRY.get(AntiqueAtlasMod.id("village"));
Identifier type = AntiqueAtlasMod.id("village");
if (!player.getEntityWorld().isClient()) {
Markers.API.putMarker(player.getEntityWorld(), true, AtlasItem.getAtlasID(atlas), type, new TranslatableText("gui.antiqueatlas.marker.mansion"), x, z);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ public static void resolve(StructureStart<?> structureStart, ServerWorld world)
AtlasAPI.markers.putGlobalMarker(
world,
false,
MarkerType.REGISTRY.get(STRUCTURE_PIECE_TO_MARKER_MAP.get(structureId).getLeft()),
STRUCTURE_PIECE_TO_MARKER_MAP.get(structureId).getLeft(),
STRUCTURE_PIECE_TO_MARKER_MAP.get(structureId).getRight(),
structureStart.getBoundingBox().getCenter().getX(),
structureStart.getBoundingBox().getCenter().getZ()
Expand Down

0 comments on commit 7ddbc86

Please sign in to comment.