-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
11c6352
commit 85889b8
Showing
12 changed files
with
290 additions
and
12 deletions.
There are no files selected for viewing
28 changes: 28 additions & 0 deletions
28
common/src/main/java/com/github/manasmods/manascore/attribute/ManasCoreAttributeUtils.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
package com.github.manasmods.manascore.attribute; | ||
|
||
import net.minecraft.world.entity.Entity; | ||
import net.minecraft.world.entity.player.Player; | ||
import net.minecraft.world.phys.Vec3; | ||
|
||
import java.util.Optional; | ||
|
||
public class ManasCoreAttributeUtils { | ||
public static double getAttackRange(Player player) { | ||
double range = player.getAttributeValue(ManasCoreAttributes.ENTITY_REACH.get()); | ||
return range == 0 ? 0 : range + (player.isCreative() ? 3 : 0); | ||
} | ||
|
||
public static double getReachDistance(Player player) { | ||
double reach = player.getAttributeValue(ManasCoreAttributes.BLOCK_REACH.get()); | ||
return reach == 0 ? 0 : reach + (player.isCreative() ? 0.5 : 0); | ||
} | ||
|
||
public static boolean cantHit(Player player, Entity entity, double padding) { | ||
Vec3 eye = player.getEyePosition(); | ||
Vec3 targetCenter = entity.getPosition(1.0F).add(0, entity.getBbHeight() / 2, 0); | ||
Optional<Vec3> hit = entity.getBoundingBox().clip(eye, targetCenter); | ||
|
||
double dist = getAttackRange(player) + padding; | ||
return !(hit.map(eye::distanceToSqr).orElseGet(() -> player.distanceToSqr(entity)) < dist * dist); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
18 changes: 18 additions & 0 deletions
18
common/src/main/java/com/github/manasmods/manascore/core/MixinItem.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
package com.github.manasmods.manascore.core; | ||
|
||
import com.github.manasmods.manascore.attribute.ManasCoreAttributeUtils; | ||
import net.minecraft.world.entity.player.Player; | ||
import net.minecraft.world.item.Item; | ||
import net.minecraft.world.level.Level; | ||
import org.spongepowered.asm.mixin.Mixin; | ||
import org.spongepowered.asm.mixin.injection.Constant; | ||
import org.spongepowered.asm.mixin.injection.ModifyConstant; | ||
|
||
@Mixin(Item.class) | ||
public class MixinItem { | ||
@ModifyConstant(method = "getPlayerPOVHitResult(Lnet/minecraft/world/level/Level;Lnet/minecraft/world/entity/player/Player;Lnet/minecraft/world/level/ClipContext$Fluid;)Lnet/minecraft/world/phys/BlockHitResult;", | ||
require = 4, allow = 4, constant = @Constant(doubleValue = 5.0)) | ||
private static double getReachDistance(double reachDistance, Level level, Player player) { | ||
return ManasCoreAttributeUtils.getReachDistance(player); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
36 changes: 34 additions & 2 deletions
36
common/src/main/java/com/github/manasmods/manascore/core/MixinPlayer.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
28 changes: 28 additions & 0 deletions
28
.../src/main/java/com/github/manasmods/manascore/core/MixinServerGamePacketListenerImpl.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
package com.github.manasmods.manascore.core; | ||
|
||
import com.github.manasmods.manascore.attribute.ManasCoreAttributeUtils; | ||
import net.minecraft.server.level.ServerPlayer; | ||
import net.minecraft.server.network.ServerGamePacketListenerImpl; | ||
import org.objectweb.asm.Opcodes; | ||
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.Redirect; | ||
|
||
@Mixin(ServerGamePacketListenerImpl.class) | ||
public class MixinServerGamePacketListenerImpl { | ||
@Shadow public ServerPlayer player; | ||
@Redirect(method = "handleUseItemOn", at = @At(value = "FIELD", | ||
target = "Lnet/minecraft/server/network/ServerGamePacketListenerImpl;MAX_INTERACTION_DISTANCE:D", opcode = Opcodes.GETSTATIC)) | ||
private double getBlockInteractDistance() { | ||
double reach = ManasCoreAttributeUtils.getReachDistance(this.player) + 3; | ||
return reach * reach; | ||
} | ||
|
||
@Redirect(method = "handleInteract", at = @At(value = "FIELD", | ||
target = "Lnet/minecraft/server/network/ServerGamePacketListenerImpl;MAX_INTERACTION_DISTANCE:D", opcode = Opcodes.GETSTATIC)) | ||
private double getEntityInteractDistance() { | ||
double reach = ManasCoreAttributeUtils.getAttackRange(this.player) + 3; | ||
return reach * reach; | ||
} | ||
} |
22 changes: 22 additions & 0 deletions
22
common/src/main/java/com/github/manasmods/manascore/core/MixinServerPlayerGameMode.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
package com.github.manasmods.manascore.core; | ||
|
||
import com.github.manasmods.manascore.attribute.ManasCoreAttributeUtils; | ||
import net.minecraft.server.level.ServerPlayer; | ||
import net.minecraft.server.level.ServerPlayerGameMode; | ||
import org.objectweb.asm.Opcodes; | ||
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.Redirect; | ||
|
||
@Mixin(ServerPlayerGameMode.class) | ||
public class MixinServerPlayerGameMode { | ||
@Shadow @Final protected ServerPlayer player; | ||
@Redirect(method = "handleBlockBreakAction", at = @At(value = "FIELD", | ||
target = "Lnet/minecraft/server/network/ServerGamePacketListenerImpl;MAX_INTERACTION_DISTANCE:D", opcode = Opcodes.GETSTATIC)) | ||
private double getReachDistance() { | ||
double reach = ManasCoreAttributeUtils.getReachDistance(player) + 1; | ||
return reach * reach; | ||
} | ||
} |
30 changes: 30 additions & 0 deletions
30
common/src/main/java/com/github/manasmods/manascore/core/client/MixinGameRenderer.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
package com.github.manasmods.manascore.core.client; | ||
|
||
import com.github.manasmods.manascore.attribute.ManasCoreAttributeUtils; | ||
import net.minecraft.client.Minecraft; | ||
import net.minecraft.client.renderer.GameRenderer; | ||
import net.minecraft.world.entity.player.Player; | ||
import org.spongepowered.asm.mixin.Final; | ||
import org.spongepowered.asm.mixin.Mixin; | ||
import org.spongepowered.asm.mixin.Shadow; | ||
import org.spongepowered.asm.mixin.injection.Constant; | ||
import org.spongepowered.asm.mixin.injection.ModifyConstant; | ||
|
||
@Mixin(GameRenderer.class) | ||
public class MixinGameRenderer { | ||
@Shadow @Final Minecraft minecraft; | ||
@ModifyConstant(method = "pick", require = 1, allow = 1, constant = @Constant(doubleValue = 6.0)) | ||
private double getReachDistance(double reachDistance) { | ||
Player player = this.minecraft.player; | ||
if (player == null) return reachDistance; | ||
return ManasCoreAttributeUtils.getReachDistance(player); | ||
} | ||
|
||
@ModifyConstant(method = "pick", constant = @Constant(doubleValue = 9.0)) | ||
private double getAttackRange(double attackRange) { | ||
Player player = this.minecraft.player; | ||
if (player == null) return attackRange; | ||
double range = ManasCoreAttributeUtils.getAttackRange(player); | ||
return range * range; | ||
} | ||
} |
26 changes: 26 additions & 0 deletions
26
common/src/main/java/com/github/manasmods/manascore/core/client/MixinGui.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
package com.github.manasmods.manascore.core.client; | ||
|
||
import com.github.manasmods.manascore.attribute.ManasCoreAttributeUtils; | ||
import net.minecraft.client.Minecraft; | ||
import net.minecraft.client.gui.Gui; | ||
import net.minecraft.world.entity.player.Player; | ||
import org.spongepowered.asm.mixin.Final; | ||
import org.spongepowered.asm.mixin.Mixin; | ||
import org.spongepowered.asm.mixin.Shadow; | ||
import org.spongepowered.asm.mixin.injection.Constant; | ||
import org.spongepowered.asm.mixin.injection.ModifyConstant; | ||
|
||
@Mixin(Gui.class) | ||
public class MixinGui { | ||
@Shadow @Final | ||
private Minecraft minecraft; | ||
@ModifyConstant(method = "renderCrosshair", require = 2, allow = 1, constant = @Constant(floatValue = 1.0F)) | ||
private float getActualReachDistance(float constant) { | ||
Player player = minecraft.player; | ||
if (player == null) return constant; | ||
if (minecraft.crosshairPickEntity == null) return constant; | ||
|
||
if (ManasCoreAttributeUtils.cantHit(player, minecraft.crosshairPickEntity, 0)) return 2.0F; | ||
return constant; | ||
} | ||
} |
51 changes: 51 additions & 0 deletions
51
common/src/main/java/com/github/manasmods/manascore/core/client/MixinMinecraft.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
package com.github.manasmods.manascore.core.client; | ||
|
||
import com.github.manasmods.manascore.attribute.ManasCoreAttributeUtils; | ||
import net.minecraft.client.Minecraft; | ||
import net.minecraft.client.multiplayer.ClientLevel; | ||
import net.minecraft.client.multiplayer.MultiPlayerGameMode; | ||
import net.minecraft.client.player.LocalPlayer; | ||
import net.minecraft.world.InteractionHand; | ||
import net.minecraft.world.item.ItemStack; | ||
import net.minecraft.world.phys.EntityHitResult; | ||
import net.minecraft.world.phys.HitResult; | ||
import org.jetbrains.annotations.Nullable; | ||
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.CallbackInfoReturnable; | ||
|
||
@Mixin(Minecraft.class) | ||
public class MixinMinecraft { | ||
@Shadow protected int missTime; | ||
@Shadow @Nullable public HitResult hitResult; | ||
|
||
@Shadow @Nullable public LocalPlayer player; | ||
@Shadow @Nullable public MultiPlayerGameMode gameMode; | ||
|
||
@Shadow @Nullable public ClientLevel level; | ||
@Inject(method = "startAttack", at = @At("HEAD"), cancellable = true) | ||
private void startAttack(CallbackInfoReturnable<Boolean> cir) { | ||
if (this.missTime > 0) return; | ||
if (this.hitResult == null) return; | ||
|
||
LocalPlayer player = this.player; | ||
if (player == null) return; | ||
if (player.isHandsBusy()) return; | ||
|
||
ItemStack itemStack = this.player.getItemInHand(InteractionHand.MAIN_HAND); | ||
if (level != null && !itemStack.isItemEnabled(level.enabledFeatures())) { | ||
cir.setReturnValue(false); | ||
return; | ||
} | ||
|
||
if(!(this.hitResult instanceof EntityHitResult entityHit)) return; | ||
if(ManasCoreAttributeUtils.cantHit(player, entityHit.getEntity(), 0)) { | ||
if (this.gameMode != null && this.gameMode.hasMissTime()) this.missTime = 10; | ||
this.player.resetAttackStrengthTicker(); | ||
this.player.swing(InteractionHand.MAIN_HAND); | ||
cir.setReturnValue(false); | ||
} | ||
} | ||
} |
23 changes: 23 additions & 0 deletions
23
...on/src/main/java/com/github/manasmods/manascore/core/client/MixinMultiPlayerGameMode.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
package com.github.manasmods.manascore.core.client; | ||
|
||
import com.github.manasmods.manascore.attribute.ManasCoreAttributeUtils; | ||
import net.minecraft.client.Minecraft; | ||
import net.minecraft.client.multiplayer.MultiPlayerGameMode; | ||
import net.minecraft.world.entity.player.Player; | ||
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.CallbackInfoReturnable; | ||
|
||
@Mixin(MultiPlayerGameMode.class) | ||
public class MixinMultiPlayerGameMode { | ||
@Shadow @Final private Minecraft minecraft; | ||
@Inject(method = "getPickRange", at = @At("HEAD"), cancellable = true) | ||
protected void getPickRange(CallbackInfoReturnable<Float> cir) { | ||
Player player = this.minecraft.player; | ||
if (player == null) return; | ||
cir.setReturnValue((float) ManasCoreAttributeUtils.getReachDistance(player)); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters