Skip to content

Commit

Permalink
Use Constants more instead of hard coding
Browse files Browse the repository at this point in the history
  • Loading branch information
rtm516 committed Apr 5, 2024
1 parent e2374d0 commit 9b3916a
Show file tree
Hide file tree
Showing 11 changed files with 18 additions and 28 deletions.
2 changes: 2 additions & 0 deletions shared/src/main/java/org/geysermc/hydraulic/Constants.java
Original file line number Diff line number Diff line change
Expand Up @@ -11,4 +11,6 @@ public class Constants {
public static final Gson GSON = new GsonBuilder()
.setPrettyPrinting()
.create();

public static final String BEDROCK_TEXTURE_LOCATION = "textures/%s.png";
}
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
* Main class of the Hydraulic mod.
*/
public class HydraulicImpl implements EventRegistrar {
private static final Logger LOGGER = LoggerFactory.getLogger("Hydraulic");
private static final Logger LOGGER = LoggerFactory.getLogger(Constants.MOD_NAME);

private static HydraulicImpl instance;

Expand Down Expand Up @@ -128,7 +128,7 @@ public static HydraulicImpl load(@NotNull HydraulicPlatform platform, @NotNull H
@NotNull
public static HydraulicImpl instance() {
if (instance == null) {
throw new IllegalStateException("Hydraulic has not been loaded!");
throw new IllegalStateException(Constants.MOD_NAME + " has not been loaded!");
}

return instance;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@
import net.minecraft.core.registries.BuiltInRegistries;
import net.minecraft.core.registries.Registries;
import net.minecraft.resources.ResourceLocation;
import net.minecraft.server.MinecraftServer;
import net.minecraft.util.StringRepresentable;
import net.minecraft.world.item.ItemStack;
import net.minecraft.world.level.block.Block;
Expand Down Expand Up @@ -36,6 +35,7 @@
import org.geysermc.geyser.api.util.CreativeCategory;
import org.geysermc.geyser.level.physics.PistonBehavior;
import org.geysermc.geyser.util.MathUtils;
import org.geysermc.hydraulic.Constants;
import org.geysermc.hydraulic.HydraulicImpl;
import org.geysermc.hydraulic.item.CreativeMappings;
import org.geysermc.hydraulic.pack.ConvertablePackModule;
Expand All @@ -46,7 +46,6 @@
import org.geysermc.hydraulic.pack.context.PackPostProcessContext;
import org.geysermc.hydraulic.pack.context.PackPreProcessContext;
import org.geysermc.hydraulic.storage.ModStorage;
import org.geysermc.hydraulic.util.Constants;
import org.geysermc.hydraulic.util.PackUtil;
import org.geysermc.hydraulic.util.SingletonBlockGetter;
import org.geysermc.pack.bedrock.resource.BedrockResourcePack;
Expand Down Expand Up @@ -237,7 +236,7 @@ private void onDefineCustomBlocks(PackEventContext<GeyserDefineCustomBlocksEvent

if (emptyModels.contains(key.toString())) {
context.logger().warn("Missing block model for block {}", blockLocation);
geoName = "geometry.hydraulic.empty";
geoName = "geometry." + Constants.MOD_ID + ".empty";
}

componentsBuilder.geometry(GeometryComponent.builder()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@
import net.minecraft.core.registries.BuiltInRegistries;
import net.minecraft.core.registries.Registries;
import net.minecraft.resources.ResourceLocation;
import net.minecraft.tags.ItemTags;
import net.minecraft.world.item.ArmorItem;
import net.minecraft.world.item.AxeItem;
import net.minecraft.world.item.BlockItem;
Expand All @@ -29,7 +28,6 @@
import org.geysermc.hydraulic.pack.context.PackEventContext;
import org.geysermc.hydraulic.pack.context.PackPostProcessContext;
import org.geysermc.hydraulic.pack.context.PackPreProcessContext;
import org.geysermc.hydraulic.util.ItemGroup;
import org.geysermc.hydraulic.util.PackUtil;
import org.geysermc.pack.bedrock.resource.BedrockResourcePack;
import org.geysermc.pack.converter.converter.model.ModelStitcher;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,16 +1,12 @@
package org.geysermc.hydraulic.mixin.ext;

import com.github.steveice10.mc.protocol.data.game.entity.player.GameMode;
import com.llamalad7.mixinextras.sugar.Share;
import com.llamalad7.mixinextras.sugar.ref.LocalBooleanRef;
import org.geysermc.geyser.registry.type.ItemMapping;
import org.geysermc.geyser.registry.type.ItemMappings;
import org.geysermc.geyser.session.GeyserSession;
import org.geysermc.geyser.util.InventoryUtils;
import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.injection.At;
import org.spongepowered.asm.mixin.injection.Inject;
import org.spongepowered.asm.mixin.injection.Redirect;
import org.spongepowered.asm.mixin.injection.callback.CallbackInfo;

@Mixin(value = InventoryUtils.class, remap = false)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
import org.geysermc.event.subscribe.Subscribe;
import org.geysermc.geyser.api.GeyserApi;
import org.geysermc.geyser.api.event.lifecycle.GeyserLoadResourcePacksEvent;
import org.geysermc.hydraulic.Constants;
import org.geysermc.hydraulic.HydraulicImpl;
import org.geysermc.hydraulic.platform.mod.ModInfo;
import org.geysermc.hydraulic.util.FormatUtil;
Expand Down Expand Up @@ -49,7 +50,7 @@ public class PackListener {
public Thread newThread(final @NotNull Runnable run) {
Thread ret = new Thread(run);

ret.setName("Hydraulic Conversion Thread #" + this.threadCounter.getAndIncrement());
ret.setName(Constants.MOD_NAME + " Conversion Thread #" + this.threadCounter.getAndIncrement());
ret.setUncaughtExceptionHandler((thread, throwable) -> LOGGER.error("Uncaught exception in thread " + thread.getName(), throwable));

return ret;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,8 @@

import net.kyori.adventure.key.Key;
import org.apache.commons.lang3.StringUtils;
import org.geysermc.hydraulic.Constants;
import org.geysermc.hydraulic.pack.context.PackContext;
import org.geysermc.hydraulic.pack.context.PackPostProcessContext;
import org.geysermc.hydraulic.util.Constants;
import org.geysermc.pack.converter.data.TextureConversionData;
import org.jetbrains.annotations.NotNull;

Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package org.geysermc.hydraulic.pack.modules;

import com.google.auto.service.AutoService;
import org.geysermc.hydraulic.Constants;
import org.geysermc.hydraulic.pack.PackModule;
import org.geysermc.hydraulic.pack.context.PackPostProcessContext;
import org.geysermc.hydraulic.util.GeoUtil;
Expand All @@ -15,21 +16,21 @@ public HydraulicPackModule() {
this.postProcess(context -> {
// Map all block textures files as valid names
for (Map.Entry<String, String> entry : TextureMappings.textureMappings().textures("block").entrySet()) {
context.bedrockResourcePack().addBlockTexture("hydraulic:" + entry.getValue(), "textures/blocks/" + entry.getValue());
context.bedrockResourcePack().addBlockTexture(Constants.MOD_ID + ":" + entry.getValue(), "textures/blocks/" + entry.getValue());
}

// Map all item textures files as valid names
for (Map.Entry<String, String> entry : TextureMappings.textureMappings().textures("item").entrySet()) {
context.bedrockResourcePack().addItemTexture("hydraulic:" + entry.getValue(), "textures/items/" + entry.getValue());
context.bedrockResourcePack().addItemTexture(Constants.MOD_ID + ":" + entry.getValue(), "textures/items/" + entry.getValue());
}

// Add the empty geometry
context.bedrockResourcePack().addBlockModel(GeoUtil.empty("geometry.hydraulic.empty"), "empty.json");
context.bedrockResourcePack().addBlockModel(GeoUtil.empty("geometry." + Constants.MOD_ID + ".empty"), "empty.json");
});
}

@Override
public boolean test(@NotNull PackPostProcessContext<HydraulicPackModule> context) {
return context.mod().id().equals("hydraulic");
return context.mod().id().equals(Constants.MOD_ID);
}
}
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package org.geysermc.hydraulic.pack.modules;

import com.google.auto.service.AutoService;
import org.geysermc.hydraulic.Constants;
import org.geysermc.hydraulic.pack.PackModule;
import org.geysermc.hydraulic.pack.context.PackPostProcessContext;
import org.geysermc.hydraulic.util.PackUtil;
Expand All @@ -18,7 +19,7 @@ public MetadataPackModule() {
this.postProcess(context -> {
// Set the pack name and description
context.bedrockResourcePack().manifest().header().name(context.mod().name().trim() + " Resource Pack");
context.bedrockResourcePack().manifest().header().description(context.mod().name().trim() + " " + context.mod().version() + " - Generated by Hydraulic");
context.bedrockResourcePack().manifest().header().description(context.mod().name().trim() + " " + context.mod().version() + " - Generated by " + Constants.MOD_NAME);

// Generate the pack uuid from the mod file
String packUuid = PackUtil.getModUUID(context.mod().roots()).toString();
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
import com.google.common.hash.HashingOutputStream;
import com.mojang.logging.LogUtils;
import net.kyori.adventure.key.Key;
import org.geysermc.hydraulic.Constants;
import org.geysermc.pack.converter.converter.texture.TextureMappings;
import org.jetbrains.annotations.NotNull;
import org.slf4j.Logger;
Expand Down Expand Up @@ -41,7 +42,7 @@ public static String getTextureName(@NotNull String modelName) {
if (textureName.isEmpty()) {
textureName = value;
} else {
textureName = "hydraulic:" + textureName;
textureName = Constants.MOD_ID + ":" + textureName;
}
return textureName;
}
Expand Down

0 comments on commit 9b3916a

Please sign in to comment.