Skip to content

Commit

Permalink
Add files via upload
Browse files Browse the repository at this point in the history
  • Loading branch information
RS-256 authored Feb 17, 2024
1 parent 3928728 commit 969cafa
Show file tree
Hide file tree
Showing 24 changed files with 634 additions and 55 deletions.
73 changes: 69 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,20 +4,85 @@ A carpet extension made for [taichi SMP](https://discord.gg/6U6Y8c7HQ2). This in

## Rules

### optimizedFallDamageRaycast
### optimizedDragonRespawn
Optimize dragon respawn method. Ported from carpet AMS addition.
> [!WARNING]
> Couldn’t ensure same behavior as vanilla Minecraft after enabling this rule.
- Type: `boolean`
- Default value: `false`
- Categories: `OPTIMIZATION`, `TAICHI`

### optimizedFallDamageRaycast
Disable fallDamageRaycast while the entity is moving upwards. Ported from chronos carpet by bread, pentasteve.
- Type: `boolean`
- Default value: `false`
- Categories: `OPTIMIZATION`, `TAICHI`

### commandView
Enable /view command to changes the view distance of the server without op.
- Type: `boolean`
- Default value: `false`

`/carpet carpetCommandPermissionLevel` allows other rules to be changed, but this command only allows the viewDistance to be changed.
- Type: `String`
- Default value: `ops`
- Allowed options: `true`, `false`, `ops`, `0`, `1`, `2`, `3`, `4`
- Categories: `SURVIVAL`, `COMMAND`, `TAICHI`

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

`/carpet carpetCommandPermissionLevel` allows other rules to be changed, but this command only allows the simulationDistance to be changed.
- Type: `String`
- Default value: `ops`
- Allowed options: `true`, `false`, `ops`, `0`, `1`, `2`, `3`, `4`
- Categories: `SURVIVAL`, `COMMAND`, `TAICHI`

### commandNotice
Enable /notice command to change notice logger value.
- Type: `String`
- Default value: `ops`
- Allowed options: `true`, `false`, `ops`, `0`, `1`, `2`, `3`, `4`
- Categories: `SURVIVAL`, `COMMAND`, `TAICHI`

### disableNetherPortalCollisionCheck
Disable laggy nether portal collision checks introduced in 1.19.3.
Ported from chronos carpet.
- Type: `boolean`
- Default value: `false`
- Categories: `SURVIVAL`, `COMMAND`, `TAICHI`
- Categories: `OPTIMIZATION`, `TAICHI`

## commands

### view

`/view` : display current simulationDistance

`/view [<distance>]` : change the value of viewDistance in carpet without op

`[<distance>]` : must be between `0` to `32`

### simulation
`/simulation` : display current simulationDistance

`/simulation [<distance>]` : change the value of simulationDistance in carpet without op

`[<distance>]` : must be between `0` to `32`

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

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


## Loggers

### notice
`/log notice`

Simple logger that notice to everyone something running or doing.
To change value, use `/notice`

### autosave
`/log autosave`

Simple logger that display when the server will autosave and how long ago the last autosave was.
This logger does not directly detect autosave, but rather a calculated value based on the time elapsed since the server started, which could be incorrect.
27 changes: 27 additions & 0 deletions src/main/java/AMS/helpers/BlockPatternHelper.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
package AMS.helpers;

import AMS.mixins.BlockPatternTestTransformInvoker;

import com.google.common.cache.LoadingCache;
import net.minecraft.block.pattern.BlockPattern;
import net.minecraft.block.pattern.CachedBlockPosition;
import net.minecraft.util.math.BlockPos;
import net.minecraft.util.math.Direction;
import net.minecraft.world.WorldView;

public class BlockPatternHelper {
public static BlockPattern.Result partialSearchAround(BlockPattern pattern, WorldView world, BlockPos pos) {
LoadingCache<BlockPos, CachedBlockPosition> loadingCache = BlockPattern.makeCache(world, false);
int i = Math.max(Math.max(pattern.getWidth(), pattern.getHeight()), pattern.getDepth());
for (BlockPos blockPos : BlockPos.iterate(pos, pos.add(i - 1, 0, i - 1))) {
for (Direction direction : Direction.values()) {
for (Direction direction2 : Direction.values()) {
BlockPattern.Result result;
if (direction2 == direction || direction2 == direction.getOpposite() || (result = ((BlockPatternTestTransformInvoker)pattern).invokeTestTransform(blockPos, direction, direction2, loadingCache)) == null) continue;
return result;
}
}
}
return null;
}
}
17 changes: 17 additions & 0 deletions src/main/java/AMS/mixins/BlockPatternTestTransformInvoker.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
package AMS.mixins;

import com.google.common.cache.LoadingCache;

import net.minecraft.block.pattern.BlockPattern;
import net.minecraft.block.pattern.CachedBlockPosition;
import net.minecraft.util.math.BlockPos;
import net.minecraft.util.math.Direction;

import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.gen.Invoker;

@Mixin(BlockPattern.class)
public interface BlockPatternTestTransformInvoker {
@Invoker("testTransform")
BlockPattern.Result invokeTestTransform(BlockPos frontTopLeft, Direction forwards, Direction up, LoadingCache<BlockPos, CachedBlockPosition> cache);
}
126 changes: 126 additions & 0 deletions src/main/java/AMS/mixins/EnderDragonFightMixin.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,126 @@
package AMS.mixins;

import net.minecraft.block.entity.BlockEntity;
import net.minecraft.block.entity.EndGatewayBlockEntity;
import net.minecraft.block.entity.EndPortalBlockEntity;
import net.minecraft.block.pattern.BlockPattern;
import net.minecraft.entity.boss.dragon.EnderDragonFight;
import net.minecraft.entity.decoration.EndCrystalEntity;
import net.minecraft.server.world.ServerWorld;
import net.minecraft.util.math.BlockPos;
import net.minecraft.world.Heightmap;
import net.minecraft.world.chunk.WorldChunk;
import net.minecraft.world.gen.feature.EndPortalFeature;

import org.spongepowered.asm.mixin.*;
import org.jetbrains.annotations.Nullable;
import org.spongepowered.asm.mixin.injection.At;
import org.spongepowered.asm.mixin.injection.Inject;
import org.spongepowered.asm.mixin.injection.callback.CallbackInfo;

import taichiCarpet.TaichiCarpetSettings;

import AMS.helpers.BlockPatternHelper;

import java.util.List;

@Mixin(value = EnderDragonFight.class, priority = 888)
public abstract class EnderDragonFightMixin {

@Shadow
@Final
private ServerWorld world;

@Shadow
@Final
private BlockPattern endPortalPattern;

@Nullable
@Shadow
private BlockPos exitPortalLocation;

@Shadow
private boolean doLegacyCheck;

@Unique
private int cacheChunkIteratorX = -8;

@Unique
private int cacheChunkIteratorZ = -8;

@Unique
private int cacheOriginIteratorY = -1;

/**
* @author WenDavid
* @reason Optimize the search of end portal
*/

@Overwrite
private @Nullable BlockPattern.Result findEndPortal() {
int i,j;
if(!TaichiCarpetSettings.optimizedDragonRespawn) {
cacheChunkIteratorX = -8;
cacheChunkIteratorZ = -8;
}
for(i = cacheChunkIteratorX; i <= 8; ++i) {
for(j = cacheChunkIteratorZ; j <= 8; ++j) {
WorldChunk worldChunk = this.world.getChunk(i, j);
for(BlockEntity blockEntity : worldChunk.getBlockEntities().values()) {
if(TaichiCarpetSettings.optimizedDragonRespawn && blockEntity instanceof EndGatewayBlockEntity) continue;
if (blockEntity instanceof EndPortalBlockEntity) {
BlockPattern.Result result = this.endPortalPattern.searchAround(this.world, blockEntity.getPos());
if (result != null) {
BlockPos blockPos = result.translate(3, 3, 3).getBlockPos();
if (this.exitPortalLocation == null) {
this.exitPortalLocation = blockPos;
}
//No need to judge whether optimizing option is open
cacheChunkIteratorX = i;
cacheChunkIteratorZ = j;
return result;
}
}
}
}
}
if(this.doLegacyCheck || this.exitPortalLocation == null){
if(TaichiCarpetSettings.optimizedDragonRespawn && cacheOriginIteratorY != -1) {
i = cacheOriginIteratorY;
}
else {
i = this.world.getTopPosition(Heightmap.Type.MOTION_BLOCKING, EndPortalFeature.offsetOrigin(BlockPos.ORIGIN)).getY();
}
boolean notFirstSearch = false;
for(j = i; j >= 0; --j) {
BlockPattern.Result result2 = null;
if(TaichiCarpetSettings.optimizedDragonRespawn && notFirstSearch) {
result2 = BlockPatternHelper.partialSearchAround(this.endPortalPattern, this.world, new BlockPos(EndPortalFeature.offsetOrigin(BlockPos.ORIGIN).getX(), j, EndPortalFeature.offsetOrigin(BlockPos.ORIGIN).getZ()));
}
else {
result2 = this.endPortalPattern.searchAround(this.world, new BlockPos(EndPortalFeature.offsetOrigin(BlockPos.ORIGIN).getX(), j, EndPortalFeature.offsetOrigin(BlockPos.ORIGIN).getZ()));
}
if (result2 != null) {
if (this.exitPortalLocation == null) {
this.exitPortalLocation = result2.translate(3, 3, 3).getBlockPos();
}
cacheOriginIteratorY = j;
return result2;
}
notFirstSearch = true;
}
}

return null;
}

@Inject(
method = "respawnDragon(Ljava/util/List;)V",
at = @At("HEAD")
)
private void resetCache(List<EndCrystalEntity> crystals, CallbackInfo ci) {
cacheChunkIteratorX = -8;
cacheChunkIteratorZ = -8;
cacheOriginIteratorY = -1;
}
}
23 changes: 23 additions & 0 deletions src/main/java/chronos/mixins/NetherPortalMixin.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
package chronos.mixins;

import net.minecraft.entity.Entity;
import net.minecraft.entity.EntityDimensions;
import net.minecraft.server.world.ServerWorld;
import net.minecraft.util.math.Vec3d;
import net.minecraft.world.dimension.NetherPortal;
import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.injection.At;
import org.spongepowered.asm.mixin.injection.Inject;
import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable;
import taichiCarpet.TaichiCarpetSettings;

@Mixin(NetherPortal.class)
public class NetherPortalMixin {

@Inject(method = "findOpenPosition", at = @At("HEAD"), cancellable = true)
private static void cancelCollisionCheck(Vec3d fallback, ServerWorld world, Entity entity, EntityDimensions dimensions, CallbackInfoReturnable<Vec3d> cir) {
if (TaichiCarpetSettings.disableNetherPortalCollisionCheck) {
cir.setReturnValue(fallback);
}
}
}
21 changes: 16 additions & 5 deletions src/main/java/taichiCarpet/TaichiCarpetExtension.java
Original file line number Diff line number Diff line change
Expand Up @@ -5,15 +5,21 @@
import carpet.api.settings.SettingsManager;

import taichiCarpet.commands.*;
import taichiCarpet.logging.*;
import taichiCarpet.utils.*;

import com.google.common.reflect.TypeToken;
import com.google.gson.Gson;

import com.mojang.brigadier.CommandDispatcher;

import net.fabricmc.api.ModInitializer;

import net.minecraft.command.CommandRegistryAccess;
import net.minecraft.server.MinecraftServer;
import net.minecraft.server.command.ServerCommandSource;
import net.minecraft.server.network.ServerPlayerEntity;

import org.apache.commons.io.IOUtils;

import java.io.IOException;
Expand All @@ -23,10 +29,6 @@

public class TaichiCarpetExtension implements CarpetExtension, ModInitializer {
public static void noop() { }
static
{
CarpetServer.manageExtension(new TaichiCarpetExtension());
}

public static void loadExtension()
{
Expand All @@ -36,7 +38,7 @@ public static void loadExtension()
@Override
public void onGameStarted()
{
CarpetServer.settingsManager.parseSettingsClass(TaichiCarpetSettings.class);;
CarpetServer.settingsManager.parseSettingsClass(TaichiCarpetSettings.class);
}

@Override
Expand All @@ -54,6 +56,7 @@ public void registerCommands(CommandDispatcher<ServerCommandSource> dispatcher,
{
viewCommand.register(dispatcher);
simulationCommand.register(dispatcher);
noticeCommand.register(dispatcher);
}

@Override
Expand All @@ -65,6 +68,7 @@ public SettingsManager extensionSettingsManager()
@Override
public void onPlayerLoggedIn(ServerPlayerEntity player)
{
sendMassage.loginMessageNotifier(player);
}

@Override
Expand All @@ -78,6 +82,13 @@ public void onInitialize() {
TaichiCarpetExtension.loadExtension();
}

@Override
public void registerLoggers() {
taichiLoggerRegistry.registerLoggers();
}



@Override
public Map<String, String> canHasTranslations(String lang) {
InputStream langFile = TaichiCarpetExtension.class.getClassLoader().getResourceAsStream("assets/taichiCarpet/lang/%s.json".formatted(lang));
Expand Down
Loading

0 comments on commit 969cafa

Please sign in to comment.