Skip to content

Commit

Permalink
Resolve Registry Tech Debt + Pattern Fixes (#182)
Browse files Browse the repository at this point in the history
Co-authored-by: Craig <[email protected]>
  • Loading branch information
50ap5ud5 and Jeryn99 authored Dec 12, 2023
1 parent 11a6e2b commit 9e67bf7
Show file tree
Hide file tree
Showing 186 changed files with 4,165 additions and 1,625 deletions.
31 changes: 16 additions & 15 deletions common/src/main/java/whocraft/tardis_refined/TRConfig.java
Original file line number Diff line number Diff line change
@@ -1,44 +1,45 @@
package whocraft.tardis_refined;

import com.google.common.collect.Lists;
import net.neoforged.common.ForgeConfigSpec;


import net.neoforged.neoforge.common.ModConfigSpec;
import org.apache.commons.lang3.tuple.Pair;
import whocraft.tardis_refined.constants.ModMessages;

import java.util.List;

public class TRConfig {


public static Common COMMON;
public static ForgeConfigSpec COMMON_SPEC;
public static ModConfigSpec COMMON_SPEC;
public static Server SERVER;
public static ForgeConfigSpec SERVER_SPEC;
public static ModConfigSpec SERVER_SPEC;
public static Client CLIENT;
public static ForgeConfigSpec CLIENT_SPEC;
public static ModConfigSpec CLIENT_SPEC;

static {
Pair<Common, ForgeConfigSpec> specPair = new ForgeConfigSpec.Builder().configure(Common::new);
Pair<Common, ModConfigSpec> specPair = new ModConfigSpec.Builder().configure(Common::new);
COMMON_SPEC = specPair.getRight();
COMMON = specPair.getLeft();

Pair<Server, ForgeConfigSpec> specServerPair = new ForgeConfigSpec.Builder().configure(Server::new);
Pair<Server, ModConfigSpec> specServerPair = new ModConfigSpec.Builder().configure(Server::new);
SERVER_SPEC = specServerPair.getRight();
SERVER = specServerPair.getLeft();


Pair<Client, ForgeConfigSpec> specClientPair = new ForgeConfigSpec.Builder().configure(Client::new);
Pair<Client, ModConfigSpec> specClientPair = new ModConfigSpec.Builder().configure(Client::new);
CLIENT_SPEC = specClientPair.getRight();
CLIENT = specClientPair.getLeft();
}



public static class Client {
public final ForgeConfigSpec.BooleanValue CONTROL_NAMES;
public final ForgeConfigSpec.BooleanValue PLAY_CONSOLE_IDLE_ANIMATIONS;
public final ModConfigSpec.BooleanValue CONTROL_NAMES;
public final ModConfigSpec.BooleanValue PLAY_CONSOLE_IDLE_ANIMATIONS;

public Client(ForgeConfigSpec.Builder builder) {
public Client(ModConfigSpec.Builder builder) {
builder.push("rendering");
CONTROL_NAMES = builder.comment("Toggle control name rendering").translation(ModMessages.CONFIG_CONTROL_NAMES).define("control_name_rendering", true);
PLAY_CONSOLE_IDLE_ANIMATIONS = builder.comment("Play idle console animations").translation(ModMessages.CONFIG_IDLE_CONSOLE_ANIMS).define("console_idle_animations", true);
Expand All @@ -48,9 +49,9 @@ public Client(ForgeConfigSpec.Builder builder) {
}

public static class Common {
public final ForgeConfigSpec.BooleanValue COMPATIBILITY_IP;
public final ModConfigSpec.BooleanValue COMPATIBILITY_IP;

public Common(ForgeConfigSpec.Builder builder) {
public Common(ModConfigSpec.Builder builder) {
builder.push("compatibility");
COMPATIBILITY_IP = builder.comment("Toggle Immersive Portals compatibility").translation(ModMessages.CONFIG_IP_COMPAT).define("immersive_portals", true);
builder.pop();
Expand All @@ -59,9 +60,9 @@ public Common(ForgeConfigSpec.Builder builder) {
}

public static class Server {
public final ForgeConfigSpec.ConfigValue<List<? extends String>> BANNED_DIMENSIONS;
public final ModConfigSpec.ConfigValue<List<? extends String>> BANNED_DIMENSIONS;

public Server(ForgeConfigSpec.Builder builder) {
public Server(ModConfigSpec.Builder builder) {
builder.push("travel");
BANNED_DIMENSIONS = builder.translation("config.tardis_refined.banned_dimensions").comment("A list of Dimensions the TARDIS cannot land in.").defineList("banned_dimensions", Lists.newArrayList("example:dimension"), String.class::isInstance);
builder.pop();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@
import whocraft.tardis_refined.common.network.messages.SyncDesktopsMessage;
import whocraft.tardis_refined.common.network.messages.SyncShellPatternsMessage;
import whocraft.tardis_refined.common.tardis.TardisDesktops;
import whocraft.tardis_refined.common.tardis.themes.ConsoleTheme;
import whocraft.tardis_refined.common.tardis.themes.ShellTheme;
import whocraft.tardis_refined.common.world.ChunkGenerators;
import whocraft.tardis_refined.common.world.Features;
import whocraft.tardis_refined.patterns.ConsolePatterns;
Expand Down Expand Up @@ -48,6 +50,8 @@ public static void init() {
Features.FEATURES.register();
TRParticles.TYPES.register();
Upgrades.UPGRADE_DEFERRED_REGISTRY.register();
ConsoleTheme.CONSOLE_THEMES.register();
ShellTheme.SHELL_THEMES.register();
TagKeys.init();
TardisNetwork.init();
TardisDesktops.getReloadListener().setSyncPacket(TardisNetwork.NETWORK, SyncDesktopsMessage::new);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import net.minecraft.core.BlockPos;
import net.minecraft.core.Direction;
import net.minecraft.resources.ResourceLocation;
import net.minecraft.world.entity.player.Player;
import net.minecraft.world.level.Level;
import net.minecraft.world.level.LevelAccessor;
Expand Down Expand Up @@ -38,9 +39,9 @@ public class TardisEvents {
}
});

public static final Event<ShellChange> SHELL_CHANGE_EVENT = new Event<>(ShellChange.class, listeners -> (tardisLevelOperator, theme) -> {
public static final Event<ShellChange> SHELL_CHANGE_EVENT = new Event<>(ShellChange.class, listeners -> (tardisLevelOperator, theme, isSetupTardis) -> {
for (ShellChange listener : listeners) {
listener.onShellChange(tardisLevelOperator, theme);
listener.onShellChange(tardisLevelOperator, theme, isSetupTardis);
}
});

Expand Down Expand Up @@ -117,8 +118,9 @@ public interface ShellChange {
*
* @param tardisLevelOperator The operator of the TARDIS level.
* @param theme The theme the TARDIS changed to.
* @param isSetupTardis if the Shell Change event was caused by a Tardis being setup from a Root Shell to a fully functioning version
*/
void onShellChange(TardisLevelOperator tardisLevelOperator, ShellTheme theme);
void onShellChange(TardisLevelOperator tardisLevelOperator, ResourceLocation theme, boolean isSetupTardis);
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,14 +42,14 @@ public ResourceKey<Level> getLevelKey() {
private boolean isCrashing = false;
private boolean isOnCooldown = false;
private float flightShakeScale = 0;
private ShellTheme shellTheme = ShellTheme.FACTORY;
private ShellPattern shellPattern = safeGrabPattern();
private ResourceLocation shellTheme = ShellTheme.FACTORY.getId();
private ShellPattern shellPattern = ShellPatterns.DEFAULT;

private ShellPattern safeGrabPattern() {
if (ShellPatterns.getRegistry().isEmpty())
return ShellPatterns.getPatternsForThemeDefault(shellTheme).get(0);
return ShellPatterns.getPatternsForTheme(shellTheme).get(0);
}
// private ShellPattern safeGrabPattern() {
// if (ShellPatterns.getRegistry().isEmpty())
// return ShellPatterns.getPatternsForThemeDefault(shellTheme).get(0);
// return ShellPatterns.getPatternsForTheme(shellTheme).get(0);
// }

public TardisClientData setShellPattern(ShellPattern shellPattern) {
this.shellPattern = shellPattern;
Expand Down Expand Up @@ -96,8 +96,8 @@ public boolean isThrottleDown() {
public void setFlightShakeScale(float scale) {this.flightShakeScale = scale;}
public float flightShakeScale() {return flightShakeScale;}

public void setShellTheme(ShellTheme theme) {this.shellTheme = theme;}
public ShellTheme getShellTheme() {return shellTheme;}
public void setShellTheme(ResourceLocation theme) {this.shellTheme = theme;}
public ResourceLocation getShellTheme() {return this.shellTheme;}

/**
* Serializes the Tardis instance to a CompoundTag.
Expand All @@ -111,13 +111,15 @@ public CompoundTag serializeNBT() {
compoundTag.putBoolean("throttleDown", throttleDown);
compoundTag.putBoolean("isLanding", isLanding);
compoundTag.putBoolean("isTakingOff", isTakingOff);
compoundTag.putString("shellTheme", String.valueOf(shellTheme));
if (shellTheme != null)
compoundTag.putString("shellTheme", shellTheme.toString());
compoundTag.putBoolean("isInDangerZone", this.isInDangerZone);
compoundTag.putFloat("flightShakeScale", this.flightShakeScale);
compoundTag.putBoolean("isOnCooldown", this.isOnCooldown);

if (this.shellPattern != null) {
compoundTag.putString(NbtConstants.TARDIS_EXT_CURRENT_PATTERN, shellPattern.id().toString());
if (this.shellTheme != null) {
if ( this.shellPattern != null)
compoundTag.putString(NbtConstants.TARDIS_EXT_CURRENT_PATTERN, shellPattern.id().toString());
}

return compoundTag;
Expand All @@ -126,20 +128,21 @@ public CompoundTag serializeNBT() {
/**
* Deserializes the Tardis instance from a CompoundTag.
*
* @param arg A CompoundTag containing the serialized Tardis data.
* @param compoundTag A CompoundTag containing the serialized Tardis data.
*/
public void deserializeNBT(CompoundTag arg) {
flying = arg.getBoolean("flying");
throttleDown = arg.getBoolean("throttleDown");
isLanding = arg.getBoolean("isLanding");
isTakingOff = arg.getBoolean("isTakingOff");
shellTheme = ShellTheme.findOr(arg.getString("shellTheme"), ShellTheme.FACTORY);
isInDangerZone = arg.getBoolean("isInDangerZone");
flightShakeScale = arg.getFloat("flightShakeScale");
isOnCooldown = arg.getBoolean("isOnCooldown");

if (arg.getString(NbtConstants.TARDIS_EXT_CURRENT_PATTERN) != null) {
this.shellPattern = ShellPatterns.getPatternOrDefault(shellTheme, new ResourceLocation(arg.getString(NbtConstants.TARDIS_EXT_CURRENT_PATTERN)));
public void deserializeNBT(CompoundTag compoundTag) {
flying = compoundTag.getBoolean("flying");
throttleDown = compoundTag.getBoolean("throttleDown");
isLanding = compoundTag.getBoolean("isLanding");
isTakingOff = compoundTag.getBoolean("isTakingOff");
if (compoundTag.contains("shellTheme"))
shellTheme = new ResourceLocation(compoundTag.getString("shellTheme"));
isInDangerZone = compoundTag.getBoolean("isInDangerZone");
flightShakeScale = compoundTag.getFloat("flightShakeScale");
isOnCooldown = compoundTag.getBoolean("isOnCooldown");

if (compoundTag.getString(NbtConstants.TARDIS_EXT_CURRENT_PATTERN) != null) {
this.shellPattern = ShellPatterns.getPatternOrDefault(shellTheme, new ResourceLocation(compoundTag.getString(NbtConstants.TARDIS_EXT_CURRENT_PATTERN)));
}

}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,15 @@
package whocraft.tardis_refined.client.model.blockentity.console;

import net.minecraft.client.Minecraft;
import net.minecraft.client.model.geom.EntityModelSet;
import net.minecraft.resources.ResourceLocation;
import whocraft.tardis_refined.client.ModelRegistry;
import whocraft.tardis_refined.client.model.blockentity.shell.*;
import whocraft.tardis_refined.common.tardis.themes.ConsoleTheme;
import whocraft.tardis_refined.common.tardis.themes.ShellTheme;

import java.util.HashMap;
import java.util.Map;

/***
* A collection of models for rendering the console unit.
Expand All @@ -11,47 +18,45 @@ public class ConsoleModelCollection {

ConsoleUnit toyotaConsoleModel, coralConsoleModel, copperConsoleModel, nukaConsoleModel, factoryConsoleModel, crystalConsoleModel, victorianConsoleModel, mystConsoleModel, initiativeConsoleModel;

public static Map<ResourceLocation, ConsoleUnit> CONSOLE_MODELS = new HashMap<>();

public ConsoleModelCollection() {
factoryConsoleModel = new FactoryConsoleModel(Minecraft.getInstance().getEntityModels().bakeLayer((ModelRegistry.FACTORY_CONSOLE)));
nukaConsoleModel = new NukaConsoleModel(Minecraft.getInstance().getEntityModels().bakeLayer((ModelRegistry.NUKA_CONSOLE)));
copperConsoleModel = new CopperConsoleModel(Minecraft.getInstance().getEntityModels().bakeLayer((ModelRegistry.COPPER_CONSOLE)));
coralConsoleModel = new CoralConsoleModel(Minecraft.getInstance().getEntityModels().bakeLayer((ModelRegistry.CORAL_CONSOLE)));
toyotaConsoleModel = new ToyotaConsoleModel(Minecraft.getInstance().getEntityModels().bakeLayer((ModelRegistry.TOYOTA_CONSOLE)));
crystalConsoleModel = new CrystalConsoleModel(Minecraft.getInstance().getEntityModels().bakeLayer((ModelRegistry.CRYSTAL_CONSOLE)));
victorianConsoleModel = new VictorianConsoleModel(Minecraft.getInstance().getEntityModels().bakeLayer((ModelRegistry.VICTORIAN_CONSOLE)));
mystConsoleModel = new MystConsoleModel(Minecraft.getInstance().getEntityModels().bakeLayer((ModelRegistry.MYST_CONSOLE)));
initiativeConsoleModel = new InitiativeConsoleModel(Minecraft.getInstance().getEntityModels().bakeLayer((ModelRegistry.INITIATIVE_CONSOLE)));
var context = Minecraft.getInstance().getEntityModels();
this.registerModels(context);
}

public void registerModels(EntityModelSet context){

factoryConsoleModel = new FactoryConsoleModel(context.bakeLayer((ModelRegistry.FACTORY_CONSOLE)));
nukaConsoleModel = new NukaConsoleModel(context.bakeLayer((ModelRegistry.NUKA_CONSOLE)));
copperConsoleModel = new CopperConsoleModel(context.bakeLayer((ModelRegistry.COPPER_CONSOLE)));
coralConsoleModel = new CoralConsoleModel(context.bakeLayer((ModelRegistry.CORAL_CONSOLE)));
toyotaConsoleModel = new ToyotaConsoleModel(context.bakeLayer((ModelRegistry.TOYOTA_CONSOLE)));
crystalConsoleModel = new CrystalConsoleModel(context.bakeLayer((ModelRegistry.CRYSTAL_CONSOLE)));
victorianConsoleModel = new VictorianConsoleModel(context.bakeLayer((ModelRegistry.VICTORIAN_CONSOLE)));
mystConsoleModel = new MystConsoleModel(context.bakeLayer((ModelRegistry.MYST_CONSOLE)));
initiativeConsoleModel = new InitiativeConsoleModel(context.bakeLayer((ModelRegistry.INITIATIVE_CONSOLE)));

CONSOLE_MODELS.put(ConsoleTheme.FACTORY.getId(), factoryConsoleModel);
CONSOLE_MODELS.put(ConsoleTheme.NUKA.getId(), nukaConsoleModel);
CONSOLE_MODELS.put(ConsoleTheme.COPPER.getId(), copperConsoleModel);
CONSOLE_MODELS.put(ConsoleTheme.CORAL.getId(), coralConsoleModel);
CONSOLE_MODELS.put(ConsoleTheme.TOYOTA.getId(), toyotaConsoleModel);
CONSOLE_MODELS.put(ConsoleTheme.CRYSTAL.getId(), crystalConsoleModel);
CONSOLE_MODELS.put(ConsoleTheme.VICTORIAN.getId(), victorianConsoleModel);
CONSOLE_MODELS.put(ConsoleTheme.MYST.getId(), mystConsoleModel);
CONSOLE_MODELS.put(ConsoleTheme.INITIATIVE.getId(), initiativeConsoleModel);

}

/**
* Get the associated console model from a console theme.
*
* @param theme The Console theme.
* @param themeId The Console theme.
* @return Console unit model tied with the console theme.
**/
public ConsoleUnit getConsoleModel(ConsoleTheme theme) {
switch (theme) {
case FACTORY:
return factoryConsoleModel;
case COPPER:
return copperConsoleModel;
case CORAL:
return coralConsoleModel;
case TOYOTA:
return toyotaConsoleModel;
case NUKA:
return nukaConsoleModel;
case CRYSTAL:
return crystalConsoleModel;
case VICTORIAN:
return victorianConsoleModel;
case MYST:
return mystConsoleModel;
case INITIATIVE:
return initiativeConsoleModel;
default:
throw new RuntimeException("Renderer has accessed theme that isn't accounted for! - " + theme.getSerializedName());
}
public ConsoleUnit getConsoleModel(ResourceLocation themeId) {
return CONSOLE_MODELS.get(themeId);
}

private static ConsoleModelCollection instance = null;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1034,7 +1034,7 @@ public boolean isDoorModel() {

@Override
public void handleSpecialAnimation(GlobalShellBlockEntity entity, PoseStack poseStack, VertexConsumer vertexConsumer, int packedLight, int packedOverlay, float red, float green, float blue, float baseAlpha) {
TardisClientData reactions = TardisClientData.getInstance(ResourceKey.create(Registries.DIMENSION, new ResourceLocation(TardisRefined.MODID, entity.TARDIS_ID.toString())));
TardisClientData reactions = TardisClientData.getInstance(entity.getTardisId());
this.animate(entity.liveliness, LOOP, Minecraft.getInstance().player.tickCount, reactions.isFlying() ? 5 : 1);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@ public void renderShell(GlobalShellBlockEntity entity, boolean open, boolean isB

@Override
public void handleSpecialAnimation(GlobalShellBlockEntity entity, PoseStack poseStack, VertexConsumer vertexConsumer, int packedLight, int packedOverlay, float red, float green, float blue, float baseAlpha) {
TardisClientData reactions = TardisClientData.getInstance(ResourceKey.create(Registries.DIMENSION, new ResourceLocation(TardisRefined.MODID, entity.TARDIS_ID.toString())));
TardisClientData reactions = TardisClientData.getInstance(entity.getTardisId());
this.animate(entity.liveliness, NUKAANIM, Minecraft.getInstance().player.tickCount, reactions.isFlying() ? 5 : 1);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -64,11 +64,11 @@ public float getCurrentAlpha() {
}

public void handleAllAnimations(GlobalShellBlockEntity entity, ModelPart root, boolean isBaseModel, boolean isDoorOpen, PoseStack poseStack, VertexConsumer vertexConsumer, int packedLight, int packedOverlay, float red, float green, float blue, float baseAlpha) {
if (entity.TARDIS_ID == null) return;
if (entity.getTardisId() == null) return;
entity.liveliness.start(12);

this.root().getAllParts().forEach(ModelPart::resetPose);
TardisClientData reactions = TardisClientData.getInstance(ResourceKey.create(Registries.DIMENSION, new ResourceLocation(TardisRefined.MODID, entity.TARDIS_ID.toString())));
TardisClientData reactions = TardisClientData.getInstance(entity.getTardisId());

setDoorOpen(isDoorOpen);

Expand Down
Loading

0 comments on commit 9e67bf7

Please sign in to comment.