Search in sources :

Example 1 with ArmorStandEntityAccessor

use of eu.pb4.armorstandeditor.mixin.ArmorStandEntityAccessor in project ArmorStandEditor by Patbox.

the class Events method modifyArmorStand.

public static void modifyArmorStand(ServerPlayerEntity player, ArmorStandEntity armorStand, int val, Entity realEntity) {
    SPEInterface spei = (SPEInterface) player;
    ArmorStandEntityAccessor asea = (ArmorStandEntityAccessor) armorStand;
    double power = spei.getArmorStandEditorPower();
    int dX = spei.getArmorStandEditorXYZ() == 0 ? 1 : 0;
    int dY = spei.getArmorStandEditorXYZ() == 1 ? 1 : 0;
    int dZ = spei.getArmorStandEditorXYZ() == 2 ? 1 : 0;
    double posX = armorStand.getX();
    double posY = armorStand.getY();
    double posZ = armorStand.getZ();
    float angleChange = (float) (val * power * 30);
    EulerAngle angle;
    switch(spei.getArmorStandEditorAction()) {
        case MOVE:
            armorStand.teleport(posX + dX * power * val, posY + dY * power * val, posZ + dZ * power * val);
            break;
        case ROTATE:
            armorStand.setYaw(armorStand.getYaw(1.0F) + angleChange);
            armorStand.updatePositionAndAngles(posX, posY, posZ, armorStand.getYaw(1.0F), 0);
            break;
        case TOGGLE_GRAVITY:
            armorStand.setNoGravity(!armorStand.hasNoGravity());
            break;
        case TOGGLE_BASE:
            asea.callSetHideBasePlate(!armorStand.shouldHideBasePlate());
            break;
        case TOGGLE_SIZE:
            asea.callSetSmall(!armorStand.isSmall());
            break;
        case TOGGLE_ARMS:
            asea.callSetShowArms(!armorStand.shouldShowArms());
            break;
        case TOGGLE_VISIBILITY:
            armorStand.setInvisible(!armorStand.isInvisible());
            break;
        case MODIFY_HEAD:
            angle = armorStand.getHeadRotation();
            armorStand.setHeadRotation(new EulerAngle(angle.getPitch() + dX * angleChange, angle.getYaw() + dY * angleChange, angle.getRoll() + dZ * angleChange));
            break;
        case MODIFY_BODY:
            angle = armorStand.getBodyRotation();
            armorStand.setBodyRotation(new EulerAngle(angle.getPitch() + dX * angleChange, angle.getYaw() + dY * angleChange, angle.getRoll() + dZ * angleChange));
            break;
        case MODIFY_LEFT_ARM:
            angle = asea.getLeftArmRotation();
            armorStand.setLeftArmRotation(new EulerAngle(angle.getPitch() + dX * angleChange, angle.getYaw() + dY * angleChange, angle.getRoll() + dZ * angleChange));
            break;
        case MODIFY_RIGHT_ARM:
            angle = asea.getRightArmRotation();
            armorStand.setRightArmRotation(new EulerAngle(angle.getPitch() + dX * angleChange, angle.getYaw() + dY * angleChange, angle.getRoll() + dZ * angleChange));
            break;
        case MODIFY_LEFT_LEG:
            angle = asea.getLeftLegRotation();
            armorStand.setLeftLegRotation(new EulerAngle(angle.getPitch() + dX * angleChange, angle.getYaw() + dY * angleChange, angle.getRoll() + dZ * angleChange));
            break;
        case MODIFY_RIGHT_LEG:
            angle = asea.getRightLegRotation();
            armorStand.setRightLegRotation(new EulerAngle(angle.getPitch() + dX * angleChange, angle.getYaw() + dY * angleChange, angle.getRoll() + dZ * angleChange));
            break;
        case RESET_POSE:
            armorStand.setHeadRotation(new EulerAngle(0, 0, 0));
            armorStand.setBodyRotation(new EulerAngle(0, 0, 0));
            armorStand.setLeftArmRotation(new EulerAngle(0, 0, 0));
            armorStand.setRightArmRotation(new EulerAngle(0, 0, 0));
            armorStand.setLeftLegRotation(new EulerAngle(0, 0, 0));
            armorStand.setRightLegRotation(new EulerAngle(0, 0, 0));
            break;
        case FLIP_POSE:
            ArmorStandData data = new ArmorStandData(armorStand);
            armorStand.setHeadRotation(new EulerAngle(data.headRotation.getPitch(), 360 - data.headRotation.getYaw(), 360 - data.headRotation.getRoll()));
            armorStand.setBodyRotation(new EulerAngle(data.bodyRotation.getPitch(), 360 - data.bodyRotation.getYaw(), 360 - data.bodyRotation.getRoll()));
            armorStand.setRightArmRotation(new EulerAngle(data.leftArmRotation.getPitch(), 360 - data.leftArmRotation.getYaw(), 360 - data.leftArmRotation.getRoll()));
            armorStand.setLeftArmRotation(new EulerAngle(data.rightArmRotation.getPitch(), 360 - data.rightArmRotation.getYaw(), 360 - data.rightArmRotation.getRoll()));
            armorStand.setRightLegRotation(new EulerAngle(data.leftLegRotation.getPitch(), 360 - data.leftLegRotation.getYaw(), 360 - data.leftLegRotation.getRoll()));
            armorStand.setLeftLegRotation(new EulerAngle(data.rightLegRotation.getPitch(), 360 - data.rightLegRotation.getYaw(), 360 - data.rightLegRotation.getRoll()));
            break;
        case COPY:
            spei.setArmorStandEditorData(new ArmorStandData(armorStand));
            spei.setArmorStandEditorAction(EditorActions.PASTE);
            player.sendMessage(new TranslatableText("armorstandeditor.message.copied"), true);
            break;
        case PASTE:
            if (spei.getArmorStandEditorData() != null) {
                ArmorStandData base = spei.getArmorStandEditorData();
                base.apply(armorStand, player.isCreative());
                if (realEntity != null) {
                    realEntity.setCustomNameVisible(base.customNameVisible);
                    if (base.customName != null) {
                        realEntity.setCustomName(base.customName);
                    }
                    if (player.isCreative() && realEntity instanceof LivingEntity) {
                        realEntity.equipStack(EquipmentSlot.HEAD, base.headItem);
                        realEntity.equipStack(EquipmentSlot.CHEST, base.chestItem);
                        realEntity.equipStack(EquipmentSlot.LEGS, base.legsItem);
                        realEntity.equipStack(EquipmentSlot.FEET, base.feetItem);
                        realEntity.equipStack(EquipmentSlot.MAINHAND, base.mainHandItem);
                        realEntity.equipStack(EquipmentSlot.OFFHAND, base.offhandItem);
                    }
                }
                player.sendMessage(new TranslatableText("armorstandeditor.message.pasted"), true);
            }
            break;
        case INVENTORY:
            if (realEntity instanceof LivingEntity) {
                EditorGuis.openInventoryEditor(player, (LivingEntity) realEntity);
            } else {
                EditorGuis.openInventoryEditor(player, armorStand);
            }
            break;
        case RENAME:
            Entity nameTarget = realEntity != null ? realEntity : armorStand;
            EditorGuis.openRenaming(player, nameTarget);
            break;
    }
    if (realEntity != null) {
        ((EntityDisguise) realEntity).disguiseAs(armorStand);
    }
}
Also used : TranslatableText(net.minecraft.text.TranslatableText) LivingEntity(net.minecraft.entity.LivingEntity) ItemFrameEntity(net.minecraft.entity.decoration.ItemFrameEntity) Entity(net.minecraft.entity.Entity) PlayerEntity(net.minecraft.entity.player.PlayerEntity) LivingEntity(net.minecraft.entity.LivingEntity) ArmorStandEntity(net.minecraft.entity.decoration.ArmorStandEntity) ServerPlayerEntity(net.minecraft.server.network.ServerPlayerEntity) SPEInterface(eu.pb4.armorstandeditor.helpers.SPEInterface) ArmorStandEntityAccessor(eu.pb4.armorstandeditor.mixin.ArmorStandEntityAccessor) ArmorStandData(eu.pb4.armorstandeditor.helpers.ArmorStandData) EulerAngle(net.minecraft.util.math.EulerAngle) EntityDisguise(xyz.nucleoid.disguiselib.casts.EntityDisguise)

