Skip to content
Permalink

Comparing changes

Choose two branches to see what’s changed or to start a new pull request. If you need to, you can also or learn more about diff comparisons.

Open a pull request

Create a new pull request by comparing changes across two branches. If you need to, you can also . Learn more about diff comparisons here.
base repository: klima7/Rubiks-Cube-Mod
Failed to load repositories. Confirm that selected base ref is valid, then try again.
Loading
base: main
Choose a base ref
...
head repository: Luligabi1/FSI-Cubo
Failed to load repositories. Confirm that selected head ref is valid, then try again.
Loading
compare: main
Choose a head ref
Able to merge. These branches can be automatically merged.
  • 1 commit
  • 15 files changed
  • 1 contributor

Commits on Feb 5, 2025

  1. .

    Luligabi1 committed Feb 5, 2025
    Copy the full SHA
    7c50203 View commit details
13 changes: 12 additions & 1 deletion src/main/java/com/github/klima7/RubiksCubeMod.java
Original file line number Diff line number Diff line change
@@ -4,7 +4,18 @@
import com.github.klima7.core.init.BlockRegistry;
import com.github.klima7.core.init.ItemRegistry;
import com.github.klima7.core.init.SoundRegistry;
import com.github.klima7.core.misc.RubiksCubeData;
import com.mojang.brigadier.CommandDispatcher;
import com.mojang.brigadier.arguments.StringArgumentType;
import com.mojang.brigadier.builder.ArgumentBuilder;
import com.mojang.brigadier.tree.LiteralCommandNode;
import net.minecraft.ChatFormatting;
import net.minecraft.commands.CommandSourceStack;
import net.minecraft.commands.Commands;
import net.minecraft.network.chat.Component;
import net.minecraftforge.event.RegisterCommandsEvent;
import net.minecraftforge.eventbus.api.IEventBus;
import net.minecraftforge.eventbus.api.SubscribeEvent;
import net.minecraftforge.fml.common.Mod;
import net.minecraftforge.fml.javafmlmod.FMLJavaModLoadingContext;

@@ -21,4 +32,4 @@ public RubiksCubeMod() {
SoundRegistry.register(modEventBus);
}

}
}
Original file line number Diff line number Diff line change
@@ -72,10 +72,10 @@ public InteractionResult use(BlockState state, Level level, BlockPos pos, Player
UUID playerUUID = player.getUUID();

PacketHandler.CHANNEL.sendToServer(
new ServerboundUpdateRubiksCubePacket(pos, playerUUID, direction, isReversed, isRotation)
new ServerboundUpdateRubiksCubePacket(pos, playerUUID, direction, isReversed, isRotation, true)
);

return InteractionResult.SUCCESS;
}

}
}
Original file line number Diff line number Diff line change
@@ -1,16 +1,14 @@
package com.github.klima7.common.entity;

import com.github.klima7.core.init.SoundRegistry;
import com.github.klima7.domain.operation.Operation;
import com.github.klima7.domain.operation.move.Move;
import net.minecraft.core.BlockPos;
import net.minecraft.core.Direction;
import net.minecraft.nbt.CompoundTag;
import net.minecraft.network.Connection;
import net.minecraft.network.chat.Component;
import net.minecraft.network.chat.MutableComponent;
import net.minecraft.network.protocol.game.ClientboundBlockEntityDataPacket;
import net.minecraft.sounds.SoundEvent;
import net.minecraft.sounds.SoundSource;
import net.minecraft.world.level.Level;
import net.minecraft.world.level.block.entity.BlockEntity;
import net.minecraft.world.level.block.entity.BlockEntityType;
@@ -104,6 +102,11 @@ public void onDataPacket(Connection connection, ClientboundBlockEntityDataPacket
}

public void serverTick() {

if(shouldFinishAnimationlessOperation()) {
finishAnimationlessOperation(operation);
}

if(shouldFinishOperation()) {
finishOperation(operation);
}
@@ -115,14 +118,24 @@ public void executeOperation(Operation operation, UUID playerUUID) {
}

if(isSomethingBlocking(operation, level)) {
level.playSound(null, getBlockPos(), SoundRegistry.BLOCKED.get(), SoundSource.BLOCKS, 1.0f, 1.0f);
//level.playSound(null, getBlockPos(), SoundRegistry.BLOCKED.get(), SoundSource.BLOCKS, 1.0f, 1.0f);
MutableComponent message = Component.translatable("message.rubiks_cube.blocking");
level.getPlayerByUUID(playerUUID).displayClientMessage(message, true);
return;
}

startOperation(operation, playerUUID);
playOperationSound(operation);
//playOperationSound(operation);
}

public void executeAnimationlessOperation(Operation operation, UUID playerUUID) {

if (operation instanceof Move move) {
move.hasAnimation = false;
operation = move;
}

startAnimationlessOperation(operation, playerUUID);
}

