use of com.simibubi.create.content.curiosities.symmetry.mirror.SymmetryMirror in project Create by Creators-of-Create.
the class SymmetryWandItem method remove.
public static void remove(Level world, ItemStack wand, Player player, BlockPos pos) {
BlockState air = Blocks.AIR.defaultBlockState();
BlockState ogBlock = world.getBlockState(pos);
checkNBT(wand);
if (!isEnabled(wand))
return;
Map<BlockPos, BlockState> blockSet = new HashMap<>();
blockSet.put(pos, air);
SymmetryMirror symmetry = SymmetryMirror.fromNBT((CompoundTag) wand.getTag().getCompound(SYMMETRY));
Vec3 mirrorPos = symmetry.getPosition();
if (mirrorPos.distanceTo(Vec3.atLowerCornerOf(pos)) > AllConfigs.SERVER.curiosities.maxSymmetryWandRange.get())
return;
symmetry.process(blockSet);
BlockPos to = new BlockPos(mirrorPos);
List<BlockPos> targets = new ArrayList<>();
targets.add(pos);
for (BlockPos position : blockSet.keySet()) {
if (!player.isCreative() && ogBlock.getBlock() != world.getBlockState(position).getBlock())
continue;
if (position.equals(pos))
continue;
BlockState blockstate = world.getBlockState(position);
if (blockstate.getMaterial() != Material.AIR) {
targets.add(position);
world.levelEvent(2001, position, Block.getId(blockstate));
world.setBlock(position, air, 3);
if (!player.isCreative()) {
if (!player.getMainHandItem().isEmpty())
player.getMainHandItem().mineBlock(world, blockstate, position, player);
BlockEntity tileentity = blockstate.hasBlockEntity() ? world.getBlockEntity(position) : null;
// Add fortune, silk touch and other loot modifiers
Block.dropResources(blockstate, world, pos, tileentity, player, player.getMainHandItem());
}
}
}
AllPackets.channel.send(PacketDistributor.TRACKING_ENTITY_AND_SELF.with(() -> player), new SymmetryEffectPacket(to, targets));
}
use of com.simibubi.create.content.curiosities.symmetry.mirror.SymmetryMirror 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.SymmetryMirror 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.SymmetryMirror 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;
}
use of com.simibubi.create.content.curiosities.symmetry.mirror.SymmetryMirror in project Create by Creators-of-Create.
the class SymmetryWandItem method apply.
public static void apply(Level world, ItemStack wand, Player player, BlockPos pos, BlockState block) {
checkNBT(wand);
if (!isEnabled(wand))
return;
if (!BlockItem.BY_BLOCK.containsKey(block.getBlock()))
return;
Map<BlockPos, BlockState> blockSet = new HashMap<>();
blockSet.put(pos, block);
SymmetryMirror symmetry = SymmetryMirror.fromNBT((CompoundTag) wand.getTag().getCompound(SYMMETRY));
Vec3 mirrorPos = symmetry.getPosition();
if (mirrorPos.distanceTo(Vec3.atLowerCornerOf(pos)) > AllConfigs.SERVER.curiosities.maxSymmetryWandRange.get())
return;
if (!player.isCreative() && isHoldingBlock(player, block) && BlockHelper.findAndRemoveInInventory(block, player, 1) == 0)
return;
symmetry.process(blockSet);
BlockPos to = new BlockPos(mirrorPos);
List<BlockPos> targets = new ArrayList<>();
targets.add(pos);
for (BlockPos position : blockSet.keySet()) {
if (position.equals(pos))
continue;
if (world.isUnobstructed(block, position, CollisionContext.of(player))) {
BlockState blockState = blockSet.get(position);
for (Direction face : Iterate.directions) blockState = blockState.updateShape(face, world.getBlockState(position.relative(face)), world, position, position.relative(face));
if (player.isCreative()) {
world.setBlockAndUpdate(position, blockState);
targets.add(position);
continue;
}
BlockState toReplace = world.getBlockState(position);
if (!toReplace.getMaterial().isReplaceable())
continue;
if (toReplace.getDestroySpeed(world, position) == -1)
continue;
if (AllBlocks.CART_ASSEMBLER.has(blockState)) {
BlockState railBlock = CartAssemblerBlock.getRailBlock(blockState);
if (BlockHelper.findAndRemoveInInventory(railBlock, player, 1) == 0)
continue;
if (BlockHelper.findAndRemoveInInventory(blockState, player, 1) == 0)
blockState = railBlock;
} else {
if (BlockHelper.findAndRemoveInInventory(blockState, player, 1) == 0)
continue;
}
BlockSnapshot blocksnapshot = BlockSnapshot.create(world.dimension(), world, position);
FluidState ifluidstate = world.getFluidState(position);
world.setBlock(position, ifluidstate.createLegacyBlock(), Block.UPDATE_KNOWN_SHAPE);
world.setBlockAndUpdate(position, blockState);
CompoundTag wandNbt = wand.getOrCreateTag();
wandNbt.putBoolean("Simulate", true);
boolean placeInterrupted = ForgeEventFactory.onBlockPlace(player, blocksnapshot, Direction.UP);
wandNbt.putBoolean("Simulate", false);
if (placeInterrupted) {
blocksnapshot.restore(true, false);
continue;
}
targets.add(position);
}
}
AllPackets.channel.send(PacketDistributor.TRACKING_ENTITY_AND_SELF.with(() -> player), new SymmetryEffectPacket(to, targets));
}
Aggregations