Skip to content
Merged
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
26 changes: 26 additions & 0 deletions checkstyle.xml
Original file line number Diff line number Diff line change
Expand Up @@ -284,6 +284,32 @@
<message key="matchxpath.match" value="Inject local capture is not allowed, use @Local instead"/>
</module>

<!-- Prevent ordinal usage in @Local annotations on method parameters -->
<module name="MatchXpath">
<property name="query" value="
//PARAMETER_DEF/MODIFIERS/ANNOTATION[
./IDENT[@text='Local']
and
./ANNOTATION_MEMBER_VALUE_PAIR/IDENT[@text='ordinal']
]
"/>
<message key="matchxpath.match" value="ordinal is not allowed in @Local annotations on method parameters"/>
</module>

<!-- Prevent specifying name and argsOnly in @Local annotations on method parameters -->
<module name="MatchXpath">
<property name="query" value="
//PARAMETER_DEF/MODIFIERS/ANNOTATION[
./IDENT[@text='Local']
and
./ANNOTATION_MEMBER_VALUE_PAIR/IDENT[@text='name']
and
./ANNOTATION_MEMBER_VALUE_PAIR/IDENT[@text='argsOnly']
]
"/>
<message key="matchxpath.match" value="name and argsOnly cannot both be specified in @Local, perfer argsOnly"/>
</module>

