use of com.simibubi.create.content.curiosities.symmetry.mirror.EmptyMirror in project Create by Creators-of-Create.
the class SymmetryWandItem method checkNBT.
private static void checkNBT(ItemStack wand) {
if (!wand.hasTag() || !wand.getTag().contains(SYMMETRY)) {
wand.setTag(new CompoundTag());
wand.getTag().put(SYMMETRY, new EmptyMirror(new Vec3(0, 0, 0)).writeToNbt());
wand.getTag().putBoolean(ENABLE, false);
}
}
use of com.simibubi.create.content.curiosities.symmetry.mirror.EmptyMirror in project Create by Creators-of-Create.
the class SymmetryHandler method render.
@OnlyIn(Dist.CLIENT)
@SubscribeEvent
public static void render(RenderLevelLastEvent event) {
Minecraft mc = Minecraft.getInstance();
LocalPlayer player = mc.player;
Random random = new Random();
for (int i = 0; i < Inventory.getSelectionSize(); i++) {
ItemStack stackInSlot = player.getInventory().getItem(i);
if (!AllItems.WAND_OF_SYMMETRY.isIn(stackInSlot))
continue;
if (!SymmetryWandItem.isEnabled(stackInSlot))
continue;
SymmetryMirror mirror = SymmetryWandItem.getMirror(stackInSlot);
if (mirror instanceof EmptyMirror)
continue;
BlockPos pos = new BlockPos(mirror.getPosition());
float yShift = 0;
double speed = 1 / 16d;
yShift = Mth.sin((float) (AnimationTickHolder.getRenderTime() * speed)) / 5f;
MultiBufferSource.BufferSource buffer = mc.renderBuffers().bufferSource();
Camera info = mc.gameRenderer.getMainCamera();
Vec3 view = info.getPosition();
PoseStack ms = event.getPoseStack();
ms.pushPose();
ms.translate(-view.x(), -view.y(), -view.z());
ms.translate(pos.getX(), pos.getY(), pos.getZ());
ms.translate(0, yShift + .2f, 0);
mirror.applyModelTransform(ms);
BakedModel model = mirror.getModel().get();
VertexConsumer builder = buffer.getBuffer(RenderType.solid());
mc.getBlockRenderer().getModelRenderer().tesselateBlock(player.level, model, Blocks.AIR.defaultBlockState(), pos, ms, builder, true, random, Mth.getSeed(pos), OverlayTexture.NO_OVERLAY, EmptyModelData.INSTANCE);
buffer.endBatch();
ms.popPose();
}
}
use of com.simibubi.create.content.curiosities.symmetry.mirror.EmptyMirror in project Create by Creators-of-Create.
the class SymmetryHandler method onClientTick.
@OnlyIn(Dist.CLIENT)
@SubscribeEvent
public static void onClientTick(ClientTickEvent event) {
if (event.phase == Phase.START)
return;
Minecraft mc = Minecraft.getInstance();
LocalPlayer player = mc.player;
if (mc.level == null)
return;
if (mc.isPaused())
return;
tickCounter++;
if (tickCounter % 10 == 0) {
for (int i = 0; i < Inventory.getSelectionSize(); i++) {
ItemStack stackInSlot = player.getInventory().getItem(i);
if (stackInSlot != null && AllItems.WAND_OF_SYMMETRY.isIn(stackInSlot) && SymmetryWandItem.isEnabled(stackInSlot)) {
SymmetryMirror mirror = SymmetryWandItem.getMirror(stackInSlot);
if (mirror instanceof EmptyMirror)
continue;
Random r = new Random();
double offsetX = (r.nextDouble() - 0.5) * 0.3;
double offsetZ = (r.nextDouble() - 0.5) * 0.3;
Vec3 pos = mirror.getPosition().add(0.5 + offsetX, 1 / 4d, 0.5 + offsetZ);
Vec3 speed = new Vec3(0, r.nextDouble() * 1 / 8f, 0);
mc.level.addParticle(ParticleTypes.END_ROD, pos.x, pos.y, pos.z, speed.x, speed.y, speed.z);
}
}
}
}
use of com.simibubi.create.content.curiosities.symmetry.mirror.EmptyMirror 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