Skip to content

Commit

Permalink
[new] optimizedFallDamageRaycastOutOfWorld
Browse files Browse the repository at this point in the history
  • Loading branch information
topi-banana committed Apr 23, 2024
1 parent a01fca8 commit 911c588
Show file tree
Hide file tree
Showing 7 changed files with 41 additions and 27 deletions.
9 changes: 9 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,12 @@ Disable fallDamageRaycast while the entity is moving upwards. Ported from chrono
- Default value: `false`
- Categories: `OPTIMIZATION`, `TAICHI`

### optimizedFallDamageRaycastOutOfWorld
...
- Type: `boolean`
- Default value: `false`
- Categories: `OPTIMIZATION`, `TAICHI`

### commandView
Enable /view command to changes the view distance of the server without op.

Expand Down Expand Up @@ -167,9 +173,12 @@ Set packet rate limit TaichiCarpet-Protocol
`/sit` : ...

### notice
`/notice` : send everyone current notice text

`/notice <text>` : change notice logger text

`<text>` : must be string and can be enclosed in `" "` to allow the input of a string including spaces
- `"#None"` or `""`: reset


## Loggers
Expand Down
2 changes: 1 addition & 1 deletion gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ yarn_mappings=1.20.1+build.10
loader_version=0.15.7

# Mod Properties
mod_version = 1.2.4
mod_version = 1.2.5-pre1
maven_group = org.taichiServer
archives_base_name = taichi-carpet

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,6 @@
import net.minecraft.entity.ai.pathing.EntityNavigation;
import net.minecraft.entity.ai.pathing.Path;
import net.minecraft.entity.mob.MobEntity;
import net.minecraft.registry.RegistryKey;
import net.minecraft.world.World;
import org.jetbrains.annotations.Nullable;
import org.spongepowered.asm.mixin.Final;
import org.spongepowered.asm.mixin.Mixin;
Expand All @@ -13,6 +11,7 @@
import org.spongepowered.asm.mixin.injection.Inject;
import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable;
import taichiCarpet.TaichiCarpetSettings;
import taichiCarpet.utils.OutOfWorld;

@Mixin(EntityNavigation.class)
public class EntityNavigationMixin {
Expand All @@ -21,10 +20,6 @@ public class EntityNavigationMixin {
@Shadow
protected MobEntity entity;

@Final
@Shadow
protected World world;

@Inject(method = "startMovingAlong(Lnet/minecraft/entity/ai/pathing/Path;D)Z", at = @At("HEAD"), cancellable = true)
private void startMovingAlong(@Nullable Path path, double speed, CallbackInfoReturnable<Boolean> cir){

Expand All @@ -36,22 +31,8 @@ private void startMovingAlong(@Nullable Path path, double speed, CallbackInfoRet
}

if(TaichiCarpetSettings.disableWanderingOutOfWorld) {
RegistryKey<World> dim = world.getRegistryKey();
if(dim.equals(World.OVERWORLD)){
if( entity.prevY > 319 || entity.prevY < -64 ){
cir.setReturnValue(false);
return;
}
} else if (dim.equals(World.NETHER)){
if( entity.prevY > 255 || entity.prevY < 0 ){
cir.setReturnValue(false);
return;
}
} else if (dim.equals(World.END)){
if( entity.prevY > 255 || entity.prevY < 0 ){
cir.setReturnValue(false);
return;
}
if(OutOfWorld.checker(entity)){
cir.setReturnValue(false);
}
}
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package chronos.mixins;
package taichiCarpet.mixins.optimizedFallDamageRaycast;

import net.minecraft.entity.Entity;
import net.minecraft.util.hit.BlockHitResult;
Expand All @@ -10,13 +10,18 @@
import org.spongepowered.asm.mixin.injection.At;
import org.spongepowered.asm.mixin.injection.Redirect;
import taichiCarpet.TaichiCarpetSettings;
import taichiCarpet.utils.OutOfWorld;

@Mixin(Entity.class)
public class EntityMixin {

@Redirect(method = "move", at = @At(value = "INVOKE", target = "Lnet/minecraft/world/World;raycast(Lnet/minecraft/world/RaycastContext;)Lnet/minecraft/util/hit/BlockHitResult;"))
private BlockHitResult cancelRaycast(World instance, RaycastContext raycastContext) {
if (raycastContext.getStart().y < raycastContext.getEnd().y && TaichiCarpetSettings.optimizedFallDamageRaycast) {
Entity self = (Entity)(Object)this;
if (
( TaichiCarpetSettings.optimizedFallDamageRaycast && raycastContext.getStart().y < raycastContext.getEnd().y ) ||
( TaichiCarpetSettings.optimizedFallDamageRaycastOutOfWorld && OutOfWorld.checker(self) )
) {
return BlockHitResult.createMissed(raycastContext.getEnd(), Direction.getFacing(raycastContext.getStart().x, raycastContext.getStart().y, raycastContext.getStart().z), BlockPos.ofFloored(raycastContext.getEnd()));
} else {
return instance.raycast(raycastContext);
Expand Down
19 changes: 19 additions & 0 deletions src/main/java/taichiCarpet/utils/OutOfWorld.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
package taichiCarpet.utils;

import net.minecraft.entity.Entity;
import net.minecraft.registry.RegistryKey;
import net.minecraft.world.World;

public class OutOfWorld {
public static boolean checker(Entity entity){
RegistryKey<World> dim = entity.getWorld().getRegistryKey();
if(dim.equals(World.OVERWORLD)){
return entity.prevY > 319 || entity.prevY < -64;
} else if (dim.equals(World.NETHER)){
return entity.prevY > 255 || entity.prevY < 0;
} else if (dim.equals(World.END)){
return entity.prevY > 255 || entity.prevY < 0;
}
return false;
}
}
1 change: 0 additions & 1 deletion src/main/resources/chronos.mixins.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
"compatibilityLevel": "JAVA_17",
"mixins": [
"CrashReport_noopMixin",
"EntityMixin",
"NetherPortalMixin"
],
"client": [
Expand Down
3 changes: 2 additions & 1 deletion src/main/resources/taichi.mixins.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,8 @@
"PlayerCommandMixin",
"ServerPlayerEntityMixin",
"disablePushFromAway.EntityMixin",
"disableWandering.EntityNavigationMixin"
"disableWandering.EntityNavigationMixin",
"optimizedFallDamageRaycast.EntityMixin"
],
"client": [
],
Expand Down

0 comments on commit 911c588

Please sign in to comment.