Search in sources :

Example 1 with EmptyMirror

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);
    }
}
Also used : Vec3(net.minecraft.world.phys.Vec3) EmptyMirror(com.simibubi.create.content.curiosities.symmetry.mirror.EmptyMirror) CompoundTag(net.minecraft.nbt.CompoundTag)

Example 2 with EmptyMirror

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();
    }
}
Also used : PoseStack(com.mojang.blaze3d.vertex.PoseStack) LocalPlayer(net.minecraft.client.player.LocalPlayer) MultiBufferSource(net.minecraft.client.renderer.MultiBufferSource) SymmetryMirror(com.simibubi.create.content.curiosities.symmetry.mirror.SymmetryMirror) Minecraft(net.minecraft.client.Minecraft) Random(java.util.Random) Vec3(net.minecraft.world.phys.Vec3) BakedModel(net.minecraft.client.resources.model.BakedModel) EmptyMirror(com.simibubi.create.content.curiosities.symmetry.mirror.EmptyMirror) BlockPos(net.minecraft.core.BlockPos) VertexConsumer(com.mojang.blaze3d.vertex.VertexConsumer) Camera(net.minecraft.client.Camera) ItemStack(net.minecraft.world.item.ItemStack) SubscribeEvent(net.minecraftforge.eventbus.api.SubscribeEvent) OnlyIn(net.minecraftforge.api.distmarker.OnlyIn)

Example 3 with EmptyMirror

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);
            }
        }
    }
}
Also used : Random(java.util.Random) LocalPlayer(net.minecraft.client.player.LocalPlayer) Vec3(net.minecraft.world.phys.Vec3) EmptyMirror(com.simibubi.create.content.curiosities.symmetry.mirror.EmptyMirror) SymmetryMirror(com.simibubi.create.content.curiosities.symmetry.mirror.SymmetryMirror) ItemStack(net.minecraft.world.item.ItemStack) Minecraft(net.minecraft.client.Minecraft) SubscribeEvent(net.minecraftforge.eventbus.api.SubscribeEvent) OnlyIn(net.minecraftforge.api.distmarker.OnlyIn)

Example 4 with EmptyMirror

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

EmptyMirror (com.simibubi.create.content.curiosities.symmetry.mirror.EmptyMirror)4 Vec3 (net.minecraft.world.phys.Vec3)4 SymmetryMirror (com.simibubi.create.content.curiosities.symmetry.mirror.SymmetryMirror)3 ItemStack (net.minecraft.world.item.ItemStack)3 Random (java.util.Random)2 Minecraft (net.minecraft.client.Minecraft)2 LocalPlayer (net.minecraft.client.player.LocalPlayer)2 BlockPos (net.minecraft.core.BlockPos)2 CompoundTag (net.minecraft.nbt.CompoundTag)2 OnlyIn (net.minecraftforge.api.distmarker.OnlyIn)2 SubscribeEvent (net.minecraftforge.eventbus.api.SubscribeEvent)2 PoseStack (com.mojang.blaze3d.vertex.PoseStack)1 VertexConsumer (com.mojang.blaze3d.vertex.VertexConsumer)1 CrossPlaneMirror (com.simibubi.create.content.curiosities.symmetry.mirror.CrossPlaneMirror)1 PlaneMirror (com.simibubi.create.content.curiosities.symmetry.mirror.PlaneMirror)1 Nonnull (javax.annotation.Nonnull)1 Camera (net.minecraft.client.Camera)1 MultiBufferSource (net.minecraft.client.renderer.MultiBufferSource)1 BakedModel (net.minecraft.client.resources.model.BakedModel)1 Player (net.minecraft.world.entity.player.Player)1