diff options
author | nea <nea@nea.moe> | 2023-07-21 14:03:50 +0200 |
---|---|---|
committer | nea <nea@nea.moe> | 2023-07-21 14:03:50 +0200 |
commit | f404c08a48f6d731491be3c3e09116c13e53ebb4 (patch) | |
tree | 904e289bd0e52edb6df9c9495877130be9262b96 /src/main | |
parent | da99c51f0bd53f7dd0f19b54bca0b441ef79bc1d (diff) | |
download | SkyblockPlayersAnonymous-f404c08a48f6d731491be3c3e09116c13e53ebb4.tar.gz SkyblockPlayersAnonymous-f404c08a48f6d731491be3c3e09116c13e53ebb4.tar.bz2 SkyblockPlayersAnonymous-f404c08a48f6d731491be3c3e09116c13e53ebb4.zip |
Add more interactions and portal
Diffstat (limited to 'src/main')
5 files changed, 95 insertions, 3 deletions
diff --git a/src/main/java/com/github/romangraef/skyblockplayersanonymous/SPA.java b/src/main/java/com/github/romangraef/skyblockplayersanonymous/SPA.java index dd3c780..0862c43 100644 --- a/src/main/java/com/github/romangraef/skyblockplayersanonymous/SPA.java +++ b/src/main/java/com/github/romangraef/skyblockplayersanonymous/SPA.java @@ -1,13 +1,45 @@ package com.github.romangraef.skyblockplayersanonymous; -import net.minecraft.init.Blocks; +import net.minecraft.client.Minecraft; +import net.minecraft.client.entity.EntityOtherPlayerMP; +import net.minecraft.entity.Entity; +import net.minecraft.item.ItemStack; +import net.minecraft.util.ChatComponentText; +import net.minecraft.util.Vec3; import net.minecraftforge.fml.common.Mod; import net.minecraftforge.fml.common.event.FMLInitializationEvent; +import net.minecraftforge.fml.common.eventhandler.SubscribeEvent; +import net.minecraftforge.fml.common.gameevent.TickEvent; -@Mod(modid = "skyblockplayersanonymous", useMetadata=true) +import static net.minecraftforge.common.MinecraftForge.EVENT_BUS; + +@Mod(modid = "skyblockplayersanonymous", useMetadata = true) public class SPA { + + public static boolean isSkyblockNpc(Entity entity) { + if (entity == null) return false; + if (!(entity instanceof EntityOtherPlayerMP)) return false; + ItemStack heldItem = ((EntityOtherPlayerMP) entity).getHeldItem(); + return heldItem != null && heldItem.getDisplayName().equals("§bSkyBlock"); + } + + public static void warnPlayer() { + Minecraft.getMinecraft().ingameGUI.getChatGUI() + .printChatMessage(new ChatComponentText("§c§l§kaaa§c§l WARNING!!!! YOU TRIED TO JOIN SKYBLOCK!!!! §c§l§kaaa")); + } + @Mod.EventHandler public void init(FMLInitializationEvent event) { + EVENT_BUS.register(this); + } + @SubscribeEvent + public void onTick(TickEvent.ClientTickEvent tick) { + if (tick.phase == TickEvent.Phase.END && Minecraft.getMinecraft().thePlayer != null) { + if (new Vec3(-175, 125, 118).squareDistanceTo(Minecraft.getMinecraft().thePlayer.getPositionVector()) < 100) { + Minecraft.getMinecraft().ingameGUI.getChatGUI() + .printChatMessage(new ChatComponentText("§c§l§kaaa§c§l WARNING!!!! YOU ARE DANGEROUSLY CLOSE TO THE PORTAL TO SKYBLOCK!!!! §c§l§kaaa")); + } + } } } diff --git a/src/main/java/com/github/romangraef/skyblockplayersanonymous/mixin/MixinBlockPortal.java b/src/main/java/com/github/romangraef/skyblockplayersanonymous/mixin/MixinBlockPortal.java new file mode 100644 index 0000000..62911a5 --- /dev/null +++ b/src/main/java/com/github/romangraef/skyblockplayersanonymous/mixin/MixinBlockPortal.java @@ -0,0 +1,25 @@ +package com.github.romangraef.skyblockplayersanonymous.mixin; + +import net.minecraft.block.BlockPortal; +import net.minecraft.block.state.IBlockState; +import net.minecraft.util.AxisAlignedBB; +import net.minecraft.util.BlockPos; +import net.minecraft.world.World; +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; + +@Mixin(BlockPortal.class) +public class MixinBlockPortal { + @Inject(method = "getCollisionBoundingBox", at = @At("HEAD"), cancellable = true) + public void onGetCollisionBoundingbox(World worldIn, BlockPos pos, IBlockState state, CallbackInfoReturnable<AxisAlignedBB> cir) { + if (pos.getX() == -175 + && (125 <= pos.getY() && pos.getY() <= 129) + && (116 <= pos.getZ() && pos.getZ() <= 118)) { + cir.setReturnValue(new AxisAlignedBB(pos.getX(), pos.getY(), pos.getZ(), (double) pos.getX() + 1, (double) pos.getY() + 1, (double) pos.getZ() + 1)); + } +// -175 125 118 +// -175 129 116 + } +} diff --git a/src/main/java/com/github/romangraef/skyblockplayersanonymous/mixin/MixinNetHandlerPlayClient.java b/src/main/java/com/github/romangraef/skyblockplayersanonymous/mixin/MixinNetHandlerPlayClient.java index 2cc0a17..9629564 100644 --- a/src/main/java/com/github/romangraef/skyblockplayersanonymous/mixin/MixinNetHandlerPlayClient.java +++ b/src/main/java/com/github/romangraef/skyblockplayersanonymous/mixin/MixinNetHandlerPlayClient.java @@ -8,6 +8,8 @@ import org.spongepowered.asm.mixin.injection.At; import org.spongepowered.asm.mixin.injection.Inject; import org.spongepowered.asm.mixin.injection.callback.CallbackInfo; +import static com.github.romangraef.skyblockplayersanonymous.SPA.warnPlayer; + @Mixin(NetHandlerPlayClient.class) public class MixinNetHandlerPlayClient { @Inject(method = "addToSendQueue", cancellable = true, at = @At("HEAD")) @@ -16,6 +18,7 @@ public class MixinNetHandlerPlayClient { String message = ((C01PacketChatMessage) p_147297_1_).getMessage(); if (message != null && (message.equalsIgnoreCase("/play sb") || message.equalsIgnoreCase("/play skyblock") || message.equalsIgnoreCase("/skyblock"))) { ci.cancel(); + warnPlayer(); } } } diff --git a/src/main/java/com/github/romangraef/skyblockplayersanonymous/mixin/MixinPlayerController.java b/src/main/java/com/github/romangraef/skyblockplayersanonymous/mixin/MixinPlayerController.java index 5ed370d..9185406 100644 --- a/src/main/java/com/github/romangraef/skyblockplayersanonymous/mixin/MixinPlayerController.java +++ b/src/main/java/com/github/romangraef/skyblockplayersanonymous/mixin/MixinPlayerController.java @@ -1,18 +1,48 @@ package com.github.romangraef.skyblockplayersanonymous.mixin; import net.minecraft.client.multiplayer.PlayerControllerMP; +import net.minecraft.entity.Entity; import net.minecraft.entity.player.EntityPlayer; import net.minecraft.init.Items; import net.minecraft.inventory.Slot; import net.minecraft.item.ItemStack; +import net.minecraft.util.MovingObjectPosition; 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.CallbackInfo; import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable; +import static com.github.romangraef.skyblockplayersanonymous.SPA.isSkyblockNpc; +import static com.github.romangraef.skyblockplayersanonymous.SPA.warnPlayer; + @Mixin(PlayerControllerMP.class) public class MixinPlayerController { + @Inject(method = "attackEntity", cancellable = true, at = @At("HEAD")) + public void onAttack(EntityPlayer playerIn, Entity targetEntity, CallbackInfo ci) { + if (isSkyblockNpc(targetEntity)) { + ci.cancel(); + warnPlayer(); + } + } + + @Inject(method = "isPlayerRightClickingOnEntity", cancellable = true, at = @At("HEAD")) + public void onRightClick(EntityPlayer player, Entity entityIn, MovingObjectPosition movingObject, CallbackInfoReturnable<Boolean> cir) { + if (isSkyblockNpc(entityIn)) { + cir.setReturnValue(false); + warnPlayer(); + } + } + + @Inject(method = "interactWithEntitySendPacket", cancellable = true, at = @At("HEAD")) + public void interactWithEntity(EntityPlayer playerIn, Entity targetEntity, CallbackInfoReturnable<Boolean> cir) { + if (isSkyblockNpc(targetEntity)) { + cir.setReturnValue(false); + warnPlayer(); + } + } + @Inject(method = "windowClick", cancellable = true, at = @At("HEAD")) public void onClick(int windowId, int slotId, int mouseButtonClicked, int mode, EntityPlayer playerIn, CallbackInfoReturnable<ItemStack> cir) { if (playerIn == null || playerIn.openContainer == null) return; @@ -26,6 +56,7 @@ public class MixinPlayerController { } if (stack.getItem() == Items.skull && stack.getDisplayName().startsWith("§aSkyBlock")) { cir.setReturnValue(null); + warnPlayer(); } } } diff --git a/src/main/resources/mixins.skyblockplayersanonymous.json b/src/main/resources/mixins.skyblockplayersanonymous.json index a869938..66d88d3 100644 --- a/src/main/resources/mixins.skyblockplayersanonymous.json +++ b/src/main/resources/mixins.skyblockplayersanonymous.json @@ -7,6 +7,7 @@ ], "client": [ "MixinNetHandlerPlayClient", - "MixinPlayerController" + "MixinPlayerController", + "MixinBlockPortal" ] } |