Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Changed GaslightingTracker to be instanced, not static #701

Draft
wants to merge 4 commits into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -3,25 +3,25 @@
{
"model": "hexcasting:block/quenched_allay_0",
"predicate": {
"hexcasting:variant": 0.0
"hexcasting:quenched_allay_variants": 0.0
}
},
{
"model": "hexcasting:block/quenched_allay_1",
"predicate": {
"hexcasting:variant": 1.0
"hexcasting:quenched_allay_variants": 1.0
}
},
{
"model": "hexcasting:block/quenched_allay_2",
"predicate": {
"hexcasting:variant": 2.0
"hexcasting:quenched_allay_variants": 2.0
}
},
{
"model": "hexcasting:block/quenched_allay_3",
"predicate": {
"hexcasting:variant": 3.0
"hexcasting:quenched_allay_variants": 3.0
}
}
]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,25 +3,25 @@
{
"model": "hexcasting:block/deco/quenched_allay_bricks_0",
"predicate": {
"hexcasting:variant": 0.0
"hexcasting:quenched_allay_variants": 0.0
}
},
{
"model": "hexcasting:block/deco/quenched_allay_bricks_1",
"predicate": {
"hexcasting:variant": 1.0
"hexcasting:quenched_allay_variants": 1.0
}
},
{
"model": "hexcasting:block/deco/quenched_allay_bricks_2",
"predicate": {
"hexcasting:variant": 2.0
"hexcasting:quenched_allay_variants": 2.0
}
},
{
"model": "hexcasting:block/deco/quenched_allay_bricks_3",
"predicate": {
"hexcasting:variant": 3.0
"hexcasting:quenched_allay_variants": 3.0
}
}
]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,25 +3,25 @@
{
"model": "hexcasting:block/deco/quenched_allay_bricks_small_0",
"predicate": {
"hexcasting:variant": 0.0
"hexcasting:quenched_allay_variants": 0.0
}
},
{
"model": "hexcasting:block/deco/quenched_allay_bricks_small_1",
"predicate": {
"hexcasting:variant": 1.0
"hexcasting:quenched_allay_variants": 1.0
}
},
{
"model": "hexcasting:block/deco/quenched_allay_bricks_small_2",
"predicate": {
"hexcasting:variant": 2.0
"hexcasting:quenched_allay_variants": 2.0
}
},
{
"model": "hexcasting:block/deco/quenched_allay_bricks_small_3",
"predicate": {
"hexcasting:variant": 3.0
"hexcasting:quenched_allay_variants": 3.0
}
}
]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,25 +3,25 @@
{
"model": "hexcasting:item/quenched_shard_0",
"predicate": {
"hexcasting:variant": 0.0
"hexcasting:quenched_allay_variants": 0.0
}
},
{
"model": "hexcasting:item/quenched_shard_1",
"predicate": {
"hexcasting:variant": 1.0
"hexcasting:quenched_allay_variants": 1.0
}
},
{
"model": "hexcasting:item/quenched_shard_2",
"predicate": {
"hexcasting:variant": 2.0
"hexcasting:quenched_allay_variants": 2.0
}
},
{
"model": "hexcasting:item/quenched_shard_3",
"predicate": {
"hexcasting:variant": 3.0
"hexcasting:quenched_allay_variants": 3.0
}
}
]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,25 +3,25 @@
{
"model": "hexcasting:block/deco/quenched_allay_tiles_0",
"predicate": {
"hexcasting:variant": 0.0
"hexcasting:quenched_allay_variants": 0.0
}
},
{
"model": "hexcasting:block/deco/quenched_allay_tiles_1",
"predicate": {
"hexcasting:variant": 1.0
"hexcasting:quenched_allay_variants": 1.0
}
},
{
"model": "hexcasting:block/deco/quenched_allay_tiles_2",
"predicate": {
"hexcasting:variant": 2.0
"hexcasting:quenched_allay_variants": 2.0
}
},
{
"model": "hexcasting:block/deco/quenched_allay_tiles_3",
"predicate": {
"hexcasting:variant": 3.0
"hexcasting:quenched_allay_variants": 3.0
}
}
]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,25 +3,25 @@
{
"model": "hexcasting:item/staff/quenched_0",
"predicate": {
"hexcasting:variant": 0.0
"hexcasting:quenched_allay_variants": 0.0
}
},
{
"model": "hexcasting:item/staff/quenched_1",
"predicate": {
"hexcasting:variant": 1.0
"hexcasting:quenched_allay_variants": 1.0
}
},
{
"model": "hexcasting:item/staff/quenched_2",
"predicate": {
"hexcasting:variant": 2.0
"hexcasting:quenched_allay_variants": 2.0
}
},
{
"model": "hexcasting:item/staff/quenched_3",
"predicate": {
"hexcasting:variant": 3.0
"hexcasting:quenched_allay_variants": 3.0
}
}
]
Expand Down
kineticneticat marked this conversation as resolved.
Show resolved Hide resolved
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
package at.petrak.hexcasting.api.client;

