Skip to content

Commit f91dea8

Browse files
committed
More refactoring
1 parent 34b41b0 commit f91dea8

14 files changed

+181
-165
lines changed

src/main/java/org/visuals/legacy/animatium/Animatium.java

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,6 @@
3232
import org.visuals.legacy.animatium.util.config.ConfigUtil;
3333
import org.visuals.legacy.animatium.util.enums.ServerFeature;
3434

35-
import java.io.IOException;
3635
import java.util.EnumSet;
3736

3837
@UtilityClass
@@ -48,16 +47,17 @@ public AnimatiumInfoPayloadPacket getInfoPayload() {
4847
return new AnimatiumInfoPayloadPacket(VERSION, DEVELOPMENT_VERSION.isEmpty() ? null : DEVELOPMENT_VERSION);
4948
}
5049

51-
public ResourceLocation id(String path) {
50+
public ResourceLocation location(String path) {
5251
return ResourceLocation.fromNamespaceAndPath(MOD_ID, path);
5352
}
5453

5554
public void initialize() {
5655
AnimatiumConfig.load();
5756
try {
5857
ConfigUtil.load();
59-
} catch (IOException ignored) {
60-
Animatium.ENABLED = true;
58+
System.err.println("Successfully loaded the animatium utility config!");
59+
} catch (Exception ignored) {
60+
Animatium.ENABLED = ConfigUtil.bool("enabled");
6161
System.err.println("Failed to load animatium utility config, defaulting...");
6262
}
6363
}

src/main/java/org/visuals/legacy/animatium/AnimatiumFabricClient.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ public void onInitializeClient() {
4848
Animatium.initialize();
4949

5050
final ModContainer modContainer = FabricLoader.getInstance().getModContainer(Animatium.MOD_ID).orElseThrow(() -> new RuntimeException("Mod container data could not be found for Animatium!"));
51-
ResourceManagerHelper.registerBuiltinResourcePack(Animatium.id("classic_textures"), modContainer, ResourcePackActivationType.DEFAULT_ENABLED);
51+
ResourceManagerHelper.registerBuiltinResourcePack(Animatium.location("classic_textures"), modContainer, ResourcePackActivationType.DEFAULT_ENABLED);
5252
ClientCommandRegistrationCallback.EVENT.register((dispatcher, context) -> dispatcher.register(AnimatiumCommand.create()));
5353
DebugScreenEntries.register(AnimatiumDebugEntry.GROUP, new AnimatiumDebugEntry());
5454
registerPayloads();

src/main/java/org/visuals/legacy/animatium/mixins/v1/gui/MixinPanoramaRenderer_LegacyRendering.java

Lines changed: 5 additions & 103 deletions
Original file line numberDiff line numberDiff line change
@@ -30,74 +30,33 @@
3030
import com.mojang.blaze3d.opengl.GlStateManager;
3131
import com.mojang.blaze3d.opengl.GlTexture;
3232
import com.mojang.blaze3d.opengl.GlTextureView;
33-
import com.mojang.blaze3d.pipeline.BlendFunction;
3433
import com.mojang.blaze3d.pipeline.RenderPipeline;
35-
import com.mojang.blaze3d.pipeline.RenderTarget;
36-
import com.mojang.blaze3d.platform.DestFactor;
37-
import com.mojang.blaze3d.platform.SourceFactor;
3834
import com.mojang.blaze3d.systems.GpuDevice;
3935
import com.mojang.blaze3d.systems.RenderSystem;
40-
import com.mojang.blaze3d.textures.FilterMode;
4136
import com.mojang.blaze3d.textures.TextureFormat;
42-
import com.mojang.blaze3d.vertex.BufferBuilder;
43-
import com.mojang.blaze3d.vertex.ByteBufferBuilder;
44-
import com.mojang.blaze3d.vertex.DefaultVertexFormat;
45-
import com.mojang.blaze3d.vertex.VertexFormat;
46-
import net.minecraft.client.Minecraft;
4737
import net.minecraft.client.gui.GuiGraphics;
4838
import net.minecraft.client.renderer.PanoramaRenderer;
49-
import net.minecraft.client.renderer.RenderPipelines;
5039
import net.minecraft.resources.ResourceLocation;
51-
import net.minecraft.util.ARGB;
52-
import org.joml.Matrix3x2f;
53-
import org.spongepowered.asm.mixin.Final;
5440
import org.spongepowered.asm.mixin.Mixin;
55-
import org.spongepowered.asm.mixin.Shadow;
5641
import org.spongepowered.asm.mixin.Unique;
5742
import org.spongepowered.asm.mixin.injection.At;
5843
import org.spongepowered.asm.mixin.injection.Inject;
5944
import org.spongepowered.asm.mixin.injection.callback.CallbackInfo;
6045
import org.visuals.legacy.animatium.Animatium;
6146
import org.visuals.legacy.animatium.config.AnimatiumConfig;
62-
import org.visuals.legacy.animatium.util.RenderUtils;
47+
import org.visuals.legacy.animatium.util.PanoramaRendererUtility;
6348

6449
@Mixin(PanoramaRenderer.class)
6550
public abstract class MixinPanoramaRenderer_LegacyRendering {
66-
@Unique
67-
private static final RenderPipeline.Snippet animatium$TEXTURE_SNIPPET =
68-
RenderPipeline.builder(RenderPipelines.MATRICES_PROJECTION_SNIPPET)
69-
.withVertexShader("core/position_tex")
70-
.withFragmentShader("core/position_tex")
71-
.withSampler("Sampler0")
72-
.withVertexFormat(DefaultVertexFormat.POSITION_TEX_COLOR, VertexFormat.Mode.QUADS)
73-
.buildSnippet();
74-
@Unique
75-
private static final RenderPipeline animatium$BLUR_TEXTURE =
76-
RenderPipeline.builder(animatium$TEXTURE_SNIPPET)
77-
.withLocation(Animatium.id("pipeline/blur_texture"))
78-
.withColorWrite(true, false)
79-
.withBlend(new BlendFunction(SourceFactor.SRC_ALPHA, DestFactor.ONE_MINUS_SRC_ALPHA, SourceFactor.ONE, DestFactor.ZERO))
80-
.build();
81-
@Unique
82-
private static final RenderPipeline animatium$BASIC_TEXTURE =
83-
RenderPipeline.builder(animatium$TEXTURE_SNIPPET)
84-
.withLocation(Animatium.id("pipeline/basic_texture"))
85-
.build();
86-
@Shadow
87-
@Final
88-
private Minecraft minecraft;
89-
@Unique
90-
private GlTexture animatium$backgroundTexture;
91-
9251
@Unique
9352
private GlTextureView animatium$backgroundTextureView;
9453

9554
@Inject(method = "render", at = @At("HEAD"))
9655
private void animatium$panoramaStart(GuiGraphics guiGraphics, int width, int height, boolean spin, CallbackInfo ci) {
9756
if (Animatium.ENABLED && AnimatiumConfig.instance().screen.panoramaRendering) {
98-
if (animatium$backgroundTexture == null) {
99-
GpuDevice device = RenderSystem.getDevice();
100-
animatium$backgroundTexture = (GlTexture) device.createTexture(() -> "Background texture", 15, TextureFormat.RGBA8, 256, 256, 1, 1);
57+
if (animatium$backgroundTextureView == null) {
58+
final GpuDevice device = RenderSystem.getDevice();
59+
final GlTexture animatium$backgroundTexture = (GlTexture) device.createTexture(() -> "Background texture", 15, TextureFormat.RGBA8, 256, 256, 1, 1);
10160
animatium$backgroundTextureView = (GlTextureView) device.createTextureView(animatium$backgroundTexture);
10261
}
10362

@@ -108,13 +67,7 @@ public abstract class MixinPanoramaRenderer_LegacyRendering {
10867
@Inject(method = "render", at = @At(value = "INVOKE", target = "Lnet/minecraft/client/renderer/CubeMap;render(Lnet/minecraft/client/Minecraft;FF)V", ordinal = 0, shift = At.Shift.AFTER))
10968
private void animatium$panoramaFinish(GuiGraphics guiGraphics, int width, int height, boolean spin, CallbackInfo ci) {
11069
if (Animatium.ENABLED && AnimatiumConfig.instance().screen.panoramaRendering) {
111-
final RenderTarget renderTarget = minecraft.getMainRenderTarget();
112-
for (int i = 0; i < 6; ++i) {
113-
this.animatium$writeAndBlitBlurTexture(guiGraphics, renderTarget, animatium$backgroundTextureView, width, height);
114-
}
115-
116-
GlStateManager._viewport(0, 0, renderTarget.width, renderTarget.height);
117-
animatium$renderFinalTexture(renderTarget, animatium$backgroundTextureView, width, height);
70+
PanoramaRendererUtility.render(guiGraphics.pose(), animatium$backgroundTextureView, width, height);
11871
}
11972
}
12073

@@ -127,55 +80,4 @@ public abstract class MixinPanoramaRenderer_LegacyRendering {
12780
original.call(instance, pipeline, atlas, x, y, u, v, width, height, uWidth, vHeight, textureWidth, textureHeight);
12881
}
12982
}
130-
131-
@Unique
132-
private void animatium$writeAndBlitBlurTexture(GuiGraphics guiGraphics, RenderTarget renderTarget, GlTextureView texture, int width, int height) {
133-
texture.texture().setTextureFilter(FilterMode.LINEAR, false);
134-
// Ensures enough width/height for it to not crash when window is resized
135-
if (renderTarget.width >= 256 && renderTarget.height >= 256) {
136-
RenderSystem.getDevice().createCommandEncoder().copyTextureToTexture(
137-
renderTarget.getColorTexture(),
138-
texture.texture(),
139-
0, // mips?
140-
0, 0, // srcXY
141-
0, 0, // dstXY
142-
256, 256 // w/h
143-
);
144-
}
145-
146-
RenderPipeline pipeline = animatium$BLUR_TEXTURE;
147-
ByteBufferBuilder byteBufferBuilder = new ByteBufferBuilder(pipeline.getVertexFormat().getVertexSize() * 12);
148-
BufferBuilder bufferBuilder = new BufferBuilder(byteBufferBuilder, pipeline.getVertexFormatMode(), pipeline.getVertexFormat());
149-
final Matrix3x2f matrix = guiGraphics.pose();
150-
for (int i = 0; i < 3; ++i) {
151-
final float growth = (float) (i - 1) / 256.0F;
152-
final int color = ARGB.colorFromFloat(1.0F / (float) (i + 1), 1.0F, 1.0F, 1.0F);
153-
bufferBuilder.addVertexWith2DPose(matrix, width, height).setUv(0.0F + growth, 1.0F).setColor(color);
154-
bufferBuilder.addVertexWith2DPose(matrix, width, 0.0F).setUv(1.0F + growth, 1.0F).setColor(color);
155-
bufferBuilder.addVertexWith2DPose(matrix, 0.0F, 0.0F).setUv(1.0F + growth, 0.0F).setColor(color);
156-
bufferBuilder.addVertexWith2DPose(matrix, 0.0F, height).setUv(0.0F + growth, 0.0F).setColor(color);
157-
}
158-
159-
RenderUtils.drawBuffer(animatium$BLUR_TEXTURE, renderTarget, bufferBuilder.buildOrThrow(), (pass) -> {
160-
pass.bindSampler("Sampler0", texture);
161-
});
162-
}
163-
164-
@Unique
165-
private void animatium$renderFinalTexture(RenderTarget renderTarget, GlTextureView texture, int width, int height) {
166-
float f = 120.0F / (float) (Math.max(width, height));
167-
float g = (float) height * f / 256.0F;
168-
float h = (float) width * f / 256.0F;
169-
final int color = ARGB.white(1.0F);
170-
RenderPipeline pipeline = animatium$BASIC_TEXTURE;
171-
ByteBufferBuilder byteBufferBuilder = new ByteBufferBuilder(pipeline.getVertexFormat().getVertexSize() * 4);
172-
BufferBuilder bufferBuilder = new BufferBuilder(byteBufferBuilder, pipeline.getVertexFormatMode(), pipeline.getVertexFormat());
173-
bufferBuilder.addVertex(0.0F, height, 0.0F).setUv(0.5F - g, 0.5F + h).setColor(color);
174-
bufferBuilder.addVertex(width, height, 0.0F).setUv(0.5F - g, 0.5F - h).setColor(color);
175-
bufferBuilder.addVertex(width, 0.0F, 0.0F).setUv(0.5F + g, 0.5F - h).setColor(color);
176-
bufferBuilder.addVertex(0.0F, 0.0F, 0.0F).setUv(0.5F + g, 0.5F + h).setColor(color);
177-
RenderUtils.drawBuffer(animatium$BASIC_TEXTURE, renderTarget, bufferBuilder.buildOrThrow(), (pass) -> {
178-
pass.bindSampler("Sampler0", texture);
179-
});
180-
}
18183
}

src/main/java/org/visuals/legacy/animatium/packet/AnimatiumInfoPayloadPacket.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@
3737
public record AnimatiumInfoPayloadPacket(double version,
3838
@Nullable String developmentVersion) implements CustomPacketPayload {
3939
public static final StreamCodec<FriendlyByteBuf, AnimatiumInfoPayloadPacket> CODEC = CustomPacketPayload.codec(AnimatiumInfoPayloadPacket::write, null);
40-
public static final CustomPacketPayload.Type<AnimatiumInfoPayloadPacket> PAYLOAD_ID = new CustomPacketPayload.Type<>(Animatium.id("info"));
40+
public static final CustomPacketPayload.Type<AnimatiumInfoPayloadPacket> PAYLOAD_ID = new CustomPacketPayload.Type<>(Animatium.location("info"));
4141

4242
private void write(FriendlyByteBuf buffer) {
4343
buffer.writeDouble(version);

src/main/java/org/visuals/legacy/animatium/packet/RequestInfoPayloadPacket.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@
3333

3434
public record RequestInfoPayloadPacket() implements CustomPacketPayload {
3535
public static final StreamCodec<FriendlyByteBuf, RequestInfoPayloadPacket> CODEC = CustomPacketPayload.codec(null, RequestInfoPayloadPacket::read);
36-
public static final Type<RequestInfoPayloadPacket> PAYLOAD_ID = new Type<>(Animatium.id("request_info"));
36+
public static final Type<RequestInfoPayloadPacket> PAYLOAD_ID = new Type<>(Animatium.location("request_info"));
3737

3838
private static RequestInfoPayloadPacket read(FriendlyByteBuf buffer) {
3939
return new RequestInfoPayloadPacket();

src/main/java/org/visuals/legacy/animatium/packet/SetServerFeaturesPayloadPacket.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@
3838

3939
public record SetServerFeaturesPayloadPacket(EnumSet<ServerFeature> features) implements CustomPacketPayload {
4040
public static final StreamCodec<FriendlyByteBuf, SetServerFeaturesPayloadPacket> CODEC = CustomPacketPayload.codec(null, SetServerFeaturesPayloadPacket::read);
41-
public static final Type<SetServerFeaturesPayloadPacket> PAYLOAD_ID = new Type<>(Animatium.id("set_features"));
41+
public static final Type<SetServerFeaturesPayloadPacket> PAYLOAD_ID = new Type<>(Animatium.location("set_features"));
4242

4343
private static SetServerFeaturesPayloadPacket read(FriendlyByteBuf buffer) {
4444
buffer.markReaderIndex();

src/main/java/org/visuals/legacy/animatium/util/AnimatiumDebugEntry.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@
4141

4242
public class AnimatiumDebugEntry implements DebugScreenEntry {
4343
public static final DebugEntryCategory CATEGORY = new DebugEntryCategory(Component.translatable("animatium.category.debug"), 9999.0F);
44-
public static final ResourceLocation GROUP = Animatium.id("debug");
44+
public static final ResourceLocation GROUP = Animatium.location("debug");
4545

4646
@Override
4747
public void display(DebugScreenDisplayer debugScreenDisplayer, @Nullable Level level, @Nullable LevelChunk levelChunk, @Nullable LevelChunk levelChunk2) {

src/main/java/org/visuals/legacy/animatium/util/ItemUtils.java

Lines changed: 17 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -43,67 +43,52 @@ public boolean isSwordItem(ItemStack stack) {
4343
}
4444

4545
public boolean isAxeItem(ItemStack stack) {
46-
return stack.is(ItemTags.AXES);
46+
return stack.getItem() instanceof AxeItem || stack.is(ItemTags.AXES);
4747
}
4848

4949
public boolean isPickaxeItem(ItemStack stack) {
5050
return stack.is(ItemTags.PICKAXES);
5151
}
5252

5353
public boolean isShovelItem(ItemStack stack) {
54-
return stack.is(ItemTags.SHOVELS);
54+
return stack.getItem() instanceof ShovelItem || stack.is(ItemTags.SHOVELS);
5555
}
5656

5757
public boolean isHoeItem(ItemStack stack) {
58-
return stack.is(ItemTags.HOES);
58+
return stack.getItem() instanceof HoeItem || stack.is(ItemTags.HOES);
5959
}
6060

6161
public boolean isDiggerItem(ItemStack stack) {
6262
return isAxeItem(stack) || isPickaxeItem(stack) || isShovelItem(stack) || isHoeItem(stack);
6363
}
6464

6565
public boolean isShieldItem(ItemStack stack) {
66-
return stack.is(Items.SHIELD);
66+
return stack.getItem() instanceof ShieldItem || stack.is(Items.SHIELD);
6767
}
6868

6969
public boolean isFishingRodItem(ItemStack stack) {
70-
if (!stack.isEmpty()) {
71-
final Item item = stack.getItem();
72-
return item instanceof FishingRodItem ||
73-
item instanceof FoodOnAStickItem<?>;
74-
} else {
75-
return false;
76-
}
70+
final Item item = stack.getItem();
71+
return item instanceof FishingRodItem || item instanceof FoodOnAStickItem<?>;
7772
}
7873

7974
public boolean isRangedWeaponItem(ItemStack stack) {
80-
if (!stack.isEmpty()) {
81-
return stack.getItem() instanceof ProjectileWeaponItem;
82-
} else {
83-
return false;
84-
}
75+
return stack.getItem() instanceof ProjectileWeaponItem;
8576
}
8677

8778
public boolean isHandheldItem(ItemStack stack) {
88-
if (!stack.isEmpty()) {
89-
return isDiggerItem(stack) ||
90-
isSwordItem(stack) ||
91-
isFishingRodItem(stack) ||
92-
List.of(Items.MACE, Items.TRIDENT, Items.STICK, Items.BREEZE_ROD, Items.BLAZE_ROD).contains(stack.getItem());
93-
} else {
94-
return false;
95-
}
79+
return isDiggerItem(stack) ||
80+
isSwordItem(stack) ||
81+
isFishingRodItem(stack) ||
82+
List.of(Items.MACE, Items.TRIDENT, Items.STICK, Items.BREEZE_ROD, Items.BLAZE_ROD).contains(stack.getItem());
9683
}
9784

9885
public boolean isThinBlockItem(ItemStack stack) {
99-
if (!stack.isEmpty()) {
100-
final Block block = Block.byItem(stack.getItem());
101-
return block instanceof CarpetBlock ||
102-
block instanceof TrapDoorBlock || block instanceof PressurePlateBlock ||
103-
block instanceof SnowLayerBlock || block instanceof DaylightDetectorBlock;
104-
} else {
105-
return false;
106-
}
86+
final Block block = Block.byItem(stack.getItem());
87+
return block instanceof CarpetBlock ||
88+
block instanceof TrapDoorBlock ||
89+
block instanceof PressurePlateBlock ||
90+
block instanceof SnowLayerBlock ||
91+
block instanceof DaylightDetectorBlock;
10792
}
10893

10994
public boolean isSkullBlock(ItemStack stack) {

0 commit comments

Comments
 (0)