Skip to content

Commit

Permalink
Update to Fabric 1.20.5
Browse files Browse the repository at this point in the history
  • Loading branch information
MattCzyr committed May 2, 2024
1 parent c9025a7 commit 1b155d0
Show file tree
Hide file tree
Showing 17 changed files with 240 additions and 180 deletions.
27 changes: 18 additions & 9 deletions build.gradle
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
plugins {
id 'fabric-loom' version '1.4-SNAPSHOT'
id 'fabric-loom' version '1.6-SNAPSHOT'
id 'maven-publish'
}

Expand All @@ -18,6 +18,18 @@ repositories {
// for more information about repositories.
}

loom {
splitEnvironmentSourceSets()

mods {
"modid" {
sourceSet sourceSets.main
sourceSet sourceSets.client
}
}

}

dependencies {
// To change the versions see the gradle.properties file
minecraft "com.mojang:minecraft:${project.minecraft_version}"
Expand All @@ -27,10 +39,6 @@ dependencies {
// Fabric API. This is technically optional, but you probably want it anyway.
modImplementation "net.fabricmc.fabric-api:fabric-api:${project.fabric_version}"

// Uncomment the following line to enable the deprecated Fabric API modules.
// These are included in the Fabric API production distribution and allow you to update your mod to the latest modules at a later more convenient time.

// modImplementation "net.fabricmc.fabric-api:fabric-api-deprecated:${project.fabric_version}"
}

processResources {
Expand All @@ -42,7 +50,7 @@ processResources {
}

tasks.withType(JavaCompile).configureEach {
it.options.release = 17
it.options.release = 21
}

java {
Expand All @@ -51,8 +59,8 @@ java {
// If you remove this line, sources will not be generated.
withSourcesJar()

sourceCompatibility = JavaVersion.VERSION_17
targetCompatibility = JavaVersion.VERSION_17
sourceCompatibility = JavaVersion.VERSION_21
targetCompatibility = JavaVersion.VERSION_21
}

jar {
Expand All @@ -64,7 +72,8 @@ jar {
// configure the maven publication
publishing {
publications {
mavenJava(MavenPublication) {
create("mavenJava", MavenPublication) {
artifactId = project.archives_base_name
from components.java
}
}
Expand Down
10 changes: 5 additions & 5 deletions gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,14 @@ org.gradle.parallel=true

# Fabric Properties
# check these on https://fabricmc.net/develop
minecraft_version=1.20.4
yarn_mappings=1.20.4+build.1
loader_version=0.15.0
minecraft_version=1.20.5
yarn_mappings=1.20.5+build.1
loader_version=0.15.10

# Mod Properties
mod_version=1.20.4-2.2.3-fabric
mod_version=1.20.5-2.2.4-fabric
maven_group=com.chaosthedude.naturescompass
archives_base_name=naturescompass

# Dependencies
fabric_version=0.91.1+1.20.4
fabric_version=0.97.5+1.20.5
Binary file modified gradle/wrapper/gradle-wrapper.jar
Binary file not shown.
2 changes: 1 addition & 1 deletion gradle/wrapper/gradle-wrapper.properties
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-8.5-bin.zip
distributionUrl=https\://services.gradle.org/distributions/gradle-8.7-bin.zip
networkTimeout=10000
validateDistributionUrl=true
zipStoreBase=GRADLE_USER_HOME
Expand Down
20 changes: 10 additions & 10 deletions gradlew.bat
Original file line number Diff line number Diff line change
Expand Up @@ -43,11 +43,11 @@ set JAVA_EXE=java.exe
%JAVA_EXE% -version >NUL 2>&1
if %ERRORLEVEL% equ 0 goto execute

echo.
echo ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH.
echo.
echo Please set the JAVA_HOME variable in your environment to match the
echo location of your Java installation.
echo. 1>&2
echo ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. 1>&2
echo. 1>&2
echo Please set the JAVA_HOME variable in your environment to match the 1>&2
echo location of your Java installation. 1>&2

goto fail

Expand All @@ -57,11 +57,11 @@ set JAVA_EXE=%JAVA_HOME%/bin/java.exe

if exist "%JAVA_EXE%" goto execute

echo.
echo ERROR: JAVA_HOME is set to an invalid directory: %JAVA_HOME%
echo.
echo Please set the JAVA_HOME variable in your environment to match the
echo location of your Java installation.
echo. 1>&2
echo ERROR: JAVA_HOME is set to an invalid directory: %JAVA_HOME% 1>&2
echo. 1>&2
echo Please set the JAVA_HOME variable in your environment to match the 1>&2
echo location of your Java installation. 1>&2

goto fail

Expand Down
31 changes: 28 additions & 3 deletions src/main/java/com/chaosthedude/naturescompass/NaturesCompass.java
Original file line number Diff line number Diff line change
Expand Up @@ -9,14 +9,19 @@
import com.chaosthedude.naturescompass.config.NaturesCompassConfig;
import com.chaosthedude.naturescompass.items.NaturesCompassItem;
import com.chaosthedude.naturescompass.network.SearchPacket;
import com.chaosthedude.naturescompass.network.SyncPacket;
import com.chaosthedude.naturescompass.network.TeleportPacket;
import com.google.common.collect.ArrayListMultimap;
import com.google.common.collect.ListMultimap;
import com.mojang.serialization.Codec;

import net.fabricmc.api.ModInitializer;
import net.fabricmc.fabric.api.itemgroup.v1.ItemGroupEvents;
import net.fabricmc.fabric.api.networking.v1.PayloadTypeRegistry;
import net.fabricmc.fabric.api.networking.v1.ServerPlayNetworking;
import net.minecraft.component.DataComponentType;
import net.minecraft.item.ItemGroups;
import net.minecraft.network.codec.PacketCodecs;
import net.minecraft.registry.Registries;
import net.minecraft.registry.Registry;
import net.minecraft.util.Identifier;
Expand All @@ -29,6 +34,14 @@ public class NaturesCompass implements ModInitializer {

public static final NaturesCompassItem NATURES_COMPASS_ITEM = new NaturesCompassItem();

public static final DataComponentType<String> BIOME_ID_COMPONENT = DataComponentType.<String>builder().codec(Codec.STRING).packetCodec(PacketCodecs.STRING).build();
public static final DataComponentType<Integer> COMPASS_STATE_COMPONENT = DataComponentType.<Integer>builder().codec(Codec.INT).packetCodec(PacketCodecs.INTEGER).build();
public static final DataComponentType<Integer> FOUND_X_COMPONENT = DataComponentType.<Integer>builder().codec(Codec.INT).packetCodec(PacketCodecs.INTEGER).build();
public static final DataComponentType<Integer> FOUND_Z_COMPONENT = DataComponentType.<Integer>builder().codec(Codec.INT).packetCodec(PacketCodecs.INTEGER).build();
public static final DataComponentType<Integer> SEARCH_RADIUS_COMPONENT = DataComponentType.<Integer>builder().codec(Codec.INT).packetCodec(PacketCodecs.INTEGER).build();
public static final DataComponentType<Integer> SAMPLES_COMPONENT = DataComponentType.<Integer>builder().codec(Codec.INT).packetCodec(PacketCodecs.INTEGER).build();
public static final DataComponentType<Boolean> DISPLAY_COORDS_COMPONENT = DataComponentType.<Boolean>builder().codec(Codec.BOOL).packetCodec(PacketCodecs.BOOL).build();

public static boolean canTeleport;
public static List<Identifier> allowedBiomes;
public static ListMultimap<Identifier, Identifier> dimensionIDsForAllowedBiomeIDs;
Expand All @@ -38,11 +51,23 @@ public void onInitialize() {
NaturesCompassConfig.load();

Registry.register(Registries.ITEM, new Identifier(MODID, "naturescompass"), NATURES_COMPASS_ITEM);

Registry.register(Registries.DATA_COMPONENT_TYPE, new Identifier(MODID, "biome_id"), BIOME_ID_COMPONENT);
Registry.register(Registries.DATA_COMPONENT_TYPE, new Identifier(MODID, "compass_state"), COMPASS_STATE_COMPONENT);
Registry.register(Registries.DATA_COMPONENT_TYPE, new Identifier(MODID, "found_x"), FOUND_X_COMPONENT);
Registry.register(Registries.DATA_COMPONENT_TYPE, new Identifier(MODID, "found_z"), FOUND_Z_COMPONENT);
Registry.register(Registries.DATA_COMPONENT_TYPE, new Identifier(MODID, "search_radius"), SEARCH_RADIUS_COMPONENT);
Registry.register(Registries.DATA_COMPONENT_TYPE, new Identifier(MODID, "samples"), SAMPLES_COMPONENT);
Registry.register(Registries.DATA_COMPONENT_TYPE, new Identifier(MODID, "display_coords"), DISPLAY_COORDS_COMPONENT);

ItemGroupEvents.modifyEntriesEvent(ItemGroups.TOOLS).register(entries -> entries.add(NATURES_COMPASS_ITEM));

ServerPlayNetworking.registerGlobalReceiver(SearchPacket.ID, SearchPacket::apply);
ServerPlayNetworking.registerGlobalReceiver(TeleportPacket.ID, TeleportPacket::apply);

PayloadTypeRegistry.playC2S().register(SearchPacket.PACKET_ID, SearchPacket.PACKET_CODEC);
PayloadTypeRegistry.playC2S().register(TeleportPacket.PACKET_ID, TeleportPacket.PACKET_CODEC);
PayloadTypeRegistry.playS2C().register(SyncPacket.PACKET_ID, SyncPacket.PACKET_CODEC);

ServerPlayNetworking.registerGlobalReceiver(SearchPacket.PACKET_ID, SearchPacket::apply);
ServerPlayNetworking.registerGlobalReceiver(TeleportPacket.PACKET_ID, TeleportPacket::apply);

allowedBiomes = new ArrayList<Identifier>();
dimensionIDsForAllowedBiomeIDs = ArrayListMultimap.create();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ public class NaturesCompassClient implements ClientModInitializer {

@Override
public void onInitializeClient() {
ClientPlayNetworking.registerGlobalReceiver(SyncPacket.ID, SyncPacket::apply);
ClientPlayNetworking.registerGlobalReceiver(SyncPacket.PACKET_ID, SyncPacket::apply);

ModelPredicateProviderRegistry.register(NaturesCompass.NATURES_COMPASS_ITEM, new Identifier("angle"), new ClampedModelPredicateProvider() {
private double rotation;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,8 @@ public void init() {

@Override
public void render(DrawContext context, int mouseX, int mouseY, float partialTicks) {
super.render(context, mouseX, mouseY, partialTicks);

context.drawText(textRenderer, BiomeUtils.getBiomeNameForDisplay(parentScreen.world, biome), (width / 2) - (textRenderer.getWidth(BiomeUtils.getBiomeNameForDisplay(parentScreen.world, biome)) / 2), 20, 0xffffff, false);

context.drawText(textRenderer, Text.translatable("string.naturescompass.source"), width / 2 - 100, 40, 0xffffff, false);
Expand All @@ -90,8 +92,6 @@ public void render(DrawContext context, int mouseX, int mouseY, float partialTic

//context.drawText(textRenderer, Text.translatable("string.naturescompass.highHumidity"), width / 2 + 40, 100, 0xffffff, false);
//context.drawText(textRenderer, highHumidity, width / 2 + 40, 110, 0x808080, false);

super.render(context, mouseX, mouseY, partialTicks);
}

private void setupButtons() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,16 +21,16 @@ public BiomeSearchList(NaturesCompassScreen guiNaturesCompass, MinecraftClient m
this.guiNaturesCompass = guiNaturesCompass;
refreshList();
}

@Override
protected int getScrollbarPositionX() {
return super.getScrollbarPositionX() + 20;
}


@Override
public int getRowWidth() {
return super.getRowWidth() + 50;
}

@Override
protected int getDefaultScrollbarX() {
return getRowLeft() + getRowWidth() - 2;
}

@Override
protected boolean isSelectedEntry(int slotIndex) {
Expand All @@ -44,15 +44,18 @@ public void renderWidget(DrawContext context, int mouseX, int mouseY, float par3

@Override
protected void renderList(DrawContext context, int mouseX, int mouseY, float par5) {
context.fill(getRowLeft() - 4, getY(), getRowLeft() + getRowWidth() + 4, getY() + getHeight() + 4, 255 / 2 << 24);

enableScissor(context);
int i = getEntryCount();
for (int j = 0; j < i; ++j) {
int k = getRowTop(j);
int l = getRowBottom(j);
if (l >= getY() && k <= getBottom()) {
int j1 = this.itemHeight - 4;
int j1 = itemHeight - 4;
BiomeSearchEntry e = getEntry(j);
int k1 = getRowWidth();
if (/*renderSelection*/ true && isSelectedEntry(j)) {
if (isSelectedEntry(j)) {
final int insideLeft = getX() + width / 2 - getRowWidth() / 2 + 2;
context.fill(insideLeft - 4, k - 4, insideLeft + getRowWidth() + 4, k + itemHeight, 255 / 2 << 24);
}
Expand All @@ -61,9 +64,10 @@ protected void renderList(DrawContext context, int mouseX, int mouseY, float par
e.render(context, j, k, j2, k1, j1, mouseX, mouseY, isMouseOver((double) mouseX, (double) mouseY) && Objects .equals(getEntryAtPosition((double) mouseX, (double) mouseY), e), par5);
}
}
context.disableScissor();

if (getMaxScroll() > 0) {
int left = getScrollbarPositionX();
int left = getScrollbarX();
int right = left + 6;
int height = (int) ((float) ((getBottom() - getY()) * (getBottom() - getY())) / (float) getMaxPosition());
height = MathHelper.clamp(height, 32, getBottom() - getY() - 8);
Expand All @@ -76,7 +80,13 @@ protected void renderList(DrawContext context, int mouseX, int mouseY, float par
context.fill(left, scrollbarTop, right, scrollbarTop + height, (int) (1.9F * 255.0F) / 2 << 24);
}
}

@Override
protected void enableScissor(DrawContext context) {
context.enableScissor(getX(), getY(), getRight(), getBottom());
}

@Override
protected int getRowBottom(int index) {
return getRowTop(index) + itemHeight;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,10 +20,12 @@
import net.minecraft.client.gui.DrawContext;
import net.minecraft.client.gui.screen.Screen;
import net.minecraft.client.gui.widget.ButtonWidget;
import net.minecraft.client.gui.widget.TextFieldWidget;
import net.minecraft.client.resource.language.I18n;
import net.minecraft.entity.player.PlayerEntity;
import net.minecraft.item.ItemStack;
import net.minecraft.text.Text;
import net.minecraft.util.Colors;
import net.minecraft.util.Identifier;
import net.minecraft.world.World;
import net.minecraft.world.biome.Biome;
Expand All @@ -41,7 +43,7 @@ public class NaturesCompassScreen extends Screen {
private ButtonWidget teleportButton;
private ButtonWidget cancelButton;
private ButtonWidget sortByButton;
private TransparentTextField searchTextField;
private TextFieldWidget searchTextField;
private BiomeSearchList selectionList;
private ISorting sortingCategory;

Expand Down Expand Up @@ -91,8 +93,8 @@ public void tick() {

@Override
public void render(DrawContext context, int mouseX, int mouseY, float partialTicks) {
context.drawCenteredTextWithShadow(textRenderer, I18n.translate("string.naturescompass.selectBiome"), 65, 15, 0xffffff);
super.render(context, mouseX, mouseY, partialTicks);
context.drawCenteredTextWithShadow(textRenderer, I18n.translate("string.naturescompass.selectBiome"), 65, 15, Colors.WHITE);
}

@Override
Expand Down Expand Up @@ -121,12 +123,12 @@ public void selectBiome(BiomeSearchEntry entry) {
}

public void searchForBiome(Biome biome) {
ClientPlayNetworking.send(SearchPacket.ID, new SearchPacket(BiomeUtils.getIdentifierForBiome(world, biome), player.getBlockPos()));
ClientPlayNetworking.send(new SearchPacket(BiomeUtils.getIdentifierForBiome(world, biome), player.getBlockPos()));
client.setScreen(null);
}

public void teleport() {
ClientPlayNetworking.send(TeleportPacket.ID, new TeleportPacket());
ClientPlayNetworking.send(new TeleportPacket());
client.setScreen(null);
}

Expand Down Expand Up @@ -185,8 +187,7 @@ private void setupButtons() {
}

private void setupTextFields() {
searchTextField = new TransparentTextField(textRenderer, 130, 10, 140, 20, Text.translatable("string.naturescompass.search"));
addDrawableChild(searchTextField);
searchTextField = addDrawableChild(new TransparentTextField(textRenderer, 130, 10, 140, 20, Text.translatable("string.naturescompass.search")));
}

private void loadAllowedBiomes(List<Identifier> allowedBiomeIDs) {
Expand Down
Loading

0 comments on commit 1b155d0

Please sign in to comment.