<module name="MatchXpath">
<property name="query" value="//LITERAL_ASSERT"/>
<message key="matchxpath.match" value="Avoid using 'assert'."/>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ abstract class LivingEntityMixin {
allow = 1,
cancellable = true
)
private void allowTaggedBlocksForTrapdoorClimbing(BlockPos pos, BlockState state, CallbackInfoReturnable<Boolean> info, @Local(ordinal = 1) BlockState belowState) {
private void allowTaggedBlocksForTrapdoorClimbing(BlockPos pos, BlockState state, CallbackInfoReturnable<Boolean> info, @Local(name = "belowState") BlockState belowState) {
if (belowState.is(BlockFunctionalityTags.CAN_CLIMB_TRAPDOOR_ABOVE)) {
if (belowState.getBlock() instanceof LadderBlock) {
// Check that the ladder and trapdoor are placed in the same direction.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ public abstract class RenderRegionCacheMixin {
private static final Logger LOGGER = LoggerFactory.getLogger(RenderRegionCacheMixin.class);

@Inject(method = "createRegion", at = @At(value = "INVOKE", target = "Lnet/minecraft/client/renderer/chunk/RenderRegionCache;getSectionDataCopy(Lnet/minecraft/world/level/Level;III)Lnet/minecraft/client/renderer/chunk/SectionCopy;"))
private void copyDataForChunk(Level level, long packedChunkPos, CallbackInfoReturnable<RenderSectionRegion> cir, @Share("dataMap") LocalRef<Long2ObjectOpenHashMap<Object>> mapRef, @Local(ordinal = 11) int x, @Local(ordinal = 10) int y, @Local(ordinal = 9) int z) {
private void copyDataForChunk(Level level, long packedChunkPos, CallbackInfoReturnable<RenderSectionRegion> cir, @Share("dataMap") LocalRef<Long2ObjectOpenHashMap<Object>> mapRef, @Local(name = "regionSectionX") int regionSectionX, @Local(name = "regionSectionY") int regionSectionY, @Local(name = "regionSectionZ") int regionSectionZ) {
// Hash maps in chunks should generally not be modified outside of client thread
// but does happen in practice, due to mods or inconsistent vanilla behaviors, causing
// CMEs when we iterate the map. (Vanilla does not iterate these maps when it builds
Expand All @@ -59,7 +59,7 @@ private void copyDataForChunk(Level level, long packedChunkPos, CallbackInfoRetu
// We handle this simply by retrying until it works. Ugly but effective.
while (true) {
try {
mapRef.set(mapChunk(level.getChunk(x, z), SectionPos.of(packedChunkPos), mapRef.get()));
mapRef.set(mapChunk(level.getChunk(regionSectionX, regionSectionZ), SectionPos.of(packedChunkPos), mapRef.get()));
break;
} catch (ConcurrentModificationException e) {
final int count = ERROR_COUNTER.incrementAndGet();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,9 +38,9 @@
@Mixin(CreateWorldScreen.class)
public class CreateWorldScreenMixin {
@Inject(method = "onCreate", at = @At(value = "INVOKE", target = "Lnet/minecraft/client/gui/screens/worldselection/WorldOpenFlows;confirmWorldCreation(Lnet/minecraft/client/Minecraft;Lnet/minecraft/client/gui/screens/worldselection/CreateWorldScreen;Lcom/mojang/serialization/Lifecycle;Ljava/lang/Runnable;Z)V"), cancellable = true)
private void createLevelDataForServers(CallbackInfo ci, @Local LayeredRegistryAccess<RegistryLayer> registries, @Local PrimaryLevelData levelData) {
private void createLevelDataForServers(CallbackInfo ci, @Local(name = "finalLayers") LayeredRegistryAccess<RegistryLayer> finalLayers, @Local(name = "worldData") PrimaryLevelData worldData) {
if (DedicatedServerImplUtil.saveLevelDataTo != null) {
CompoundTag levelDatInner = levelData.createTag(registries.compositeAccess(), null);
CompoundTag levelDatInner = worldData.createTag(finalLayers.compositeAccess(), null);
CompoundTag levelDat = new CompoundTag();
levelDat.put("Data", levelDatInner);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ public abstract class PathfindingContextMixin {
* Overrides the node type for the specified position, if the position is found as neighbor block in a path.
*/
@Inject(method = "getPathTypeFromState", at = @At(value = "INVOKE_ASSIGN", target = "Lnet/minecraft/core/BlockPos$MutableBlockPos;set(III)Lnet/minecraft/core/BlockPos$MutableBlockPos;"), cancellable = true)
private void onGetNodeType(int x, int y, int z, CallbackInfoReturnable<PathType> cir, @Local BlockPos pos) {
private void onGetNodeType(int x, int y, int z, CallbackInfoReturnable<PathType> cir, @Local(name = "pos") BlockPos pos) {
final PathType neighborPathType = LandPathTypeRegistry.getPathType(getBlockState(pos), level(), pos, true);

if (neighborPathType != null) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,8 +37,8 @@ public class WalkNodeEvaluatorMixin {
* Overrides the node type for the specified position, if the position is a direct target in a path.
*/
@Inject(method = "getPathTypeFromState", at = @At(value = "INVOKE", target = "Lnet/minecraft/world/level/block/state/BlockState;getBlock()Lnet/minecraft/world/level/block/Block;"), cancellable = true)
private static void getCommonNodeType(BlockGetter level, BlockPos pos, CallbackInfoReturnable<PathType> cir, @Local BlockState state) {
PathType pathType = LandPathTypeRegistry.getPathType(state, level, pos, false);
private static void getCommonNodeType(BlockGetter level, BlockPos pos, CallbackInfoReturnable<PathType> cir, @Local(name = "blockState") BlockState blockState) {
PathType pathType = LandPathTypeRegistry.getPathType(blockState, level, pos, false);

if (pathType != null) {
cir.setReturnValue(pathType);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ abstract class ClientPacketListenerMixin {
from = @At(value = "INVOKE", target = "Lnet/minecraft/client/multiplayer/ClientPacketListener;startWaitingForNewLevel(Lnet/minecraft/client/player/LocalPlayer;Lnet/minecraft/client/multiplayer/ClientLevel;Lnet/minecraft/client/gui/screens/LevelLoadingScreen$Reason;)V")
)
)
private void copyAttachmentsOnClientRespawn(Minecraft client, LocalPlayer newPlayer, Operation<Void> init, ClientboundRespawnPacket packet, @Local(ordinal = 0) LocalPlayer oldPlayer) {
private void copyAttachmentsOnClientRespawn(Minecraft client, LocalPlayer newPlayer, Operation<Void> init, ClientboundRespawnPacket packet, @Local(name = "oldPlayer") LocalPlayer oldPlayer) {
/*
* The KEEP_ATTRIBUTES flag is not set on a death respawn, and set in all other cases
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -73,10 +73,10 @@ private void registerItemModels(ItemModelGenerators instance, Operation<Void> or

@Inject(method = "run", at = @At(value = "INVOKE", target = "Lnet/minecraft/client/data/models/BlockModelGenerators;run()V"))
private void setFabricPackOutput(CachedOutput output, CallbackInfoReturnable<CompletableFuture<?>> cir,
@Local ModelProvider.BlockStateGeneratorCollector blockStateGeneratorCollector,
@Local ModelProvider.ItemInfoCollector itemInfoCollectors) {
((FabricModelProviderDefinitions) blockStateGeneratorCollector).setFabricPackOutput(fabricPackOutput);
((FabricModelProviderDefinitions) itemInfoCollectors).setFabricPackOutput(fabricPackOutput);
((FabricItemAssetDefinitions) itemInfoCollectors).fabric_setProcessedBlocks(blockStateGeneratorCollector.generators.keySet());
@Local(name = "blockStateGenerators") ModelProvider.BlockStateGeneratorCollector blockStateGenerators,
@Local(name = "itemModels") ModelProvider.ItemInfoCollector itemModels) {
((FabricModelProviderDefinitions) blockStateGenerators).setFabricPackOutput(fabricPackOutput);
((FabricModelProviderDefinitions) itemModels).setFabricPackOutput(fabricPackOutput);
((FabricItemAssetDefinitions) itemModels).fabric_setProcessedBlocks(blockStateGenerators.generators.keySet());
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -58,8 +58,8 @@ private void initPathResolver(PackOutput output, ResourceKey<? extends Registry<
}

@ModifyArg(method = "lambda$run$5", at = @At(value = "INVOKE", target = "Lnet/minecraft/tags/TagFile;<init>(Ljava/util/List;Z)V"), index = 1)
private boolean addReplaced(boolean replaced, @Local TagBuilder tagBuilder) {
if (tagBuilder instanceof FabricTagBuilder fabricTagBuilder) {
private boolean addReplaced(boolean replaced, @Local(name = "builder") TagBuilder builder) {
if (builder instanceof FabricTagBuilder fabricTagBuilder) {
return fabricTagBuilder.fabric_isReplaced();
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@
TransmuteRecipeBuilder.class,
})
abstract class AllCraftingRecipeJsonBuildersMixin {
@ModifyVariable(method = "save(Lnet/minecraft/data/recipes/RecipeOutput;Lnet/minecraft/resources/ResourceKey;)V", at = @At("HEAD"), argsOnly = true)
@ModifyVariable(method = "save(Lnet/minecraft/data/recipes/RecipeOutput;Lnet/minecraft/resources/ResourceKey;)V", at = @At("HEAD"), argsOnly = true, name = "id")
private ResourceKey<Recipe<?>> modifyRecipeKey(ResourceKey<Recipe<?>> recipeKey, RecipeOutput output) {
return ResourceKey.create(recipeKey.registryKey(), output.getRecipeIdentifier(recipeKey.identifier()));
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@

@Mixin(SmithingTransformRecipeBuilder.class)
abstract class SmithingTransformRecipeBuilderMixin {
@ModifyVariable(method = "save(Lnet/minecraft/data/recipes/RecipeOutput;Lnet/minecraft/resources/ResourceKey;)V", at = @At("HEAD"), argsOnly = true)
@ModifyVariable(method = "save(Lnet/minecraft/data/recipes/RecipeOutput;Lnet/minecraft/resources/ResourceKey;)V", at = @At("HEAD"), argsOnly = true, name = "id")
private ResourceKey<Recipe<?>> modifyRecipeKey(ResourceKey<Recipe<?>> recipeKey, RecipeOutput output) {
return ResourceKey.create(recipeKey.registryKey(), output.getRecipeIdentifier(recipeKey.identifier()));
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@

@Mixin(SmithingTrimRecipeBuilder.class)
abstract class SmithingTrimRecipeBuilderMixin {
@ModifyVariable(method = "save(Lnet/minecraft/data/recipes/RecipeOutput;Lnet/minecraft/resources/ResourceKey;)V", at = @At("HEAD"), argsOnly = true)
@ModifyVariable(method = "save(Lnet/minecraft/data/recipes/RecipeOutput;Lnet/minecraft/resources/ResourceKey;)V", at = @At("HEAD"), argsOnly = true, name = "id")
private ResourceKey<Recipe<?>> modifyRecipeKey(ResourceKey<Recipe<?>> recipeKey, RecipeOutput output) {
return ResourceKey.create(recipeKey.registryKey(), output.getRecipeIdentifier(recipeKey.identifier()));
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@

@Mixin(SpecialRecipeBuilder.class)
abstract class SpecialRecipeBuilderMixin {
@ModifyVariable(method = "save(Lnet/minecraft/data/recipes/RecipeOutput;Lnet/minecraft/resources/ResourceKey;)V", at = @At("HEAD"), argsOnly = true)
@ModifyVariable(method = "save(Lnet/minecraft/data/recipes/RecipeOutput;Lnet/minecraft/resources/ResourceKey;)V", at = @At("HEAD"), argsOnly = true, name = "id")
private ResourceKey<Recipe<?>> modifyRecipeKey(ResourceKey<Recipe<?>> recipeKey, RecipeOutput output) {
return ResourceKey.create(recipeKey.registryKey(), output.getRecipeIdentifier(recipeKey.identifier()));
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -85,9 +85,9 @@ private void beforeDamage(ServerLevel level, DamageSource source, float amount,
}

@Inject(method = "hurtServer", at = @At("TAIL"))
private void afterDamage(ServerLevel level, DamageSource source, float amount, CallbackInfoReturnable<Boolean> cir, @Local(ordinal = 1) float dealt, @Local(ordinal = 0) boolean blocked) {
private void afterDamage(ServerLevel level, DamageSource source, float amount, CallbackInfoReturnable<Boolean> cir, @Local(name = "originalDamage") float originalDamage, @Local(name = "blocked") boolean blocked) {
if (!isDeadOrDying()) {
ServerLivingEntityEvents.AFTER_DAMAGE.invoker().afterDamage((LivingEntity) (Object) this, source, dealt, amount, blocked);
ServerLivingEntityEvents.AFTER_DAMAGE.invoker().afterDamage((LivingEntity) (Object) this, source, originalDamage, amount, blocked);
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -179,13 +179,13 @@ private void beforeRemoveEffect(Holder<MobEffect> holder, CallbackInfoReturnable
target = "Ljava/util/Iterator;remove()V"
)
)
private void beforeExpireRemoveEffect(CallbackInfo ci, @Local MobEffectInstance effectInstance) {
private void beforeExpireRemoveEffect(CallbackInfo ci, @Local(name = "effect") MobEffectInstance effect) {
if (this.isClient()) {
return;
}

ServerMobEffectEvents.BEFORE_REMOVE.invoker()
.beforeRemove(effectInstance, this.self(), MobEffectUtil.getCommandContext());
.beforeRemove(effect, this.self(), MobEffectUtil.getCommandContext());
}

@Inject(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ public abstract class MinecraftMixin {
method = "startUseItem",
cancellable = true
)
private void injectUseEntityCallback(CallbackInfo ci, @Local InteractionHand hand, @Local EntityHitResult hitResult, @Local Entity entity) {
private void injectUseEntityCallback(CallbackInfo ci, @Local(name = "hand") InteractionHand hand, @Local(name = "entityHit") EntityHitResult hitResult, @Local(name = "entity") Entity entity) {
InteractionResult result = UseEntityCallback.EVENT.invoker().interact(player, player.level(), hand, entity, hitResult);

if (result != InteractionResult.PASS) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -91,8 +91,8 @@ private void fabric_fireAttackBlockCallback(BlockPos pos, Direction direction, C
}

@Inject(method = "destroyBlock", at = @At(value = "INVOKE", target = "Lnet/minecraft/world/level/block/Block;destroy(Lnet/minecraft/world/level/LevelAccessor;Lnet/minecraft/core/BlockPos;Lnet/minecraft/world/level/block/state/BlockState;)V"))
private void fabric$onBlockBroken(BlockPos pos, CallbackInfoReturnable<Boolean> cir, @Local BlockState blockState) {
ClientPlayerBlockBreakEvents.AFTER.invoker().afterBlockBreak(minecraft.level, minecraft.player, pos, blockState);
private void fabric$onBlockBroken(BlockPos pos, CallbackInfoReturnable<Boolean> cir, @Local(name = "oldState") BlockState oldState) {
ClientPlayerBlockBreakEvents.AFTER.invoker().afterBlockBreak(minecraft.level, minecraft.player, pos, oldState);
}

@Inject(at = @At(value = "INVOKE", target = "Lnet/minecraft/client/multiplayer/MultiPlayerGameMode;startPrediction(Lnet/minecraft/client/multiplayer/ClientLevel;Lnet/minecraft/client/multiplayer/prediction/PredictiveAction;)V"), method = "useItemOn", cancellable = true)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -80,8 +80,8 @@ public ItemStack onPickItemFromEntity(Entity entity, Operation<ItemStack> operat
return ItemStack.EMPTY;
}

@Inject(method = "handleInteract", at = @At(value = "INVOKE", target = "Lnet/minecraft/server/level/ServerPlayer;getItemInHand(Lnet/minecraft/world/InteractionHand;)Lnet/minecraft/world/item/ItemStack;"))
public void handleInteract(ServerboundInteractPacket packet, CallbackInfo info, @Local Entity target) {
@Inject(method = "handleInteract", at = @At(value = "INVOKE", target = "Lnet/minecraft/server/level/ServerPlayer;getItemInHand(Lnet/minecraft/world/InteractionHand;)Lnet/minecraft/world/item/ItemStack;"), cancellable = true)
public void handleInteract(ServerboundInteractPacket packet, CallbackInfo info, @Local(name = "target") Entity target) {
Level level = player.level();

EntityHitResult hitResult = new EntityHitResult(target, packet.location().add(target.getX(), target.getY(), target.getZ()));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -104,18 +104,18 @@ public void interactItem(ServerPlayer player, Level level, ItemStack stack, Inte
}

@Inject(at = @At(value = "INVOKE", target = "Lnet/minecraft/world/level/block/Block;playerWillDestroy(Lnet/minecraft/world/level/Level;Lnet/minecraft/core/BlockPos;Lnet/minecraft/world/level/block/state/BlockState;Lnet/minecraft/world/entity/player/Player;)Lnet/minecraft/world/level/block/state/BlockState;"), method = "destroyBlock", cancellable = true)
private void breakBlock(BlockPos pos, CallbackInfoReturnable<Boolean> cir, @Local BlockEntity entity, @Local BlockState state) {
boolean result = PlayerBlockBreakEvents.BEFORE.invoker().beforeBlockBreak(this.level, this.player, pos, state, entity);
private void breakBlock(BlockPos pos, CallbackInfoReturnable<Boolean> cir, @Local(name = "blockEntity") BlockEntity blockEntity, @Local(name = "state") BlockState state) {
boolean result = PlayerBlockBreakEvents.BEFORE.invoker().beforeBlockBreak(this.level, this.player, pos, state, blockEntity);

if (!result) {
PlayerBlockBreakEvents.CANCELED.invoker().onBlockBreakCanceled(this.level, this.player, pos, state, entity);
PlayerBlockBreakEvents.CANCELED.invoker().onBlockBreakCanceled(this.level, this.player, pos, state, blockEntity);

cir.setReturnValue(false);
}
}

@Inject(at = @At(value = "INVOKE", target = "Lnet/minecraft/world/level/block/Block;destroy(Lnet/minecraft/world/level/LevelAccessor;Lnet/minecraft/core/BlockPos;Lnet/minecraft/world/level/block/state/BlockState;)V"), method = "destroyBlock")
private void onBlockBroken(BlockPos pos, CallbackInfoReturnable<Boolean> cir, @Local BlockEntity entity, @Local BlockState state) {
PlayerBlockBreakEvents.AFTER.invoker().afterBlockBreak(this.level, this.player, pos, state, entity);
private void onBlockBroken(BlockPos pos, CallbackInfoReturnable<Boolean> cir, @Local(name = "blockEntity") BlockEntity blockEntity, @Local(name = "adjustedState") BlockState adjustedState) {
PlayerBlockBreakEvents.AFTER.invoker().afterBlockBreak(this.level, this.player, pos, adjustedState, blockEntity);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ private Stream<Identifier> streamTemplatesFromResource() {
}

@Inject(method = "<init>", at = @At(value = "INVOKE", target = "Lcom/google/common/collect/ImmutableList$Builder;add(Ljava/lang/Object;)Lcom/google/common/collect/ImmutableList$Builder;", ordinal = 2, shift = At.Shift.AFTER))
private void addFabricTemplateProvider(ResourceManager resourceManager, LevelStorageSource.LevelStorageAccess storageAccess, DataFixer dataFixer, HolderGetter<Block> blockLookup, CallbackInfo ci, @Local ImmutableList.Builder<StructureTemplateManager.Source> builder) {
private void addFabricTemplateProvider(ResourceManager resourceManager, LevelStorageSource.LevelStorageAccess storageAccess, DataFixer dataFixer, HolderGetter<Block> blockLookup, CallbackInfo ci, @Local(name = "builder") ImmutableList.Builder<StructureTemplateManager.Source> builder) {
builder.add(new StructureTemplateManager.Source(this::fabric_loadSnbtFromResource, this::streamTemplatesFromResource));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ private static boolean isEulaAgreedTo(boolean isEulaAgreedTo) {

// Inject after packRepository is stored
@Inject(method = "main", cancellable = true, at = @At(value = "INVOKE_ASSIGN", target = "Lnet/minecraft/server/packs/repository/ServerPacksSource;createPackRepository(Lnet/minecraft/world/level/storage/LevelStorageSource$LevelStorageAccess;)Lnet/minecraft/server/packs/repository/PackRepository;"))
private static void main(String[] args, CallbackInfo info, @Local LevelStorageSource.LevelStorageAccess storageAccess, @Local PackRepository packRepository) {
private static void main(String[] args, CallbackInfo info, @Local(name = "access") LevelStorageSource.LevelStorageAccess storageAccess, @Local(name = "packRepository") PackRepository packRepository) {
if (FabricGameTestRunner.ENABLED) {
FabricGameTestRunner.runHeadlessServer(storageAccess, packRepository);
info.cancel(); // Do not progress in starting the normal dedicated server
Expand Down
Loading
Loading