Skip to content

Commit

Permalink
cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
AViewFromTheTop committed Aug 21, 2024
1 parent b2947a1 commit c0a1e46
Show file tree
Hide file tree
Showing 58 changed files with 368 additions and 374 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,3 +6,4 @@ Put changelog here:

-----------------
- Prevented softlocks during worldgen.
- Removed the `frozenlib:heavy_items` and `frozenlib:can_interact_while_crouching` tags and their functionalities as they've seen no usage.
Original file line number Diff line number Diff line change
Expand Up @@ -43,8 +43,14 @@ public class ServerAdvancementManagerMixin {
@Final
private HolderLookup.Provider registries;

@Inject(method = "apply(Ljava/util/Map;Lnet/minecraft/server/packs/resources/ResourceManager;Lnet/minecraft/util/profiling/ProfilerFiller;)V", at = @At(value = "INVOKE", target = "Ljava/util/Map;values()Ljava/util/Collection;"))
private void modifyAdvancement(Map<ResourceLocation, JsonElement> object, ResourceManager resourceManager, ProfilerFiller profiler, CallbackInfo ci) {
@Inject(
method = "apply(Ljava/util/Map;Lnet/minecraft/server/packs/resources/ResourceManager;Lnet/minecraft/util/profiling/ProfilerFiller;)V",
at = @At(
value = "INVOKE",
target = "Ljava/util/Map;values()Ljava/util/Collection;"
)
)
private void modifyAdvancement(Map<ResourceLocation, JsonElement> object, ResourceManager resourceManager, ProfilerFiller profiler, CallbackInfo info) {
for (AdvancementHolder holder : advancements.values()) {
AdvancementEvents.INIT.invoker().onInit(holder, this.registries);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@

package net.frozenblock.lib.block.mixin.dripstone;

import com.llamalad7.mixinextras.sugar.Local;
import java.util.Optional;
import java.util.function.BiPredicate;
import java.util.function.Predicate;
Expand All @@ -32,38 +33,40 @@
import net.minecraft.world.level.LevelAccessor;
import net.minecraft.world.level.block.AbstractCauldronBlock;
import net.minecraft.world.level.block.Block;
import net.minecraft.world.level.block.Blocks;
import net.minecraft.world.level.block.PointedDripstoneBlock;
import net.minecraft.world.level.block.state.BlockState;
import net.minecraft.world.level.block.state.properties.BlockStateProperties;
import net.minecraft.world.level.material.Fluid;
import net.minecraft.world.level.material.Fluids;
import net.minecraft.world.phys.shapes.BooleanOp;
import net.minecraft.world.phys.shapes.Shapes;
import net.minecraft.world.phys.shapes.VoxelShape;
import org.spongepowered.asm.mixin.Final;
import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.Shadow;
import org.spongepowered.asm.mixin.injection.At;
import org.spongepowered.asm.mixin.injection.Inject;
import org.spongepowered.asm.mixin.injection.callback.CallbackInfo;
import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable;
import org.spongepowered.asm.mixin.injection.callback.LocalCapture;

@Mixin(PointedDripstoneBlock.class)
public class PointedDripstoneBlockMixin {

@Final @Shadow
private static VoxelShape REQUIRED_SPACE_TO_DRIP_THROUGH_NON_SOLID_BLOCK;

@SuppressWarnings("UnresolvedMixinReference")
@Inject(method = {"m_ulptarvl","method_33279","lambda$getFluidAboveStalactite$11"}, at = @At(value = "INVOKE_ASSIGN", target = "Lnet/minecraft/world/level/block/state/BlockState;is(Lnet/minecraft/world/level/block/Block;)Z", shift = At.Shift.BEFORE), locals = LocalCapture.CAPTURE_FAILEXCEPTION, cancellable = true, require = 1)
private static void getFluidAboveStalactite(Level level, BlockPos pos, CallbackInfoReturnable<PointedDripstoneBlock.FluidInfo> cir, BlockPos blockPos, BlockState blockState) {
@Inject(
method = {"m_ulptarvl", "method_33279", "lambda$getFluidAboveStalactite$11"},
at = @At(
value = "INVOKE_ASSIGN",
target = "Lnet/minecraft/world/level/block/state/BlockState;is(Lnet/minecraft/world/level/block/Block;)Z",
shift = At.Shift.BEFORE
),
cancellable = true,
require = 1
)
private static void frozenLib$getFluidAboveStalactite(
Level level, BlockPos pos, CallbackInfoReturnable<PointedDripstoneBlock.FluidInfo> info,
@Local(ordinal = 1) BlockPos blockPos, @Local BlockState blockState
) {
if (!FrozenBools.useNewDripstoneLiquid && blockPos != null) {
if (DripstoneDripWaterFrom.ON_DRIP_BLOCK.containsKey(blockState.getBlock()) && !level.dimensionType().ultraWarm()) {
cir.setReturnValue(new PointedDripstoneBlock.FluidInfo(blockPos, Fluids.WATER, blockState));
info.setReturnValue(new PointedDripstoneBlock.FluidInfo(blockPos, Fluids.WATER, blockState));
} else if (DripstoneDripLavaFrom.ON_DRIP_BLOCK.containsKey(blockState.getBlock())) {
cir.setReturnValue(new PointedDripstoneBlock.FluidInfo(blockPos, Fluids.LAVA, blockState));
info.setReturnValue(new PointedDripstoneBlock.FluidInfo(blockPos, Fluids.LAVA, blockState));
}
}
}
Expand Down Expand Up @@ -97,24 +100,35 @@ private static void getFluidAboveStalactite(Level level, BlockPos pos, BlockStat
}
}

@Inject(method = "maybeTransferFluid", at = @At(value = "INVOKE", target = "Lnet/minecraft/world/level/block/state/BlockState;is(Lnet/minecraft/world/level/block/Block;)Z", shift = At.Shift.BEFORE), locals = LocalCapture.CAPTURE_FAILEXCEPTION, cancellable = true)
private static void maybeTransferFluid(BlockState state, ServerLevel level, BlockPos pos, float randChance, CallbackInfo ci, Optional<PointedDripstoneBlock.FluidInfo> optional, Fluid fluid, float f, BlockPos blockPos) {
@Inject(
method = "maybeTransferFluid",
at = @At(
value = "INVOKE",
target = "Lnet/minecraft/world/level/block/state/BlockState;is(Lnet/minecraft/world/level/block/Block;)Z",
shift = At.Shift.BEFORE
),
cancellable = true
)
private static void frozenLib$maybeTransferFluid(
BlockState state, ServerLevel level, BlockPos pos, float randChance, CallbackInfo info,
@Local Optional<PointedDripstoneBlock.FluidInfo> optional, @Local Fluid fluid, @Local(ordinal = 1) BlockPos blockPos
) {
if (optional.isPresent()) {
PointedDripstoneBlock.FluidInfo fluidInfo = optional.get();
Block block = optional.get().sourceState().getBlock();
if (DripstoneDripWaterFrom.ON_DRIP_BLOCK.containsKey(block) && fluid == Fluids.WATER) {
DripstoneDripWaterFrom.ON_DRIP_BLOCK.get(block).drip(level, fluidInfo, blockPos);
ci.cancel();
info.cancel();
}
if (DripstoneDripLavaFrom.ON_DRIP_BLOCK.containsKey(block) && fluid == Fluids.LAVA) {
DripstoneDripLavaFrom.ON_DRIP_BLOCK.get(block).drip(level, fluidInfo, blockPos);
ci.cancel();
info.cancel();
}
}
}

@Inject(at = @At("HEAD"), method = "findFillableCauldronBelowStalactiteTip", cancellable = true)
private static void findFillableCauldronBelowStalactiteTip(Level world, BlockPos pos2, Fluid fluid, CallbackInfoReturnable<BlockPos> info) {
private static void frozenLib$findFillableCauldronBelowStalactiteTip(Level world, BlockPos pos2, Fluid fluid, CallbackInfoReturnable<BlockPos> info) {
Predicate<BlockState> tagPredicate = state -> state.is(FrozenBlockTags.DRIPSTONE_CAN_DRIP_ON);
if (tagPredicate.test(world.getBlockState(pos2.mutable().move(Direction.get(Direction.DOWN.getAxisDirection(), Direction.Axis.Y))))) {
Predicate<BlockState> predicate = tagPredicate.or(state -> (state.getBlock() instanceof AbstractCauldronBlock && ((AbstractCauldronBlock) state.getBlock()).canReceiveStalactiteDrip(fluid)));
Expand All @@ -126,53 +140,22 @@ private static void findFillableCauldronBelowStalactiteTip(Level world, BlockPos

@Shadow
private static boolean canDripThrough(BlockGetter world, BlockPos pos, BlockState state) {
if (state.isAir()) {
return true;
}
if (state.isSolidRender(world, pos)) {
return false;
}
if (!state.getFluidState().isEmpty()) {
return false;
}
VoxelShape voxelShape = state.getCollisionShape(world, pos);
return !Shapes.joinIsNotEmpty(REQUIRED_SPACE_TO_DRIP_THROUGH_NON_SOLID_BLOCK, voxelShape, BooleanOp.AND);
throw new AssertionError("Mixin injection failed - FrozenLib PointedDripstoneBlockMixin.");
}

@Shadow
private static Optional<BlockPos> findBlockVertical(LevelAccessor world, BlockPos pos, Direction.AxisDirection direction, BiPredicate<BlockPos, BlockState> continuePredicate, Predicate<BlockState> stopPredicate, int range) {
Direction direction2 = Direction.get(direction, Direction.Axis.Y);
BlockPos.MutableBlockPos mutable = pos.mutable();
for (int i = 1; i < range; ++i) {
mutable.move(direction2);
BlockState blockState = world.getBlockState(mutable);
if (stopPredicate.test(blockState)) {
return Optional.of(mutable.immutable());
}
if (!world.isOutsideBuildHeight(mutable.getY()) && continuePredicate.test(mutable, blockState)) continue;
return Optional.empty();
}
return Optional.empty();
throw new AssertionError("Mixin injection failed - FrozenLib PointedDripstoneBlockMixin.");
}

@Shadow
private static boolean isStalactite(BlockState state) {
return isPointedDripstoneWithDirection(state, Direction.DOWN);
}

@Shadow
private static boolean isStalagmite(BlockState state) {
return isPointedDripstoneWithDirection(state, Direction.UP);
}

@Shadow
private static boolean isPointedDripstoneWithDirection(BlockState state, Direction dir) {
return state.is(Blocks.POINTED_DRIPSTONE) && state.getValue(BlockStateProperties.VERTICAL_DIRECTION) == dir;
throw new AssertionError("Mixin injection failed - FrozenLib PointedDripstoneBlockMixin.");
}

@Shadow
private static Optional<BlockPos> findRootBlock(Level level, BlockPos pos, BlockState state, int maxIterations) {
return Optional.empty();
throw new AssertionError("Mixin injection failed - FrozenLib PointedDripstoneBlockMixin.");
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,13 @@
@Mixin(Bootstrap.class)
public class BootstrapMixin {

@Inject(method = "bootStrap", at = @At(value = "INVOKE", target = "Ljava/util/concurrent/atomic/AtomicLong;set(J)V"))
@Inject(
method = "bootStrap",
at = @At(
value = "INVOKE",
target = "Ljava/util/concurrent/atomic/AtomicLong;set(J)V"
)
)
private static void frozenLib$finishBootStrap(CallbackInfo info) {
FrozenBools.isInitialized = true;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,8 +50,15 @@ private static int setWarningLevel(CommandSourceStack source, Collection<? exten
return 0;
}

@WrapOperation(method = "register", at = @At(value = "INVOKE", target = "Lcom/mojang/brigadier/CommandDispatcher;register(Lcom/mojang/brigadier/builder/LiteralArgumentBuilder;)Lcom/mojang/brigadier/tree/LiteralCommandNode;", remap = false))
private static LiteralCommandNode<CommandSourceStack> register(CommandDispatcher<CommandSourceStack> dispatcher, LiteralArgumentBuilder<CommandSourceStack> builder, Operation<LiteralCommandNode<CommandSourceStack>> operation) {
@WrapOperation(
method = "register",
at = @At(
value = "INVOKE",
target = "Lcom/mojang/brigadier/CommandDispatcher;register(Lcom/mojang/brigadier/builder/LiteralArgumentBuilder;)Lcom/mojang/brigadier/tree/LiteralCommandNode;",
remap = false
)
)
private static LiteralCommandNode<CommandSourceStack> frozenLib$register(CommandDispatcher<CommandSourceStack> dispatcher, LiteralArgumentBuilder<CommandSourceStack> builder, Operation<LiteralCommandNode<CommandSourceStack>> operation) {
if (FrozenLibConfig.get().wardenSpawnTrackerCommand) {
return dispatcher.register(
Commands.literal("warden_spawn_tracker")
Expand Down Expand Up @@ -81,17 +88,31 @@ private static LiteralCommandNode<CommandSourceStack> register(CommandDispatcher
} else return operation.call(dispatcher, builder);
}

@WrapOperation(method = "setWarningLevel", at = @At(value = "INVOKE", target = "Lnet/minecraft/commands/CommandSourceStack;sendSuccess(Ljava/util/function/Supplier;Z)V", ordinal = 0))
private static void modifySetWarningLevel(CommandSourceStack source, Supplier<Component> supplier, boolean broadcastToOps, Operation<Void> operation, CommandSourceStack source1, Collection<? extends Player> targets, int warningLevel) {
@WrapOperation(
method = "setWarningLevel",
at = @At(
value = "INVOKE",
target = "Lnet/minecraft/commands/CommandSourceStack;sendSuccess(Ljava/util/function/Supplier;Z)V",
ordinal = 0
)
)
private static void frozenLib$modifySetWarningLevel(CommandSourceStack source, Supplier<Component> supplier, boolean broadcastToOps, Operation<Void> operation, CommandSourceStack source1, Collection<? extends Player> targets, int warningLevel) {
if (FrozenLibConfig.get().wardenSpawnTrackerCommand) {
source.sendSuccess(
() -> Component.translatable("commands.warden_spawn_tracker.set.success.single", warningLevel, targets.iterator().next().getDisplayName()), true
);
} else operation.call(source, supplier, broadcastToOps);
}

@WrapOperation(method = "setWarningLevel", at = @At(value = "INVOKE", target = "Lnet/minecraft/commands/CommandSourceStack;sendSuccess(Ljava/util/function/Supplier;Z)V", ordinal = 1))
private static void modifySetWarningLevelMultiple(CommandSourceStack source, Supplier<Component> supplier, boolean broadcastToOps, Operation<Void> operation, CommandSourceStack source1, Collection<? extends Player> targets, int warningLevel) {
@WrapOperation(
method = "setWarningLevel",
at = @At(
value = "INVOKE",
target = "Lnet/minecraft/commands/CommandSourceStack;sendSuccess(Ljava/util/function/Supplier;Z)V",
ordinal = 1
)
)
private static void frozenLib$modifySetWarningLevelMultiple(CommandSourceStack source, Supplier<Component> supplier, boolean broadcastToOps, Operation<Void> operation, CommandSourceStack source1, Collection<? extends Player> targets, int warningLevel) {
if (FrozenLibConfig.get().wardenSpawnTrackerCommand) {
source.sendSuccess(
() -> Component.translatable("commands.warden_spawn_tracker.set.success.multiple", warningLevel, targets.size()), true
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ private AbstractFishMixin(EntityType<? extends WaterAnimal> entityType, Level le
}

@Inject(method = "aiStep", at = @At("HEAD"), cancellable = true)
private void noFlop(CallbackInfo ci) {
private void frozenLib$noFlop(CallbackInfo ci) {
AbstractFish fish = AbstractFish.class.cast(this);
if (fish instanceof NoFlopAbstractFish) {
super.aiStep();
Expand Down
20 changes: 13 additions & 7 deletions src/main/java/net/frozenblock/lib/entity/mixin/EntityMixin.java
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@

package net.frozenblock.lib.entity.mixin;

import com.llamalad7.mixinextras.sugar.Local;
import net.frozenblock.lib.entity.impl.EntityStepOnBlockInterface;
import net.frozenblock.lib.entity.impl.FrozenStartTrackingEntityInterface;
import net.frozenblock.lib.screenshake.impl.EntityScreenShakeInterface;
Expand All @@ -28,7 +29,6 @@
import net.minecraft.world.entity.Entity;
import net.minecraft.world.entity.MoverType;
import net.minecraft.world.level.Level;
import net.minecraft.world.level.block.Block;
import net.minecraft.world.level.block.state.BlockState;
import net.minecraft.world.phys.Vec3;
import org.spongepowered.asm.mixin.Mixin;
Expand All @@ -37,7 +37,6 @@
import org.spongepowered.asm.mixin.injection.At;
import org.spongepowered.asm.mixin.injection.Inject;
import org.spongepowered.asm.mixin.injection.callback.CallbackInfo;
import org.spongepowered.asm.mixin.injection.callback.LocalCapture;

@Mixin(Entity.class)
public abstract class EntityMixin implements FrozenStartTrackingEntityInterface, EntityStepOnBlockInterface {
Expand All @@ -49,14 +48,21 @@ public abstract class EntityMixin implements FrozenStartTrackingEntityInterface,
@Override
public void frozenLib$playerStartsTracking(ServerPlayer serverPlayer) {
Entity entity = Entity.class.cast(this);
((EntityLoopingSoundInterface)entity).getSoundManager().syncWithPlayer(serverPlayer);
((EntityLoopingFadingDistanceSoundInterface)entity).getFadingSoundManager().syncWithPlayer(serverPlayer);
((EntityLoopingSoundInterface)entity).frozenLib$getSoundManager().syncWithPlayer(serverPlayer);
((EntityLoopingFadingDistanceSoundInterface)entity).frozenLib$getFadingSoundManager().syncWithPlayer(serverPlayer);
((EntitySpottingIconInterface)entity).getSpottingIconManager().sendIconPacket(serverPlayer);
((EntityScreenShakeInterface)entity).getScreenShakeManager().syncWithPlayer(serverPlayer);
((EntityScreenShakeInterface)entity).frozenLib$getScreenShakeManager().syncWithPlayer(serverPlayer);
}

@Inject(method = "move", at = @At(value = "INVOKE", target = "Lnet/minecraft/world/level/block/Block;stepOn(Lnet/minecraft/world/level/Level;Lnet/minecraft/core/BlockPos;Lnet/minecraft/world/level/block/state/BlockState;Lnet/minecraft/world/entity/Entity;)V", shift = At.Shift.AFTER), locals = LocalCapture.CAPTURE_FAILHARD)
public void frozenLib$runSteppedOn(MoverType type, Vec3 pos, CallbackInfo ci, Vec3 vec3, double d, boolean bl, boolean bl2, BlockPos blockPos, BlockState blockState, Block block) {
@Inject(
method = "move",
at = @At(
value = "INVOKE",
target = "Lnet/minecraft/world/level/block/Block;stepOn(Lnet/minecraft/world/level/Level;Lnet/minecraft/core/BlockPos;Lnet/minecraft/world/level/block/state/BlockState;Lnet/minecraft/world/entity/Entity;)V",
shift = At.Shift.AFTER
)
)
public void frozenLib$runSteppedOn(MoverType type, Vec3 pos, CallbackInfo ci, @Local BlockPos blockPos, @Local BlockState blockState) {
this.frozenLib$onSteppedOnBlock(this.level(), blockPos, blockState);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@

package net.frozenblock.lib.entity.mixin;

import com.llamalad7.mixinextras.sugar.Local;
import java.util.Optional;
import net.frozenblock.lib.entity.api.WolfVariantBiomeRegistry;
import net.minecraft.core.Holder;
Expand All @@ -30,7 +31,6 @@
import org.spongepowered.asm.mixin.injection.At;
import org.spongepowered.asm.mixin.injection.Inject;
import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable;
import org.spongepowered.asm.mixin.injection.callback.LocalCapture;

@Mixin(WolfVariants.class)
public class WolfVariantsMixin {
Expand All @@ -42,10 +42,12 @@ public class WolfVariantsMixin {
target = "Lnet/minecraft/core/Registry;holders()Ljava/util/stream/Stream;",
shift = At.Shift.BEFORE
),
locals = LocalCapture.CAPTURE_FAILEXCEPTION,
cancellable = true
)
private static void frozenLib$checkForNewBiomes(RegistryAccess registryManager, Holder<Biome> holder, CallbackInfoReturnable<Holder<WolfVariant>> info, Registry<WolfVariant> registry) {
private static void frozenLib$checkForNewBiomes(
RegistryAccess registryManager, Holder<Biome> holder, CallbackInfoReturnable<Holder<WolfVariant>> info,
@Local Registry<WolfVariant> registry
) {
Optional<ResourceKey<Biome>> optionalBiome = holder.unwrapKey();
if (optionalBiome.isPresent()) {
ResourceKey<Biome> biomeKey = optionalBiome.get();
Expand Down
Loading

0 comments on commit c0a1e46

Please sign in to comment.