Example 2 with ArmorStandEntityAccessor

use of eu.pb4.armorstandeditor.mixin.ArmorStandEntityAccessor in project ArmorStandEditor by Patbox.

the class ArmorStandData method apply.

public void apply(ArmorStandEntity armorStand, boolean modifyInventory) {
    ArmorStandEntityAccessor asea = (ArmorStandEntityAccessor) armorStand;
    if (this.yaw != -1) {
        armorStand.setYaw(this.yaw);
        double posX = armorStand.getX();
        double posY = armorStand.getY();
        double posZ = armorStand.getZ();
        armorStand.updatePositionAndAngles(posX, posY, posZ, this.yaw, 0);
    }
    armorStand.setNoGravity(this.noGravity);
    asea.callSetHideBasePlate(this.hidePlate);
    asea.callSetSmall(this.small);
    asea.callSetShowArms(this.showArms);
    armorStand.setInvisible(this.invisible);
    armorStand.setHeadRotation(this.headRotation);
    armorStand.setBodyRotation(this.bodyRotation);
    armorStand.setLeftArmRotation(this.leftArmRotation);
    armorStand.setRightArmRotation(this.rightArmRotation);
    armorStand.setLeftLegRotation(this.leftLegRotation);
    armorStand.setRightLegRotation(this.rightLegRotation);
    armorStand.setCustomNameVisible(this.customNameVisible);
    armorStand.setCustomName(this.customName);
    asea.setDisabledSlots(this.disabledSlots);
    if (modifyInventory) {
        armorStand.equipStack(EquipmentSlot.HEAD, this.headItem);
        armorStand.equipStack(EquipmentSlot.CHEST, this.chestItem);
        armorStand.equipStack(EquipmentSlot.LEGS, this.legsItem);
        armorStand.equipStack(EquipmentSlot.FEET, this.feetItem);
        armorStand.equipStack(EquipmentSlot.MAINHAND, this.mainHandItem);
        armorStand.equipStack(EquipmentSlot.OFFHAND, this.offhandItem);
    }
}
Also used : ArmorStandEntityAccessor(eu.pb4.armorstandeditor.mixin.ArmorStandEntityAccessor)

