Skip to content

Commit

Permalink
utilize loom interface injection
Browse files Browse the repository at this point in the history
  • Loading branch information
SpaceWalkerRS committed Aug 3, 2023
1 parent 60e6dcd commit 4514e5e
Show file tree
Hide file tree
Showing 155 changed files with 794 additions and 723 deletions.
3 changes: 1 addition & 2 deletions src/main/java/carpet/CarpetServer.java
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@
import carpet.commands.PerimeterInfoCommand;
import carpet.commands.PlayerCommand;
import carpet.commands.ProfileCommand;
import carpet.fakes.MinecraftServerInterface;
import carpet.helpers.ServerTickRateManager;
import carpet.script.ScriptCommand;
import carpet.commands.SpawnCommand;
Expand Down Expand Up @@ -119,7 +118,7 @@ public static void onServerLoadedWorlds(MinecraftServer minecraftServer)

public static void tick(MinecraftServer server)
{
ServerTickRateManager trm = ((MinecraftServerInterface)server).getTickRateManager();
ServerTickRateManager trm = server.carpet$getTickRateManager();
trm.tick();
HUDController.update_hud(server, null);
if (scriptServer != null) scriptServer.tick();
Expand Down
3 changes: 1 addition & 2 deletions src/main/java/carpet/commands/PlayerCommand.java
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
import carpet.helpers.EntityPlayerActionPack.Action;
import carpet.helpers.EntityPlayerActionPack.ActionType;
import carpet.CarpetSettings;
import carpet.fakes.ServerPlayerInterface;
import carpet.patches.EntityPlayerMPFake;
import carpet.utils.CommandHelper;
import carpet.utils.Messenger;
Expand Down Expand Up @@ -312,7 +311,7 @@ private static int manipulate(CommandContext<CommandSourceStack> context, Consum
{
if (cantManipulate(context)) return 0;
ServerPlayer player = getPlayer(context);
action.accept(((ServerPlayerInterface) player).getActionPack());
action.accept(player.carpet$getActionPack());
return 1;
}

Expand Down
6 changes: 2 additions & 4 deletions src/main/java/carpet/commands/SpawnCommand.java
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
package carpet.commands;

import carpet.CarpetSettings;
import carpet.fakes.MinecraftServerInterface;
import carpet.fakes.SpawnGroupInterface;
import carpet.helpers.HopperCounter;
import carpet.helpers.ServerTickRateManager;
import carpet.utils.CommandHelper;
Expand Down Expand Up @@ -180,7 +178,7 @@ private static int runTest(CommandSourceStack source, int ticks, String counter)


// tick warp 0
ServerTickRateManager trm = ((MinecraftServerInterface)source.getServer()).getTickRateManager();
ServerTickRateManager trm = source.getServer().carpet$getTickRateManager();
trm.requestGameToWarpSpeed(null, 0, null, null);
// tick warp given player
CommandSourceStack csource = null;
Expand Down Expand Up @@ -240,7 +238,7 @@ private static int setSpawnRates(CommandSourceStack source, String mobtype, int

private static int setMobcaps(CommandSourceStack source, int hostile_cap)
{
double desired_ratio = (double)hostile_cap/ ((SpawnGroupInterface)(Object)MobCategory.MONSTER).getInitialSpawnCap();
double desired_ratio = (double)hostile_cap/ MobCategory.MONSTER.carpet$getInitialSpawnCap();
SpawnReporter.mobcap_exponent = 4.0*Math.log(desired_ratio)/Math.log(2.0);
Messenger.m(source, String.format("gi Mobcaps for hostile mobs changed to %d, other groups will follow", hostile_cap));
return 1;
Expand Down
17 changes: 8 additions & 9 deletions src/main/java/carpet/commands/TickCommand.java
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package carpet.commands;

import carpet.CarpetSettings;
import carpet.fakes.MinecraftServerInterface;
import carpet.helpers.ServerTickRateManager;
import carpet.network.ServerNetworkHandler;
import carpet.utils.CarpetProfiler;
Expand Down Expand Up @@ -73,15 +72,15 @@ public static void register(CommandDispatcher<CommandSourceStack> dispatcher, Co

private static int setTps(CommandSourceStack source, float tps)
{
ServerTickRateManager trm = ((MinecraftServerInterface)source.getServer()).getTickRateManager();
ServerTickRateManager trm = source.getServer().carpet$getTickRateManager();
trm.setTickRate(tps, true);
queryTps(source);
return (int)tps;
}

private static int queryTps(CommandSourceStack source)
{
ServerTickRateManager trm = ((MinecraftServerInterface)source.getServer()).getTickRateManager();
ServerTickRateManager trm = source.getServer().carpet$getTickRateManager();

Messenger.m(source, "w Current tps is: ",String.format("wb %.1f", trm.tickrate()));
return (int) trm.tickrate();
Expand All @@ -90,15 +89,15 @@ private static int queryTps(CommandSourceStack source)
private static int setWarp(CommandSourceStack source, int advance, String tail_command)
{
ServerPlayer player = source.getPlayer(); // may be null
ServerTickRateManager trm = ((MinecraftServerInterface)source.getServer()).getTickRateManager();
ServerTickRateManager trm = source.getServer().carpet$getTickRateManager();
Component message = trm.requestGameToWarpSpeed(player, advance, tail_command, source);
source.sendSuccess(() -> message, false);
return 1;
}

private static int freezeStatus(CommandSourceStack source)
{
ServerTickRateManager trm = ((MinecraftServerInterface)source.getServer()).getTickRateManager();
ServerTickRateManager trm = source.getServer().carpet$getTickRateManager();
if(trm.gameIsPaused())
{
Messenger.m(source, "gi Freeze Status: Game is "+(trm.deeplyFrozen()?"deeply ":"")+"frozen");
Expand All @@ -112,7 +111,7 @@ private static int freezeStatus(CommandSourceStack source)

private static int setFreeze(CommandSourceStack source, boolean isDeep, boolean freeze)
{
ServerTickRateManager trm = ((MinecraftServerInterface)source.getServer()).getTickRateManager();
ServerTickRateManager trm = source.getServer().carpet$getTickRateManager();
trm.setFrozenState(freeze, isDeep);
if (trm.gameIsPaused())
{
Expand All @@ -127,21 +126,21 @@ private static int setFreeze(CommandSourceStack source, boolean isDeep, boolean

private static int toggleFreeze(CommandSourceStack source, boolean isDeep)
{
ServerTickRateManager trm = ((MinecraftServerInterface)source.getServer()).getTickRateManager();
ServerTickRateManager trm = source.getServer().carpet$getTickRateManager();
return setFreeze(source, isDeep, !trm.gameIsPaused());
}

private static int step(CommandSourceStack source, int advance)
{
ServerTickRateManager trm = ((MinecraftServerInterface)source.getServer()).getTickRateManager();
ServerTickRateManager trm = source.getServer().carpet$getTickRateManager();
trm.stepGameIfPaused(advance);
Messenger.m(source, "gi Stepping " + advance + " tick" + (advance != 1 ? "s" : ""));
return 1;
}

private static int toggleSuperHot(CommandSourceStack source)
{
ServerTickRateManager trm = ((MinecraftServerInterface)source.getServer()).getTickRateManager();
ServerTickRateManager trm = source.getServer().carpet$getTickRateManager();
trm.setSuperHot(!trm.isSuperHot());
ServerNetworkHandler.updateSuperHotStateToConnectedPlayers(source.getServer());
if (trm.isSuperHot())
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,9 @@

public interface AbstractContainerMenuInterface
{
DataSlot getDataSlot(int index);
boolean callButtonClickListener(int button, Player player);
boolean callSelectRecipeListener(ServerPlayer player, Recipe<?> recipe, boolean craftAll);
default DataSlot carpet$getDataSlot(int index) { throw new UnsupportedOperationException(); }

default boolean carpet$notifyButtonClickListeners(int button, Player player) { throw new UnsupportedOperationException(); }

default boolean carpet$notifySelectRecipeListeners(ServerPlayer player, Recipe<?> recipe, boolean craftAll) { throw new UnsupportedOperationException(); }
}
8 changes: 8 additions & 0 deletions src/main/java/carpet/fakes/AbstractHorseInterface.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
package carpet.fakes;

import net.minecraft.world.Container;

public interface AbstractHorseInterface
{
default Container carpet$getInventory() { throw new UnsupportedOperationException(); }
}
5 changes: 3 additions & 2 deletions src/main/java/carpet/fakes/BiomeInterface.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import net.minecraft.world.level.biome.Biome;

public interface BiomeInterface {
Biome.ClimateSettings getClimateSettings();
public interface BiomeInterface
{
default Biome.ClimateSettings carpet$getClimateSettings() { throw new UnsupportedOperationException(); }
}
2 changes: 1 addition & 1 deletion src/main/java/carpet/fakes/BlockEntityInterface.java
Original file line number Diff line number Diff line change
Expand Up @@ -4,5 +4,5 @@

public interface BlockEntityInterface
{
void setCMPos(BlockPos pos);
default void carpet$setPos(BlockPos pos) { throw new UnsupportedOperationException(); }
}
8 changes: 8 additions & 0 deletions src/main/java/carpet/fakes/BlockInputInterface.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
package carpet.fakes;

import net.minecraft.nbt.CompoundTag;

public interface BlockInputInterface
{
default CompoundTag carpet$getTag() { throw new UnsupportedOperationException(); }
}
4 changes: 2 additions & 2 deletions src/main/java/carpet/fakes/BlockPistonBehaviourInterface.java
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,10 @@ public interface BlockPistonBehaviourInterface {
/**
* @return whether this block is sticky in any way when moved by pistons
*/
boolean isSticky(BlockState state);
boolean carpet$isSticky(BlockState state);

/**
* @return whether the neighboring block is pulled along if this block is moved by pistons
*/
boolean isStickyToNeighbor(Level level, BlockPos pos, BlockState state, BlockPos neighborPos, BlockState neighborState, Direction dir, Direction moveDir);
boolean carpet$isStickyToNeighbor(Level level, BlockPos pos, BlockState state, BlockPos neighborPos, BlockState neighborState, Direction dir, Direction moveDir);
}
11 changes: 7 additions & 4 deletions src/main/java/carpet/fakes/BlockPredicateInterface.java
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,11 @@

public interface BlockPredicateInterface
{
BlockState getCMBlockState();
TagKey<Block> getCMBlockTagKey();
Map<Value, Value> getCMProperties();
CompoundTag getCMDataTag();
default BlockState carpet$getBlockState() { throw new UnsupportedOperationException(); }

default TagKey<Block> carpet$getTagKey() { throw new UnsupportedOperationException(); }

default Map<Value, Value> carpet$getProperties() { throw new UnsupportedOperationException(); }

default CompoundTag carpet$getDataTag() { throw new UnsupportedOperationException(); }
}
8 changes: 0 additions & 8 deletions src/main/java/carpet/fakes/BlockStateArgumentInterface.java

This file was deleted.

2 changes: 1 addition & 1 deletion src/main/java/carpet/fakes/ChunkHolderInterface.java
Original file line number Diff line number Diff line change
Expand Up @@ -10,5 +10,5 @@

public interface ChunkHolderInterface
{
CompletableFuture<Either<ChunkAccess, ChunkHolder.ChunkLoadingFailure>> setDefaultProtoChunk(ChunkPos chpos, BlockableEventLoop<Runnable> executor, ServerLevel world);
default CompletableFuture<Either<ChunkAccess, ChunkHolder.ChunkLoadingFailure>> carpet$setDefaultProtoChunk(ChunkPos pos, BlockableEventLoop<Runnable> executor, ServerLevel level) { throw new UnsupportedOperationException(); }
}
17 changes: 17 additions & 0 deletions src/main/java/carpet/fakes/ChunkMapInterface.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
package carpet.fakes;

import java.util.List;
import java.util.Map;
import net.minecraft.server.level.ChunkHolder;
import net.minecraft.world.level.ChunkPos;

public interface ChunkMapInterface
{
default Map<String, Integer> carpet$regenerateChunkRegion(List<ChunkPos> requestedChunks) { throw new UnsupportedOperationException(); }

default void carpet$relightChunk(ChunkPos pos) { throw new UnsupportedOperationException(); }

default void carpet$releaseRelightTicket(ChunkPos pos) { throw new UnsupportedOperationException(); }

default Iterable<ChunkHolder> carpet$getChunks() { throw new UnsupportedOperationException(); }
}
16 changes: 0 additions & 16 deletions src/main/java/carpet/fakes/ChunkTicketManagerInterface.java

This file was deleted.

7 changes: 0 additions & 7 deletions src/main/java/carpet/fakes/ClientConnectionInterface.java

This file was deleted.

3 changes: 2 additions & 1 deletion src/main/java/carpet/fakes/CommandDispatcherInterface.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package carpet.fakes;

public interface CommandDispatcherInterface {
public interface CommandDispatcherInterface
{
void carpet$unregister(String node);
}
3 changes: 2 additions & 1 deletion src/main/java/carpet/fakes/CommandNodeInterface.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package carpet.fakes;

public interface CommandNodeInterface {
public interface CommandNodeInterface
{
void carpet$removeChild(String name);
}
8 changes: 8 additions & 0 deletions src/main/java/carpet/fakes/ConnectionInterface.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
package carpet.fakes;

import io.netty.channel.Channel;

public interface ConnectionInterface
{
default void setChannel(Channel channel) { throw new UnsupportedOperationException(); } // compat with adventure-platform-fabric
}
3 changes: 1 addition & 2 deletions src/main/java/carpet/fakes/CoralFeatureInterface.java
Original file line number Diff line number Diff line change
@@ -1,12 +1,11 @@
package carpet.fakes;

import java.util.Random;
import net.minecraft.core.BlockPos;
import net.minecraft.util.RandomSource;
import net.minecraft.world.level.Level;
import net.minecraft.world.level.block.state.BlockState;

public interface CoralFeatureInterface
{
boolean growSpecific(Level worldIn, RandomSource random, BlockPos pos, BlockState blockUnder);
default boolean carpet$growSpecific(Level level, RandomSource random, BlockPos pos, BlockState blockUnder) { throw new UnsupportedOperationException(); }
}
16 changes: 16 additions & 0 deletions src/main/java/carpet/fakes/DistanceManagerInterface.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
package carpet.fakes;

import it.unimi.dsi.fastutil.longs.Long2ObjectOpenHashMap;
import net.minecraft.server.level.ChunkHolder;
import net.minecraft.server.level.Ticket;
import net.minecraft.util.SortedArraySet;
import net.minecraft.world.level.ChunkPos;

public interface DistanceManagerInterface
{
default void carpet$changeSpawnChunks(ChunkPos pos, int distance) { throw new UnsupportedOperationException(); }

default Long2ObjectOpenHashMap<SortedArraySet<Ticket<?>>> carpet$getTicketsByPosition() { throw new UnsupportedOperationException(); }

default void carpet$replaceHolder(ChunkHolder oldHolder, ChunkHolder newHolder) { throw new UnsupportedOperationException(); }
}
16 changes: 8 additions & 8 deletions src/main/java/carpet/fakes/EntityInterface.java
Original file line number Diff line number Diff line change
Expand Up @@ -4,19 +4,19 @@

public interface EntityInterface
{
float getMainYaw(float partialTicks);
default float carpet$getMainYaw(float partialTicks) { throw new UnsupportedOperationException(); }

EntityEventsGroup getEventContainer();
default EntityEventsGroup carpet$getEventContainer() { throw new UnsupportedOperationException(); }

boolean isPermanentVehicle();
default boolean carpet$isPermanentVehicle() { throw new UnsupportedOperationException(); }

void setPermanentVehicle(boolean permanent);
default void carpet$setPermanentVehicle(boolean permanent) { throw new UnsupportedOperationException(); }

int getPortalTimer();
default int carpet$getPortalTimer() { throw new UnsupportedOperationException(); }

void setPortalTimer(int amount);
default void carpet$setPortalTimer(int amount) { throw new UnsupportedOperationException(); }

int getPublicNetherPortalCooldown();
void setPublicNetherPortalCooldown(int what);
default int carpet$getPublicNetherPortalCooldown() { throw new UnsupportedOperationException(); }

default void carpet$setPublicNetherPortalCooldown(int what) { throw new UnsupportedOperationException(); }
}
2 changes: 1 addition & 1 deletion src/main/java/carpet/fakes/IngredientInterface.java
Original file line number Diff line number Diff line change
Expand Up @@ -10,5 +10,5 @@ public interface IngredientInterface
* Gets all the stacks of the ingredients for a given item recipe. Also used for {@link carpet.helpers.HopperCounter#guessColor}
* to guess the colour of an item to display it prettily
*/
List<Collection<ItemStack>> getRecipeStacks();
default List<Collection<ItemStack>> carpet$getRecipeStacks() { throw new UnsupportedOperationException(); }
}
8 changes: 0 additions & 8 deletions src/main/java/carpet/fakes/InventoryBearerInterface.java

This file was deleted.

2 changes: 1 addition & 1 deletion src/main/java/carpet/fakes/ItemEntityInterface.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,5 @@

public interface ItemEntityInterface
{
int getPickupDelayCM();
default int carpet$getPickupDelay() { throw new UnsupportedOperationException(); }
}
10 changes: 10 additions & 0 deletions src/main/java/carpet/fakes/LevelChunkInterface.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
package carpet.fakes;

import net.minecraft.core.BlockPos;
import net.minecraft.world.level.block.entity.BlockEntity;
import net.minecraft.world.level.block.state.BlockState;

public interface LevelChunkInterface
{
default BlockState carpet$setBlockStateWithBlockEntity(BlockPos pos, BlockState state, BlockEntity blockEntity, boolean movedByPiston) { throw new UnsupportedOperationException(); }
}
Loading

0 comments on commit 4514e5e

Please sign in to comment.