Search in sources :

Example 1 with CrossPlaneMirror

use of com.simibubi.create.content.curiosities.symmetry.mirror.CrossPlaneMirror in project Create by Creators-of-Create.

the class SymmetryWandScreen method init.

@Override
public void init() {
    setWindowSize(background.width, background.height);
    setWindowOffset(-20, 0);
    super.init();
    int x = guiLeft;
    int y = guiTop;
    labelType = new Label(x + 49, y + 28, TextComponent.EMPTY).colored(0xFFFFFFFF).withShadow();
    labelAlign = new Label(x + 49, y + 50, TextComponent.EMPTY).colored(0xFFFFFFFF).withShadow();
    int state = currentElement instanceof TriplePlaneMirror ? 2 : currentElement instanceof CrossPlaneMirror ? 1 : 0;
    areaType = new SelectionScrollInput(x + 45, y + 21, 109, 18).forOptions(SymmetryMirror.getMirrors()).titled(mirrorType.plainCopy()).writingTo(labelType).setState(state);
    areaType.calling(position -> {
        switch(position) {
            case 0:
                currentElement = new PlaneMirror(currentElement.getPosition());
                break;
            case 1:
                currentElement = new CrossPlaneMirror(currentElement.getPosition());
                break;
            case 2:
                currentElement = new TriplePlaneMirror(currentElement.getPosition());
                break;
            default:
                break;
        }
        initAlign(currentElement, x, y);
    });
    initAlign(currentElement, x, y);
    addRenderableWidget(labelAlign);
    addRenderableWidget(areaType);
    addRenderableWidget(labelType);
    confirmButton = new IconButton(x + background.width - 33, y + background.height - 24, AllIcons.I_CONFIRM);
    confirmButton.withCallback(() -> {
        onClose();
    });
    addRenderableWidget(confirmButton);
}
Also used : TriplePlaneMirror(com.simibubi.create.content.curiosities.symmetry.mirror.TriplePlaneMirror) CrossPlaneMirror(com.simibubi.create.content.curiosities.symmetry.mirror.CrossPlaneMirror) PlaneMirror(com.simibubi.create.content.curiosities.symmetry.mirror.PlaneMirror) IconButton(com.simibubi.create.foundation.gui.widget.IconButton) Label(com.simibubi.create.foundation.gui.widget.Label) CrossPlaneMirror(com.simibubi.create.content.curiosities.symmetry.mirror.CrossPlaneMirror) TriplePlaneMirror(com.simibubi.create.content.curiosities.symmetry.mirror.TriplePlaneMirror) SelectionScrollInput(com.simibubi.create.foundation.gui.widget.SelectionScrollInput)

Example 2 with CrossPlaneMirror

use of com.simibubi.create.content.curiosities.symmetry.mirror.CrossPlaneMirror in project Create by Creators-of-Create.

the class SymmetryWandItem method useOn.

@Nonnull
@Override
public InteractionResult useOn(UseOnContext context) {
    Player player = context.getPlayer();
    BlockPos pos = context.getClickedPos();
    if (player == null)
        return InteractionResult.PASS;
    player.getCooldowns().addCooldown(this, 5);
    ItemStack wand = player.getItemInHand(context.getHand());
    checkNBT(wand);
    // Shift -> open GUI
    if (player.isShiftKeyDown()) {
        if (player.level.isClientSide) {
            DistExecutor.unsafeRunWhenOn(Dist.CLIENT, () -> () -> {
                openWandGUI(wand, context.getHand());
            });
            player.getCooldowns().addCooldown(this, 5);
        }
        return InteractionResult.SUCCESS;
    }
    if (context.getLevel().isClientSide || context.getHand() != InteractionHand.MAIN_HAND)
        return InteractionResult.SUCCESS;
    CompoundTag compound = wand.getTag().getCompound(SYMMETRY);
    pos = pos.relative(context.getClickedFace());
    SymmetryMirror previousElement = SymmetryMirror.fromNBT(compound);
    // No Shift -> Make / Move Mirror
    wand.getTag().putBoolean(ENABLE, true);
    Vec3 pos3d = new Vec3(pos.getX(), pos.getY(), pos.getZ());
    SymmetryMirror newElement = new PlaneMirror(pos3d);
    if (previousElement instanceof EmptyMirror) {
        newElement.setOrientation((player.getDirection() == Direction.NORTH || player.getDirection() == Direction.SOUTH) ? PlaneMirror.Align.XY.ordinal() : PlaneMirror.Align.YZ.ordinal());
        newElement.enable = true;
        wand.getTag().putBoolean(ENABLE, true);
    } else {
        previousElement.setPosition(pos3d);
        if (previousElement instanceof PlaneMirror) {
            previousElement.setOrientation((player.getDirection() == Direction.NORTH || player.getDirection() == Direction.SOUTH) ? PlaneMirror.Align.XY.ordinal() : PlaneMirror.Align.YZ.ordinal());
        }
        if (previousElement instanceof CrossPlaneMirror) {
            float rotation = player.getYHeadRot();
            float abs = Math.abs(rotation % 90);
            boolean diagonal = abs > 22 && abs < 45 + 22;
            previousElement.setOrientation(diagonal ? CrossPlaneMirror.Align.D.ordinal() : CrossPlaneMirror.Align.Y.ordinal());
        }
        newElement = previousElement;
    }
    compound = newElement.writeToNbt();
    wand.getTag().put(SYMMETRY, compound);
    player.setItemInHand(context.getHand(), wand);
    return InteractionResult.SUCCESS;
}
Also used : CrossPlaneMirror(com.simibubi.create.content.curiosities.symmetry.mirror.CrossPlaneMirror) PlaneMirror(com.simibubi.create.content.curiosities.symmetry.mirror.PlaneMirror) Player(net.minecraft.world.entity.player.Player) Vec3(net.minecraft.world.phys.Vec3) BlockPos(net.minecraft.core.BlockPos) EmptyMirror(com.simibubi.create.content.curiosities.symmetry.mirror.EmptyMirror) SymmetryMirror(com.simibubi.create.content.curiosities.symmetry.mirror.SymmetryMirror) CrossPlaneMirror(com.simibubi.create.content.curiosities.symmetry.mirror.CrossPlaneMirror) ItemStack(net.minecraft.world.item.ItemStack) CompoundTag(net.minecraft.nbt.CompoundTag) Nonnull(javax.annotation.Nonnull)

Aggregations

CrossPlaneMirror (com.simibubi.create.content.curiosities.symmetry.mirror.CrossPlaneMirror)2 PlaneMirror (com.simibubi.create.content.curiosities.symmetry.mirror.PlaneMirror)2 EmptyMirror (com.simibubi.create.content.curiosities.symmetry.mirror.EmptyMirror)1 SymmetryMirror (com.simibubi.create.content.curiosities.symmetry.mirror.SymmetryMirror)1 TriplePlaneMirror (com.simibubi.create.content.curiosities.symmetry.mirror.TriplePlaneMirror)1 IconButton (com.simibubi.create.foundation.gui.widget.IconButton)1 Label (com.simibubi.create.foundation.gui.widget.Label)1 SelectionScrollInput (com.simibubi.create.foundation.gui.widget.SelectionScrollInput)1 Nonnull (javax.annotation.Nonnull)1 BlockPos (net.minecraft.core.BlockPos)1 CompoundTag (net.minecraft.nbt.CompoundTag)1 Player (net.minecraft.world.entity.player.Player)1 ItemStack (net.minecraft.world.item.ItemStack)1 Vec3 (net.minecraft.world.phys.Vec3)1