Example 3 with ArmorStandEntityAccessor

use of eu.pb4.armorstandeditor.mixin.ArmorStandEntityAccessor in project ArmorStandEditor by Patbox.

the class ArmorStandData method copyFrom.

public void copyFrom(ArmorStandEntity armorStand) {
    ArmorStandEntityAccessor asea = (ArmorStandEntityAccessor) armorStand;
    this.yaw = armorStand.yaw;
    this.noGravity = armorStand.hasNoGravity();
    this.hidePlate = armorStand.shouldHideBasePlate();
    this.small = armorStand.isSmall();
    this.showArms = armorStand.shouldShowArms();
    this.invisible = armorStand.isInvisible();
    this.headRotation = armorStand.getHeadRotation();
    this.bodyRotation = armorStand.getBodyRotation();
    this.leftArmRotation = asea.getLeftArmRotation();
    this.rightArmRotation = asea.getRightArmRotation();
    this.leftLegRotation = asea.getLeftLegRotation();
    this.rightLegRotation = asea.getRightLegRotation();
    this.customNameVisible = armorStand.isCustomNameVisible() && armorStand.hasCustomName();
    if (armorStand.getCustomName() != null) {
        this.customName = armorStand.getCustomName().shallowCopy();
    }
    this.headItem = armorStand.getEquippedStack(EquipmentSlot.HEAD).copy();
    this.chestItem = armorStand.getEquippedStack(EquipmentSlot.CHEST).copy();
    this.legsItem = armorStand.getEquippedStack(EquipmentSlot.LEGS).copy();
    this.feetItem = armorStand.getEquippedStack(EquipmentSlot.FEET).copy();
    this.mainHandItem = armorStand.getEquippedStack(EquipmentSlot.MAINHAND).copy();
    this.offhandItem = armorStand.getEquippedStack(EquipmentSlot.OFFHAND).copy();
    this.disabledSlots = asea.getDisabledSlots();
}
Also used : ArmorStandEntityAccessor(eu.pb4.armorstandeditor.mixin.ArmorStandEntityAccessor)

Example 4 with ArmorStandEntityAccessor

use of eu.pb4.armorstandeditor.mixin.ArmorStandEntityAccessor in project ArmorStandEditor by Patbox.

the class EditorGuis method openInventoryEditor.

