Skip to content

Commit

Permalink
add handheld atlas to creative
Browse files Browse the repository at this point in the history
  • Loading branch information
sisby-folk committed Feb 16, 2025
1 parent a5de079 commit 494e2e6
Show file tree
Hide file tree
Showing 8 changed files with 60 additions and 28 deletions.
6 changes: 5 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,11 @@ Drag the map to pan, scroll to zoom, and use the bookmark buttons to create and

> ![marker styles](https://cdn.modrinth.com/data/Y5Ve4Ui4/images/b7064c3287c5535cd9ac6d454c10ead984c7a7b3.png)
If you need an equally distraction-free compass to substitute a minimap, try [PicoHUD](https://modrinth.com/mod/picohud)!
- Books renamed "Antique Atlas" will display your immediate surroundings, like a minimap:

> ![handheld atlas](https://cdn.modrinth.com/data/Y5Ve4Ui4/images/b3002225851522c2d4eabc7462a374fbcdd2db6b.png)
If you'd instead prefer a low-tech compass, try [PicoHUD](https://modrinth.com/mod/picohud)!

## Mixed-Side Features

Expand Down
2 changes: 1 addition & 1 deletion gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ authors=Hunternif, tyra314, Sisby folk
contributors=Kenkron, asiekierka, Haven King, TheCodeWarrior, osipxd, coolAlias, TehNut, lumiscosity, frodolon
license=LGPL-3.0-or-later
# Mod Version
baseVersion=2.11.1
baseVersion=2.11.2
# Branch Metadata
branch=1.20
tagBranch=1.20
Expand Down
31 changes: 30 additions & 1 deletion src/main/java/folk/sisby/antique_atlas/AntiqueAtlas.java
Original file line number Diff line number Diff line change
Expand Up @@ -12,17 +12,27 @@
import net.fabricmc.fabric.api.client.event.lifecycle.v1.ClientTickEvents;
import net.fabricmc.fabric.api.client.networking.v1.ClientPlayConnectionEvents;
import net.fabricmc.fabric.api.event.lifecycle.v1.CommonLifecycleEvents;
import net.fabricmc.fabric.api.itemgroup.v1.ItemGroupEvents;
import net.fabricmc.fabric.api.resource.ResourceManagerHelper;
import net.fabricmc.loader.api.FabricLoader;
import net.minecraft.client.item.ModelPredicateProviderRegistry;
import net.minecraft.client.util.ModelIdentifier;
import net.minecraft.item.ItemGroups;
import net.minecraft.item.ItemStack;
import net.minecraft.item.Items;
import net.minecraft.nbt.NbtList;
import net.minecraft.nbt.NbtString;
import net.minecraft.registry.RegistryKeys;
import net.minecraft.resource.ResourceType;
import net.minecraft.text.Style;
import net.minecraft.text.Text;
import net.minecraft.util.Formatting;
import net.minecraft.util.Identifier;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;

import java.util.List;

public class AntiqueAtlas implements ClientModInitializer {
public static final String ID = "antique_atlas";
public static final String NAME = "Antique Atlas";
Expand All @@ -34,10 +44,28 @@ public class AntiqueAtlas implements ClientModInitializer {

public static final ModelIdentifier ATLAS_MODEL = new ModelIdentifier(AntiqueAtlas.id("atlas"), "inventory");

public static final List<String> ATLAS_NAMES = List.of(
"Antique Atlas"
);

public static Identifier id(String path) {
return path.contains(":") ? new Identifier(path) : new Identifier(ID, path);
}

public static ItemStack getHandheldAtlas() {
ItemStack stack = Items.BOOK.getDefaultStack().copy();
stack.setCustomName(Text.translatable("item.antique_atlas.atlas").setStyle(Style.EMPTY.withItalic(false)));
NbtList lore = new NbtList();
lore.add(NbtString.of(Text.Serializer.toJson(Text.translatable("item.antique_atlas.atlas.lore").setStyle(Style.EMPTY.withColor(Formatting.GRAY).withItalic(false)))));
lore.add(NbtString.of(Text.Serializer.toJson(Text.translatable("item.antique_atlas.atlas.hint", Text.translatable("item.antique_atlas.atlas")).setStyle(Style.EMPTY.withColor(Formatting.GRAY).withItalic(false)))));
stack.getSubNbt(ItemStack.DISPLAY_KEY).put(ItemStack.LORE_KEY, lore);
return stack;
}

public static boolean isHandheldAtlas(ItemStack stack) {
return stack.isOf(Items.BOOK) && ATLAS_NAMES.stream().anyMatch(n -> stack.getName().getString().contains(n));
}

@Override
public void onInitializeClient() {
AntiqueAtlasKeybindings.init();
Expand All @@ -56,7 +84,8 @@ public void onInitializeClient() {
ClientPlayConnectionEvents.DISCONNECT.register(((handler, client) -> BiomeTileProviders.getInstance().clearFallbacks()));
ClientPlayConnectionEvents.DISCONNECT.register(((handler, client) -> WorldAtlasData.WORLDS.clear()));

ModelPredicateProviderRegistry.register(Items.BOOK, AntiqueAtlas.id("atlas"), ((stack, world, entity, seed) -> stack.getName().getString().contains("Antique Atlas") ? 1.0F : 0.0F));
ModelPredicateProviderRegistry.register(Items.BOOK, AntiqueAtlas.id("atlas"), ((stack, world, entity, seed) -> isHandheldAtlas(stack) ? 1.0F : 0.0F));
ItemGroupEvents.modifyEntriesEvent(ItemGroups.TOOLS).register(e -> e.addAfter(Items.MAP, getHandheldAtlas()));

WorldSummary.enableTerrain();
WorldSummary.enableStructures();
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package folk.sisby.antique_atlas.mixin;

import com.llamalad7.mixinextras.injector.ModifyExpressionValue;
import com.mojang.blaze3d.systems.RenderSystem;
import folk.sisby.antique_atlas.AntiqueAtlas;
import folk.sisby.antique_atlas.WorldAtlasData;
import folk.sisby.antique_atlas.gui.AtlasScreen;
import folk.sisby.antique_atlas.gui.tiles.TileRenderIterator;
Expand All @@ -18,14 +18,12 @@
import net.minecraft.client.util.math.MatrixStack;
import net.minecraft.client.util.math.Rect2i;
import net.minecraft.item.ItemStack;
import net.minecraft.item.Items;
import net.minecraft.util.DyeColor;
import net.minecraft.util.Hand;
import net.minecraft.util.math.ColorHelper;
import net.minecraft.util.math.MathHelper;
import net.minecraft.util.math.RotationAxis;
import org.joml.Vector2d;
import org.lwjgl.opengl.GL11;
import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.injection.At;
import org.spongepowered.asm.mixin.injection.Inject;
Expand All @@ -42,12 +40,10 @@ public class MixinHeldItemRenderer {
@Inject(method = "renderFirstPersonMap", at = @At("HEAD"), cancellable = true)
void renderFirstPersonAtlas(MatrixStack matrices, VertexConsumerProvider vertexConsumers, int light, ItemStack stack, CallbackInfo ci) {
if (MinecraftClient.getInstance().player == null || MinecraftClient.getInstance().world == null) return;
if (!stack.isOf(Items.BOOK) || !stack.getName().getString().contains("Antique Atlas")) return;
if (!(AntiqueAtlas.isHandheldAtlas(stack))) return;
// Refactor to actually abstract AtlasScreen code eventually pls

matrices.push();
RenderSystem.enableBlend();
RenderSystem.blendFunc(GL11.GL_SRC_ALPHA, GL11.GL_ONE_MINUS_SRC_ALPHA);
matrices.multiply(RotationAxis.POSITIVE_Y.rotationDegrees(180.0F));
matrices.multiply(RotationAxis.POSITIVE_Z.rotationDegrees(180.0F));

Expand Down Expand Up @@ -121,7 +117,6 @@ void renderFirstPersonAtlas(MatrixStack matrices, VertexConsumerProvider vertexC
double playerOffsetY = worldZToScreenY(MinecraftClient.getInstance().player.getPos().getZ(), bookY, mapOffsetY, mapHeight, 1) - bookY;
float playerRotation = ((float) Math.round(MinecraftClient.getInstance().player.getHeadYaw() / 360f * PLAYER_ROTATION_STEPS) / PLAYER_ROTATION_STEPS) * 360f;
DrawUtil.drawCenteredWithRotation(matrices, vertexConsumers, PLAYER, playerOffsetX, playerOffsetY, 1, PLAYER_ICON_WIDTH, PLAYER_ICON_HEIGHT, playerRotation, light, argb);
RenderSystem.setShaderColor(1, 1, 1, 1);
});

matrices.pop();
Expand All @@ -133,14 +128,12 @@ void renderFirstPersonAtlas(MatrixStack matrices, VertexConsumerProvider vertexC
}
matrices.pop();

RenderSystem.disableBlend();

matrices.pop();
ci.cancel();
}

@ModifyExpressionValue(method = "renderFirstPersonItem", at = @At(value = "INVOKE", target = "Lnet/minecraft/item/ItemStack;isOf(Lnet/minecraft/item/Item;)Z", ordinal = 0))
private boolean enableFirstPersonAtlasRendering(boolean original, AbstractClientPlayerEntity player, float tickDelta, float pitch, Hand hand, float swingProgress, ItemStack stack, float equipProgress, MatrixStack matrices, VertexConsumerProvider vertexConsumers, int light) {
return original || (stack.isOf(Items.BOOK) && stack.getName().getString().contains("Antique Atlas"));
return original || AntiqueAtlas.isHandheldAtlas(stack);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -5,15 +5,14 @@
import net.minecraft.client.render.item.ItemModels;
import net.minecraft.client.render.model.BakedModel;
import net.minecraft.item.ItemStack;
import net.minecraft.item.Items;
import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.injection.At;

@Mixin(ItemModels.class)
public class MixinItemModels {
@ModifyReturnValue(method = "getModel(Lnet/minecraft/item/ItemStack;)Lnet/minecraft/client/render/model/BakedModel;", at = @At("RETURN"))
private BakedModel useAtlasBookModel(BakedModel original, ItemStack stack) {
if (stack.isOf(Items.BOOK) && stack.getName().getString().contains("Antique Atlas") ) {
if (AntiqueAtlas.isHandheldAtlas(stack)) {
return ((ItemModels) (Object) this).getModelManager().getModel(AntiqueAtlas.ATLAS_MODEL);
}
return original;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
package folk.sisby.antique_atlas.mixin;

import com.llamalad7.mixinextras.injector.ModifyReturnValue;
import folk.sisby.antique_atlas.AntiqueAtlas;
import folk.sisby.antique_atlas.gui.AtlasScreen;
import net.minecraft.client.MinecraftClient;
import net.minecraft.entity.player.PlayerEntity;
import net.minecraft.item.ItemStack;
import net.minecraft.item.Items;
import net.minecraft.util.ActionResult;
import net.minecraft.util.Hand;
import net.minecraft.util.TypedActionResult;
Expand All @@ -18,7 +18,7 @@ public class MixinItemStack {
@ModifyReturnValue(method = "use", at = @At("RETURN"))
private TypedActionResult<ItemStack> openAtlasWithItem(TypedActionResult<ItemStack> original, World world, PlayerEntity user, Hand hand) {
ItemStack stack = user.getStackInHand(hand);
if (world.isClient() && original.getResult() == ActionResult.PASS && stack.isOf(Items.BOOK) && stack.getName().getString().contains("Antique Atlas") && MinecraftClient.getInstance().currentScreen == null) {
if (world.isClient() && original.getResult() == ActionResult.PASS && AntiqueAtlas.isHandheldAtlas(stack) && MinecraftClient.getInstance().currentScreen == null) {
AtlasScreen screen = new AtlasScreen();
screen.init();
screen.prepareToOpen();
Expand Down
24 changes: 14 additions & 10 deletions src/main/java/folk/sisby/antique_atlas/util/DrawBatcher.java
Original file line number Diff line number Diff line change
Expand Up @@ -22,18 +22,22 @@ public class DrawBatcher implements AutoCloseable {
private final float textureHeight;
private final int light;

public DrawBatcher(MatrixStack matrices, VertexConsumerProvider vertexConsumers, Identifier texture, int textureWidth, int textureHeight, int light) {
public DrawBatcher(MatrixStack matrices, Identifier texture, int textureWidth, int textureHeight, int light) {
RenderSystem.setShaderTexture(0, texture);
RenderSystem.setShader(GameRenderer::getPositionColorTexLightmapProgram);
this.matrix4f = matrices.peek().getPositionMatrix();
if (vertexConsumers == null) {
this.bufferBuilder = Tessellator.getInstance().getBuffer();
bufferBuilder.begin(VertexFormat.DrawMode.QUADS, VertexFormats.POSITION_COLOR_TEXTURE_LIGHT);
this.vertexConsumer = bufferBuilder;
} else {
this.bufferBuilder = null;
this.vertexConsumer = vertexConsumers.getBuffer(RenderLayer.getText(texture));
}
this.bufferBuilder = Tessellator.getInstance().getBuffer();
this.bufferBuilder.begin(VertexFormat.DrawMode.QUADS, VertexFormats.POSITION_COLOR_TEXTURE_LIGHT);
this.vertexConsumer = bufferBuilder;
this.textureWidth = textureWidth;
this.textureHeight = textureHeight;
this.light = light;
}

public DrawBatcher(MatrixStack matrices, VertexConsumerProvider vertexConsumers, Identifier texture, int textureWidth, int textureHeight, int light) {
this.matrix4f = matrices.peek().getPositionMatrix();
this.bufferBuilder = null;
this.vertexConsumer = vertexConsumers.getBuffer(RenderLayer.getText(texture));
this.textureWidth = textureWidth;
this.textureHeight = textureHeight;
this.light = light;
Expand All @@ -58,6 +62,6 @@ private void innerAdd(int x1, int x2, int y1, int y2, int z, float u1, float u2,

@Override
public void close() {
if (bufferBuilder != null) BufferRenderer.drawWithGlobalProgram(bufferBuilder.end());
if (bufferBuilder != null) BufferRenderer.draw(bufferBuilder.end());
}
}
5 changes: 4 additions & 1 deletion src/main/resources/assets/antique_atlas/lang/en_us.json
Original file line number Diff line number Diff line change
Expand Up @@ -40,5 +40,8 @@
"gui.antique_atlas.marker.death.euphemisms.verb.7": "Flattened",
"gui.antique_atlas.marker.death.euphemisms.verb.8": "Wrecked",
"gui.antique_atlas.marker.death.euphemisms.verb.9": "Whipped",
"gui.antique_atlas.marker.death.euphemisms.verb.10": "Done In"
"gui.antique_atlas.marker.death.euphemisms.verb.10": "Done In",
"item.antique_atlas.atlas": "Antique Atlas",
"item.antique_atlas.atlas.lore": "Displays your surroundings when held.",
"item.antique_atlas.atlas.hint": "Obtainable in survival by renaming a book \"%s\"."
}

0 comments on commit 494e2e6

Please sign in to comment.