Skip to content

Commit

Permalink
remove all items and item changes
Browse files Browse the repository at this point in the history
  • Loading branch information
sisby-folk committed May 15, 2023
1 parent a4c9380 commit 2456e8b
Show file tree
Hide file tree
Showing 40 changed files with 41 additions and 1,030 deletions.
38 changes: 2 additions & 36 deletions common/src/main/java/hunternif/mc/api/AtlasAPI.java
Original file line number Diff line number Diff line change
@@ -1,18 +1,8 @@
package hunternif.mc.api;

import hunternif.mc.impl.atlas.AntiqueAtlasMod;
import hunternif.mc.impl.atlas.api.impl.MarkerApiImpl;
import hunternif.mc.impl.atlas.api.impl.TileApiImpl;
import hunternif.mc.impl.atlas.item.AtlasItem;
import net.minecraft.entity.player.PlayerEntity;
import net.minecraft.item.Item;
import net.minecraft.item.ItemStack;
import net.minecraft.util.Identifier;
import net.minecraft.util.registry.Registry;

import java.util.ArrayList;
import java.util.Collections;
import java.util.List;

/**
* Use this class to obtain a reference to the APIs.
Expand All @@ -32,10 +22,6 @@ public static int getVersion() {
return VERSION;
}

public static Item getAtlasItem() {
return Registry.ITEM.get(new Identifier("antiqueatlas:antique_atlas"));
}

/**
* API for biomes and custom tiles (i.e. dungeons, towns etc).
*/
Expand All @@ -50,27 +36,7 @@ public static MarkerAPI getMarkerAPI() {
return markers;
}

