Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

为铁砧锤选择光点添加初始化 #1269

Merged
merged 7 commits into from
Dec 6, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import dev.dubhe.anvilcraft.api.hammer.IHammerChangeable;
import dev.dubhe.anvilcraft.api.hammer.IHammerRemovable;
import dev.dubhe.anvilcraft.client.gui.screen.AnvilHammerScreen;
import dev.dubhe.anvilcraft.init.ModBlockTags;
import dev.dubhe.anvilcraft.item.AnvilHammerItem;
import dev.dubhe.anvilcraft.network.HammerUsePacket;
import dev.dubhe.anvilcraft.util.StateUtil;
Expand Down Expand Up @@ -59,9 +60,11 @@ private static void clientHandle(PlayerInteractEvent.@NotNull RightClickBlock ev
&& AnvilHammerItem.possibleToUseEnhancedHammerChange(targetBlockState)
&& property != null
) {
if (targetBlockState.getBlock() instanceof IHammerChangeable ihc
&& ihc.checkBlockState(targetBlockState)
&& event.getEntity().getAbilities().mayBuild
if (
(targetBlockState.getBlock() instanceof IHammerChangeable ihc
&& ihc.checkBlockState(targetBlockState)
) || (targetBlockState.is(ModBlockTags.HAMMER_CHANGEABLE))
&& event.getEntity().getAbilities().mayBuild
) {
List<BlockState> possibleStates = StateUtil.findPossibleStatesForProperty(targetBlockState, property);
if (possibleStates.isEmpty()) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -59,12 +59,7 @@ public class AnvilHammerScreen extends Screen implements IHasHammerEffect {
private static final Vector2f ROTATION_START = new Vector2f(0, 1);

/// Nonlinear, should bigger than 1, 1 means no animation
private static final float SELECTION_ANIMATION_SPEED_FACTOR = 10f;

private Vector2f centerPos;
private Vector2f selectionEffectPosFromCenter = MathUtil.copy(ROTATION_START).mul(RADIUS);
/// *rad*
private float targetAngle = 0f;
private static final float SELECTION_ANIMATION_SPEED_FACTOR = 5.0f;

static {
MethodType mt = MethodType.methodType(
Expand Down Expand Up @@ -93,6 +88,10 @@ public class AnvilHammerScreen extends Screen implements IHasHammerEffect {
private long displayTime = System.currentTimeMillis();
private boolean animationStarted = false;
private boolean closingAnimationStarted = false;
private Vector2f centerPos;
private Vector2f selectionEffectPosFromCenter = MathUtil.copy(ROTATION_START).mul(RADIUS);
/// *rad*
private float targetAngle = 0f;

public AnvilHammerScreen(BlockPos targetBlockPos, BlockState initialBlockState, Property<?> property, List<BlockState> possibleStates) {
super(Component.translatable("screen.anvilcraft.anvil_hammer.title"));
Expand Down Expand Up @@ -141,7 +140,16 @@ protected void init() {
} catch (Throwable ignored) {
}
}

SelectionItem selected = items.stream()
.filter(it -> it.state == currentBlockState)
.findFirst()
.orElseThrow();
targetAngle = selected.angle;
selectionEffectPosFromCenter = MathUtil.rotate(
MathUtil.copy(ROTATION_START)
.mul(RADIUS),
-targetAngle
).mul(1, -1);
}

@Override
Expand Down Expand Up @@ -330,27 +338,27 @@ public void render(GuiGraphics guiGraphics, int mouseX, int mouseY, float partia
private void renderSelection(GuiGraphics guiGraphics) {

float selectionEffectAngle =
MathUtil.angle(
MathUtil.copy(ROTATION_START).negate(),
selectionEffectPosFromCenter
);
MathUtil.angle(
MathUtil.copy(ROTATION_START).negate(),
selectionEffectPosFromCenter
);

float diffAngle = targetAngle - selectionEffectAngle;

if (diffAngle > Math.PI) {
diffAngle -= (float) (Math.PI*2);
diffAngle -= (float) (Math.PI * 2);
} else if (diffAngle < -Math.PI) {
diffAngle += (float) (Math.PI*2);
diffAngle += (float) (Math.PI * 2);
}

selectionEffectPosFromCenter =
MathUtil.rotate(
selectionEffectPosFromCenter,
diffAngle / SELECTION_ANIMATION_SPEED_FACTOR
);
MathUtil.rotate(
selectionEffectPosFromCenter,
diffAngle / SELECTION_ANIMATION_SPEED_FACTOR
);

Vector2f pos =
MathUtil.copy(selectionEffectPosFromCenter)
MathUtil.copy(selectionEffectPosFromCenter)
.mul(1, -1)
.add(centerPos);

Expand Down
22 changes: 0 additions & 22 deletions src/main/java/dev/dubhe/anvilcraft/mixin/PluginCallerMixin.java

This file was deleted.

1 change: 0 additions & 1 deletion src/main/resources/anvilcraft.mixins.json
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@
"PistonMovingBlockEntityMixin",
"PistonStructureResolverMixin",
"PlayerHitEntityMixin",
"PluginCallerMixin",
"RecipeManagerMixin",
"ServerLevelMixin",
"accessor.BaseSpawnerAccessor",
Expand Down
Loading