AntiFriendHit created.

This commit is contained in:
EmotionalLove 2019-12-12 19:58:51 -08:00
parent af902e05c5
commit a21cee3470
4 changed files with 77 additions and 20 deletions

View File

@ -0,0 +1,23 @@
package me.zeroeightsix.kami.event.events;
import me.zeroeightsix.kami.event.KamiEvent;
import net.minecraft.entity.Entity;
import javax.annotation.Nonnull;
public class ClientPlayerAttackEvent extends KamiEvent {
private Entity targetEntity;
public ClientPlayerAttackEvent(@Nonnull Entity targetEntity) {
if (this.targetEntity == null) {
throw new IllegalArgumentException("Target Entity cannot be null");
}
this.targetEntity = targetEntity;
}
public Entity getTargetEntity() {
return targetEntity;
}
}

View File

@ -2,7 +2,6 @@ package me.zeroeightsix.kami.mixin.client;
import me.zeroeightsix.kami.KamiMod;
import me.zeroeightsix.kami.event.events.GuiScreenEvent;
import me.zeroeightsix.kami.module.modules.sdashb.capes.Capes;
import me.zeroeightsix.kami.util.Wrapper;
import net.minecraft.client.Minecraft;
import net.minecraft.client.audio.SoundHandler;
@ -50,12 +49,9 @@ public class MixinMinecraft {
KamiMod.EVENT_BUS.post(screenEvent1);
guiScreenIn = screenEvent1.getScreen();
if (guiScreenIn == null && this.world == null)
{
if (guiScreenIn == null && this.world == null) {
guiScreenIn = new GuiMainMenu();
}
else if (guiScreenIn == null && this.player.getHealth() <= 0.0F)
{
} else if (guiScreenIn == null && this.player.getHealth() <= 0.0F) {
guiScreenIn = new GuiGameOver(null);
}
@ -65,38 +61,33 @@ public class MixinMinecraft {
if (net.minecraftforge.common.MinecraftForge.EVENT_BUS.post(event)) return;
guiScreenIn = event.getGui();
if (old != null && guiScreenIn != old)
{
if (old != null && guiScreenIn != old) {
old.onGuiClosed();
}
if (guiScreenIn instanceof GuiMainMenu || guiScreenIn instanceof GuiMultiplayer)
{
if (guiScreenIn instanceof GuiMainMenu || guiScreenIn instanceof GuiMultiplayer) {
this.gameSettings.showDebugInfo = false;
this.ingameGUI.getChatGUI().clearChatMessages(true);
}
this.currentScreen = guiScreenIn;
if (guiScreenIn != null)
{
if (guiScreenIn != null) {
Minecraft.getMinecraft().setIngameNotInFocus();
KeyBinding.unPressAllKeys();
while (Mouse.next())
{}
while (Mouse.next()) {
}
while (Keyboard.next())
{}
while (Keyboard.next()) {
}
ScaledResolution scaledresolution = new ScaledResolution(Minecraft.getMinecraft());
int i = scaledresolution.getScaledWidth();
int j = scaledresolution.getScaledHeight();
guiScreenIn.setWorldAndResolution(Minecraft.getMinecraft(), i, j);
this.skipRenderWorld = false;
}
else
{
} else {
this.soundHandler.resumeSounds();
Minecraft.getMinecraft().setIngameFocus();
}
@ -117,7 +108,7 @@ public class MixinMinecraft {
@Inject(method = "init", at = @At(value = "FIELD", target = "Lnet/minecraft/client/Minecraft;ingameGUI:Lnet/minecraft/client/gui/GuiIngame;", shift = At.Shift.AFTER))
public void startCapes(CallbackInfo ci) {
System.out.println("Loaded capes");
new Capes();
// new Capes(); // TODO: Fix capes.
}
private void save() {

View File

@ -1,15 +1,22 @@
package me.zeroeightsix.kami.mixin.client;
import me.zero.alpine.EventBus;
import me.zeroeightsix.kami.KamiMod;
import me.zeroeightsix.kami.event.events.ClientPlayerAttackEvent;
import me.zeroeightsix.kami.module.modules.player.TpsSync;
import me.zeroeightsix.kami.util.LagCompensator;
import net.minecraft.block.state.IBlockState;
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.util.math.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.Redirect;
import org.spongepowered.asm.mixin.injection.callback.CallbackInfo;
/**
* Created by 086 on 3/10/2018.
@ -22,4 +29,15 @@ public class MixinPlayerControllerMP {
return state.getPlayerRelativeBlockHardness(player, worldIn, pos) * (TpsSync.isSync() ? (LagCompensator.INSTANCE.getTickRate() / 20f) : 1);
}
@Inject(method = "attackEntity", at = @At("HEAD"), cancellable = true)
public void attackEntity(EntityPlayer playerIn, Entity targetEntity, CallbackInfo ci) {
if (targetEntity == null) return;
if (targetEntity instanceof EntityPlayerSP) {
ClientPlayerAttackEvent e = new ClientPlayerAttackEvent(targetEntity);
KamiMod.EVENT_BUS.post(e);
if (e.isCancelled()) {
ci.cancel();
}
}
}
}

View File

@ -0,0 +1,25 @@
package me.zeroeightsix.kami.module.modules.combat;
import me.zero.alpine.listener.EventHandler;
import me.zero.alpine.listener.Listener;
import me.zeroeightsix.kami.event.events.ClientPlayerAttackEvent;
import me.zeroeightsix.kami.module.Module;
import me.zeroeightsix.kami.util.Friends;
import net.minecraft.client.entity.EntityOtherPlayerMP;
import net.minecraft.entity.Entity;
@Module.Info(name = "AntiFriendHit", description = "Don't hit your friends", category = Module.Category.COMBAT, alwaysListening = true)
public class AntiFriendHit extends Module {
@EventHandler
Listener<ClientPlayerAttackEvent> listener = new Listener<>(event -> {
if (!this.isEnabled()) return;
Entity e = mc.objectMouseOver.entityHit;
if (e instanceof EntityOtherPlayerMP && Friends.isFriend(e.getName())) {
event.cancel();
}
});
}