Skip to content

Commit

Permalink
Merge pull request #748 from FTBTeam/dev
Browse files Browse the repository at this point in the history
Dev
  • Loading branch information
desht authored Jul 31, 2024
2 parents 706940d + 1014998 commit bc3d65a
Show file tree
Hide file tree
Showing 13 changed files with 102 additions and 48 deletions.
11 changes: 11 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,17 @@ All notable changes to this project will be documented in this file.
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).

# [2100.1.5]

### Changed
* FTB Quests items are now registered to the `FTB Suite` creative tab instead of FTB Quests own tab
* In practice, this means they share a tab with other FTB mods, but only FTB Filter System registers an item at this time

### Fixed
* Rotated images now have a correctly rotated hitbox
* In addition, rotated images with a non-default aspect ratio now preview correctly during rotation
* Fixed copy/pasting images

# [2100.1.4]

### Fixed
Expand Down
4 changes: 2 additions & 2 deletions common/src/main/java/dev/ftb/mods/ftbquests/FTBQuests.java
Original file line number Diff line number Diff line change
Expand Up @@ -37,13 +37,13 @@ public class FTBQuests {
public FTBQuests() {
FTBQuestsAPI._init(FTBQuestsAPIImpl.INSTANCE);

PROXY = EnvExecutor.getEnvSpecific(() -> FTBQClientProxy::new, () -> FTBQServerProxy::new);

TaskTypes.init();
RewardTypes.init();
FTBQuestsNetHandler.init();
FTBQuestsEventHandler.INSTANCE.init();

PROXY = EnvExecutor.getEnvSpecific(() -> FTBQClientProxy::new, () -> FTBQServerProxy::new);

ReloadListenerRegistry.register(PackType.SERVER_DATA, new TagReloadListener());

EnvExecutor.runInEnv(Env.CLIENT, () -> FTBQuestsClient::init);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
import dev.architectury.registry.ReloadListenerRegistry;
import dev.architectury.registry.client.keymappings.KeyMappingRegistry;
import dev.architectury.registry.client.rendering.RenderTypeRegistry;
import dev.ftb.mods.ftblibrary.FTBLibrary;
import dev.ftb.mods.ftblibrary.config.ImageResourceConfig;
import dev.ftb.mods.ftblibrary.config.ui.EditConfigScreen;
import dev.ftb.mods.ftblibrary.ui.Widget;
Expand Down Expand Up @@ -157,7 +158,7 @@ public static void rebuildCreativeTabs() {
player.canUseGameMasterBlocks(),
player.level().registryAccess()
);
ModItems.CREATIVE_TAB.get().buildContents(params);
FTBLibrary.getCreativeModeTab().get().buildContents(params);
CreativeModeTabs.searchTab().buildContents(params);
}
}
Expand All @@ -173,4 +174,4 @@ public static Optional<CreativeModeTab.ItemDisplayParameters> creativeTabDisplay
public static void copyToClipboard(QuestObjectBase qo) {
Widget.setClipboardString(qo.getCodeString());
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
import dev.ftb.mods.ftbquests.quest.Movable;
import dev.ftb.mods.ftbquests.quest.theme.property.ThemeProperties;
import net.minecraft.ChatFormatting;
import net.minecraft.Util;
import net.minecraft.client.gui.GuiGraphics;
import net.minecraft.client.gui.screens.Screen;
import net.minecraft.network.chat.Component;
Expand All @@ -25,11 +26,29 @@
import java.util.ArrayList;
import java.util.List;
import java.util.Optional;
import java.util.function.BiFunction;

public class ChapterImageButton extends Button implements QuestPositionableButton {
private final QuestScreen questScreen;
private final ChapterImage chapterImage;

private static final BiFunction<XYPair, Double, XYPair> MEMOIZED_ROTATE = Util.memoize((xy, rotateDeg) -> {
// cartesian -> polar, rotate, polar -> cartesian
double radius = xy.radius();
double angle = xy.angle();
double rotateRad = Math.toRadians(rotateDeg);
// yes, negative is needed here
return new XYPair(radius * Math.cos(angle - rotateRad), radius * Math.sin(angle - rotateRad));
});
private record XYPair(double x, double y) {
double radius() {
return Math.sqrt(x * x + y * y);
}
double angle() {
return Math.atan2(y, x);
}
}

public ChapterImageButton(Panel panel, ChapterImage i) {
super(panel, Component.empty(), i.getImage());
questScreen = (QuestScreen) panel.getGui();
Expand Down Expand Up @@ -60,6 +79,17 @@ public boolean checkMouseOver(int mouseX, int mouseY) {
return false;
}

if (chapterImage.getRotation() != 0) {
// need a bit of trig here, and we'll memoize it for performance
// rotate the effective mouse position about either the corner or the center of the image
double cx = chapterImage.isAlignToCorner() ? getX() : getX() + getWidth() / 2.0;
double cy = chapterImage.isAlignToCorner() ? getY() : getY() + getHeight() / 2.0;

XYPair rotated = MEMOIZED_ROTATE.apply(new XYPair(mouseX - cx, mouseY - cy), chapterImage.getRotation());
mouseX = (int) (cx + rotated.x);
mouseY = (int) (cy + rotated.y);
}

return super.checkMouseOver(mouseX, mouseY);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -320,10 +320,17 @@ public void draw(GuiGraphics graphics, Theme theme, int x, int y, int w, int h)
double sx = (questX + ox - questMinX) / dx * questScreen.scrollWidth + px;
double sy = (questY + oy - questMinY) / dy * questScreen.scrollHeight + py;
poseStack.pushPose();
poseStack.translate(sx - bs * m.getWidth() / 2D, sy - bs * m.getHeight() / 2D, 0D);
// translate/rotate order is highly dependent on whether the object aligns at center or corner. fun fun fun
if (m.isAlignToCorner()) {
poseStack.translate(sx - bs * m.getWidth() / 2D, sy - bs * m.getHeight() / 2D, 0D);
} else {
poseStack.translate(sx, sy, 0D);
}
poseStack.mulPose(Axis.ZP.rotationDegrees((float) m.getRotation()));
if (!m.isAlignToCorner()) {
poseStack.translate(-bs * m.getWidth() / 2D, -bs * m.getHeight() / 2D, 0D);
}
poseStack.scale((float) (bs * m.getWidth()), (float) (bs * m.getHeight()), 1F);
GuiHelper.setupDrawing();
RenderSystem.enableDepthTest();
m.drawMoved(graphics);
poseStack.popPose();
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package dev.ftb.mods.ftbquests.quest;

import com.mojang.blaze3d.vertex.PoseStack;
import com.mojang.math.Axis;
import dev.architectury.networking.NetworkManager;
import dev.ftb.mods.ftblibrary.config.ConfigGroup;
import dev.ftb.mods.ftblibrary.config.ImageResourceConfig;
Expand Down Expand Up @@ -45,7 +44,7 @@ public ChapterImage decode(FriendlyByteBuf buf) {
long chapterId = buf.readLong();
ChapterImage img = new ChapterImage(ServerQuestFile.INSTANCE.getChapter(chapterId));
img.readNetData(buf);
return null;
return img;
}

@Override
Expand Down Expand Up @@ -121,10 +120,12 @@ public int getOrder() {
return order;
}

@Override
public double getRotation() {
return rotation;
}

@Override
public boolean isAlignToCorner() {
return alignToCorner;
}
Expand Down Expand Up @@ -301,20 +302,18 @@ public void drawMoved(GuiGraphics graphics) {
poseStack.pushPose();

if (alignToCorner) {
poseStack.mulPose(Axis.ZP.rotationDegrees((float) rotation));
image.withColor(Color4I.WHITE.withAlpha(50)).draw(graphics, 0, 0, 1, 1);
} else {
poseStack.translate(0.5D, 0.5D, 0);
poseStack.mulPose(Axis.ZP.rotationDegrees((float) rotation));
poseStack.scale(0.5F, 0.5F, 1);
image.withColor(Color4I.WHITE.withAlpha(50)).draw(graphics, -1, -1, 2, 2);
}

poseStack.popPose();
// QuestShape.get(getShape()).getOutline()
// .withColor(Color4I.WHITE.withAlpha(30))
// .draw(graphics, 0, 0, 1, 1);

QuestShape.get(getShape()).getOutline()
.withColor(Color4I.WHITE.withAlpha(30))
.draw(graphics, 0, 0, 1, 1);
poseStack.popPose();
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,14 @@ public interface Movable {

String getShape();

default double getRotation() {
return 0.0;
}

default boolean isAlignToCorner() {
return false;
}

/**
* Called client-side to initiate moving the object
*
Expand Down
29 changes: 10 additions & 19 deletions common/src/main/java/dev/ftb/mods/ftbquests/registry/ModItems.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,22 +2,21 @@

import dev.architectury.registry.CreativeTabRegistry;
import dev.architectury.registry.registries.DeferredRegister;
import dev.architectury.registry.registries.RegistrarManager;
import dev.architectury.registry.registries.RegistrySupplier;
import dev.ftb.mods.ftblibrary.FTBLibrary;
import dev.ftb.mods.ftbquests.FTBQuests;
import dev.ftb.mods.ftbquests.api.FTBQuestsAPI;
import dev.ftb.mods.ftbquests.item.*;
import dev.ftb.mods.ftbquests.item.ScreenBlockItem.ScreenSize;
import net.minecraft.core.registries.Registries;
import net.minecraft.network.chat.Component;
import net.minecraft.world.item.BlockItem;
import net.minecraft.world.item.CreativeModeTab;
import net.minecraft.world.item.Item;
import net.minecraft.world.item.ItemStack;
import net.minecraft.world.level.block.Block;

import java.util.List;
import java.util.function.Supplier;
import java.util.stream.Stream;

public class ModItems {
public static final DeferredRegister<Item> ITEMS = DeferredRegister.create(FTBQuestsAPI.MOD_ID, Registries.ITEM);
Expand Down Expand Up @@ -66,25 +65,17 @@ private static RegistrySupplier<Item> blockItemFor(String id, Supplier<BlockItem

public static void register() {
ITEMS.register();
}

public static final RegistrySupplier<CreativeModeTab> CREATIVE_TAB = RegistrarManager.get(FTBQuestsAPI.MOD_ID)
.get(Registries.CREATIVE_MODE_TAB)
.register(FTBQuestsAPI.rl("default"), ModItems::buildDefaultTab);
CreativeTabRegistry.appendStack(FTBLibrary.getCreativeModeTab(), BASE_ITEMS.stream().map(item -> () -> new ItemStack(item.get())));

public static Item.Properties defaultProps() {
return new Item.Properties();
Stream<Supplier<ItemStack>> lootCreates = FTBQuests.PROXY.getKnownLootCrates()
.stream()
.map(crate -> crate::createStack);

CreativeTabRegistry.appendStack(FTBLibrary.getCreativeModeTab(), lootCreates);
}

private static CreativeModeTab buildDefaultTab() {
return CreativeTabRegistry.create(builder -> builder.title(Component.translatable("ftbquests"))
.icon(() -> new ItemStack(BOOK.get()))
.displayItems((params, output) -> {
// base items, always present
output.acceptAll(BASE_ITEMS.stream().map(item -> new ItemStack(item.get())).toList());
// dynamically add loot crates based on current reward tables
FTBQuests.PROXY.getKnownLootCrates().forEach(crate -> output.accept(crate.createStack()));
})
);
public static Item.Properties defaultProps() {
return new Item.Properties();
}
}
8 changes: 7 additions & 1 deletion fabric/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ dependencies {
}

modApi("dev.ftb.mods:ftb-library-fabric:${rootProject.ftb_library_version}") { transitive false }

modApi("dev.ftb.mods:ftb-teams-fabric:${rootProject.ftb_teams_version}") { transitive false }

common(project(path: ":common", configuration: "namedElements")) { transitive false }
Expand All @@ -42,7 +43,12 @@ processResources {
inputs.property "version", project.version

filesMatching("fabric.mod.json") {
expand "version": project.version
expand "version": project.version,
"archversion": project.architectury_api_version,
"fabricapiversionrange": project.fabric_api_version_range,
"mcversion": project.minecraft_version,
"ftblibraryversion": project.ftb_library_version,
"ftbteamsversion": project.ftb_teams_version
}
}

Expand Down
10 changes: 5 additions & 5 deletions fabric/src/main/resources/fabric.mod.json
Original file line number Diff line number Diff line change
Expand Up @@ -24,11 +24,11 @@
"ftbquests-fabric.mixins.json"
],
"depends": {
"fabric": "*",
"minecraft": "~1.21",
"architectury": ">=13.0.0",
"ftblibrary": ">=2100.1.0",
"ftbteams": ">=2100.1.0"
"fabric": "${fabricapiversionrange}",
"minecraft": "~${mcversion}",
"architectury": ">=${archversion}",
"ftblibrary": ">=${ftblibraryversion}",
"ftbteams": ">=${ftbteamsversion}"
},
"breaks": {
}
Expand Down
13 changes: 7 additions & 6 deletions gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -9,21 +9,22 @@ maven_group=dev.ftb.mods
mod_author=FTB Team

# Build time
mod_version=2100.1.4
mod_version=2100.1.5
minecraft_version=1.21


# Cross env
#forge_version=50.0.9
#forge_loader_version=49
neoforge_version=21.0.40-beta
# https://maven.neoforged.net/#/releases/net/neoforged/fancymodloader/loader
neoforge_version=21.0.146
neoforge_version_range=[21.0.143,)
neoforge_loader_version=4
fabric_loader_version=0.15.11
fabric_api_version=0.100.1+1.21
architectury_api_version=13.0.2
fabric_api_version=0.100.8+1.21
fabric_api_version_range=>=0.100.1+1.21
architectury_api_version=13.0.6

ftb_library_version=2100.1.2
ftb_library_version=2100.1.4
ftb_teams_version=2100.1.0

# Optional deps
Expand Down
2 changes: 1 addition & 1 deletion neoforge/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ processResources {
filesMatching("META-INF/neoforge.mods.toml") {
expand "version": project.version,
"archversion": project.architectury_api_version,
"neoforgeversion": project.neoforge_version,
"neoforgeversionrange": project.neoforge_version_range,
"neoforgeloaderversion": project.neoforge_loader_version,
"mcversion": project.minecraft_version,
"ftblibraryversion": project.ftb_library_version,
Expand Down
2 changes: 1 addition & 1 deletion neoforge/src/main/resources/META-INF/neoforge.mods.toml
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ Lets you easily create and play with quests
[[dependencies.ftbquests]]
modId = "neoforge"
type = "required"
versionRange = "[${neoforgeversion},)"
versionRange = "${neoforgeversionrange}"
ordering = "NONE"
side = "BOTH"

Expand Down

0 comments on commit bc3d65a

Please sign in to comment.