use of eu.pb4.armorstandeditor.helpers.SPEInterface in project ArmorStandEditor by Patbox.
the class EditorGuis method createIcon.
private static void createIcon(ServerPlayerEntity player, SimpleGui gui, int index, Item item, String text, EditorActions action) {
if (!Permissions.check(player, "armorstandeditor" + action.permission, ConfigManager.getConfig().configData.toggleAllPermissionOnByDefault)) {
return;
}
ItemStack itemStack = item.getDefaultStack();
itemStack.setCustomName(new TranslatableText("armorstandeditor.gui.name." + text).setStyle(Style.EMPTY.withItalic(false)));
itemStack.addHideFlag(ItemStack.TooltipSection.ENCHANTMENTS);
itemStack.addHideFlag(ItemStack.TooltipSection.MODIFIERS);
if (((SPEInterface) player).getArmorStandEditorAction() == action) {
itemStack.addEnchantment(Enchantments.POWER, 1);
}
gui.setSlot(index, itemStack, (index2, type, actionType) -> {
((SPEInterface) player).setArmorStandEditorAction(action);
});
}
use of eu.pb4.armorstandeditor.helpers.SPEInterface 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);
}
}
use of eu.pb4.armorstandeditor.helpers.SPEInterface in project ArmorStandEditor by Patbox.
the class EditorGuis method openPresetSelector.
public static void openPresetSelector(ServerPlayerEntity player) {
List<ArmorStandPreset> presets = new ArrayList<>(ConfigManager.PRESETS.values());
final int presetsSize = presets.size();
AtomicInteger page = new AtomicInteger();
final int maxPage = (int) Math.ceil((double) presetsSize / 18);
SimpleGui gui = new SimpleGui(ScreenHandlerType.GENERIC_9X3, player, false) {
@Override
public void onUpdate(boolean firstUpdate) {
super.onUpdate(firstUpdate);
if (firstUpdate) {
for (int x = 0; x < 9; x++) {
this.setSlot(x + 18, new GuiElementBuilder(Items.GRAY_STAINED_GLASS_PANE).setName(new LiteralText("")));
}
}
for (int x = 0; x < 18; x++) {
this.clearSlot(x);
if (page.get() * 18 + x < presetsSize) {
final ArmorStandPreset preset = presets.get(page.get() * 18 + x);
this.setSlot(x, new GuiElementBuilder(Items.ARMOR_STAND).setName(new LiteralText(preset.name).setStyle(Style.EMPTY.withItalic(false).withColor(Formatting.GREEN))).addLoreLine(new TranslatableText("armorstandeditor.gui.preset-author", preset.author).setStyle(Style.EMPTY.withItalic(false).withColor(Formatting.GRAY))).setCallback((t1, t2, t3) -> {
((SPEInterface) this.player).setArmorStandEditorData(preset.asData());
((SPEInterface) this.player).setArmorStandEditorAction(EditorActions.PASTE);
player.sendMessage(new TranslatableText("armorstandeditor.message.copied"), true);
this.close();
}));
}
}
this.setSlot(this.size - 5, new GuiElementBuilder(Items.BARRIER).setName(new TranslatableText("dataPack.validation.back").setStyle(Style.EMPTY.withItalic(false))).setCallback((index, type, action) -> {
this.close();
}));
this.setSlot(this.size - 8, new GuiElementBuilder(page.get() != 0 ? Items.ARROW : Items.LIGHT_GRAY_STAINED_GLASS_PANE).setName(new TranslatableText("spectatorMenu.previous_page").setStyle(Style.EMPTY.withItalic(false))).setCallback((index, type, action) -> {
if (page.addAndGet(-1) < 0) {
page.set(0);
}
this.onUpdate(false);
}));
this.setSlot(this.size - 2, new GuiElementBuilder(page.get() != maxPage - 1 ? Items.ARROW : Items.LIGHT_GRAY_STAINED_GLASS_PANE).setName(new TranslatableText("spectatorMenu.next_page").setStyle(Style.EMPTY.withItalic(false))).setCallback((index, type, action) -> {
if (page.addAndGet(1) >= maxPage) {
page.set(maxPage - 1);
}
this.onUpdate(false);
}));
}
};
gui.setTitle(new TranslatableText("armorstandeditor.gui.presets_title"));
gui.open();
}
use of eu.pb4.armorstandeditor.helpers.SPEInterface in project ArmorStandEditor by Patbox.
the class EditorGuis method createIconCustomPower.
private static void createIconCustomPower(ServerPlayerEntity player, SimpleGui gui, int index, Item item) {
ItemStack itemStack = item.getDefaultStack();
itemStack.setCustomName(new TranslatableText("armorstandeditor.gui.name.custom_change").setStyle(Style.EMPTY.withItalic(false)));
SPEInterface spe = (SPEInterface) player;
float power = spe.getArmorStandEditorPower();
ListTag lore = new ListTag();
lore.add(StringTag.of(Text.Serializer.toJson(new TranslatableText("armorstandeditor.gui.blocksdeg", (Math.round(power * 100) / 100f), Math.floor(power * 3000) / 100).setStyle(Style.EMPTY.withItalic(false).withColor(Formatting.GRAY)))));
itemStack.getOrCreateTag().getCompound("display").put("Lore", lore);
itemStack.addHideFlag(ItemStack.TooltipSection.ENCHANTMENTS);
itemStack.addHideFlag(ItemStack.TooltipSection.MODIFIERS);
if (power != 1f && power != 0.01f && power != 0.1f) {
itemStack.addEnchantment(Enchantments.POWER, 1);
}
gui.setSlot(index, itemStack, (index2, type, actionType) -> {
if (!type.isMiddle) {
float tmp = power + (0.01f * (type.shift ? 10 : 1) * (type.isLeft ? -1 : 1));
float value = (Math.round(tmp * 100) / 100f);
if (value > 0 && value < 5) {
spe.setArmorStandEditorPower(value);
}
}
});
}
use of eu.pb4.armorstandeditor.helpers.SPEInterface in project ArmorStandEditor by Patbox.
the class EditorGuis method createIcon.
private static void createIcon(ServerPlayerEntity player, SimpleGui gui, int index, Item item, String text, int xyz) {
ItemStack itemStack = item.getDefaultStack();
itemStack.setCustomName(new TranslatableText("armorstandeditor.gui.name." + text).setStyle(Style.EMPTY.withItalic(false)));
itemStack.addHideFlag(ItemStack.TooltipSection.ENCHANTMENTS);
itemStack.addHideFlag(ItemStack.TooltipSection.MODIFIERS);
if (((SPEInterface) player).getArmorStandEditorXYZ() == xyz) {
itemStack.addEnchantment(Enchantments.POWER, 1);
}
gui.setSlot(index, itemStack, (index2, type, actionType) -> {
((SPEInterface) player).setArmorStandEditorXYZ(xyz);
});
}
Aggregations