Skip to content

Commit

Permalink
Update to 1.21.2
Browse files Browse the repository at this point in the history
  • Loading branch information
Aeltumn committed Oct 17, 2024
1 parent 8f72419 commit f55950b
Show file tree
Hide file tree
Showing 38 changed files with 752 additions and 414 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ public class ProtocolVersion {
* of Noxesium is available on the client. The protocol version will increment every full release, as such
* ít is recommended to work with >= comparisons.
*/
public static final int VERSION = 11;
public static final int VERSION = 12;

/**
* The name space to use for Noxesium.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,8 @@ public class EntityRuleIndices {
public static final int DISABLE_BUBBLES = 0;

/**
* Defines a color to use for a beam created by this entity. Applies only to guardian
* beams at this time.
* Defines a color to use for a beam created by this entity. Applies to guardian beams
* and end crystal beams.
*/
public static final int BEAM_COLOR = 1;

Expand All @@ -27,4 +27,9 @@ public class EntityRuleIndices {
* qib collisions. The regular width is seen as its width on the X-axis.
*/
public static final int QIB_WIDTH_Z = 3;

/**
* Defines a color used in combination with [BEAM_COLOR] to create a linear fade.
*/
public static final int BEAM_COLOR_FADE = 4;
}
113 changes: 55 additions & 58 deletions fabric/src/main/java/com/noxcrew/noxesium/NoxesiumMod.java
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package com.noxcrew.noxesium;

import com.google.common.base.Preconditions;
import com.mojang.blaze3d.shaders.Program;
import com.mojang.blaze3d.shaders.CompiledShader;
import com.noxcrew.noxesium.api.protocol.ClientSettings;
import com.noxcrew.noxesium.api.protocol.ProtocolVersion;
import com.noxcrew.noxesium.config.NoxesiumConfig;
Expand Down Expand Up @@ -30,12 +30,10 @@
import net.fabricmc.fabric.api.resource.SimpleResourceReloadListener;
import net.fabricmc.loader.api.FabricLoader;
import net.minecraft.client.Minecraft;
import net.minecraft.client.renderer.GameRenderer;
import net.minecraft.resources.ResourceLocation;
import net.minecraft.server.packs.PackType;
import net.minecraft.server.packs.resources.Resource;
import net.minecraft.server.packs.resources.ResourceManager;
import net.minecraft.util.profiling.ProfilerFiller;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
import org.slf4j.Logger;
Expand Down Expand Up @@ -79,7 +77,7 @@ public class NoxesiumMod implements ClientModInitializer {
* The mapping of cached shaders.
*/
@Nullable
private GameRenderer.ResourceCache cachedShaders = null;
private Map<ResourceLocation, Resource> cachedShaders = null;

private final NoxesiumConfig config = NoxesiumConfig.load();
private final Logger logger = LoggerFactory.getLogger("Noxesium");
Expand Down Expand Up @@ -109,7 +107,7 @@ public NoxesiumConfig getConfig() {
* Returns a cache with all shaders in the Sodium namespace.
*/
@Nullable
public GameRenderer.ResourceCache getCachedShaders() {
public Map<ResourceLocation, Resource> getCachedShaders() {
return cachedShaders;
}

Expand Down Expand Up @@ -208,50 +206,49 @@ public void onInitializeClient() {

// Listen to shaders that are loaded and cache them
ResourceManagerHelper
.get(PackType.CLIENT_RESOURCES)
.registerReloadListener(
new SimpleResourceReloadListener<Void>() {
@Override
public ResourceLocation getFabricId() {
return ResourceLocation.fromNamespaceAndPath(ProtocolVersion.NAMESPACE, "shaders");
}

@Override
public CompletableFuture<Void> load(ResourceManager manager, ProfilerFiller profiler, Executor executor) {
return CompletableFuture.supplyAsync(() -> {
var map = manager.listResources(
"shaders",
folder -> {
// We include all namespaces because you need to be able to import shaders from elsewhere!
var s = folder.getPath();
return s.endsWith(".json")
|| s.endsWith(Program.Type.FRAGMENT.getExtension())
|| s.endsWith(Program.Type.VERTEX.getExtension())
|| s.endsWith(".glsl");
}
);
var map1 = new HashMap<ResourceLocation, Resource>();
map.forEach((key, value) -> {
try (InputStream inputstream = value.open()) {
byte[] abyte = inputstream.readAllBytes();
map1.put(ResourceLocation.fromNamespaceAndPath(key.getNamespace(), key.getPath().substring("shaders/".length())), new Resource(value.source(), () -> new ByteArrayInputStream(abyte)));
} catch (Exception exception) {
getLogger().warn("Failed to read resource {}", key, exception);
}
});

// Save the shaders here instead of in apply so we go before any other resource re-loader!
cachedShaders = new GameRenderer.ResourceCache(manager, map1);
return null;
});
}

@Override
public CompletableFuture<Void> apply(Void data, ResourceManager manager, ProfilerFiller profiler, Executor executor) {
return CompletableFuture.completedFuture(null);
}
}
);
.get(PackType.CLIENT_RESOURCES)
.registerReloadListener(
new SimpleResourceReloadListener<Void>() {
@Override
public ResourceLocation getFabricId() {
return ResourceLocation.fromNamespaceAndPath(ProtocolVersion.NAMESPACE, "shaders");
}

@Override
public CompletableFuture<Void> load(ResourceManager manager, Executor executor) {
return CompletableFuture.supplyAsync(() -> {
var map = manager.listResources(
"shaders",
folder -> {
// We include all namespaces because you need to be able to import shaders from elsewhere!
var s = folder.getPath();
return s.endsWith(".json")
|| CompiledShader.Type.byLocation(folder) != null
|| s.endsWith(".glsl");
}
);
var cache = new HashMap<ResourceLocation, Resource>();
map.forEach((key, value) -> {
try (InputStream inputstream = value.open()) {
byte[] abyte = inputstream.readAllBytes();
cache.put(ResourceLocation.fromNamespaceAndPath(key.getNamespace(), key.getPath().substring("shaders/".length())), new Resource(value.source(), () -> new ByteArrayInputStream(abyte)));
} catch (Exception exception) {
getLogger().warn("Failed to read resource {}", key, exception);
}
});

// Save the shaders here instead of in apply so we go before any other resource re-loader!
cachedShaders = cache;
return null;
});
}

@Override
public CompletableFuture<Void> apply(Void data, ResourceManager manager, Executor executor) {
return CompletableFuture.completedFuture(null);
}
}
);

// Run rebuilds on a separate thread to not destroy fps unnecessarily
var rebuildThread = new Thread("Noxesium Spatial Container Rebuild Thread") {
Expand Down Expand Up @@ -324,15 +321,15 @@ public static void syncGuiScale() {
var options = Minecraft.getInstance().options;

new ServerboundClientSettingsPacket(
new ClientSettings(
options.guiScale().get(),
window.getGuiScale(),
window.getGuiScaledWidth(),
window.getGuiScaledHeight(),
Minecraft.getInstance().isEnforceUnicode(),
options.touchscreen().get(),
options.notificationDisplayTime().get()
)
new ClientSettings(
options.guiScale().get(),
window.getGuiScale(),
window.getGuiScaledWidth(),
window.getGuiScaledHeight(),
Minecraft.getInstance().isEnforceUnicode(),
options.touchscreen().get(),
options.notificationDisplayTime().get()
)
).send();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -5,5 +5,21 @@
*/
public enum MapLocation {
TOP,
BOTTOM
BOTTOM,
TOP_FLIPPED,
BOTTOM_FLIPPED;

/**
* Returns whether this location is on the bottom side.
*/
public boolean isBottom() {
return this == BOTTOM || this == BOTTOM_FLIPPED;
}

/**
* Returns whether this location should be flipped.
*/
public boolean isFlipped() {
return this == TOP_FLIPPED || this == BOTTOM_FLIPPED;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
package com.noxcrew.noxesium.feature.entity;

import net.minecraft.world.phys.AABB;

/**
* Defines an extension for armor stand culling bounding boxes.
*/
public interface ArmorStandCullingExtension {

/**
* Returns the culling bounding box.
*/
public default AABB noxesium$getCullingBoundingBox() {
throw new UnsupportedOperationException("Unimplemented");
}

/**
* Updates the culling bounding box.
*/
public default void noxesium$setCullingBoundingBox(AABB boundingBox) {
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
package com.noxcrew.noxesium.feature.entity;

/**
* Extends the guardian and end crystal states with a beam color.
*/
public interface BeamColorStateExtension {

default Integer noxesium$getBeamColor() {
throw new UnsupportedOperationException("Unimplemented");
}

default Integer noxesium$getBeamColorFade() {
throw new UnsupportedOperationException("Unimplemented");
}

default void noxesium$setBeamColor(Integer color, Integer fade) {
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
package com.noxcrew.noxesium.feature.entity;

/**
* Stores the color being used for rendering an end crystal beam.
*/
public class EndCrystalRenderHolder {
/**
* The current color being used when rendering end crystal beams.
*/
public static Integer noxesium$endCrystalBeamColor = null;

/**
* The current fade color for the end crystal beams.
*/
public static Integer noxesium$endCrystalBeamColorFade = null;

/**
* The current vertex index.
*/
public static int noxesium$index = 0;
}
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,8 @@ public class ExtraEntityData {
public static ClientServerRule<Boolean> DISABLE_BUBBLES = register(new BooleanServerRule(EntityRuleIndices.DISABLE_BUBBLES, false));

/**
* If `true` bubbles are removed from guardian beams shot by this entity.
* Defines a color to use for a beam created by this entity. Applies to guardian beams
* and end crystal beams.
*/
public static ClientServerRule<Optional<Color>> BEAM_COLOR = register(new ColorServerRule(EntityRuleIndices.BEAM_COLOR, Optional.empty()));

Expand All @@ -37,6 +38,11 @@ public class ExtraEntityData {
*/
public static ClientServerRule<Double> QIB_WIDTH_Z = register(new DoubleServerRule(EntityRuleIndices.QIB_WIDTH_Z, 1.0));

/**
* Defines a color used in combination with [BEAM_COLOR] to create a linear fade.
*/
public static ClientServerRule<Optional<Color>> BEAM_COLOR_FADE = register(new ColorServerRule(EntityRuleIndices.BEAM_COLOR_FADE, Optional.empty()));

/**
* Registers a new extra entity data key.
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -270,7 +270,7 @@ private void executeBehavior(LocalPlayer player, Entity entity, QibEffect effect
);
}
case QibEffect.GivePotionEffect giveEffect -> {
var type = BuiltInRegistries.MOB_EFFECT.getHolder(ResourceLocation.fromNamespaceAndPath(giveEffect.namespace(), giveEffect.path())).orElse(null);
var type = BuiltInRegistries.MOB_EFFECT.get(ResourceLocation.fromNamespaceAndPath(giveEffect.namespace(), giveEffect.path())).orElse(null);
player.noxesium$addClientsidePotionEffect(
new MobEffectInstance(
type,
Expand All @@ -283,7 +283,7 @@ private void executeBehavior(LocalPlayer player, Entity entity, QibEffect effect
);
}
case QibEffect.RemovePotionEffect removeEffect -> {
player.noxesium$removeClientsidePotionEffect(BuiltInRegistries.MOB_EFFECT.getHolder(ResourceLocation.fromNamespaceAndPath(removeEffect.namespace(), removeEffect.path())).orElse(null));
player.noxesium$removeClientsidePotionEffect(BuiltInRegistries.MOB_EFFECT.get(ResourceLocation.fromNamespaceAndPath(removeEffect.namespace(), removeEffect.path())).orElse(null));
}
case QibEffect.Move move -> {
player.move(MoverType.SELF, new Vec3(move.x(), move.y(), move.z()));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,9 @@
import net.fabricmc.fabric.api.client.rendering.v1.WorldRenderEvents;
import net.minecraft.SharedConstants;
import net.minecraft.client.Minecraft;
import net.minecraft.client.renderer.GameRenderer;
import net.minecraft.client.renderer.LevelRenderer;
import net.minecraft.client.renderer.ShaderInstance;
import net.minecraft.client.renderer.CoreShaders;
import net.minecraft.client.renderer.ShapeRenderer;
import net.minecraft.util.profiling.Profiler;
import org.lwjgl.opengl.GL32;

import java.awt.Color;
Expand Down Expand Up @@ -49,15 +49,15 @@ private void onRenderHook() {

var models = SpatialInteractionEntityTree.getModelContents();

Minecraft.getInstance().getProfiler().push("noxesium-debug");
Profiler.get().push("noxesium-debug");
RenderSystem.disableCull();
RenderSystem.enableBlend();
RenderSystem.enableDepthTest();
RenderSystem.blendFunc(GlStateManager.SourceFactor.SRC_ALPHA, GlStateManager.DestFactor.ONE_MINUS_SRC_ALPHA);
RenderSystem.depthMask(true);

final ShaderInstance oldShader = RenderSystem.getShader();
RenderSystem.setShader(GameRenderer::getRendertypeLinesShader);
final var oldShader = RenderSystem.getShader();
RenderSystem.setShader(CoreShaders.RENDERTYPE_LINES);
RenderSystem.setShaderColor(1.0F, 1.0F, 1.0F, 1.0F);

var vec3 = Minecraft.getInstance().gameRenderer.getMainCamera().getPosition();
Expand All @@ -73,7 +73,7 @@ private void onRenderHook() {
// Start the buffer after setting up the depth settings
var buffer = Tesselator.getInstance().begin(VertexFormat.Mode.LINES, DefaultVertexFormat.POSITION_COLOR_NORMAL);
try {
LevelRenderer.renderLineBox(poseStack, buffer, model, color.getRed() / 255f, color.getGreen() / 255f, color.getBlue() / 255f, 1.0F);
ShapeRenderer.renderLineBox(poseStack, buffer, model, color.getRed() / 255f, color.getGreen() / 255f, color.getBlue() / 255f, 1.0F);
} catch (Exception x) {
// Ignore exceptions from in here
if (SharedConstants.IS_RUNNING_IN_IDE) throw x;
Expand All @@ -86,10 +86,10 @@ private void onRenderHook() {
}

RenderSystem.depthFunc(GL32.GL_LEQUAL);
RenderSystem.setShader(() -> oldShader);
RenderSystem.setShader(oldShader);
RenderSystem.disableBlend();
RenderSystem.enableCull();

Minecraft.getInstance().getProfiler().pop();
Profiler.get().pop();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -107,8 +107,9 @@ public static void rebuild() {

if (NoxesiumMod.getInstance().getConfig().enableQibSystemDebugging) {
if (Minecraft.getInstance().player != null) {
Minecraft.getInstance().player.sendSystemMessage(
Component.literal("§eRebuilt spatial model, before: §f[" + oldStaticEntities + ", " + addedEntities.size() + ", " + removingEntities.size() + "]§e, after: §f[" + staticEntities.size() + ", " + pendingEntities.size() + ", " + removedEntities.size() + "]")
Minecraft.getInstance().getChatListener().handleSystemMessage(
Component.literal("§eRebuilt spatial model, before: §f[" + oldStaticEntities + ", " + addedEntities.size() + ", " + removingEntities.size() + "]§e, after: §f[" + staticEntities.size() + ", " + pendingEntities.size() + ", " + removedEntities.size() + "]"),
false
);
}

Expand Down
Loading

0 comments on commit f55950b

Please sign in to comment.