public Direction getFacing() {
@@ -161,6 +174,13 @@ private void startOperation(Operation operation, UUID playerUUID) {
sync();
}

private void startAnimationlessOperation(Operation operation, UUID playerUUID) {
this.operation = operation;
this.startTime = -1;
this.playerUUID = playerUUID;
sync();
}

private void finishOperation(Operation operation) {
assert level != null;
applyOperation(operation);
@@ -171,18 +191,23 @@ private void finishOperation(Operation operation) {
sync();
}

private void playOperationSound(Operation operation) {
assert level != null;
SoundEvent soundEvent = operation.getSoundEvent();
if(soundEvent != null) {
level.playSound(null, getBlockPos(), soundEvent, SoundSource.BLOCKS, 1.0f, 1.0f);
}
private void finishAnimationlessOperation(Operation operation) {
applyOperation(operation);
this.operation = null;
this.startTime = 0;
this.playerUUID = null;
this.finishTime = -1;
sync();
}

private boolean shouldFinishOperation() {
return isExecutingOperation() && currentOperationTimeElapsed();
}

private boolean shouldFinishAnimationlessOperation() {
return isExecutingOperation() && startTime == -1;
}

private boolean currentOperationTimeElapsed() {
assert level != null;
long currentTime = level.getGameTime();
@@ -192,7 +217,7 @@ private boolean currentOperationTimeElapsed() {
private <E extends IAnimatable> PlayState predicate(AnimationEvent<E> event) {
AnimationController<?> controller = event.getController();

if(isExecutingOperation()) {
if(isExecutingOperation() && operation.hasAnimation()) {
controller.easingType = operation.getEasing();
event.getController().setAnimation(new AnimationBuilder().addAnimation(operation.getAnimationName()));
} else {
@@ -201,12 +226,12 @@ private <E extends IAnimatable> PlayState predicate(AnimationEvent<E> event) {
return PlayState.CONTINUE;
}

private void sync() {
void sync() {
if(level != null && !level.isClientSide()) {
setChanged();
BlockState state = getBlockState();
level.sendBlockUpdated(getBlockPos(), state, state, 3);
}
}

}
}
Original file line number Diff line number Diff line change
@@ -85,9 +85,10 @@ public CubeStickers getCubeStickers() {
}

@Override
protected void applyOperation(Operation operation) {
public void applyOperation(Operation operation) {
ScrambleState oldScrambleState = scrambleState;
operation.execute(this.cubeStickers);
sync();

// update scrambleState
if(cubeStickers.isSolved()) {
@@ -96,23 +97,15 @@ protected void applyOperation(Operation operation) {
scrambleState = ScrambleState.MANUALLY_SCRAMBLED;
}

// grant advancements
if(oldScrambleState == ScrambleState.AUTO_SCRAMBLED && scrambleState == ScrambleState.SOLVED) {
grantAdvancement(playerUUID, "rubiks_cube_solved");
}

if(oldScrambleState == ScrambleState.AUTO_SCRAMBLED && cubeStickers.getSolvedFacesCount() >= 1) {
grantAdvancement(playerUUID, "face_solved");
}
}

private void grantAdvancement(UUID playerUUID, String advancementName) {
if(level instanceof final ServerLevel serverLevel) {
ServerAdvancementManager advancementManager = serverLevel.getServer().getAdvancements();
Advancement advancement = advancementManager.getAdvancement(new ResourceLocation(RubiksCubeMod.MODID, advancementName));
ServerPlayer player = (ServerPlayer) level.getPlayerByUUID(playerUUID);
player.getAdvancements().award(advancement, "set_programmatically");
}
@Override
public StandardRubiksCubeBlockEntity clone() {
StandardRubiksCubeBlockEntity cloned = new StandardRubiksCubeBlockEntity(getBlockPos(), getBlockState());
cloned.level = this.level;
cloned.cubeStickers = this.cubeStickers;
cloned.scrambleState = this.scrambleState;
return cloned;
}

}
}
Original file line number Diff line number Diff line change
@@ -44,7 +44,7 @@ public InteractionResultHolder<ItemStack> use(Level level, Player player, Intera
if (!level.isClientSide) {
StandardRubiksCubeItemWrapper itemWrapper = new StandardRubiksCubeItemWrapper(itemStack);
itemWrapper.createTag(level);
itemWrapper.scramble();
itemWrapper.scramble(level.getServer());
}
player.startUsingItem(hand);
return InteractionResultHolder.pass(itemStack);
@@ -73,4 +73,4 @@ private void appendScrambleState(ItemStack itemStack, List<Component> components
components.add(Component.translatable(tooltipId));
}

}
}
Original file line number Diff line number Diff line change
@@ -4,6 +4,7 @@
import com.github.klima7.domain.scramble.ScrambleState;
import com.github.klima7.domain.scramble.Scrambler;
import net.minecraft.nbt.CompoundTag;
import net.minecraft.server.MinecraftServer;
import net.minecraft.world.item.ItemStack;
import net.minecraft.world.level.Level;

@@ -78,9 +79,9 @@ public void setScrambleState(ScrambleState scrambleState) {
itemStack.getTag().putString("scrambleState", scrambleState.name());
}

public void scramble() {
public void scramble(MinecraftServer server) {
CubeStickers cubeStickers = getCubeStickersOrDefault();
Scrambler.scramble(cubeStickers);
Scrambler.scramble(cubeStickers, server);
setCubeStickers(cubeStickers);
setScrambleState(ScrambleState.AUTO_SCRAMBLED);
}
@@ -91,4 +92,4 @@ private void assertTagPresent() {
}
}

}
}
Original file line number Diff line number Diff line change
@@ -15,4 +15,4 @@ public static void commonSetup(FMLCommonSetupEvent event) {
event.enqueueWork(PacketHandler::init);
}

}
}
Loading