Skip to content

Commit

Permalink
Fix #8.
Browse files Browse the repository at this point in the history
  • Loading branch information
MerchantPug committed Oct 15, 2024
1 parent 366a600 commit fa30b8b
Show file tree
Hide file tree
Showing 3 changed files with 64 additions and 42 deletions.
42 changes: 0 additions & 42 deletions src/main/java/dev/cammiescorner/arcanuscontinuum/Arcanus.java
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@
import net.fabricmc.fabric.api.event.registry.FabricRegistryBuilder;
import net.minecraft.block.BlockState;
import net.minecraft.entity.effect.StatusEffectInstance;
import net.minecraft.entity.player.PlayerEntity;
import net.minecraft.item.ItemPlacementContext;
import net.minecraft.item.ItemStack;
import net.minecraft.item.ItemUsageContext;
Expand All @@ -32,7 +31,6 @@
import net.minecraft.registry.RegistryKeys;
import net.minecraft.server.MinecraftServer;
import net.minecraft.server.network.ServerPlayerEntity;
import net.minecraft.server.world.ServerWorld;
import net.minecraft.structure.processor.StructureProcessorList;
import net.minecraft.structure.processor.StructureProcessorType;
import net.minecraft.text.MutableText;
Expand All @@ -41,17 +39,11 @@
import net.minecraft.util.Formatting;
import net.minecraft.util.Identifier;
import net.minecraft.util.math.BlockPos;
import net.minecraft.world.World;
import net.minecraft.world.poi.PointOfInterest;
import net.minecraft.world.poi.PointOfInterestStorage;
import org.jetbrains.annotations.Nullable;
import org.quiltmc.loader.api.ModContainer;
import org.quiltmc.loader.api.ModMetadata;
import org.quiltmc.loader.api.QuiltLoader;
import org.quiltmc.qsl.base.api.entrypoint.ModInitializer;
import org.quiltmc.qsl.chat.api.QuiltChatEvents;
import org.quiltmc.qsl.chat.api.QuiltMessageType;
import org.quiltmc.qsl.chat.api.types.ChatC2SMessage;
import org.quiltmc.qsl.command.api.CommandRegistrationCallback;
import org.quiltmc.qsl.lifecycle.api.event.ServerLifecycleEvents;
import org.quiltmc.qsl.networking.api.EntityTrackingEvents;
Expand All @@ -71,8 +63,6 @@
import java.util.concurrent.CompletableFuture;
import java.util.concurrent.TimeUnit;
import java.util.function.BooleanSupplier;
import java.util.stream.Collectors;
import java.util.stream.Stream;

public class Arcanus implements ModInitializer {
public static final Configurator configurator = new Configurator();
Expand Down Expand Up @@ -173,38 +163,6 @@ public void onInitialize(ModContainer mod) {
Arcanus.refreshSupporterData(server, true);
});

QuiltChatEvents.CANCEL.register(EnumSet.of(QuiltMessageType.CHAT), abstractMessage -> {
PlayerEntity player = abstractMessage.getPlayer();
World world = player.getWorld();

if(world instanceof ServerWorld server && abstractMessage instanceof ChatC2SMessage packet) {
String message = packet.getMessage();

CompletableFuture<Boolean> future = CompletableFuture.supplyAsync(() -> {
PointOfInterestStorage poiStorage = server.getChunkManager().getPointOfInterestStorage();
Stream<BlockPos> pointOfInterest = poiStorage.getInSquare(poiTypeHolder -> poiTypeHolder.isRegistryKey(ArcanusPointsOfInterest.MAGIC_DOOR), player.getBlockPos(), 8, PointOfInterestStorage.OccupationStatus.ANY).map(PointOfInterest::getPos);
boolean beep = false;

for(BlockPos pos : pointOfInterest.collect(Collectors.toSet())) {
BlockState state = world.getBlockState(pos);

if(state.getBlock() instanceof MagicDoorBlock doorBlock && world.getBlockEntity(pos) instanceof MagicDoorBlockEntity door) {
if (message.toLowerCase(Locale.ROOT).equals(door.getPassword())) {
doorBlock.setOpen(null, world, state, pos, true);
player.sendMessage(translate("door", "access_granted").formatted(Formatting.GRAY, Formatting.ITALIC), true);
beep = true;
}
}
}
return beep;
}, world.getServer());

return future.join();
}

return false;
});

