Skip to content

Commit

Permalink
Port to 1.21.2
Browse files Browse the repository at this point in the history
  • Loading branch information
Dianliang233 committed Oct 23, 2024
1 parent b28d1a0 commit dfa7fe9
Show file tree
Hide file tree
Showing 19 changed files with 241 additions and 233 deletions.
5 changes: 4 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,10 @@
# v1.7.0+1.21.1
# v1.7.0+1.21.2

Hey Wiki now supports BoB!

## Changes

- Ported to 1.21.2. Please report any issues you may have!
- Now supports searching the AE2 guide

### APIs
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,67 +27,61 @@
import static wiki.minecraft.heywiki.wiki.WikiPage.NO_FAMILY_EXCEPTION;

public class WhatStructureCommand {
public static final SimpleCommandExceptionType NO_INTEGRATED_SERVER =
new SimpleCommandExceptionType(Text.translatable("commands.whatstructure.no_integrated_server"));
public static final SimpleCommandExceptionType NO_STRUCTURE =
new SimpleCommandExceptionType(Text.translatable("commands.whatstructure.no_structure"));
public static final SimpleCommandExceptionType NO_INTEGRATED_SERVER = new SimpleCommandExceptionType(
Text.translatable("commands.whatstructure.no_integrated_server"));
public static final SimpleCommandExceptionType NO_STRUCTURE = new SimpleCommandExceptionType(
Text.translatable("commands.whatstructure.no_structure"));
private static final MinecraftClient CLIENT = MinecraftClient.getInstance();

@SuppressWarnings("UnusedReturnValue")
public static LiteralCommandNode<ClientCommandRegistrationEvent.ClientCommandSourceStack> register(
CommandDispatcher<ClientCommandRegistrationEvent.ClientCommandSourceStack> dispatcher) {
return dispatcher.register(
literal("whatstructure")
.executes(ctx -> {
if (CLIENT.player == null || CLIENT.world == null) return -1;
return dispatcher.register(literal("whatstructure").executes(ctx -> {
if (CLIENT.player == null || CLIENT.world == null) return -1;

var block = CLIENT.player.getBlockPos();
var block = CLIENT.player.getBlockPos();

if (!CLIENT.isIntegratedServerRunning()) {
throw NO_INTEGRATED_SERVER.create();
}
if (!CLIENT.isIntegratedServerRunning()) {
throw NO_INTEGRATED_SERVER.create();
}

IntegratedServer server = CLIENT.getServer();
UUID playerUuid = CLIENT.player.getUuid();
IntegratedServer server = CLIENT.getServer();
UUID playerUuid = CLIENT.player.getUuid();

var playerManager = Objects.requireNonNull(server).getPlayerManager();
var serverPlayer = playerManager.getPlayer(playerUuid);
var serverWorld = Objects.requireNonNull(serverPlayer).getServerWorld();
var chunkPos = new ChunkPos(block);
Chunk chunk = serverWorld.getChunk(chunkPos.x, chunkPos.z,
ChunkStatus.STRUCTURE_REFERENCES,
false);
if (chunk == null) {
return -1;
}
var playerManager = Objects.requireNonNull(server).getPlayerManager();
var serverPlayer = playerManager.getPlayer(playerUuid);
var serverWorld = Objects.requireNonNull(serverPlayer).getServerWorld();
var chunkPos = new ChunkPos(block);
Chunk chunk = serverWorld.getChunk(chunkPos.x, chunkPos.z, ChunkStatus.STRUCTURE_REFERENCES, false);
if (chunk == null) {
return -1;
}

Map<Structure, LongSet> references = chunk.getStructureReferences();
for (Map.Entry<Structure, LongSet> entry : references.entrySet()) {
Structure structure = entry.getKey();
LongSet positions = entry.getValue();
var startChunkPos = new ChunkPos(positions.toLongArray()[0]);
Chunk startChunk = serverWorld.getChunk(startChunkPos.x, startChunkPos.z,
ChunkStatus.STRUCTURE_STARTS,
false);
assert startChunk != null;
StructureStart structureStart = startChunk.getStructureStart(structure);
assert structureStart != null;
BlockBox boundingBox = structureStart.getBoundingBox();
if (boundingBox.contains(block)) {
var strucutreRegistryEntry = serverWorld.getRegistryManager()
.get(RegistryKeys.STRUCTURE)
.getEntry(structure);
var target = Target.of(strucutreRegistryEntry, "structure");
if (target == null) return -1;
var page = WikiPage.fromTarget(target);
if (page == null) {
throw NO_FAMILY_EXCEPTION.create();
}
page.openInBrowserCommand(null);
return Command.SINGLE_SUCCESS;
}
}
throw NO_STRUCTURE.create();
}));
Map<Structure, LongSet> references = chunk.getStructureReferences();
for (Map.Entry<Structure, LongSet> entry : references.entrySet()) {
Structure structure = entry.getKey();
LongSet positions = entry.getValue();
var startChunkPos = new ChunkPos(positions.toLongArray()[0]);
Chunk startChunk = serverWorld.getChunk(startChunkPos.x, startChunkPos.z, ChunkStatus.STRUCTURE_STARTS,
false);
assert startChunk != null;
StructureStart structureStart = startChunk.getStructureStart(structure);
assert structureStart != null;
BlockBox boundingBox = structureStart.getBoundingBox();
if (boundingBox.contains(block)) {
var strucutreRegistryEntry = serverWorld.getRegistryManager().getOrThrow(RegistryKeys.STRUCTURE)
.getEntry(structure);
var target = Target.of(strucutreRegistryEntry, "structure");
if (target == null) return -1;
var page = WikiPage.fromTarget(target);
if (page == null) {
throw NO_FAMILY_EXCEPTION.create();
}
page.openInBrowserCommand(null);
return Command.SINGLE_SUCCESS;
}
}
throw NO_STRUCTURE.create();
}));
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
package wiki.minecraft.heywiki.extension;

public interface HandledScreenInterface {
void heywiki$setHasStatusEffect();
}
Original file line number Diff line number Diff line change
Expand Up @@ -175,7 +175,7 @@ protected synchronized void init() {
buttonLayout.add(this.createButtonLayout(), positioner -> positioner.marginBottom(20));

this.layout.forEachChild(this::addDrawableChild);
this.initTabNavigation();
this.refreshWidgetPositions();
}

private IconWidget createImageWidget() {
Expand Down Expand Up @@ -240,7 +240,7 @@ public void close() {
}

@Override
protected void initTabNavigation() {
protected void refreshWidgetPositions() {
this.layout.refreshPositions();
SimplePositioningWidget.setPos(this.layout, this.getNavigationFocus());
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,7 @@ public WikiSearchScreen() {
});

this.layout.forEachChild(this::addDrawableChild);
this.initTabNavigation();
this.refreshWidgetPositions();
this.onSearchChange(this.textField.getText());
}

Expand Down Expand Up @@ -184,7 +184,7 @@ public void searchEntry(SuggestionEntryWidget selected) {
super.close();
}

@Override protected void initTabNavigation() {
@Override protected void refreshWidgetPositions() {
this.layout.refreshPositions();
SimplePositioningWidget.setPos(this.layout, this.getNavigationFocus());
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ protected void init() {
}

@Override
protected void initTabNavigation() {
protected void refreshWidgetPositions() {
this.layout.refreshPositions();
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
import net.minecraft.client.MinecraftClient;
import net.minecraft.client.gui.DrawContext;
import net.minecraft.client.gui.widget.AlwaysSelectedEntryListWidget.Entry;
import net.minecraft.client.render.RenderLayer;
import net.minecraft.client.texture.AbstractTexture;
import net.minecraft.text.MutableText;
import net.minecraft.text.Style;
Expand Down Expand Up @@ -60,7 +61,7 @@ public void render(DrawContext DrawContext, int index, int y, int x, int rowWidt
var icon = this.getIconTexture();
if (icon != null) {
RenderSystem.enableBlend();
DrawContext.drawTexture(this.getIconTexture(), x + 22, y, 0.0F, 0.0F, iconSize, iconSize, iconSize,
DrawContext.drawTexture(RenderLayer::getGuiTextured, this.getIconTexture(), x + 22, y, 0.0F, 0.0F, iconSize, iconSize, iconSize,
iconSize);
RenderSystem.disableBlend();
}
Expand Down

This file was deleted.

Loading

0 comments on commit dfa7fe9

Please sign in to comment.