import net.minecraft.resources.ResourceLocation;

import java.util.LinkedHashMap;
import java.util.Map;

// *nothing* that changes can be looked at for changes
public class GaslightingTracker {
public static Map<ResourceLocation, GaslightingTracker> GASLIGHTING_TRACKERS = new LinkedHashMap<>();
private int GASLIGHTING_AMOUNT = 0;
private final int LOOKING_COOLDOWN_MAX;
private int LOOKING_COOLDOWN;

public ResourceLocation GASLIGHTING_PRED;

public GaslightingTracker(ResourceLocation resLoc, int maxCooldown) {
this.GASLIGHTING_PRED = resLoc;
this.LOOKING_COOLDOWN_MAX = maxCooldown;
this.LOOKING_COOLDOWN = LOOKING_COOLDOWN_MAX;
GaslightingTracker.GASLIGHTING_TRACKERS.put(this.GASLIGHTING_PRED, this);
}

public int getGaslightingAmount() {
LOOKING_COOLDOWN = LOOKING_COOLDOWN_MAX;
return GASLIGHTING_AMOUNT;
}

public void postFrameCheckRendered() {
if (LOOKING_COOLDOWN > 0) {
LOOKING_COOLDOWN -= 1;
} else {
GASLIGHTING_AMOUNT += 1;
}
}
}
kineticneticat marked this conversation as resolved.
Show resolved Hide resolved
Original file line number Diff line number Diff line change
@@ -1,7 +1,10 @@
package at.petrak.hexcasting.client;

import at.petrak.hexcasting.client.render.GaslightingTracker;
import at.petrak.hexcasting.api.client.GaslightingTracker;
import net.minecraft.client.Minecraft;
import net.minecraft.resources.ResourceLocation;

import java.util.Map;