public static void openInventoryEditor(ServerPlayerEntity player, LivingEntity entity) {
    SimpleGui gui = new SimpleGui(ScreenHandlerType.GENERIC_9X2, player, false);
    ArmorStandInventory inventory = new ArmorStandInventory(entity);
    gui.setTitle(new TranslatableText("armorstandeditor.gui.inventory_title"));
    for (int x = 0; x < inventory.size(); x++) {
        gui.setSlotRedirect(x, new Slot(inventory, x, 0, 0));
        if (entity instanceof ArmorStandEntity) {
            ArmorStandEntity ae = (ArmorStandEntity) entity;
            ArmorStandEntityAccessor asea = (ArmorStandEntityAccessor) ae;
            boolean isUnlocked = isSlotUnlocked(ae, ArmorStandInventory.getEquipmentSlot(x));
            gui.setSlot(x + 9, new GuiElementBuilder(isUnlocked ? Items.GREEN_STAINED_GLASS_PANE : Items.RED_STAINED_GLASS_PANE).setName(new TranslatableText(isUnlocked ? "narrator.button.difficulty_lock.unlocked" : "narrator.button.difficulty_lock.locked").setStyle(Style.EMPTY.withItalic(false))).setCallback((index, type, action) -> {
                EquipmentSlot slot = ArmorStandInventory.getEquipmentSlot(index - 9);
                int disabledSlots = asea.getDisabledSlots();
                boolean isUnlockedTmp = isSlotUnlocked(ae, slot);
                if (isUnlockedTmp) {
                    disabledSlots |= 1 << slot.getArmorStandSlotId();
                    disabledSlots |= 1 << slot.getArmorStandSlotId() + 8;
                    disabledSlots |= 1 << slot.getArmorStandSlotId() + 16;
                } else {
                    disabledSlots &= ~(1 << slot.getArmorStandSlotId());
                    disabledSlots &= ~(1 << slot.getArmorStandSlotId() + 8);
                    disabledSlots &= ~(1 << slot.getArmorStandSlotId() + 16);
                }
                asea.setDisabledSlots(disabledSlots);
                boolean isUnlocked2 = isSlotUnlocked(ae, slot);
                ItemStack stack = new ItemStack(isUnlocked2 ? Items.GREEN_STAINED_GLASS_PANE : Items.RED_STAINED_GLASS_PANE);
                stack.setCustomName(new TranslatableText(isUnlocked2 ? "narrator.button.difficulty_lock.unlocked" : "narrator.button.difficulty_lock.locked").setStyle(Style.EMPTY.withItalic(false)));
                ((GuiElement) gui.getSlot(index)).setItemStack(stack);
            }));
        } else {
            gui.setSlot(x + 9, new GuiElementBuilder(Items.RED_STAINED_GLASS_PANE).setName(new TranslatableText("armorstandeditor.gui.cantlockslots").setStyle(Style.EMPTY.withItalic(false).withColor(Formatting.RED))));
        }
    }
    GuiElement empty = new GuiElementBuilder(Items.GRAY_STAINED_GLASS_PANE).setName(new LiteralText("")).build();
    gui.setSlot(6, empty);
    gui.setSlot(7, empty);
    gui.setSlot(8, empty);
    gui.setSlot(15, empty);
    gui.setSlot(16, empty);
    gui.setSlot(17, new GuiElementBuilder(Items.BARRIER).setName(new TranslatableText("armorstandeditor.gui.close").setStyle(Style.EMPTY.withItalic(false))).setCallback(((index, type, action) -> {
        gui.close();
    })));
    gui.open();
}
Also used : TranslatableText(net.minecraft.text.TranslatableText) LiteralText(net.minecraft.text.LiteralText) ConfigManager(eu.pb4.armorstandeditor.config.ConfigManager) Item(net.minecraft.item.Item) StringTag(net.minecraft.nbt.StringTag) Permissions(me.lucko.fabric.api.permissions.v0.Permissions) TranslatableText(net.minecraft.text.TranslatableText) ItemFrameEntity(net.minecraft.entity.decoration.ItemFrameEntity) Slot(net.minecraft.screen.slot.Slot) ArrayList(java.util.ArrayList) ItemStack(net.minecraft.item.ItemStack) Style(net.minecraft.text.Style) GuiElementInterface(eu.pb4.sgui.api.elements.GuiElementInterface) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) AnvilInputGui(eu.pb4.sgui.api.gui.AnvilInputGui) ItemFrameEntityAccessor(eu.pb4.armorstandeditor.mixin.ItemFrameEntityAccessor) Enchantments(net.minecraft.enchantment.Enchantments) EquipmentSlot(net.minecraft.entity.EquipmentSlot) GuiElementBuilder(eu.pb4.sgui.api.elements.GuiElementBuilder) ClickType(eu.pb4.sgui.api.ClickType) ScreenHandlerType(net.minecraft.screen.ScreenHandlerType) Entity(net.minecraft.entity.Entity) PlayerEntity(net.minecraft.entity.player.PlayerEntity) ArmorStandEntityAccessor(eu.pb4.armorstandeditor.mixin.ArmorStandEntityAccessor) LivingEntity(net.minecraft.entity.LivingEntity) ArmorStandEntity(net.minecraft.entity.decoration.ArmorStandEntity) Collection(java.util.Collection) ItemFrameInventory(eu.pb4.armorstandeditor.helpers.ItemFrameInventory) GuiElement(eu.pb4.sgui.api.elements.GuiElement) Items(net.minecraft.item.Items) ArmorStandData(eu.pb4.armorstandeditor.helpers.ArmorStandData) Collectors(java.util.stream.Collectors) SPEInterface(eu.pb4.armorstandeditor.helpers.SPEInterface) Formatting(net.minecraft.util.Formatting) List(java.util.List) ServerPlayerEntity(net.minecraft.server.network.ServerPlayerEntity) ArmorStandInventory(eu.pb4.armorstandeditor.helpers.ArmorStandInventory) ArmorStandPreset(eu.pb4.armorstandeditor.config.ArmorStandPreset) Text(net.minecraft.text.Text) SlotActionType(net.minecraft.screen.slot.SlotActionType) ListTag(net.minecraft.nbt.ListTag) SimpleGui(eu.pb4.sgui.api.gui.SimpleGui) EquipmentSlot(net.minecraft.entity.EquipmentSlot) ArmorStandInventory(eu.pb4.armorstandeditor.helpers.ArmorStandInventory) GuiElementBuilder(eu.pb4.sgui.api.elements.GuiElementBuilder) ArmorStandEntityAccessor(eu.pb4.armorstandeditor.mixin.ArmorStandEntityAccessor) Slot(net.minecraft.screen.slot.Slot) EquipmentSlot(net.minecraft.entity.EquipmentSlot) SimpleGui(eu.pb4.sgui.api.gui.SimpleGui) ItemStack(net.minecraft.item.ItemStack) ArmorStandEntity(net.minecraft.entity.decoration.ArmorStandEntity) GuiElement(eu.pb4.sgui.api.elements.GuiElement) LiteralText(net.minecraft.text.LiteralText)

