-
-
Notifications
You must be signed in to change notification settings - Fork 248
/
MixinPlayerControllerMP.java
80 lines (75 loc) · 4.23 KB
/
MixinPlayerControllerMP.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
package codes.biscuit.skyblockaddons.mixins;
import codes.biscuit.skyblockaddons.SkyblockAddons;
import codes.biscuit.skyblockaddons.utils.Feature;
import codes.biscuit.skyblockaddons.utils.Message;
import net.minecraft.block.Block;
import net.minecraft.client.Minecraft;
import net.minecraft.client.entity.EntityOtherPlayerMP;
import net.minecraft.client.entity.EntityPlayerSP;
import net.minecraft.client.multiplayer.PlayerControllerMP;
import net.minecraft.entity.Entity;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.init.Blocks;
import net.minecraft.init.Items;
import net.minecraft.item.ItemStack;
import net.minecraft.util.BlockPos;
import net.minecraft.util.EnumChatFormatting;
import net.minecraft.util.EnumFacing;
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.CallbackInfoReturnable;
import org.spongepowered.asm.mixin.injection.callback.LocalCapture;
@Mixin(PlayerControllerMP.class)
public class MixinPlayerControllerMP {
private long lastStemMessage = -1;
private long lastProfileMessage = -1;
/**
* Cancels stem breaks if holding an item, to avoid accidental breaking.
*/
@Inject(method = "clickBlock", at = @At(value = "HEAD"), locals = LocalCapture.CAPTURE_FAILSOFT, cancellable = true)
private void onPlayerDamageBlock(BlockPos loc, EnumFacing face, CallbackInfoReturnable<Boolean> cir) {
SkyblockAddons main = SkyblockAddons.getInstance();
Minecraft mc = Minecraft.getMinecraft();
EntityPlayerSP p = mc.thePlayer;
ItemStack heldItem = p.getHeldItem();
Block block = mc.theWorld.getBlockState(loc).getBlock();
if (heldItem != null) {
if (main.getConfigValues().isEnabled(Feature.AVOID_BREAKING_STEMS) && (block.equals(Blocks.melon_stem) || block.equals(Blocks.pumpkin_stem))) {
if (System.currentTimeMillis()- lastStemMessage > 20000) {
lastStemMessage = System.currentTimeMillis();
main.getUtils().sendMessage(EnumChatFormatting.RED+Message.MESSAGE_CANCELLED_STEM_BREAK.getMessage());
}
cir.setReturnValue(false);
return;
}
}
if (heldItem == null || heldItem.getItem().equals(Items.reeds) || heldItem.getItem().equals(Items.diamond_hoe) || heldItem.getItem().equals(Items.iron_hoe) || heldItem.getItem().equals(Items.golden_hoe)
|| heldItem.getItem().equals(Items.wooden_hoe) || heldItem.getItem().equals(Items.wooden_hoe)) {
if (main.getConfigValues().isEnabled(Feature.AVOID_BREAKING_BOTTOM_SUGAR_CANE) && (block.equals(Blocks.reeds) && mc.theWorld.getBlockState(loc.down()).getBlock() != Blocks.reeds)) {
if (System.currentTimeMillis()- lastStemMessage > 20000) {
lastStemMessage = System.currentTimeMillis();
main.getUtils().sendMessage(EnumChatFormatting.RED+Message.MESSAGE_CANCELLED_STEM_BREAK.getMessage());
}
cir.setReturnValue(false);
}
}
}
@Inject(method = "isPlayerRightClickingOnEntity", at = @At(value = "HEAD"), locals = LocalCapture.CAPTURE_FAILSOFT, cancellable = true)
private void onPlayerRightClickEntity(EntityPlayer player, Entity entityIn, MovingObjectPosition movingObject, CallbackInfoReturnable<Boolean> cir) {
SkyblockAddons main = SkyblockAddons.getInstance();
if (main.getConfigValues().isEnabled(Feature.DONT_OPEN_PROFILES_WITH_BOW)) {
if (entityIn instanceof EntityOtherPlayerMP) {
ItemStack item = player.inventory.getCurrentItem();
if (item != null && item.getItem() != null && item.getItem().equals(Items.bow)) {
if (System.currentTimeMillis()- lastProfileMessage > 20000) {
lastProfileMessage = System.currentTimeMillis();
main.getUtils().sendMessage(EnumChatFormatting.RED+Message.MESSAGE_STOPPED_OPENING_PROFILE.getMessage());
}
cir.setReturnValue(true);
}
}
}
}
}