public class ClientTickCounter {
public static long ticksInGame = 0L;
Expand All @@ -19,7 +22,9 @@ public static void clientTickEnd() {
if (!Minecraft.getInstance().isPaused()) {
++ticksInGame;
partialTicks = 0.0F;
GaslightingTracker.postFrameCheckRendered();
for (Map.Entry<ResourceLocation, GaslightingTracker> entry : GaslightingTracker.GASLIGHTING_TRACKERS.entrySet()) {
entry.getValue().postFrameCheckRendered();
}
}
}
}
kineticneticat marked this conversation as resolved.
Show resolved Hide resolved
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
import at.petrak.hexcasting.api.misc.MediaConstants;
import at.petrak.hexcasting.api.utils.NBTHelper;
import at.petrak.hexcasting.client.entity.WallScrollRenderer;
import at.petrak.hexcasting.client.render.GaslightingTracker;
import at.petrak.hexcasting.api.client.GaslightingTracker;
import at.petrak.hexcasting.client.render.ScryingLensOverlays;
import at.petrak.hexcasting.client.render.be.BlockEntityAkashicBookshelfRenderer;
import at.petrak.hexcasting.client.render.be.BlockEntityQuenchedAllayRenderer;
Expand All @@ -30,7 +30,6 @@
import net.minecraft.client.renderer.blockentity.BlockEntityRendererProvider;
import net.minecraft.client.resources.model.BakedModel;
import net.minecraft.client.resources.model.ModelBakery;
import net.minecraft.core.Registry;
import net.minecraft.core.registries.BuiltInRegistries;
import net.minecraft.resources.ResourceLocation;
import net.minecraft.server.packs.resources.ResourceManager;
Expand Down Expand Up @@ -109,12 +108,12 @@ public static void init() {
// purposely skip quenched
registerWandOverrides(HexItems.STAFF_MINDSPLICE);

registerGaslight4(HexItems.STAFF_QUENCHED);
registerGaslight4(HexBlocks.QUENCHED_ALLAY.asItem());
registerGaslight4(HexBlocks.QUENCHED_ALLAY_TILES.asItem());
registerGaslight4(HexBlocks.QUENCHED_ALLAY_BRICKS.asItem());
registerGaslight4(HexBlocks.QUENCHED_ALLAY_BRICKS_SMALL.asItem());
registerGaslight4(HexItems.QUENCHED_SHARD);
registerGaslight4(HexItems.STAFF_QUENCHED, "quenched_allay_variants");
registerGaslight4(HexBlocks.QUENCHED_ALLAY.asItem(), "quenched_allay_variants");
registerGaslight4(HexBlocks.QUENCHED_ALLAY_TILES.asItem(), "quenched_allay_variants");
registerGaslight4(HexBlocks.QUENCHED_ALLAY_BRICKS.asItem(), "quenched_allay_variants");
registerGaslight4(HexBlocks.QUENCHED_ALLAY_BRICKS_SMALL.asItem(), "quenched_allay_variants");
registerGaslight4(HexItems.QUENCHED_SHARD, "quenched_allay_variants");

x.setRenderLayer(HexBlocks.CONJURED_LIGHT, RenderType.cutout());
x.setRenderLayer(HexBlocks.CONJURED_BLOCK, RenderType.cutout());
Expand Down Expand Up @@ -143,10 +142,11 @@ public static void init() {
ScryingLensOverlays.addScryingLensStuff();
}

private static void registerGaslight4(Item item) {
private static void registerGaslight4(Item item, String gaslightingPredicate) {
IClientXplatAbstractions.INSTANCE.registerItemProperty(item,
GaslightingTracker.GASLIGHTING_PRED, (stack, level, holder, holderID) ->
Math.abs(GaslightingTracker.getGaslightingAmount() % 4));
GaslightingTracker.GASLIGHTING_TRACKERS.get(modLoc(gaslightingPredicate)).GASLIGHTING_PRED,
(stack, level, holder, holderID) ->
Math.abs(GaslightingTracker.GASLIGHTING_TRACKERS.get(modLoc(gaslightingPredicate)).getGaslightingAmount() % 4));
}

public static void registerColorProviders(BiConsumer<ItemColor, Item> itemColorRegistry,
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
@@ -1,17 +1,16 @@
package at.petrak.hexcasting.client.render.be;

import at.petrak.hexcasting.client.RegisterClientStuff;
import at.petrak.hexcasting.client.render.GaslightingTracker;
import at.petrak.hexcasting.common.blocks.BlockQuenchedAllay;
import at.petrak.hexcasting.common.blocks.entity.BlockEntityQuenchedAllay;
import at.petrak.hexcasting.common.lib.hex.HexGaslighting;
import at.petrak.hexcasting.xplat.IClientXplatAbstractions;
import com.mojang.blaze3d.vertex.PoseStack;
import net.minecraft.client.renderer.MultiBufferSource;
import net.minecraft.client.renderer.RenderType;
import net.minecraft.client.renderer.block.BlockRenderDispatcher;
import net.minecraft.client.renderer.blockentity.BlockEntityRenderer;
import net.minecraft.client.renderer.blockentity.BlockEntityRendererProvider;
import net.minecraft.core.Registry;
import net.minecraft.core.registries.BuiltInRegistries;
import net.minecraft.world.phys.AABB;

Expand All @@ -29,7 +28,7 @@ private static void doRender(BlockQuenchedAllay block, BlockRenderDispatcher dis
var buffer = bufSource.getBuffer(RenderType.translucent());
var pose = ps.last();

var idx = Math.abs(GaslightingTracker.getGaslightingAmount() % BlockQuenchedAllay.VARIANTS);
var idx = Math.abs(HexGaslighting.QUENCHED_ALLAY_GASLIGHTING.getGaslightingAmount() % BlockQuenchedAllay.VARIANTS);
var model = RegisterClientStuff.QUENCHED_ALLAY_VARIANTS.get(BuiltInRegistries.BLOCK.getKey(block)).get(idx);

dispatcher.getModelRenderer().renderModel(pose, buffer, null, model, 1f, 1f, 1f, packedLight, packedOverlay);
Expand Down
kineticneticat marked this conversation as resolved.
Show resolved Hide resolved
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
package at.petrak.hexcasting.common.lib.hex;

import at.petrak.hexcasting.api.client.GaslightingTracker;

import static at.petrak.hexcasting.api.HexAPI.modLoc;

public class HexGaslighting {
public static void init() {}

public static GaslightingTracker QUENCHED_ALLAY_GASLIGHTING = new GaslightingTracker(modLoc("quenched_allay_variants"), 40);

}
kineticneticat marked this conversation as resolved.
Show resolved Hide resolved
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,8 @@ object FabricHexInitializer : ModInitializer {

HexInterop.init()
RegisterMisc.register()

HexGaslighting.init()
}

fun initListeners() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -148,6 +148,8 @@ private static void initRegistry() {
HexAdvancementTriggers.registerTriggers();

RegisterMisc.register();

HexGaslighting.init();
}

// https://github.com/VazkiiMods/Botania/blob/1.18.x/Forge/src/main/java/vazkii/botania/forge/ForgeCommonInitializer.java
Expand Down
Loading
Loading