Skip to content

Commit

Permalink
clean sth.
Browse files Browse the repository at this point in the history
  • Loading branch information
TexBlock committed Feb 4, 2025
1 parent a2f0ffb commit 957a108
Show file tree
Hide file tree
Showing 30 changed files with 294 additions and 88 deletions.
2 changes: 1 addition & 1 deletion gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ loom.platform = neoforge
parchment_mappings=2024.11.17

# Mod Properties
mod_main_version = 0.1.100
mod_main_version = 0.1.1
carpet_version = 1.4.147
maven_group = org.thinkingstudio.sheet
archives_base_name = sheet
4 changes: 2 additions & 2 deletions src/main/java/carpet/CarpetServer.java
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@
import net.minecraft.server.MinecraftServer;
import net.minecraft.server.commands.PerfCommand;
import net.minecraft.server.level.ServerPlayer;
import org.thinkingstudio.sheet.util.NeoHelper;
import org.thinkingstudio.sheet.util.NeoHooks;

@SuppressWarnings("removal")
public class CarpetServer // static for now - easier to handle all around the code, its one anyways
Expand Down Expand Up @@ -142,7 +142,7 @@ public static void registerCarpetCommands(CommandDispatcher<CommandSourceStack>
if (environment != Commands.CommandSelection.DEDICATED)
PerfCommand.register(dispatcher);

if (NeoHelper.isDevelopmentEnvironment())
if (NeoHooks.isDevelopmentEnvironment())
TestCommand.register(dispatcher);
// todo 1.16 - re-registerer apps if that's a reload operation.
}
Expand Down
13 changes: 6 additions & 7 deletions src/main/java/carpet/CarpetSettings.java
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.thinkingstudio.sheet.util.NeoHelper;
import org.thinkingstudio.sheet.util.NeoHooks;
import org.thinkingstudio.sheet.SheetModReference;

