Skip to content
Open
Show file tree
Hide file tree
Changes from all 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
1 change: 1 addition & 0 deletions src/main/java/com/github/alexthe666/citadel/Citadel.java
Original file line number Diff line number Diff line change
Expand Up @@ -151,6 +151,7 @@ public static void registerPayloads(RegisterPayloadHandlersEvent event) {
registrar.playToClient(SyncePathMessage.TYPE, SyncePathMessage.CODEC, SyncePathMessage::handle);
// SyncPathReachedMessage is sent from server to specific player via sendToPlayer
registrar.playToClient(SyncPathReachedMessage.TYPE, SyncPathReachedMessage.CODEC, SyncPathReachedMessage::handle);
registrar.playToClient(SyncClientTickRateMessage.TYPE, SyncClientTickRateMessage.CODEC, SyncClientTickRateMessage::handle);
}

// Registered manually to NeoForge.EVENT_BUS in constructor (not a mod bus event)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ private static void blitWithColor(GuiGraphics guiGraphics, ResourceLocation p_28
private static void blitWithColor(GuiGraphics guiGraphics, ResourceLocation texture, int startX, int endX, int startY, int endY, int zLevel, float u0, float u1, float v0, float v1, int r, int g, int b, int a) {
RenderSystem.setShaderTexture(0, texture);
RenderSystem.setShader(GameRenderer::getPositionTexColorShader);
RenderSystem.setShaderColor(1.0F, 1.0F, 1.0F, 1.0F);
RenderSystem.enableBlend();
Matrix4f matrix4f = guiGraphics.pose().last().pose();
BufferBuilder bufferbuilder = Tesselator.getInstance().begin(VertexFormat.Mode.QUADS, DefaultVertexFormat.POSITION_TEX_COLOR);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -167,17 +167,15 @@ public void drawEntityOnScreen(GuiGraphics guiGraphics, MultiBufferSource buffer
quaternion1.conjugate();
entityrenderdispatcher.overrideCameraOrientation(quaternion1);
entityrenderdispatcher.setRenderShadow(false);
RenderSystem.runAsFancy(() -> entityrenderdispatcher.render(entity, 0.0D, 0.0D, 0.0D, 0.0F, 1.0F, guiGraphics.pose(), bufferSource, 15728880));
RenderSystem.runAsFancy(() -> entityrenderdispatcher.render(entity, 0.0D, 0.0D, 0.0D, 0.0F, 1.0F, guiGraphics.pose(), bufferSource, 240));
entityrenderdispatcher.setRenderShadow(true);
entity.setYRot(0);
entity.setXRot(0);
entity.xRotO = 0;
entity.yRotO = 0;
if (entity instanceof LivingEntity livingEntity) {
livingEntity.yBodyRot = 0;
livingEntity.yBodyRotO = 0;
livingEntity.yHeadRot = 0;
livingEntity.yHeadRotO = 0;
if (entity instanceof LivingEntity) {
((LivingEntity) entity).yBodyRot = 0;
((LivingEntity) entity).yBodyRotO = 0;
((LivingEntity) entity).yHeadRotO = 0;
((LivingEntity) entity).yHeadRot = 0;
}

guiGraphics.flush();
Expand Down Expand Up @@ -270,6 +268,15 @@ protected void renderBlurredBackground(float partialTick) {
// Do nothing - this prevents the blur effect from being applied
}

/**
* Override to disable the menu background that was added in Minecraft 1.21
* Without this override, the book appears darker due to the overlay
*/
@Override
protected void renderMenuBackground(GuiGraphics guiGraphics) {
// Do nothing - this prevents the dark menu background from being rendered
}

@Override
public void render(GuiGraphics guiGraphics, int x, int y, float partialTicks) {
this.mouseX = x;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,19 +29,22 @@ public static void clear(){
}

public static void registerEffect(ResourceLocation resourceLocation) {
Citadel.LOGGER.debug("PostEffectRegistry: registering effect {}", resourceLocation);
registry.add(resourceLocation);
}

public static void onInitializeOutline() {
clear();
Minecraft minecraft = Minecraft.getInstance();
Citadel.LOGGER.debug("PostEffectRegistry: initializing {} effects", registry.size());
for (ResourceLocation resourceLocation : registry) {
PostChain postChain;
RenderTarget renderTarget;
try {
postChain = new PostChain(minecraft.getTextureManager(), minecraft.getResourceManager(), minecraft.getMainRenderTarget(), resourceLocation);
postChain.resize(minecraft.getWindow().getWidth(), minecraft.getWindow().getHeight());
renderTarget = postChain.getTempTarget("final");
Citadel.LOGGER.debug("PostEffectRegistry: loaded shader {} successfully, renderTarget={}", resourceLocation, renderTarget);
} catch (IOException ioexception) {
Citadel.LOGGER.warn("Failed to load shader: {}", resourceLocation, ioexception);
postChain = null;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,22 +10,25 @@
import net.minecraft.world.phys.BlockHitResult;
import net.minecraft.world.phys.HitResult;
import net.minecraft.world.phys.Vec3;
import org.jetbrains.annotations.NotNull;

public class CustomCollisionsNavigator extends GroundPathNavigation {

public CustomCollisionsNavigator(Mob mob, Level world) {
super(mob, world);
}

@Override
protected PathFinder createPathFinder(int i) {
this.nodeEvaluator = new CustomCollisionsNodeProcessor();
return new PathFinder(this.nodeEvaluator, i);
}

public static boolean isClearForMovementBetweenRespectCustomCollisions(Mob mob, Vec3 pos1, Vec3 pos2, boolean allowSwimming) {
@Override
protected boolean canMoveDirectly(@NotNull Vec3 pos1, @NotNull Vec3 pos2) {
Vec3 vec3 = new Vec3(pos2.x, pos2.y + (double)mob.getBbHeight() * 0.5, pos2.z);
BlockHitResult hitResult = mob.level()
.clip(new ClipContext(pos1, vec3, ClipContext.Block.COLLIDER, allowSwimming ? ClipContext.Fluid.ANY : ClipContext.Fluid.NONE, mob));
.clip(new ClipContext(pos1, vec3, ClipContext.Block.COLLIDER, ClipContext.Fluid.NONE, mob));
if(hitResult.getType() == HitResult.Type.MISS){
return true;
}else{
Expand All @@ -34,10 +37,4 @@ public static boolean isClearForMovementBetweenRespectCustomCollisions(Mob mob,
return mob instanceof ICustomCollisions customCollisions && customCollisions.canPassThrough(hitPos, state, state.getCollisionShape(mob.level(), hitPos));
}
}

@Override
protected boolean canMoveDirectly(Vec3 pos1, Vec3 pos2) {
return isClearForMovementBetweenRespectCustomCollisions(this.mob, pos1, pos2, false);
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -5,17 +5,17 @@
import net.minecraft.world.level.pathfinder.PathType;
import net.minecraft.world.level.pathfinder.PathfindingContext;
import net.minecraft.world.level.pathfinder.WalkNodeEvaluator;
import org.jetbrains.annotations.NotNull;

public class CustomCollisionsNodeProcessor extends WalkNodeEvaluator {

public CustomCollisionsNodeProcessor() {
}


@Override
public PathType getPathType(PathfindingContext context, int x, int y, int z) {
BlockPos.MutableBlockPos blockpos$mutableblockpos = new BlockPos.MutableBlockPos();
BlockState state = context.getBlockState(blockpos$mutableblockpos.set(x, y, z));
public @NotNull PathType getPathType(@NotNull PathfindingContext context, int x, int y, int z) {
BlockPos.MutableBlockPos blockpos$mutableblockpos = new BlockPos.MutableBlockPos(x, y, z);
BlockState state = context.getBlockState(blockpos$mutableblockpos);
if (((ICustomCollisions) this.mob).canPassThrough(blockpos$mutableblockpos, state, state.getBlockSupportShape(context.level(), blockpos$mutableblockpos))) {
return PathType.OPEN;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -82,8 +82,11 @@ public void tick() {

private boolean isWalkable(float p_234024_1_, float p_234024_2_) {
PathNavigation pathnavigator = this.mob.getNavigation();
NodeEvaluator nodeprocessor = pathnavigator.getNodeEvaluator();
return nodeprocessor.getPathType(this.mob, BlockPos.containing(this.mob.getX() + (double) p_234024_1_, this.mob.getY(), this.mob.getZ() + (double) p_234024_2_)) == PathType.WALKABLE;
if (pathnavigator != null) {
NodeEvaluator nodeprocessor = pathnavigator.getNodeEvaluator();
return nodeprocessor == null || nodeprocessor.getPathType(this.mob, BlockPos.containing(this.mob.getX() + (double) p_234024_1_, this.mob.getY(), this.mob.getZ() + (double) p_234024_2_)) == PathType.WALKABLE;
}

return true;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -422,9 +422,90 @@ protected boolean canUpdatePath() {
return this.ourEntity.position();
}

/**
* Creates a path to the given BlockPos synchronously.
* This method is called by vanilla AI goals like MeleeAttackGoal.
* It uses the same pathfinding algorithm as the async system but runs synchronously.
*
* @param pos The target position
* @param accuracy The accuracy/distance tolerance for reaching the target
* @return A Path to the target, or null if no path could be found
*/
@Override
public Path createPath(final @NotNull BlockPos pos, final int accuracy) {
return null;
return createPathInternal(pos, accuracy);
}

/**
* Creates a path to the given Entity synchronously.
* This method is called by vanilla AI goals like MeleeAttackGoal.
*
* @param entity The target entity
* @param accuracy The accuracy/distance tolerance for reaching the target
* @return A Path to the entity, or null if no path could be found
*/
@Override
@Nullable
public Path createPath(final @NotNull Entity entity, final int accuracy) {
return createPathInternal(entity.blockPosition(), accuracy);
}

/**
* Internal method that performs synchronous pathfinding.
* Uses the Citadel advanced pathfinding algorithm for consistent behavior
* with the async pathfinding system.
*
* @param targetPos The target position to path to
* @param accuracy The accuracy/distance tolerance
* @return A Path to the target, or null if no path could be found
*/
@Nullable
private Path createPathInternal(final BlockPos targetPos, final int accuracy) {
// Quick validation checks
if (targetPos == null) {
return null;
}

// Check if entity is in a valid state for pathfinding
if (this.ourEntity.getY() < (double) level.getMinBuildHeight()) {
return null;
}

if (!this.canUpdatePath()) {
return null;
}

// Check if chunks are loaded
if (!level.isLoaded(targetPos)) {
return null;
}

// Prepare the start position
final BlockPos start = AbstractPathJob.prepareStart(ourEntity);

// Calculate the search range based on follow range and accuracy
final int followRange = (int) ourEntity.getAttributeValue(Attributes.FOLLOW_RANGE);
final int searchRange = Math.max(followRange, (int) Math.sqrt(start.distSqr(targetPos)) + 16);

try {
// Create a synchronous path job using Citadel's advanced pathfinding
final PathJobMoveToLocation pathJob = new PathJobMoveToLocation(
level,
start,
targetPos,
searchRange,
ourEntity
);

// Apply the same pathing options as async pathfinding
pathJob.setPathingOptions(getPathingOptions());

// Execute the pathfinding synchronously by calling the job directly
return pathJob.call();
} catch (final Exception e) {
Citadel.LOGGER.debug("Synchronous pathfinding failed for entity {}: {}", ourEntity, e.getMessage());
return null;
}
}

@Override
Expand Down
4 changes: 3 additions & 1 deletion src/main/resources/META-INF/accesstransformer.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -8,4 +8,6 @@ public net.minecraft.server.level.ChunkMap getVisibleChunkIfPresent(J)Lnet/minec
public-f net.minecraft.client.renderer.RenderStateShard setupState #setupState
public-f net.minecraft.client.DeltaTracker$Timer msPerTick #msPerTick
public net.minecraft.client.gui.screens.ConfirmScreen callback #callback
public net.minecraft.client.gui.screens.BackupConfirmScreen onProceed #onProceed
public net.minecraft.client.gui.screens.BackupConfirmScreen onProceed #onProceed
# Make Entity.collide() public so ICustomCollisions entities can override it
public net.minecraft.world.entity.Entity collide(Lnet/minecraft/world/phys/Vec3;)Lnet/minecraft/world/phys/Vec3; # collide
14 changes: 0 additions & 14 deletions src/main/resources/assets/citadel/shaders/program/blit.fsh

This file was deleted.

30 changes: 0 additions & 30 deletions src/main/resources/assets/citadel/shaders/program/blit.json

This file was deleted.

15 changes: 0 additions & 15 deletions src/main/resources/assets/citadel/shaders/program/blit.vsh

This file was deleted.

25 changes: 12 additions & 13 deletions src/main/resources/assets/citadel/shaders/program/blur.fsh
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ in vec2 texCoord;
in vec2 oneTexel;

uniform vec2 InSize;
uniform vec2 OutSize;

uniform vec2 BlurDir;
uniform float Radius;

Expand All @@ -17,18 +17,17 @@ void main() {
float totalStrength = 0.0;
float totalAlpha = 0.0;
float totalSamples = 0.0;
float rad = Radius;

for(float r = -rad; r <= rad; r += 1.0) {
for(float r = -Radius; r <= Radius; r += 1.0) {
vec4 sampleValue = texture(DiffuseSampler, texCoord + oneTexel * r * BlurDir);

// Gaussian weighting
float strength = 1.0 - abs(r / rad);
totalStrength += strength;
blurred.rgb += sampleValue.rgb * strength;
totalAlpha += sampleValue.a;
totalSamples += 1.0;
}

fragColor = vec4(blurred.rgb / totalStrength, totalAlpha / totalSamples);
// Accumulate average alpha
totalAlpha = totalAlpha + sampleValue.a;
totalSamples = totalSamples + 1.0;

// Accumulate smoothed blur
float strength = 1.0 - abs(r / Radius);
totalStrength = totalStrength + strength;
blurred = blurred + sampleValue;
}
fragColor = vec4(blurred.rgb / (Radius * 2.0 + 1.0), totalAlpha);
}
Loading