Aggregations

ArmorStandEntityAccessor (eu.pb4.armorstandeditor.mixin.ArmorStandEntityAccessor)4 ArmorStandData (eu.pb4.armorstandeditor.helpers.ArmorStandData)2 SPEInterface (eu.pb4.armorstandeditor.helpers.SPEInterface)2 Entity (net.minecraft.entity.Entity)2 LivingEntity (net.minecraft.entity.LivingEntity)2 ArmorStandEntity (net.minecraft.entity.decoration.ArmorStandEntity)2 ItemFrameEntity (net.minecraft.entity.decoration.ItemFrameEntity)2 PlayerEntity (net.minecraft.entity.player.PlayerEntity)2 ServerPlayerEntity (net.minecraft.server.network.ServerPlayerEntity)2 TranslatableText (net.minecraft.text.TranslatableText)2 ArmorStandPreset (eu.pb4.armorstandeditor.config.ArmorStandPreset)1 ConfigManager (eu.pb4.armorstandeditor.config.ConfigManager)1 ArmorStandInventory (eu.pb4.armorstandeditor.helpers.ArmorStandInventory)1 ItemFrameInventory (eu.pb4.armorstandeditor.helpers.ItemFrameInventory)1 ItemFrameEntityAccessor (eu.pb4.armorstandeditor.mixin.ItemFrameEntityAccessor)1 ClickType (eu.pb4.sgui.api.ClickType)1 GuiElement (eu.pb4.sgui.api.elements.GuiElement)1 GuiElementBuilder (eu.pb4.sgui.api.elements.GuiElementBuilder)1 GuiElementInterface (eu.pb4.sgui.api.elements.GuiElementInterface)1 AnvilInputGui (eu.pb4.sgui.api.gui.AnvilInputGui)1