EntitySleepEvents.STOP_SLEEPING.register((entity, sleepingPos) -> {
if(!entity.getWorld().isClient() && entity.getWorld().getTimeOfDay() == 24000) {
StatusEffectInstance copperCurse = entity.getStatusEffect(ArcanusStatusEffects.COPPER_CURSE.get());
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
package dev.cammiescorner.arcanuscontinuum.mixin.common;

import com.llamalad7.mixinextras.injector.ModifyReceiver;
import dev.cammiescorner.arcanuscontinuum.Arcanus;
import dev.cammiescorner.arcanuscontinuum.common.blocks.MagicDoorBlock;
import dev.cammiescorner.arcanuscontinuum.common.blocks.entities.MagicDoorBlockEntity;
import dev.cammiescorner.arcanuscontinuum.common.registry.ArcanusPointsOfInterest;
import net.minecraft.block.BlockState;
import net.minecraft.network.message.MessageType;
import net.minecraft.network.message.SignedChatMessage;
import net.minecraft.registry.LayeredRegistryManager;
import net.minecraft.registry.RegistryKeys;
import net.minecraft.registry.ServerRegistryLayer;
import net.minecraft.server.PlayerManager;
import net.minecraft.server.network.ServerPlayerEntity;
import net.minecraft.server.world.ServerWorld;
import net.minecraft.util.Formatting;
import net.minecraft.util.math.BlockPos;
import net.minecraft.world.poi.PointOfInterest;
import net.minecraft.world.poi.PointOfInterestStorage;
import org.jetbrains.annotations.Nullable;
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 java.util.List;
import java.util.Locale;
import java.util.function.Predicate;
import java.util.stream.Collectors;
import java.util.stream.Stream;

@Mixin(PlayerManager.class)
public class PlayerManagerMixin {
@Shadow
@Final
private LayeredRegistryManager<ServerRegistryLayer> registryManager;

@ModifyReceiver(method = "sendChatMessage(Lnet/minecraft/network/message/SignedChatMessage;Ljava/util/function/Predicate;Lnet/minecraft/server/network/ServerPlayerEntity;Lnet/minecraft/network/message/MessageType$Parameters;)V", at = @At(value = "INVOKE", target = "Ljava/util/List;iterator()Ljava/util/Iterator;"))
private List<ServerPlayerEntity> arcanuscontinuum$restrictMagicDoorChatMessage(List<ServerPlayerEntity> original, SignedChatMessage chatMessage, Predicate<ServerPlayerEntity> predicate, @Nullable ServerPlayerEntity player, MessageType.Parameters parameters) {
if (player != null && this.registryManager.getCompositeManager().get(RegistryKeys.MESSAGE_TYPE).getKey(parameters.messageType()).map(key -> key.equals(MessageType.CHAT)).orElse(false)) {
ServerWorld world = player.getServerWorld();
PointOfInterestStorage poiStorage = world.getChunkManager().getPointOfInterestStorage();
Stream<BlockPos> pointOfInterest = poiStorage.getInSquare(poiTypeHolder -> poiTypeHolder.isRegistryKey(ArcanusPointsOfInterest.MAGIC_DOOR), player.getBlockPos(), 8, PointOfInterestStorage.OccupationStatus.ANY).map(PointOfInterest::getPos);
boolean beep = false;

for (BlockPos pos : pointOfInterest.collect(Collectors.toSet())) {
BlockState state = world.getBlockState(pos);

if (state.getBlock() instanceof MagicDoorBlock doorBlock && world.getBlockEntity(pos) instanceof MagicDoorBlockEntity door) {
if (chatMessage.getContent().toLowerCase(Locale.ROOT).equals(door.getPassword())) {
doorBlock.setOpen(null, world, state, pos, true);
player.sendMessage(Arcanus.translate("door", "access_granted").formatted(Formatting.GRAY, Formatting.ITALIC), true);
beep = true;
}
}
}
if (beep)
return List.of();
}
return original;
}
}
1 change: 1 addition & 0 deletions src/main/resources/arcanuscontinuum.mixins.json
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
"common.MobEntityMixin",
"common.PistonBlockMixin",
"common.PlayerEntityMixin",
"common.PlayerManagerMixin",
"common.ScreenHandlerTypeMixin",
"common.ServerWorldMixin",
"common.ThrownEntityMixin",
Expand Down

0 comments on commit fa30b8b

Please sign in to comment.