Skip to content

Commit

Permalink
fix some things
Browse files Browse the repository at this point in the history
  • Loading branch information
SiverDX committed Nov 23, 2024
1 parent cbda685 commit 388760d
Show file tree
Hide file tree
Showing 6 changed files with 38 additions and 14 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -212,9 +212,9 @@ public static float setZoom(final Holder<DragonStage> dragonStage) {
return (float) (0.4 * dragonStage.value().sizeRange().min() + 20);
}

public final Function<Holder<DragonStage>, Holder<DragonStage>> selectLevelAction = (newLevel) -> {
public final Function<Holder<DragonStage>, Holder<DragonStage>> selectStageAction = newStage -> {
Holder<DragonStage> previousLevel = dragonStage;
dragonStage = newLevel;
dragonStage = newStage;
dragonRender.zoom = setZoom(dragonStage);
HANDLER.getSkinData().compileSkin(dragonStage);
update();
Expand Down Expand Up @@ -438,12 +438,12 @@ private void initDummyDragon(final DragonStateHandler localHandler) {

String type = dragonType.getTypeNameLowerCase();
SavedSkinPresets savedCustomizations = DragonEditorRegistry.getSavedCustomizations(null);
String levelLocation = Objects.requireNonNull(dragonStage.getKey()).location().toString();
String stageLocation = Objects.requireNonNull(dragonStage.getKey()).location().toString();

savedCustomizations.current.computeIfAbsent(type, key -> new HashMap<>());
savedCustomizations.current.get(type).putIfAbsent(levelLocation, 0);
savedCustomizations.current.get(type).putIfAbsent(stageLocation, 0);

selectedSaveSlot = savedCustomizations.current.get(type).get(levelLocation);
selectedSaveSlot = savedCustomizations.current.get(type).get(stageLocation);

savedCustomizations.skinPresets.computeIfAbsent(type, key -> new HashMap<>());
savedCustomizations.skinPresets.get(type).computeIfAbsent(selectedSaveSlot, key -> {
Expand All @@ -458,12 +458,14 @@ private void initDummyDragon(final DragonStateHandler localHandler) {
preset = new SkinPreset();
preset.deserializeNBT(Objects.requireNonNull(Minecraft.getInstance().player).registryAccess(), currentPreset.serializeNBT(Minecraft.getInstance().player.registryAccess()));

HANDLER.getSkinData().skinPreset = preset;
HANDLER.getSkinData().compileSkin(dragonStage);
HANDLER.setHasFlight(true);
HANDLER.setType(dragonType);
HANDLER.setClientSize(dragonStage, dragonStage.value().sizeRange().min());
HANDLER.setBody(dragonBody);

HANDLER.getSkinData().skinPreset = preset;
HANDLER.getSkinData().compileSkin(dragonStage);

dragonRender.zoom = setZoom(dragonStage);
}

Expand Down Expand Up @@ -836,7 +838,7 @@ public void update() {

HANDLER.setBody(dragonBody);
HANDLER.getSkinData().skinPreset = preset;
HANDLER.setClientSize(dragonStage);
HANDLER.setClientSize(dragonStage, dragonStage.value().sizeRange().min());
HANDLER.setHasFlight(true);

if (selectedSaveSlot != lastSelected) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ public class DragonStageButton extends Button {
public DragonStageButton(final DragonEditorScreen screen, final ResourceKey<DragonStage> dragonStage, int xOffset) {
super(screen.width / 2 + xOffset, screen.guiTop - 30, 120, 20, DragonStage.translatableName(dragonStage), button -> {
//noinspection DataFlowIssue -> registry is expected to be present
screen.actionHistory.add(new DragonEditorScreen.EditorAction<>(screen.selectLevelAction, CommonHooks.resolveLookup(DragonStage.REGISTRY).getOrThrow(dragonStage)));
screen.actionHistory.add(new DragonEditorScreen.EditorAction<>(screen.selectStageAction, CommonHooks.resolveLookup(DragonStage.REGISTRY).getOrThrow(dragonStage)));
}, DEFAULT_NARRATION);

this.screen = screen;
Expand All @@ -31,6 +31,6 @@ public DragonStageButton(final DragonEditorScreen screen, final ResourceKey<Drag
public void renderWidget(@NotNull final GuiGraphics graphics, int mouseX, int mouseY, float partialTick) {
active = visible = screen.showUi;
int color = isHovered || screen.dragonStage.is(dragonStage) ? WHITE : LIGHT_GRAY;
TextRenderUtil.drawCenteredScaledText(graphics, getX() + width / 2, getY() + 4, 1.5f, getMessage().getString(), color); // TODO :: previously used alpha - but does that ever change for this widget?
TextRenderUtil.drawCenteredScaledText(graphics, getX() + width / 2, getY() + 4, 1.5f, getMessage().getString(), color);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ public void render(@NotNull final GuiGraphics guiGraphics, int pMouseX, int pMou

// We need to translate this backwards with the poseStack as renderEntityInInventory pushes the poseStack forward
guiGraphics.pose().pushPose();
guiGraphics.pose().translate(0, 0, -200); // We chose -200 here as the background is translated -300 and we don't want to clip with it
guiGraphics.pose().translate(0, 0, -200); // We chose -200 here as the background is translated -300, and we don't want to clip with it

Quaternionf quaternion = Axis.ZP.rotationDegrees(180);
quaternion.mul(Axis.XP.rotationDegrees(yRot * 10));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import by.dragonsurvivalteam.dragonsurvival.commands.arguments.DragonSizeArgument;
import by.dragonsurvivalteam.dragonsurvival.common.capability.DragonStateHandler;
import by.dragonsurvivalteam.dragonsurvival.common.capability.DragonStateProvider;
import by.dragonsurvivalteam.dragonsurvival.registry.dragon.DragonStage;
import com.mojang.brigadier.tree.ArgumentCommandNode;
import com.mojang.brigadier.tree.LiteralCommandNode;
import com.mojang.brigadier.tree.RootCommandNode;
Expand All @@ -24,7 +25,13 @@ public static void register(final RegisterCommandsEvent event) {
DragonStateHandler handler = DragonStateProvider.getData(serverPlayer);

if (handler.isDragon()) {
handler.setSize(serverPlayer, handler.getStage(), size);
if (handler.getStage().value().sizeRange().matches(size)) {
// If the min. size of the next stage is set it can look like a bug
// (Because after 1 second of running the command the stage changes due to the natural growth)
handler.setSize(serverPlayer, handler.getStage(), size);
} else {
handler.setSize(serverPlayer, DragonStage.get(serverPlayer.registryAccess(), size), size);
}
}

return 1;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,7 @@ public static void sendClientData() {
Player localPlayer = Minecraft.getInstance().player;

if (localPlayer == null) {
// This check is needed since in single player the server thread will go in here (from 'deserializeNBT')
return;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ private static void validate(@Nullable final HolderLookup.Provider provider) {
}

StringBuilder nextStageCheck = new StringBuilder("The following stages are incorrectly defined:");
AtomicBoolean areStagesValid = new AtomicBoolean();
AtomicBoolean areStagesValid = new AtomicBoolean(true);

keys(provider).forEach(key -> {
//noinspection OptionalGetWithoutIsPresent -> ignore
Expand Down Expand Up @@ -175,7 +175,21 @@ public double getBoundedSize(double size) {

/** Returns {@link DragonStage#getBoundedSize(double)} of the next stage (if present) or of the current stage */
public double getNextSize(@Nullable final HolderLookup.Provider provider, double size) {
return getNextStage(provider, this).map(nextStage -> nextStage.value().getBoundedSize(size)).orElse(getBoundedSize(size));
if (!getBounds().matches(size)) {
Optional<Holder.Reference<DragonStage>> nextStage = getNextStage(provider, this);

if (nextStage.isEmpty()) {
return size;
}

if (!nextStage.get().value().sizeRange().matches(size)) {
return size;
}

return nextStage.get().value().getBoundedSize(size);
}

return size;
}

/** Returns the bounds between the smallest and largest dragon sizes */
Expand Down

0 comments on commit 388760d

Please sign in to comment.