awesome elytra macing
This commit is contained in:
@@ -4,18 +4,17 @@ import net.fabricmc.api.ClientModInitializer;
|
||||
import net.fabricmc.fabric.api.client.event.lifecycle.v1.ClientTickEvents;
|
||||
import net.fabricmc.fabric.api.client.keybinding.v1.KeyBindingHelper;
|
||||
import net.minecraft.client.MinecraftClient;
|
||||
import net.minecraft.client.network.ClientPlayerInteractionManager;
|
||||
import net.minecraft.client.option.KeyBinding;
|
||||
import net.minecraft.client.util.InputUtil;
|
||||
import net.minecraft.entity.Entity;
|
||||
import net.minecraft.entity.LivingEntity;
|
||||
import net.minecraft.entity.attribute.EntityAttributes;
|
||||
import net.minecraft.entity.player.PlayerInventory;
|
||||
import net.minecraft.entity.projectile.ProjectileUtil;
|
||||
import net.minecraft.item.Item;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.item.Items;
|
||||
import net.minecraft.item.*;
|
||||
import net.minecraft.predicate.entity.EntityPredicates;
|
||||
import net.minecraft.util.Hand;
|
||||
import net.minecraft.registry.tag.ItemTags;
|
||||
import net.minecraft.screen.slot.SlotActionType;
|
||||
import net.minecraft.util.Identifier;
|
||||
import net.minecraft.util.hit.EntityHitResult;
|
||||
import net.minecraft.util.hit.HitResult;
|
||||
@@ -35,17 +34,9 @@ public class ElytraMace implements ClientModInitializer
|
||||
keybindCategory
|
||||
)
|
||||
);
|
||||
private final KeyBinding attackKeybind = KeyBindingHelper.registerKeyBinding(
|
||||
new KeyBinding(
|
||||
"key.elytramace.attack",
|
||||
InputUtil.Type.KEYSYM,
|
||||
GLFW.GLFW_KEY_KP_7,
|
||||
keybindCategory
|
||||
)
|
||||
);
|
||||
private KeyBinding cancelFlightKeybind;
|
||||
public static LivingEntity TARGET;
|
||||
private boolean isAttacking = false;
|
||||
private boolean unequipped = false;
|
||||
private boolean lockTarget = false;
|
||||
|
||||
private LivingEntity getTarget()
|
||||
{
|
||||
@@ -69,17 +60,6 @@ public class ElytraMace implements ClientModInitializer
|
||||
return (LivingEntity)result.getEntity();
|
||||
}
|
||||
|
||||
private void getCancelFlightKeybind()
|
||||
{
|
||||
for (KeyBinding keybind : client.options.allKeys)
|
||||
{
|
||||
if (keybind.getBoundKeyTranslationKey().equals("key.elytracancel.cancel_flight"))
|
||||
{
|
||||
cancelFlightKeybind = keybind;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private void updateTarget()
|
||||
{
|
||||
LivingEntity nextTarget = getTarget();
|
||||
@@ -93,7 +73,7 @@ public class ElytraMace implements ClientModInitializer
|
||||
}
|
||||
}
|
||||
|
||||
private int getItemIndex(PlayerInventory inventory, Item item)
|
||||
private int getItem(PlayerInventory inventory, Item item)
|
||||
{
|
||||
for (int i = 0; i < 9; i++)
|
||||
{
|
||||
@@ -105,24 +85,21 @@ public class ElytraMace implements ClientModInitializer
|
||||
return -1;
|
||||
}
|
||||
|
||||
private void attack()
|
||||
private int getAxe(PlayerInventory inventory)
|
||||
{
|
||||
if (client.player == null || client.interactionManager == null)
|
||||
int index = -1;
|
||||
int durability = -1;
|
||||
for (int i = 0; i < 9; i++)
|
||||
{
|
||||
return;
|
||||
ItemStack stack = inventory.getStack(i);
|
||||
int maxDamage = stack.getMaxDamage();
|
||||
if (stack.isIn(ItemTags.AXES) && maxDamage > durability)
|
||||
{
|
||||
index = i;
|
||||
durability = maxDamage;
|
||||
}
|
||||
}
|
||||
isAttacking = true;
|
||||
PlayerInventory inventory = client.player.getInventory();
|
||||
ClientPlayerInteractionManager manager = client.interactionManager;
|
||||
int fireworkSlot = getItemIndex(inventory, Items.FIREWORK_ROCKET);
|
||||
int maceSlot = getItemIndex(inventory, Items.MACE);
|
||||
if (fireworkSlot == -1 || maceSlot == -1)
|
||||
{
|
||||
return;
|
||||
}
|
||||
inventory.setSelectedSlot(fireworkSlot);
|
||||
manager.interactItem(client.player, Hand.MAIN_HAND);
|
||||
isAttacking = false;
|
||||
return index;
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -130,17 +107,41 @@ public class ElytraMace implements ClientModInitializer
|
||||
{
|
||||
client = MinecraftClient.getInstance();
|
||||
ClientTickEvents.END_CLIENT_TICK.register(client -> {
|
||||
if (cancelFlightKeybind == null && client.options != null)
|
||||
if (client.player == null || client.interactionManager == null || client.getNetworkHandler() == null)
|
||||
{
|
||||
getCancelFlightKeybind();
|
||||
return;
|
||||
}
|
||||
while (selectTargetKeybind.wasPressed() && !isAttacking)
|
||||
if (unequipped && !client.player.isGliding())
|
||||
{
|
||||
client.interactionManager.clickSlot(client.player.playerScreenHandler.syncId, 6, 0, SlotActionType.PICKUP, client.player);
|
||||
unequipped = false;
|
||||
PlayerInventory inventory = client.player.getInventory();
|
||||
int axe = getAxe(inventory);
|
||||
int mace = getItem(inventory, Items.MACE);
|
||||
int fireworks = getItem(inventory, Items.FIREWORK_ROCKET);
|
||||
if (TARGET.isBlocking() && axe > -1)
|
||||
{
|
||||
inventory.setSelectedSlot(axe);
|
||||
client.interactionManager.attackEntity(client.player, TARGET);
|
||||
}
|
||||
inventory.setSelectedSlot(mace);
|
||||
client.interactionManager.attackEntity(client.player, TARGET);
|
||||
inventory.setSelectedSlot(fireworks);
|
||||
lockTarget = false;
|
||||
}
|
||||
if (TARGET != null && client.player.isGliding() && !unequipped && client.player.distanceTo(TARGET) <= client.player.getAttributeValue(EntityAttributes.ENTITY_INTERACTION_RANGE) + client.player.getVelocity().length() * 2)
|
||||
{
|
||||
lockTarget = true;
|
||||
client.interactionManager.clickSlot(client.player.playerScreenHandler.syncId, 6, 0, SlotActionType.PICKUP, client.player);
|
||||
unequipped = true;
|
||||
}
|
||||
while (selectTargetKeybind.wasPressed() && !lockTarget)
|
||||
{
|
||||
updateTarget();
|
||||
}
|
||||
while (attackKeybind.wasPressed() && TARGET != null && !isAttacking)
|
||||
if (TARGET != null && !TARGET.isAlive())
|
||||
{
|
||||
attack();
|
||||
TARGET = null;
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
@@ -20,7 +20,6 @@
|
||||
"depends": {
|
||||
"fabricloader": ">=${loader_version}",
|
||||
"fabric-api": "*",
|
||||
"minecraft": "${minecraft_version}",
|
||||
"elytracancel": ">=1.1"
|
||||
"minecraft": "${minecraft_version}"
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user