Skip to content

Commit

Permalink
Merge pull request #706 from FTBTeam/1.19/dev
Browse files Browse the repository at this point in the history
1.19/dev
  • Loading branch information
desht authored Nov 29, 2023
2 parents 7b005ac + d7f7d13 commit b2f43be
Show file tree
Hide file tree
Showing 8 changed files with 158 additions and 10 deletions.
8 changes: 8 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,14 @@ 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).

## [1902.5.7]

### Added
* Added a new Task Screen Configurator item, which can be used to remote-configure a Task Screen
* Sneak + right-click a Task Screen with the configurator to bind it
* Right-click the configurator to configure the Task Screen
* Limitation: Task Screen must be currently loaded and in same dimension as player

## [1902.5.6]

### Fixed
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,11 +18,6 @@
public class FTBQuestsItems {
public static final DeferredRegister<Item> ITEMS = DeferredRegister.create(FTBQuests.MOD_ID, Registry.ITEM_REGISTRY);

public static final RegistrySupplier<Item> BOOK = ITEMS.register("book", QuestBookItem::new);
public static final RegistrySupplier<Item> LOOTCRATE = ITEMS.register("lootcrate", LootCrateItem::new);
public static final RegistrySupplier<Item> MISSING_ITEM = ITEMS.register("missing_item", MissingItem::new);
public static final RegistrySupplier<Item> CUSTOM_ICON = ITEMS.register("custom_icon", CustomIconItem::new);

private static RegistrySupplier<Item> blockItem(String id, Supplier<Block> b) {
return ITEMS.register(id, () -> new BlockItem(b.get(), new Item.Properties().tab(FTBQuests.ITEM_GROUP)));
}
Expand All @@ -31,8 +26,14 @@ private static RegistrySupplier<Item> blockItemFor(String id, Supplier<BlockItem
return ITEMS.register(id, bi);
}

public static final RegistrySupplier<Item> BARRIER = ITEMS.register("barrier", QuestBarrierBlockItem::new);
public static final RegistrySupplier<Item> STAGE_BARRIER = ITEMS.register("stage_barrier", StageBarrierBlockItem::new);
public static final RegistrySupplier<Item> BOOK = ITEMS.register("book", QuestBookItem::new);
public static final RegistrySupplier<Item> LOOTCRATE = ITEMS.register("lootcrate", LootCrateItem::new);
public static final RegistrySupplier<Item> MISSING_ITEM = ITEMS.register("missing_item", MissingItem::new);
public static final RegistrySupplier<Item> CUSTOM_ICON = ITEMS.register("custom_icon", CustomIconItem::new);
public static final RegistrySupplier<Item> TASK_SCREEN_CONFIGURATOR = ITEMS.register("task_screen_configurator", TaskScreenConfiguratorItem::new);

public static final RegistrySupplier<Item> BARRIER = blockItemFor("barrier", QuestBarrierBlockItem::new);
public static final RegistrySupplier<Item> STAGE_BARRIER = blockItemFor("stage_barrier", StageBarrierBlockItem::new);
public static final RegistrySupplier<Item> DETECTOR = blockItem("detector", FTBQuestsBlocks.DETECTOR);
public static final RegistrySupplier<Item> LOOT_CRATE_OPENER = blockItem("loot_crate_opener", FTBQuestsBlocks.LOOT_CRATE_OPENER);

Expand All @@ -45,7 +46,6 @@ private static RegistrySupplier<Item> blockItemFor(String id, Supplier<BlockItem
public static final RegistrySupplier<Item> TASK_SCREEN_7 = blockItemFor("screen_7",
() -> new ScreenBlockItem(FTBQuestsBlocks.TASK_SCREEN_7.get(), ScreenSize.SEVEN_X_SEVEN));


public static void register() {
ITEMS.register();
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,107 @@
package dev.ftb.mods.ftbquests.item;

import dev.ftb.mods.ftbquests.FTBQuests;
import dev.ftb.mods.ftbquests.block.TaskScreenBlock;
import dev.ftb.mods.ftbquests.block.entity.ITaskScreen;
import dev.ftb.mods.ftbquests.net.TaskScreenConfigRequest;
import net.minecraft.ChatFormatting;
import net.minecraft.core.BlockPos;
import net.minecraft.core.GlobalPos;
import net.minecraft.core.Registry;
import net.minecraft.network.chat.Component;
import net.minecraft.resources.ResourceKey;
import net.minecraft.resources.ResourceLocation;
import net.minecraft.server.level.ServerPlayer;
import net.minecraft.sounds.SoundEvents;
import net.minecraft.sounds.SoundSource;
import net.minecraft.world.InteractionHand;
import net.minecraft.world.InteractionResult;
import net.minecraft.world.InteractionResultHolder;
import net.minecraft.world.entity.player.Player;
import net.minecraft.world.item.Item;
import net.minecraft.world.item.ItemStack;
import net.minecraft.world.item.TooltipFlag;
import net.minecraft.world.item.context.UseOnContext;
import net.minecraft.world.level.Level;
import org.jetbrains.annotations.Nullable;

import java.util.List;
import java.util.Optional;

public class TaskScreenConfiguratorItem extends Item {
public TaskScreenConfiguratorItem() {
super(new Properties().stacksTo(1).tab(FTBQuests.ITEM_GROUP));
}

@Override
public InteractionResult useOn(UseOnContext ctx) {
Level level = ctx.getLevel();
if (ctx.getPlayer() instanceof ServerPlayer sp) {
if (level.getBlockEntity(ctx.getClickedPos()) instanceof ITaskScreen) {
storeBlockPos(ctx.getItemInHand(), ctx.getLevel(), ctx.getClickedPos());
ctx.getPlayer().getLevel().playSound(null, ctx.getClickedPos(), SoundEvents.NOTE_BLOCK_CHIME, SoundSource.BLOCKS, 1f, 1f);
ctx.getPlayer().displayClientMessage(Component.translatable("ftbquests.message.configurator_bound", posToString(ctx.getClickedPos())), true);
} else {
return tryUseOn(sp, ctx.getItemInHand()) ? InteractionResult.CONSUME : InteractionResult.FAIL;
}
}
return InteractionResult.SUCCESS;
}

@Override
public InteractionResultHolder<ItemStack> use(Level level, Player player, InteractionHand hand) {
ItemStack stack = player.getItemInHand(hand);
if (player instanceof ServerPlayer sp) {
return tryUseOn(sp, stack) ? InteractionResultHolder.consume(stack) : InteractionResultHolder.fail(stack);
}
return InteractionResultHolder.success(stack);
}

@Override
public void appendHoverText(ItemStack itemStack, @Nullable Level level, List<Component> list, TooltipFlag tooltipFlag) {
list.add(Component.translatable("item.ftbquests.task_screen_configurator.tooltip").withStyle(ChatFormatting.GRAY));

readBlockPos(itemStack).ifPresent(gPos -> {
String str = gPos.dimension().location() + " / " + posToString(gPos.pos());
list.add(Component.translatable("ftbquests.message.configurator_bound", str).withStyle(ChatFormatting.DARK_AQUA));
});
}

private boolean tryUseOn(ServerPlayer player, ItemStack stack) {
return readBlockPos(stack).map(gPos -> {
Level level = player.getServer().getLevel(gPos.dimension());
if (level != player.getLevel() || !player.getLevel().isLoaded(gPos.pos())) {
player.displayClientMessage(Component.translatable("ftbquests.message.task_screen_inaccessible").withStyle(ChatFormatting.RED), true);
return false;
}
if (level.getBlockEntity(gPos.pos()) instanceof ITaskScreen taskScreen) {
if (TaskScreenBlock.hasPermissionToEdit(player, taskScreen)) {
taskScreen.getCoreScreen().ifPresent(coreScreen -> new TaskScreenConfigRequest(coreScreen.getBlockPos()).sendTo(player));
return true;
} else {
player.displayClientMessage(Component.translatable("block.ftbquests.screen.no_permission").withStyle(ChatFormatting.RED), true);
}
} else {
player.displayClientMessage(Component.translatable("ftbquests.message.missing_task_screen").withStyle(ChatFormatting.RED), true);
}
return false;
}).orElse(false);
}

public static void storeBlockPos(ItemStack itemInHand, Level level, BlockPos clickedPos) {
itemInHand.getOrCreateTag().putLong("pos", clickedPos.asLong());
itemInHand.getOrCreateTag().putString("dim", level.dimension().location().toString());
}

public static Optional<GlobalPos> readBlockPos(ItemStack stack) {
if (stack.getItem() instanceof TaskScreenConfiguratorItem && stack.hasTag() && stack.getTag().contains("pos") && stack.getTag().contains("dim")) {
ResourceKey<Level> dim = ResourceKey.create(Registry.DIMENSION_REGISTRY, new ResourceLocation(stack.getTag().getString("dim")));
return Optional.of(GlobalPos.of(dim, BlockPos.of(stack.getTag().getLong("pos"))));
}
return Optional.empty();
}

private static String posToString(BlockPos pos) {
return String.format("[%d,%d,%d]", pos.getX(), pos.getY(), pos.getZ());
}
}
10 changes: 9 additions & 1 deletion common/src/main/resources/assets/ftbquests/lang/en_us.json
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,8 @@
"item.ftbquests.lootcrate.tooltip_2": "Sneak-right-click to open all in hand",
"item.ftbquests.custom_icon": "Custom Icon",
"item.ftbquests.custom_icon.tooltip": "Right-click on 'Icon' in editor to open custom image selector",
"item.ftbquests.task_screen_configurator": "Task Screen Configurator",
"item.ftbquests.task_screen_configurator.tooltip": "Sneak + Right-Click a Task Screen block to bind",
"ftbquests.rarity.common": "Common",
"ftbquests.rarity.uncommon": "Uncommon",
"ftbquests.rarity.rare": "Rare",
Expand Down Expand Up @@ -479,5 +481,11 @@
"commands.ftbquests.weigh_from_emc.invalid_id": "Invalid Reward Table ID!",
"commands.ftbquests.weigh_from_emc.text": "Changed item reward weight based on EMC in %s",
"commands.ftbquests.export_rewards_to_chest.usage": "/ftbquests export_rewards_to_chest <reward_table>",
"commands.ftbquests.export_rewards_to_chest.text": "Exported %s / %s items from '%s'"
"commands.ftbquests.export_rewards_to_chest.text": "Exported %s / %s items from '%s'",
"ftbquests.ui.old_scroll_wheel": "Old-style Scroll Wheel Behavior",
"ftbquests.ui.old_scroll_wheel.tooltip": "When false, scroll wheel scrolls up & down; hold Shift to pan, Ctrl to zoom\nWhen true, scroll wheel only zooms (1.19 and earlier behavior)",
"ftbquests.objects": "%d object(s)",
"ftbquests.message.configurator_bound": "Configurator Bound: %s",
"ftbquests.message.task_screen_inaccessible": "Task Screen is not accessible from here!",
"ftbquests.message.missing_task_screen": "Task Screen is missing!"
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
{
"parent": "item/generated",
"textures": {
"layer0": "ftbquests:item/task_screen_configurator"
}
}
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
{
"type": "minecraft:crafting_shaped",
"group": "ftbquests:screen",
"result": {
"item": "ftbquests:task_screen_configurator"
},
"pattern": [
" S",
"T "
],
"key": {
"S": {
"item": "ftbquests:screen_1"
},
"T": {
"item": "minecraft:stick"
}
}
}
2 changes: 1 addition & 1 deletion gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ mod_id=ftbquests
archives_base_name=ftb-quests
minecraft_version=1.19.2
# Build time
mod_version=1902.5.6
mod_version=1902.5.7
maven_group=dev.ftb.mods
mod_author=FTB Team
# Curse release
Expand Down

0 comments on commit b2f43be

Please sign in to comment.