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);
}
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;
}
Aggregations