/**
* Convenience method that returns a list of atlas IDs for all atlas items
* the player is currently carrying.
**/
public static List<Integer> getPlayerAtlases(PlayerEntity player) {
if (!AntiqueAtlasMod.CONFIG.itemNeeded) {
return Collections.singletonList(player.getUuid().hashCode());
}

List<Integer> list = new ArrayList<>();
for (ItemStack stack : player.getInventory().main) {
if (!stack.isEmpty() && stack.getItem() instanceof AtlasItem) {
list.add(AtlasItem.getAtlasID(stack));
}
}
for (ItemStack stack : player.getInventory().offHand) {
if (!stack.isEmpty() && stack.getItem() instanceof AtlasItem) {
list.add(AtlasItem.getAtlasID(stack));
}
}

return list;
public static int getPlayerAtlasId(PlayerEntity player) {
return player.getUuid().hashCode();
}
}
3 changes: 1 addition & 2 deletions common/src/main/java/hunternif/mc/api/MarkerAPI.java
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,7 @@ public interface MarkerAPI {
* @param world
* @param visibleAhead whether the marker should appear visible even if
* 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 atlasID the ID of the atlas you want to put marker in.
* @param marker name of your custom marker type.
* @param label text label to be displayed on mouseover.
* @param x block coordinate
Expand Down
6 changes: 2 additions & 4 deletions common/src/main/java/hunternif/mc/api/TileAPI.java
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,7 @@ public interface TileAPI {
* </p>
*
* @param world dimension the chunk is located in.
* @param atlasID the ID of the atlas you want to put marker in. Equal
* to ItemStack damage for ItemAtlas.
* @param atlasID the ID of the atlas you want to put marker in.
* @param tile the identifier of the new tile
* @param chunkX x chunk coordinate. (block coordinate >> 4)
* @param chunkZ z chunk coordinate. (block coordinate >> 4)
Expand All @@ -42,8 +41,7 @@ public interface TileAPI {
* </p>
*
* @param world dimension the chunk is located in.
* @param atlasID the ID of the atlas you want to put marker in. Equal
* to ItemStack damage for ItemAtlas.
* @param atlasID the ID of the atlas you want to put marker in.
* @param chunkX x chunk coordinate. (block coordinate >> 4)
* @param chunkZ z chunk coordinate. (block coordinate >> 4)
* @return the identifier of the requested tile
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,10 +25,6 @@ public class AntiqueAtlasConfig implements ConfigData {
@Comment("Whether to add global markers for Nether Portals.")
public boolean autoNetherPortalMarkers = true;

@ConfigEntry.Category("gameplay")
@Comment("Player will need to craft atlas item to use atlas.")
public boolean itemNeeded = true;

//============ Interface settings =============
@ConfigEntry.Category("userInterface")
public boolean doScaleMarkers = false;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,6 @@
import hunternif.mc.impl.atlas.core.PlayerEventHandler;
import hunternif.mc.impl.atlas.core.TileDataHandler;
import hunternif.mc.impl.atlas.core.scanning.WorldScanner;
import hunternif.mc.impl.atlas.event.RecipeCraftedCallback;
import hunternif.mc.impl.atlas.event.RecipeCraftedHandler;
import hunternif.mc.impl.atlas.item.AntiqueAtlasItems;
import hunternif.mc.impl.atlas.marker.GlobalMarkersDataHandler;
import hunternif.mc.impl.atlas.marker.MarkersDataHandler;
import hunternif.mc.impl.atlas.mixinhooks.NewPlayerConnectionCallback;
Expand Down Expand Up @@ -57,8 +54,6 @@ public static void init() {
AutoConfig.register(AntiqueAtlasConfig.class, JanksonConfigSerializer::new);
CONFIG = AutoConfig.getConfigHolder(AntiqueAtlasConfig.class).getConfig();

AntiqueAtlasItems.register();

AntiqueAtlasNetworking.registerC2SListeners();

NewServerConnectionCallback.EVENT.register(tileData::onClientConnectedToServer);
Expand All @@ -72,8 +67,6 @@ public static void init() {
LifecycleEvent.SERVER_LEVEL_LOAD.register(globalMarkersData::onWorldLoad);
LifecycleEvent.SERVER_LEVEL_LOAD.register(globalTileData::onWorldLoad);

RecipeCraftedCallback.EVENT.register(new RecipeCraftedHandler());

StructurePieceAddedCallback.EVENT.register(StructureHandler::resolve);
StructureAddedCallback.EVENT.register(StructureHandler::resolve);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
import net.fabricmc.api.EnvType;
import net.fabricmc.api.Environment;
import net.minecraft.client.MinecraftClient;
import net.minecraft.item.ItemStack;

@Environment(EnvType.CLIENT)
public class AntiqueAtlasModClient {
Expand All @@ -20,10 +19,6 @@ public static GuiAtlas getAtlasGUI() {
return guiAtlas;
}

public static void openAtlasGUI(ItemStack stack) {
openAtlasGUI(getAtlasGUI().prepareToOpen(stack));
}

public static void openAtlasGUI() {
openAtlasGUI(getAtlasGUI().prepareToOpen());
}
Expand Down
7 changes: 2 additions & 5 deletions common/src/main/java/hunternif/mc/impl/atlas/ClientProxy.java
Original file line number Diff line number Diff line change
Expand Up @@ -49,11 +49,8 @@ public void initClient() {
type.initMips();
}

if (!AntiqueAtlasMod.CONFIG.itemNeeded) {
KeyHandler.registerBindings();
ClientTickEvent.CLIENT_POST.register(KeyHandler::onClientTick);
}

KeyHandler.registerBindings();
ClientTickEvent.CLIENT_POST.register(KeyHandler::onClientTick);
}

/**
Expand Down
Original file line number Diff line number Diff line change
@@ -1,12 +1,11 @@
package hunternif.mc.impl.atlas.client;

import com.mojang.blaze3d.systems.RenderSystem;
import hunternif.mc.api.AtlasAPI;
import hunternif.mc.api.client.AtlasClientAPI;
import hunternif.mc.impl.atlas.AntiqueAtlasMod;
import hunternif.mc.impl.atlas.item.AntiqueAtlasItems;
import hunternif.mc.impl.atlas.client.gui.GuiAtlas;
import hunternif.mc.impl.atlas.core.WorldData;
import hunternif.mc.impl.atlas.item.AtlasItem;
import hunternif.mc.impl.atlas.marker.DimensionMarkersData;
import hunternif.mc.impl.atlas.marker.Marker;
import hunternif.mc.impl.atlas.marker.MarkersData;
Expand All @@ -20,7 +19,6 @@
import net.minecraft.client.render.VertexConsumerProvider;
import net.minecraft.client.util.math.MatrixStack;
import net.minecraft.entity.player.PlayerEntity;
import net.minecraft.item.ItemStack;
import net.minecraft.util.math.Quaternion;
import net.minecraft.util.math.Vec3d;
import net.minecraft.util.math.Vec3f;
Expand All @@ -40,7 +38,7 @@ public class OverlayRenderer extends DrawableHelper {
private PlayerEntity player;
private World world;

public void drawOverlay(MatrixStack matrices, VertexConsumerProvider vertexConsumer, int light, ItemStack atlas) {
public void drawOverlay(MatrixStack matrices, VertexConsumerProvider vertexConsumer, int light) {
// Overlay must close if Atlas GUI is opened
if (MinecraftClient.getInstance().currentScreen instanceof GuiAtlas) {
return;
Expand All @@ -53,10 +51,7 @@ public void drawOverlay(MatrixStack matrices, VertexConsumerProvider vertexConsu
this.player = MinecraftClient.getInstance().player;
this.world = MinecraftClient.getInstance().world;

if (!atlas.isEmpty() && atlas.getItem() == AntiqueAtlasItems.ATLAS.getOrNull()) {
int atlasID = AtlasItem.getAtlasID(atlas);
drawMinimap(matrices, atlasID, vertexConsumer, light);
}
drawMinimap(matrices, AtlasAPI.getPlayerAtlasId(player), vertexConsumer, light);
}

private void drawMinimap(MatrixStack matrices, int atlasID, VertexConsumerProvider buffer, int light) {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package hunternif.mc.impl.atlas.client.gui;

import com.mojang.blaze3d.systems.RenderSystem;
import hunternif.mc.api.AtlasAPI;
import hunternif.mc.api.client.AtlasClientAPI;
import hunternif.mc.impl.atlas.AntiqueAtlasMod;
import hunternif.mc.impl.atlas.client.*;
Expand All @@ -12,7 +13,6 @@
import hunternif.mc.impl.atlas.core.WorldData;
import hunternif.mc.impl.atlas.event.MarkerClickedCallback;
import hunternif.mc.impl.atlas.event.MarkerHoveredCallback;
import hunternif.mc.impl.atlas.item.AtlasItem;
import hunternif.mc.impl.atlas.marker.DimensionMarkersData;
import hunternif.mc.impl.atlas.marker.Marker;
import hunternif.mc.impl.atlas.marker.MarkersData;
Expand All @@ -27,15 +27,13 @@
import net.minecraft.client.sound.PositionedSoundInstance;
import net.minecraft.client.util.math.MatrixStack;
import net.minecraft.entity.player.PlayerEntity;
import net.minecraft.item.ItemStack;
import net.minecraft.sound.SoundCategory;
import net.minecraft.sound.SoundEvents;
import net.minecraft.text.Text;
import net.minecraft.util.Identifier;
import net.minecraft.util.math.BlockPos;
import net.minecraft.util.math.ChunkPos;
import net.minecraft.util.math.MathHelper;
import net.minecraft.util.math.Vec3f;
import org.lwjgl.glfw.GLFW;
import org.lwjgl.opengl.GL11;

Expand Down Expand Up @@ -279,7 +277,6 @@ public void onExitState() {
// Misc stuff ==============================================================

private PlayerEntity player;
private ItemStack stack;
private WorldData biomeData;

/**
Expand Down Expand Up @@ -346,10 +343,8 @@ public boolean isEnabled() {
};
addChild(btnExportPng).offsetGuiCoords(300, 75);
btnExportPng.addListener(button -> {
if (stack != null || !AntiqueAtlasMod.CONFIG.itemNeeded) {
exportThread = new Thread(() -> exportImage(getAtlasID()), "Atlas file export thread");
exportThread.start();
}
exportThread = new Thread(() -> exportImage(getAtlasID()), "Atlas file export thread");
exportThread.start();
});

btnMarker = new GuiBookmarkButton(0, Textures.ICON_ADD_MARKER, Text.translatable("gui.antiqueatlas.addMarker"));
Expand All @@ -358,7 +353,7 @@ public boolean isEnabled() {
if (state.is(PLACING_MARKER)) {
selectedButton = null;
state.switchTo(NORMAL);
} else if (stack != null || !AntiqueAtlasMod.CONFIG.itemNeeded) {
} else {
selectedButton = button;
state.switchTo(PLACING_MARKER);

Expand Down Expand Up @@ -392,7 +387,7 @@ public boolean isEnabled() {
if (state.is(DELETING_MARKER)) {
selectedButton = null;
state.switchTo(NORMAL);
} else if (stack != null || !AntiqueAtlasMod.CONFIG.itemNeeded) {
} else {
selectedButton = button;
state.switchTo(DELETING_MARKER);
}
Expand All @@ -403,7 +398,7 @@ public boolean isEnabled() {
selectedButton = null;
if (state.is(HIDING_MARKERS)) {
state.switchTo(NORMAL);
} else if (stack != null || !AntiqueAtlasMod.CONFIG.itemNeeded) {
} else {
selectedButton = null;
state.switchTo(HIDING_MARKERS);
}
Expand All @@ -423,12 +418,6 @@ public boolean isEnabled() {
state.switchTo(NORMAL);
}

public GuiAtlas prepareToOpen(ItemStack stack) {
this.stack = stack;

return prepareToOpen();
}

public void openMarkerFinalizer(Text name) {
markerFinalizer.setMarkerData(player.getEntityWorld(),
getAtlasID(),
Expand Down Expand Up @@ -913,8 +902,7 @@ public void render(MatrixStack matrices, int mouseX, int mouseY, float par3) {
// RenderSystem.alphaFunc(GL11.GL_GREATER, 0); // So light detail on tiles is visible
Textures.BOOK.draw(matrices, getGuiX(), getGuiY());

if ((stack == null && AntiqueAtlasMod.CONFIG.itemNeeded) || biomeData == null)
return;
if (biomeData == null) return;

if (state.is(DELETING_MARKER)) {
RenderSystem.setShaderColor(1, 1, 1, 0.5f);
Expand Down Expand Up @@ -1240,9 +1228,9 @@ private double getIconScale() {
}

/**
* Returns atlas id based on "itemNeeded" option
* Returns atlas id
*/
private int getAtlasID() {
return AntiqueAtlasMod.CONFIG.itemNeeded ? AtlasItem.getAtlasID(stack) : player.getUuid().hashCode();
return AtlasAPI.getPlayerAtlasId(player);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -152,8 +152,7 @@ public boolean isSyncedToPlayer(PlayerEntity player) {
}

/**
* Send all data to the player in several zipped packets. Called once
* during the first run of ItemAtlas.onUpdate().
* Send all data to the player in several zipped packets. Called once on login.
*/
public void syncToPlayer(int atlasID, PlayerEntity player) {
NbtCompound data = new NbtCompound();
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package hunternif.mc.impl.atlas.core;

import hunternif.mc.api.AtlasAPI;
import hunternif.mc.impl.atlas.AntiqueAtlasMod;
import hunternif.mc.impl.atlas.marker.MarkersData;
import net.minecraft.entity.player.PlayerEntity;
Expand All @@ -9,7 +10,7 @@
public class PlayerEventHandler {
public static void onPlayerLogin(ServerPlayerEntity player) {
World world = player.world;
int atlasID = player.getUuid().hashCode();
int atlasID = AtlasAPI.getPlayerAtlasId(player);

AtlasData data = AntiqueAtlasMod.tileData.getData(atlasID, world);
// On the player join send the map from the server to the client:
Expand All @@ -25,12 +26,10 @@ public static void onPlayerLogin(ServerPlayerEntity player) {
}

public static void onPlayerTick(PlayerEntity player) {
if (!AntiqueAtlasMod.CONFIG.itemNeeded) {
// TODO Can we move world scanning to the server in this case as well?
AtlasData data = AntiqueAtlasMod.tileData.getData(
player.getUuid().hashCode(), player.world);
// TODO Can we move world scanning to the server in this case as well?
AtlasData data = AntiqueAtlasMod.tileData.getData(
AtlasAPI.getPlayerAtlasId(player), player.world);

AntiqueAtlasMod.worldScanner.updateAtlasAroundPlayer(data, player);
}
AntiqueAtlasMod.worldScanner.updateAtlasAroundPlayer(data, player);
}
}
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
package hunternif.mc.impl.atlas.core;

import hunternif.mc.impl.atlas.item.AtlasItem;
import net.minecraft.item.ItemStack;
import net.minecraft.server.world.ServerWorld;
import net.minecraft.world.PersistentStateManager;
import net.minecraft.world.World;
Expand All @@ -21,17 +19,6 @@ public class TileDataHandler {

private final Map<String, AtlasData> atlasDataClientCache = new ConcurrentHashMap<>();

/**
* Loads data for the given atlas ID or creates a new one.
*/
public AtlasData getData(ItemStack stack, World world) {
if (stack.getItem() instanceof AtlasItem) {
return getData(AtlasItem.getAtlasID(stack), world);
} else {
return null;
}
}

/**
* Loads data for the given atlas or creates a new one.
*/
Expand Down
Loading

0 comments on commit 2456e8b

Please sign in to comment.