import java.util.Optional;
Expand All @@ -50,20 +50,19 @@
@SuppressWarnings({"CanBeFinal", "removal"}) // removal should be removed after migrating rules to the new system
public class CarpetSettings
{
public static final String carpetVersion = NeoHelper.getModContainer(SheetModReference.MODID).orElseThrow().getModInfo().getVersion().toString();
public static final String carpetVersion = NeoHooks.getModContainer(SheetModReference.MODID).orElseThrow().getModInfo().getVersion().toString();
public static final int [] releaseTarget = {
NeoHelper.getModContainer("minecraft").orElseThrow().getModInfo().getVersion().getMajorVersion(),
NeoHelper.getModContainer("minecraft").orElseThrow().getModInfo().getVersion().getIncrementalVersion()
// ((SemanticVersion)FabricLoader.getInstance().getModContainer("minecraft").orElseThrow().getMetadata().getVersion()).getVersionComponent(1),
// ((SemanticVersion)FabricLoader.getInstance().getModContainer("minecraft").orElseThrow().getMetadata().getVersion()).getVersionComponent(2)
NeoHooks.getModContainer("minecraft").orElseThrow().getModInfo().getVersion().getMajorVersion(),
NeoHooks.getModContainer("minecraft").orElseThrow().getModInfo().getVersion().getIncrementalVersion()
};
public static final Logger LOG = LoggerFactory.getLogger(SheetModReference.MODNAME);
public static final ThreadLocal<Boolean> skipGenerationChecks = ThreadLocal.withInitial(() -> false);
public static final ThreadLocal<Boolean> impendingFillSkipUpdates = ThreadLocal.withInitial(() -> false);
public static int runPermissionLevel = 2;
public static Block structureBlockIgnoredBlock = Blocks.STRUCTURE_VOID;
private static class LanguageValidator extends Validator<String> {
@Override public String validate(CommandSourceStack source, CarpetRule<String> currentRule, String newValue, String string) {
@Override
public String validate(CommandSourceStack source, CarpetRule<String> currentRule, String newValue, String string) {
if (!Translations.isValidLanguage(newValue))
{
Messenger.m(source, "r "+newValue+" is not a valid language");
Expand Down
6 changes: 3 additions & 3 deletions src/main/java/carpet/api/settings/SettingsManager.java
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@
import net.minecraft.network.chat.Component;
import net.minecraft.server.MinecraftServer;
import net.minecraft.world.level.storage.LevelResource;
import org.thinkingstudio.sheet.util.NeoHelper;
import org.thinkingstudio.sheet.util.NeoHooks;

import static carpet.utils.Translations.tr;
import static java.util.Comparator.comparing;
Expand Down Expand Up @@ -462,9 +462,9 @@ private ConfigReadResult readSettingsFromConf(Path path)
}
catch (NoSuchFileException e)
{
if (path.equals(getFile()) && NeoHelper.getEnvironmentType().isClient())
if (path.equals(getFile()) && NeoHooks.getEnvironmentType().isClient())
{
Path defaultsPath = NeoHelper.getConfigDir().resolve("carpet/default_"+identifier+".conf");
Path defaultsPath = NeoHooks.getConfigDir().resolve("carpet/default_"+identifier+".conf");
try {
if (Files.notExists(defaultsPath))
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,7 @@ private void onCMDisconnected(DisconnectionDetails reason, CallbackInfo ci)
CarpetClient.disconnect();
}

@Inject(method = "handleCustomPayload(Lnet/minecraft/network/protocol/common/ClientboundCustomPayloadPacket;)V",
at = @At("HEAD"))
@Inject(method = "handleCustomPayload(Lnet/minecraft/network/protocol/common/ClientboundCustomPayloadPacket;)V", at = @At("HEAD"))
private void onOnCustomPayload(ClientboundCustomPayloadPacket packet, CallbackInfo ci)
{
//System.out.println("CustomPayload of : " + packet.payload());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
public abstract class Commands_customCommandsMixin
{

// Use RegisterCommandsEvent with NeoForge
// @Shadow
// @Final
// private CommandDispatcher<CommandSourceStack> dispatcher;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,6 @@ private void packetOutCount(final Packet<?> packet, final PacketSendListener pac
}

@Override
@Accessor //Compat with adventure-platform-fabric
@Accessor //Compat with adventure-platform-mod
public abstract void setChannel(Channel channel);
}
Original file line number Diff line number Diff line change
@@ -1,25 +1,25 @@
package carpet.mixins;

//import carpet.helpers.CarpetTaintedList;
//import carpet.network.CarpetClient;
//import net.minecraft.network.ConnectionProtocol;
//import net.minecraft.network.FriendlyByteBuf;
//import net.minecraft.network.codec.StreamCodec;
//import net.minecraft.network.protocol.PacketFlow;
import carpet.helpers.CarpetTaintedList;
import carpet.network.CarpetClient;
import net.minecraft.network.ConnectionProtocol;
import net.minecraft.network.FriendlyByteBuf;
import net.minecraft.network.codec.StreamCodec;
import net.minecraft.network.protocol.PacketFlow;
import net.minecraft.network.protocol.common.custom.CustomPacketPayload;
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 java.util.List;
import org.spongepowered.asm.mixin.injection.At;
import org.spongepowered.asm.mixin.injection.Inject;
import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable;

@Mixin(value = CustomPacketPayload.class, priority = 9999)
import java.util.List;

@Mixin(CustomPacketPayload.class)
public interface CustomPacketPayload_networkStuffMixin
{
//private static <B extends FriendlyByteBuf> void onCodec(final CustomPacketPayload.FallbackProvider<B> fallbackProvider, final List<CustomPacketPayload.TypeAndCodec<? super B, ?>> list, final CallbackInfoReturnable<StreamCodec<B, CustomPacketPayload>> cir)
// Not working with NeoForge patches, temporarily use RegisterPayloadHandlersEvent
// @Inject(method = "codec(Lnet/minecraft/network/protocol/common/custom/CustomPacketPayload$FallbackProvider;Ljava/util/List;Lnet/minecraft/network/ConnectionProtocol;Lnet/minecraft/network/protocol/PacketFlow;)Lnet/minecraft/network/codec/StreamCodec;", at = @At("HEAD"), cancellable = true)
// private static <B extends FriendlyByteBuf> void onCodec(CustomPacketPayload.FallbackProvider<B> fallbackProvider, List<CustomPacketPayload.TypeAndCodec<? super B, ?>> list, ConnectionProtocol protocol, PacketFlow packetFlow, CallbackInfoReturnable<StreamCodec<B, CustomPacketPayload>> cir)
// private static <B extends FriendlyByteBuf> void onCodec(final CustomPacketPayload.FallbackProvider<B> fallbackProvider, final List<CustomPacketPayload.TypeAndCodec<? super B, ?>> list, final ConnectionProtocol protocol, final PacketFlow packetFlow, final CallbackInfoReturnable<StreamCodec<B, CustomPacketPayload>> cir)
// {
// // this is stupid hack to make sure carpet payloads are always registered
// // that might collide with other mods that do the same thing
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
package carpet.mixins;

import net.minecraft.world.level.block.Blocks;
import org.spongepowered.asm.mixin.Final;
import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.Shadow;
Expand All @@ -18,14 +17,15 @@
import net.minecraft.world.level.Level;
import net.minecraft.world.level.block.piston.PistonStructureResolver;
import net.minecraft.world.level.block.state.BlockState;
import org.thinkingstudio.sheet.util.PistonStructureResolverHooks;

@Mixin(PistonStructureResolver.class)
public class PistonStructureResolver_customStickyMixin {

@Shadow @Final private Level level;
@Shadow @Final private Direction pushDirection;

// NeoForge patched
// NeoForge patched, see PistonStructureResolverHelper
// @Shadow private static boolean canStickToEachOther(BlockState blockState, BlockState blockState2) {
// throw new AssertionError();
// }
Expand Down Expand Up @@ -73,8 +73,7 @@ private boolean onAddBlockLineCanStickToEachOther(BlockState state, BlockState b
return behaviourInterface.isStickyToNeighbor(level, pos_addBlockLine, state, behindPos_addBlockLine, behindState, pushDirection.getOpposite(), pushDirection);
}

return isAdjacentBlockStuck(state, behindState);
//return state.canStickTo(behindState) || behindState.canStickTo(state);
return PistonStructureResolverHooks.isAdjacentBlockStuck(state, behindState);
}

// fields that are needed because @Redirects cannot capture locals
Expand Down Expand Up @@ -107,24 +106,6 @@ private boolean onAddBranchingBlocksCanStickToEachOther(BlockState neighborState
return behaviourInterface.isStickyToNeighbor(level, pos, state, neighborPos_addBranchingBlocks, neighborState, dir_addBranchingBlocks, pushDirection);
}

return isAdjacentBlockStuck(neighborState, state);
//return neighborState.canStickTo(state) && state.canStickTo(neighborState);
}

@Unique
private static boolean isAdjacentBlockStuck(BlockState blockState, BlockState blockState2) {
if (blockState.is(Blocks.HONEY_BLOCK) && blockState2.is(Blocks.SLIME_BLOCK)) {
return false;
} else {
return (!blockState.is(Blocks.SLIME_BLOCK) || !blockState2.is(Blocks.HONEY_BLOCK)) && (isBlockSticky(blockState) || isBlockSticky(blockState2));
}
}

@Unique
private static boolean isBlockSticky(BlockState blockState) {
if (blockState.getBlock() instanceof BlockPistonBehaviourInterface behaviourInterface){
return behaviourInterface.isSticky(blockState);
}
return blockState.is(Blocks.SLIME_BLOCK) || blockState.is(Blocks.HONEY_BLOCK);
return PistonStructureResolverHooks.isAdjacentBlockStuck(neighborState, state);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,11 @@
public class ReloadCommand_reloadAppsMixin {
// method_13530(Lcom/mojang/brigadier/context/CommandContext;)I = lambda$register$3(Lcom/mojang/brigadier/context/CommandContext;)I
// internal of register.
@Inject(method = { "method_13530(Lcom/mojang/brigadier/context/CommandContext;)I", "lambda$register$3(Lcom/mojang/brigadier/context/CommandContext;)I" }, at = @At("TAIL"), remap = false)
// dev & compile use intermediary name, runtime use mojmap name
@Inject(method = {
"method_13530(Lcom/mojang/brigadier/context/CommandContext;)I", // dev & compile
"lambda$register$3(Lcom/mojang/brigadier/context/CommandContext;)I" // runtime
}, at = @At("TAIL"), remap = false)
private static void onReload(CommandContext<CommandSourceStack> context, CallbackInfoReturnable<Integer> cir)
{
// can't fetch here the reference to the server
Expand Down
5 changes: 3 additions & 2 deletions src/main/java/carpet/mixins/ServerLevel_scarpetMixin.java
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package carpet.mixins;

import carpet.fakes.ServerWorldInterface;
import com.llamalad7.mixinextras.sugar.Local;
import net.minecraft.core.BlockPos;
import net.minecraft.core.Holder;
import net.minecraft.core.RegistryAccess;
Expand Down Expand Up @@ -48,15 +49,15 @@ protected ServerLevel_scarpetMixin(WritableLevelData writableLevelData, Resource
super(writableLevelData, resourceKey, registryAccess, holder, supplier, bl, bl2, l, i);
}

@Inject(method = "tickChunk", locals = LocalCapture.CAPTURE_FAILHARD, at = @At(
@Inject(method = "tickChunk", at = @At(
value = "INVOKE",
target = "Lnet/minecraft/server/level/ServerLevel;addFreshEntity(Lnet/minecraft/world/entity/Entity;)Z",
shift = At.Shift.BEFORE,
ordinal = 1
))
private void onNaturalLightinig(LevelChunk chunk, int randomTickSpeed, CallbackInfo ci,
//ChunkPos chunkPos, boolean bl, int i, int j, Profiler profiler, BlockPos blockPos, boolean bl2)
ChunkPos chunkPos, boolean bl, int i, int j, ProfilerFiller profiler, BlockPos blockPos, DifficultyInstance localDifficulty, boolean bl2, LightningBolt lightningEntity)
@Local BlockPos blockPos, @Local(ordinal = 1) boolean bl2)
{
if (LIGHTNING.isNeeded()) LIGHTNING.onWorldEventFlag((ServerLevel) (Object)this, blockPos, bl2?1:0);
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package carpet.mixins;

import carpet.fakes.ServerPlayerInteractionManagerInterface;
import com.llamalad7.mixinextras.sugar.Local;
import net.minecraft.core.BlockPos;
import net.minecraft.server.level.ServerLevel;
import net.minecraft.server.level.ServerPlayer;
Expand Down Expand Up @@ -39,12 +40,12 @@ public class ServerPlayerGameMode_scarpetEventsMixin implements ServerPlayerInte

@Shadow public ServerLevel level;

@Inject(method = "destroyBlock", locals = LocalCapture.CAPTURE_FAILHARD, cancellable = true, at = @At(
@Inject(method = "destroyBlock", cancellable = true, at = @At(
value = "INVOKE",
target = "Lnet/minecraft/server/level/ServerPlayerGameMode;removeBlock(Lnet/minecraft/core/BlockPos;Lnet/minecraft/world/level/block/state/BlockState;Z)Z",
shift = At.Shift.BEFORE
))
private void onBlockBroken(final BlockPos blockPos, final CallbackInfoReturnable<Boolean> cir, final BlockState blockstate1, final BlockEvent.BreakEvent event, final BlockEntity blockentity, final Block block, final BlockState blockState)
private void onBlockBroken(final BlockPos blockPos, final CallbackInfoReturnable<Boolean> cir, @Local(ordinal = 1) final BlockState blockState)
{
if(PLAYER_BREAK_BLOCK.onBlockBroken(player, blockPos, blockState)) {
this.level.sendBlockUpdated(blockPos, blockState, blockState, 3);
Expand Down
14 changes: 7 additions & 7 deletions src/main/java/carpet/script/external/Carpet.java
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@
import org.apache.maven.artifact.versioning.ArtifactVersion;
import org.apache.maven.artifact.versioning.DefaultArtifactVersion;
import org.apache.maven.artifact.versioning.VersionRange;
import org.thinkingstudio.sheet.util.NeoHelper;
import org.thinkingstudio.sheet.util.NeoHooks;

import javax.annotation.Nullable;
import java.io.IOException;
Expand Down Expand Up @@ -149,9 +149,9 @@ public static boolean getFillUpdates()
@Nullable
public static Module fetchGlobalModule(String name, boolean allowLibraries) throws IOException
{
if (NeoHelper.isDevelopmentEnvironment())
if (NeoHooks.isDevelopmentEnvironment())
{
Path globalFolder = NeoHelper.getConfigDir().resolve("carpet/scripts");
Path globalFolder = NeoHooks.getConfigDir().resolve("carpet/scripts");
if (!Files.exists(globalFolder))
{
Files.createDirectories(globalFolder);
Expand All @@ -173,9 +173,9 @@ public static Module fetchGlobalModule(String name, boolean allowLibraries) thro

public static void addGlobalModules(final List<String> moduleNames, boolean includeBuiltIns) throws IOException
{
if (includeBuiltIns && (NeoHelper.getEnvironmentType().isClient()))
if (includeBuiltIns && (NeoHooks.getEnvironmentType().isClient()))
{
Path globalScripts = NeoHelper.getConfigDir().resolve("carpet/scripts");
Path globalScripts = NeoHooks.getConfigDir().resolve("carpet/scripts");
if (!Files.exists(globalScripts))
{
Files.createDirectories(globalScripts);
Expand All @@ -201,11 +201,11 @@ public static void assertRequirementMet(CarpetScriptHost host, String requiredMo
throw new InternalExpressionException("Failed to parse version conditions for '" + requiredModId + "' in 'requires': " + e.getMessage());
}

ModContainer mod = NeoHelper.getModContainer(requiredModId).orElse(null);
ModContainer mod = NeoHooks.getModContainer(requiredModId).orElse(null);
if (mod != null)
{
ArtifactVersion presentVersion = mod.getModInfo().getVersion();
if (range.containsVersion(presentVersion) || (NeoHelper.isDevelopmentEnvironment() && !(presentVersion instanceof DefaultArtifactVersion)))
if (range.containsVersion(presentVersion) || (NeoHooks.isDevelopmentEnvironment() && !(presentVersion instanceof DefaultArtifactVersion)))
{ // in a dev env, mod version is usually replaced with ${version}, and that isn't semantic
return;
}
Expand Down
7 changes: 3 additions & 4 deletions src/main/java/carpet/script/external/Vanilla.java
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@
import carpet.fakes.ServerPlayerInteractionManagerInterface;
import carpet.fakes.ServerWorldInterface;
import carpet.fakes.SpawnHelperInnerInterface;
import carpet.fakes.ThreadedAnvilChunkStorageInterface;
import carpet.mixins.Objective_scarpetMixin;
import carpet.mixins.PoiRecord_scarpetMixin;
import carpet.mixins.Scoreboard_scarpetMixin;
Expand Down Expand Up @@ -84,7 +83,7 @@
import net.minecraft.world.scores.Scoreboard;
import net.minecraft.world.scores.criteria.ObjectiveCriteria;
import net.neoforged.neoforgespi.language.IModInfo;
import org.thinkingstudio.sheet.util.NeoHelper;
import org.thinkingstudio.sheet.util.NeoHooks;

import java.util.Collection;
import java.util.HashMap;
Expand Down Expand Up @@ -192,13 +191,13 @@ public static int MinecraftServer_getRunPermissionLevel(MinecraftServer server)

public static boolean isDevelopmentEnvironment()
{
return NeoHelper.isDevelopmentEnvironment();
return NeoHooks.isDevelopmentEnvironment();
}

public static MapValue getServerMods(MinecraftServer server)
{
Map<Value, Value> ret = new HashMap<>();
for (IModInfo mod : NeoHelper.getAllMods())
for (IModInfo mod : NeoHooks.getAllMods())
{
ret.put(new StringValue(mod.getModId()), new StringValue(mod.getVersion().toString()));
}
Expand Down
5 changes: 2 additions & 3 deletions src/main/java/carpet/utils/CarpetRulePrinter.java
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
import joptsimple.OptionSet;
import joptsimple.OptionSpec;
import joptsimple.util.PathConverter;
import joptsimple.util.PathProperties;
//import net.fabricmc.api.DedicatedServerModInitializer;
//import net.fabricmc.loader.api.FabricLoader;

Expand All @@ -18,7 +17,7 @@

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.thinkingstudio.sheet.util.NeoHelper;
import org.thinkingstudio.sheet.util.NeoHooks;

/**
* Provides a command line interface to generate a dump with all rules
Expand All @@ -30,7 +29,7 @@ public class CarpetRulePrinter /*implements DedicatedServerModInitializer*/ {
public static void onInitializeServer() {
// When launching, we use the "--" separator to prevent the game rejecting to launch because of unknown options
// Clear it in case it's present given else our option parser would also ignore them!
String[] args = Arrays.stream(NeoHelper.getLaunchArguments(true)).filter(opt -> !opt.equals("--")).toArray(String[]::new);
String[] args = Arrays.stream(NeoHooks.getLaunchArguments(true)).filter(opt -> !opt.equals("--")).toArray(String[]::new);

// Prepare an OptionParser for our parameters
OptionParser parser = new OptionParser();
Expand Down
Loading

0 comments on commit 957a108

Please sign in to comment.