Public Access
This commit is contained in:
1 parent
5066e71897
commit
972aeaaed6
22 files changed
+465
-1
No files matched your search
@@ -0,0 +1,63 @@
|
||||
package net.dnorberg.rivencraft.block;
|
||||
|
||||
import com.mojang.serialization.MapCodec;
|
||||
import net.dnorberg.rivencraft.block.entity.WritingDeskBlockEntity;
|
||||
import net.dnorberg.rivencraft.menu.WritingDeskMenu;
|
||||
import net.minecraft.core.BlockPos;
|
||||
import net.minecraft.network.chat.Component;
|
||||
import net.minecraft.server.level.ServerPlayer;
|
||||
import net.minecraft.world.Containers;
|
||||
import net.minecraft.world.InteractionResult;
|
||||
import net.minecraft.world.SimpleMenuProvider;
|
||||
import net.minecraft.world.entity.player.Player;
|
||||
import net.minecraft.world.item.context.BlockPlaceContext;
|
||||
import net.minecraft.world.level.Level;
|
||||
import net.minecraft.world.level.block.BaseEntityBlock;
|
||||
import net.minecraft.world.level.block.RenderShape;
|
||||
import net.minecraft.world.level.block.state.BlockState;
|
||||
import net.minecraft.world.level.block.state.StateDefinition;
|
||||
import net.minecraft.world.level.block.state.properties.BlockStateProperties;
|
||||
import net.minecraft.world.level.block.state.properties.DirectionProperty;
|
||||
import net.minecraft.world.level.block.entity.BlockEntity;
|
||||
import net.minecraft.world.phys.BlockHitResult;
|
||||
|
||||
public final class WritingDeskBlock extends BaseEntityBlock {
|
||||
public static final MapCodec<WritingDeskBlock> CODEC = simpleCodec(WritingDeskBlock::new);
|
||||
public static final DirectionProperty FACING = BlockStateProperties.HORIZONTAL_FACING;
|
||||
|
||||
public WritingDeskBlock(Properties properties) {
|
||||
super(properties);
|
||||
registerDefaultState(stateDefinition.any().setValue(FACING, net.minecraft.core.Direction.NORTH));
|
||||
}
|
||||
|
||||
@Override public MapCodec<? extends BaseEntityBlock> codec() { return CODEC; }
|
||||
@Override protected void createBlockStateDefinition(StateDefinition.Builder<net.minecraft.world.level.block.Block, BlockState> builder) {
|
||||
builder.add(FACING);
|
||||
}
|
||||
@Override public BlockState getStateForPlacement(BlockPlaceContext context) {
|
||||
return defaultBlockState().setValue(FACING, context.getHorizontalDirection().getOpposite());
|
||||
}
|
||||
@Override protected RenderShape getRenderShape(BlockState state) { return RenderShape.MODEL; }
|
||||
@Override public BlockEntity newBlockEntity(BlockPos pos, BlockState state) {
|
||||
return new WritingDeskBlockEntity(pos, state);
|
||||
}
|
||||
@Override protected InteractionResult useWithoutItem(BlockState state, Level level, BlockPos pos,
|
||||
Player player, BlockHitResult hit) {
|
||||
if (!level.isClientSide && player instanceof ServerPlayer serverPlayer
|
||||
&& level.getBlockEntity(pos) instanceof WritingDeskBlockEntity desk) {
|
||||
serverPlayer.openMenu(new SimpleMenuProvider(
|
||||
(id, inventory, ignored) -> new WritingDeskMenu(id, inventory, desk),
|
||||
Component.translatable("container.rivencraft.writing_desk")),
|
||||
buffer -> buffer.writeBlockPos(pos));
|
||||
}
|
||||
return InteractionResult.sidedSuccess(level.isClientSide);
|
||||
}
|
||||
@Override protected void onRemove(BlockState state, Level level, BlockPos pos, BlockState replacement, boolean moving) {
|
||||
if (!state.is(replacement.getBlock()) && !level.isClientSide
|
||||
&& level.getBlockEntity(pos) instanceof WritingDeskBlockEntity desk) {
|
||||
Containers.dropContents(level, pos, desk);
|
||||
level.updateNeighbourForOutputSignal(pos, this);
|
||||
}
|
||||
super.onRemove(state, level, pos, replacement, moving);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,85 @@
|
||||
package net.dnorberg.rivencraft.block.entity;
|
||||
|
||||
import net.dnorberg.rivencraft.registry.ModBlockEntities;
|
||||
import net.dnorberg.rivencraft.registry.ModItems;
|
||||
import net.minecraft.core.BlockPos;
|
||||
import net.minecraft.core.HolderLookup;
|
||||
import net.minecraft.core.NonNullList;
|
||||
import net.minecraft.nbt.CompoundTag;
|
||||
import net.minecraft.world.Container;
|
||||
import net.minecraft.world.ContainerHelper;
|
||||
import net.minecraft.world.entity.player.Player;
|
||||
import net.minecraft.world.item.ItemStack;
|
||||
import net.minecraft.world.level.block.entity.BlockEntity;
|
||||
import net.minecraft.world.level.block.state.BlockState;
|
||||
|
||||
/** The four Legacy-like collection tabs and four work slots are owned by the block, not its viewers. */
|
||||
public final class WritingDeskBlockEntity extends BlockEntity implements Container {
|
||||
public static final int COLLECTIONS = 4;
|
||||
public static final int INK = 4;
|
||||
public static final int SOURCE = 5;
|
||||
public static final int PAPER = 6;
|
||||
public static final int OUTPUT = 7;
|
||||
public static final int SIZE = 8;
|
||||
private NonNullList<ItemStack> items = NonNullList.withSize(SIZE, ItemStack.EMPTY);
|
||||
private int activeCollection;
|
||||
|
||||
public WritingDeskBlockEntity(BlockPos pos, BlockState state) {
|
||||
super(ModBlockEntities.WRITING_DESK.get(), pos, state);
|
||||
}
|
||||
|
||||
public int activeCollection() { return activeCollection; }
|
||||
public void setActiveCollection(int index) {
|
||||
if (index >= 0 && index < COLLECTIONS && activeCollection != index) {
|
||||
activeCollection = index;
|
||||
setChanged();
|
||||
}
|
||||
}
|
||||
|
||||
@Override public int getContainerSize() { return SIZE; }
|
||||
@Override public boolean isEmpty() { return items.stream().allMatch(ItemStack::isEmpty); }
|
||||
@Override public ItemStack getItem(int slot) { return items.get(slot); }
|
||||
@Override public ItemStack removeItem(int slot, int amount) {
|
||||
ItemStack removed = ContainerHelper.removeItem(items, slot, amount);
|
||||
if (!removed.isEmpty()) setChanged();
|
||||
return removed;
|
||||
}
|
||||
@Override public ItemStack removeItemNoUpdate(int slot) { return ContainerHelper.takeItem(items, slot); }
|
||||
@Override public void setItem(int slot, ItemStack stack) {
|
||||
items.set(slot, stack);
|
||||
if (stack.getCount() > getMaxStackSize()) stack.setCount(getMaxStackSize());
|
||||
setChanged();
|
||||
}
|
||||
@Override public boolean stillValid(Player player) {
|
||||
return level != null && level.isLoaded(worldPosition)
|
||||
&& level.getBlockEntity(worldPosition) == this
|
||||
&& player.distanceToSqr(worldPosition.getX() + 0.5, worldPosition.getY() + 0.5,
|
||||
worldPosition.getZ() + 0.5) <= 64.0;
|
||||
}
|
||||
@Override public boolean canPlaceItem(int slot, ItemStack stack) {
|
||||
if (slot < COLLECTIONS) return stack.is(ModItems.NOTEBOOK.get()) || stack.is(ModItems.PAGE.get());
|
||||
return switch (slot) {
|
||||
case INK -> stack.is(ModItems.INK_VIAL.get());
|
||||
case SOURCE -> stack.is(ModItems.PAGE.get()) || stack.is(ModItems.NOTEBOOK.get());
|
||||
case PAPER -> stack.is(ModItems.PAGE.get());
|
||||
case OUTPUT -> false;
|
||||
default -> false;
|
||||
};
|
||||
}
|
||||
@Override public void clearContent() {
|
||||
items.clear();
|
||||
items = NonNullList.withSize(SIZE, ItemStack.EMPTY);
|
||||
setChanged();
|
||||
}
|
||||
@Override protected void loadAdditional(CompoundTag tag, HolderLookup.Provider registries) {
|
||||
super.loadAdditional(tag, registries);
|
||||
items = NonNullList.withSize(SIZE, ItemStack.EMPTY);
|
||||
ContainerHelper.loadAllItems(tag, items, registries);
|
||||
activeCollection = Math.clamp(tag.getInt("ActiveCollection"), 0, COLLECTIONS - 1);
|
||||
}
|
||||
@Override protected void saveAdditional(CompoundTag tag, HolderLookup.Provider registries) {
|
||||
super.saveAdditional(tag, registries);
|
||||
ContainerHelper.saveAllItems(tag, items, registries);
|
||||
tag.putInt("ActiveCollection", activeCollection);
|
||||
}
|
||||
}
|
||||
@@ -14,6 +14,7 @@ import net.neoforged.neoforge.common.NeoForge;
|
||||
import net.neoforged.neoforge.client.event.EntityRenderersEvent;
|
||||
import net.neoforged.neoforge.client.event.RegisterMenuScreensEvent;
|
||||
import net.dnorberg.rivencraft.client.screen.NotebookScreen;
|
||||
import net.dnorberg.rivencraft.client.screen.WritingDeskScreen;
|
||||
import net.dnorberg.rivencraft.registry.ModMenus;
|
||||
|
||||
@EventBusSubscriber(modid = Rivencraft.MOD_ID, value = Dist.CLIENT)
|
||||
@@ -29,6 +30,7 @@ public final class ClientEvents {
|
||||
@SubscribeEvent
|
||||
public static void registerScreens(RegisterMenuScreensEvent event) {
|
||||
event.register(ModMenus.NOTEBOOK.get(), NotebookScreen::new);
|
||||
event.register(ModMenus.WRITING_DESK.get(), WritingDeskScreen::new);
|
||||
}
|
||||
|
||||
@SubscribeEvent
|
||||
|
||||
@@ -0,0 +1,68 @@
|
||||
package net.dnorberg.rivencraft.client.screen;
|
||||
|
||||
import net.dnorberg.rivencraft.menu.WritingDeskMenu;
|
||||
import net.minecraft.client.gui.GuiGraphics;
|
||||
import net.minecraft.client.gui.screens.inventory.AbstractContainerScreen;
|
||||
import net.minecraft.network.chat.Component;
|
||||
import net.minecraft.world.entity.player.Inventory;
|
||||
|
||||
/** Functional storage surface; full Legacy transcription controls are a later Milestone 4 slice. */
|
||||
public final class WritingDeskScreen extends AbstractContainerScreen<WritingDeskMenu> {
|
||||
public WritingDeskScreen(WritingDeskMenu menu, Inventory inventory, Component title) {
|
||||
super(menu, inventory, title);
|
||||
imageWidth = 398;
|
||||
imageHeight = 176;
|
||||
titleLabelX = 222;
|
||||
inventoryLabelX = 224;
|
||||
inventoryLabelY = 79;
|
||||
}
|
||||
|
||||
@Override protected void renderBg(GuiGraphics graphics, float partialTick, int mouseX, int mouseY) {
|
||||
int x = leftPos;
|
||||
int y = topPos;
|
||||
graphics.fill(x + 4, y + 8, x + 216, y + 174, 0xFF383230);
|
||||
graphics.fill(x + 44, y + 14, x + 210, y + 170, 0xFF221B1A);
|
||||
graphics.fill(x + 218, y + 4, x + 396, y + 174, 0xFF555454);
|
||||
graphics.fill(x + 220, y + 6, x + 394, y + 172, 0xFFB7B7B7);
|
||||
for (int i = 0; i < 4; i++) {
|
||||
graphics.fill(x + 6, y + 16 + i * 37, x + 40, y + 48 + i * 37,
|
||||
i == menu.activeCollection() ? 0xFF7777B6 : 0xFF999999);
|
||||
slotFrame(graphics, 12, 20 + i * 37);
|
||||
}
|
||||
slotFrame(graphics, 228, 20);
|
||||
slotFrame(graphics, 266, 20);
|
||||
slotFrame(graphics, 304, 20);
|
||||
slotFrame(graphics, 342, 20);
|
||||
for (int row = 0; row < 3; row++) {
|
||||
for (int column = 0; column < 9; column++) slotFrame(graphics, 224 + column * 18, 91 + row * 18);
|
||||
}
|
||||
for (int column = 0; column < 9; column++) slotFrame(graphics, 224 + column * 18, 149);
|
||||
}
|
||||
|
||||
private void slotFrame(GuiGraphics graphics, int x, int y) {
|
||||
graphics.fill(leftPos + x - 1, topPos + y - 1,
|
||||
leftPos + x + 17, topPos + y + 17, 0xFF4D4D4D);
|
||||
graphics.fill(leftPos + x, topPos + y,
|
||||
leftPos + x + 16, topPos + y + 16, 0xFF858585);
|
||||
}
|
||||
|
||||
@Override public void render(GuiGraphics graphics, int mouseX, int mouseY, float partialTick) {
|
||||
super.render(graphics, mouseX, mouseY, partialTick);
|
||||
renderTooltip(graphics, mouseX, mouseY);
|
||||
}
|
||||
|
||||
@Override public boolean mouseClicked(double mouseX, double mouseY, int button) {
|
||||
if (button == 0 && mouseX >= leftPos + 29 && mouseX < leftPos + 40) {
|
||||
for (int i = 0; i < 4; i++) {
|
||||
int top = topPos + 16 + i * 37;
|
||||
if (mouseY >= top && mouseY < top + 32) {
|
||||
if (minecraft != null && minecraft.gameMode != null) {
|
||||
minecraft.gameMode.handleInventoryButtonClick(menu.containerId, i);
|
||||
}
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
||||
return super.mouseClicked(mouseX, mouseY, button);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,85 @@
|
||||
package net.dnorberg.rivencraft.gametest;
|
||||
|
||||
import net.dnorberg.rivencraft.Rivencraft;
|
||||
import net.dnorberg.rivencraft.block.entity.WritingDeskBlockEntity;
|
||||
import net.dnorberg.rivencraft.menu.WritingDeskMenu;
|
||||
import net.dnorberg.rivencraft.registry.ModBlocks;
|
||||
import net.dnorberg.rivencraft.registry.ModItems;
|
||||
import net.minecraft.core.BlockPos;
|
||||
import net.minecraft.gametest.framework.GameTest;
|
||||
import net.minecraft.gametest.framework.GameTestHelper;
|
||||
import net.minecraft.world.entity.item.ItemEntity;
|
||||
import net.minecraft.world.item.ItemStack;
|
||||
import net.minecraft.world.level.block.Blocks;
|
||||
import net.minecraft.world.phys.AABB;
|
||||
import net.neoforged.neoforge.gametest.GameTestHolder;
|
||||
import net.neoforged.neoforge.gametest.PrefixGameTestTemplate;
|
||||
|
||||
@GameTestHolder(Rivencraft.MOD_ID)
|
||||
@PrefixGameTestTemplate(false)
|
||||
public final class WritingDeskGameTests {
|
||||
private WritingDeskGameTests() {}
|
||||
|
||||
@GameTest(template = "empty")
|
||||
public static void inventoryAndActiveCollectionPersist(GameTestHelper helper) {
|
||||
BlockPos pos = helper.absolutePos(new BlockPos(1, 1, 1));
|
||||
var original = new WritingDeskBlockEntity(pos, ModBlocks.WRITING_DESK.get().defaultBlockState());
|
||||
original.setItem(0, new ItemStack(ModItems.NOTEBOOK.get()));
|
||||
original.setItem(WritingDeskBlockEntity.INK, new ItemStack(ModItems.INK_VIAL.get()));
|
||||
original.setItem(WritingDeskBlockEntity.PAPER, new ItemStack(ModItems.PAGE.get(), 12));
|
||||
original.setActiveCollection(2);
|
||||
var saved = original.saveWithoutMetadata(helper.getLevel().registryAccess());
|
||||
var restored = new WritingDeskBlockEntity(pos, ModBlocks.WRITING_DESK.get().defaultBlockState());
|
||||
restored.loadWithComponents(saved, helper.getLevel().registryAccess());
|
||||
helper.assertTrue(restored.getItem(0).is(ModItems.NOTEBOOK.get()), "Notebook lost on save/load");
|
||||
helper.assertTrue(restored.getItem(WritingDeskBlockEntity.INK).is(ModItems.INK_VIAL.get()), "Ink lost on save/load");
|
||||
helper.assertValueEqual(restored.getItem(WritingDeskBlockEntity.PAPER).getCount(), 12, "Pages lost on save/load");
|
||||
helper.assertValueEqual(restored.activeCollection(), 2, "Active collection lost on save/load");
|
||||
helper.succeed();
|
||||
}
|
||||
|
||||
@GameTest(template = "empty")
|
||||
public static void breakingDeskDropsItsStoredItemsOnce(GameTestHelper helper) {
|
||||
BlockPos relative = new BlockPos(1, 1, 1);
|
||||
BlockPos pos = helper.absolutePos(relative);
|
||||
helper.getLevel().setBlock(pos, ModBlocks.WRITING_DESK.get().defaultBlockState(), 3);
|
||||
WritingDeskBlockEntity desk = (WritingDeskBlockEntity) helper.getLevel().getBlockEntity(pos);
|
||||
desk.setItem(0, new ItemStack(ModItems.NOTEBOOK.get()));
|
||||
desk.setItem(WritingDeskBlockEntity.INK, new ItemStack(ModItems.INK_VIAL.get()));
|
||||
desk.setItem(WritingDeskBlockEntity.PAPER, new ItemStack(ModItems.PAGE.get(), 12));
|
||||
helper.getLevel().setBlock(pos, Blocks.AIR.defaultBlockState(), 3);
|
||||
var drops = helper.getLevel().getEntitiesOfClass(ItemEntity.class, new AABB(pos).inflate(2));
|
||||
int notebooks = drops.stream().filter(e -> e.getItem().is(ModItems.NOTEBOOK.get())).mapToInt(e -> e.getItem().getCount()).sum();
|
||||
int ink = drops.stream().filter(e -> e.getItem().is(ModItems.INK_VIAL.get())).mapToInt(e -> e.getItem().getCount()).sum();
|
||||
int pages = drops.stream().filter(e -> e.getItem().is(ModItems.PAGE.get())).mapToInt(e -> e.getItem().getCount()).sum();
|
||||
helper.assertValueEqual(notebooks, 1, "Notebook must drop exactly once");
|
||||
helper.assertValueEqual(ink, 1, "Ink must drop exactly once");
|
||||
helper.assertValueEqual(pages, 12, "Pages must drop without loss");
|
||||
helper.succeed();
|
||||
}
|
||||
|
||||
@GameTest(template = "empty")
|
||||
public static void menuTransfersWithoutDuplicationAndClosesWhenReplaced(GameTestHelper helper) {
|
||||
BlockPos pos = helper.absolutePos(new BlockPos(1, 1, 1));
|
||||
helper.getLevel().setBlock(pos, ModBlocks.WRITING_DESK.get().defaultBlockState(), 3);
|
||||
WritingDeskBlockEntity desk = (WritingDeskBlockEntity) helper.getLevel().getBlockEntity(pos);
|
||||
var player = helper.makeMockServerPlayerInLevel();
|
||||
player.moveTo(pos.getX() + 0.5, pos.getY() + 0.5, pos.getZ() + 0.5);
|
||||
player.getInventory().setItem(9, new ItemStack(ModItems.PAGE.get(), 12));
|
||||
WritingDeskMenu menu = new WritingDeskMenu(1, player.getInventory(), desk);
|
||||
helper.assertTrue(menu.stillValid(player), "Placed desk must keep its menu valid");
|
||||
helper.assertTrue(menu.clickMenuButton(player, 3), "Active collection control must accept a valid tab");
|
||||
helper.assertValueEqual(desk.activeCollection(), 3, "Selected tab must be stored on the desk");
|
||||
menu.quickMoveStack(player, 8);
|
||||
helper.assertValueEqual(desk.getItem(WritingDeskBlockEntity.PAPER).getCount(), 12, "Shift-click must deposit all pages");
|
||||
helper.assertTrue(player.getInventory().getItem(9).isEmpty(), "Shift-click must consume player source stack");
|
||||
menu.quickMoveStack(player, WritingDeskBlockEntity.PAPER);
|
||||
helper.assertTrue(desk.getItem(WritingDeskBlockEntity.PAPER).isEmpty(), "Shift-click must empty desk source slot");
|
||||
int total = player.getInventory().items.stream().filter(stack -> stack.is(ModItems.PAGE.get()))
|
||||
.mapToInt(ItemStack::getCount).sum();
|
||||
helper.assertValueEqual(total, 12, "Round-trip must not lose or duplicate pages");
|
||||
helper.getLevel().setBlock(pos, Blocks.AIR.defaultBlockState(), 3);
|
||||
helper.assertFalse(menu.stillValid(player), "Removed desk must invalidate menu");
|
||||
helper.succeed();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,101 @@
|
||||
package net.dnorberg.rivencraft.menu;
|
||||
|
||||
import net.dnorberg.rivencraft.block.entity.WritingDeskBlockEntity;
|
||||
import net.dnorberg.rivencraft.registry.ModItems;
|
||||
import net.dnorberg.rivencraft.registry.ModMenus;
|
||||
import net.minecraft.network.RegistryFriendlyByteBuf;
|
||||
import net.minecraft.world.Container;
|
||||
import net.minecraft.world.SimpleContainer;
|
||||
import net.minecraft.world.entity.player.Inventory;
|
||||
import net.minecraft.world.entity.player.Player;
|
||||
import net.minecraft.world.inventory.AbstractContainerMenu;
|
||||
import net.minecraft.world.inventory.DataSlot;
|
||||
import net.minecraft.world.inventory.Slot;
|
||||
import net.minecraft.world.item.ItemStack;
|
||||
|
||||
public final class WritingDeskMenu extends AbstractContainerMenu {
|
||||
private static final int PLAYER_START = WritingDeskBlockEntity.SIZE;
|
||||
private final Container desk;
|
||||
private final WritingDeskBlockEntity blockEntity;
|
||||
private int syncedActiveCollection;
|
||||
|
||||
public WritingDeskMenu(int id, Inventory inventory, RegistryFriendlyByteBuf data) {
|
||||
this(id, inventory, inventory.player.level().getBlockEntity(data.readBlockPos())
|
||||
instanceof WritingDeskBlockEntity found ? found : null);
|
||||
}
|
||||
|
||||
public WritingDeskMenu(int id, Inventory inventory, WritingDeskBlockEntity blockEntity) {
|
||||
super(ModMenus.WRITING_DESK.get(), id);
|
||||
this.blockEntity = blockEntity;
|
||||
this.desk = blockEntity == null ? new SimpleContainer(WritingDeskBlockEntity.SIZE) : blockEntity;
|
||||
addDataSlot(new DataSlot() {
|
||||
@Override public int get() { return WritingDeskMenu.this.blockEntity == null
|
||||
? syncedActiveCollection : WritingDeskMenu.this.blockEntity.activeCollection(); }
|
||||
@Override public void set(int value) { syncedActiveCollection = value; }
|
||||
});
|
||||
for (int i = 0; i < WritingDeskBlockEntity.COLLECTIONS; i++) {
|
||||
addSlot(new DeskSlot(desk, i, 12, 20 + i * 37, 1));
|
||||
}
|
||||
addSlot(new DeskSlot(desk, WritingDeskBlockEntity.INK, 228, 20, 1));
|
||||
addSlot(new DeskSlot(desk, WritingDeskBlockEntity.SOURCE, 266, 20, 1));
|
||||
addSlot(new DeskSlot(desk, WritingDeskBlockEntity.PAPER, 304, 20, 64));
|
||||
addSlot(new DeskSlot(desk, WritingDeskBlockEntity.OUTPUT, 342, 20, 64));
|
||||
for (int row = 0; row < 3; row++) {
|
||||
for (int column = 0; column < 9; column++) {
|
||||
addSlot(new Slot(inventory, column + row * 9 + 9, 224 + column * 18, 91 + row * 18));
|
||||
}
|
||||
}
|
||||
for (int column = 0; column < 9; column++) {
|
||||
addSlot(new Slot(inventory, column, 224 + column * 18, 149));
|
||||
}
|
||||
}
|
||||
|
||||
public int activeCollection() { return syncedActiveCollection; }
|
||||
|
||||
@Override public boolean clickMenuButton(Player player, int id) {
|
||||
if (blockEntity == null || !stillValid(player) || id < 0 || id >= WritingDeskBlockEntity.COLLECTIONS) return false;
|
||||
blockEntity.setActiveCollection(id);
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override public boolean stillValid(Player player) {
|
||||
return blockEntity != null && blockEntity.stillValid(player);
|
||||
}
|
||||
|
||||
@Override public ItemStack quickMoveStack(Player player, int index) {
|
||||
if (!stillValid(player) || index < 0 || index >= slots.size()) return ItemStack.EMPTY;
|
||||
Slot slot = slots.get(index);
|
||||
if (!slot.hasItem()) return ItemStack.EMPTY;
|
||||
ItemStack moving = slot.getItem();
|
||||
ItemStack original = moving.copy();
|
||||
if (index < PLAYER_START) {
|
||||
if (!moveItemStackTo(moving, PLAYER_START, slots.size(), true)) return ItemStack.EMPTY;
|
||||
} else if (!moveIntoDesk(moving)) {
|
||||
return ItemStack.EMPTY;
|
||||
}
|
||||
if (moving.isEmpty()) slot.setByPlayer(ItemStack.EMPTY);
|
||||
else slot.setChanged();
|
||||
return original;
|
||||
}
|
||||
|
||||
private boolean moveIntoDesk(ItemStack moving) {
|
||||
if (moving.is(ModItems.INK_VIAL.get())) return moveItemStackTo(moving, 4, 5, false);
|
||||
if (moving.is(ModItems.NOTEBOOK.get())) return moveItemStackTo(moving, 0, 4, false);
|
||||
if (moving.is(ModItems.PAGE.get())) {
|
||||
return moveItemStackTo(moving, 6, 7, false)
|
||||
|| moveItemStackTo(moving, 0, 4, false)
|
||||
|| moveItemStackTo(moving, 5, 6, false);
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
private static final class DeskSlot extends Slot {
|
||||
private final int limit;
|
||||
private DeskSlot(Container container, int index, int x, int y, int limit) {
|
||||
super(container, index, x, y);
|
||||
this.limit = limit;
|
||||
}
|
||||
@Override public boolean mayPlace(ItemStack stack) { return container.canPlaceItem(getContainerSlot(), stack); }
|
||||
@Override public int getMaxStackSize() { return limit; }
|
||||
}
|
||||
}
|
||||
@@ -2,6 +2,7 @@ package net.dnorberg.rivencraft.registry;
|
||||
|
||||
import net.dnorberg.rivencraft.Rivencraft;
|
||||
import net.dnorberg.rivencraft.block.entity.BookStandBlockEntity;
|
||||
import net.dnorberg.rivencraft.block.entity.WritingDeskBlockEntity;
|
||||
import net.minecraft.core.registries.Registries;
|
||||
import net.minecraft.world.level.block.entity.BlockEntityType;
|
||||
import net.neoforged.bus.api.IEventBus;
|
||||
@@ -16,6 +17,9 @@ public final class ModBlockEntities {
|
||||
BLOCK_ENTITIES.register("book_stand", () -> BlockEntityType.Builder
|
||||
.of(BookStandBlockEntity::new, ModBlocks.BOOK_STAND.get())
|
||||
.build(null));
|
||||
public static final DeferredHolder<BlockEntityType<?>, BlockEntityType<WritingDeskBlockEntity>> WRITING_DESK =
|
||||
BLOCK_ENTITIES.register("writing_desk", () -> BlockEntityType.Builder
|
||||
.of(WritingDeskBlockEntity::new, ModBlocks.WRITING_DESK.get()).build(null));
|
||||
|
||||
private ModBlockEntities() {
|
||||
}
|
||||
|
||||
@@ -2,6 +2,7 @@ package net.dnorberg.rivencraft.registry;
|
||||
|
||||
import net.dnorberg.rivencraft.Rivencraft;
|
||||
import net.dnorberg.rivencraft.block.BookStandBlock;
|
||||
import net.dnorberg.rivencraft.block.WritingDeskBlock;
|
||||
import net.minecraft.world.level.block.Blocks;
|
||||
import net.minecraft.world.level.block.state.BlockBehaviour;
|
||||
import net.neoforged.bus.api.IEventBus;
|
||||
@@ -16,6 +17,10 @@ public final class ModBlocks {
|
||||
BookStandBlock::new,
|
||||
BlockBehaviour.Properties.ofFullCopy(Blocks.LECTERN)
|
||||
);
|
||||
public static final DeferredBlock<WritingDeskBlock> WRITING_DESK = BLOCKS.registerBlock(
|
||||
"writing_desk", WritingDeskBlock::new,
|
||||
BlockBehaviour.Properties.ofFullCopy(Blocks.CRAFTING_TABLE)
|
||||
);
|
||||
|
||||
private ModBlocks() {
|
||||
}
|
||||
|
||||
@@ -22,6 +22,7 @@ public final class ModCreativeTabs {
|
||||
output.accept(ModItems.LINKING_BOOK.get());
|
||||
output.accept(ModItems.NOTEBOOK.get());
|
||||
output.accept(ModItems.INK_VIAL.get());
|
||||
output.accept(ModItems.WRITING_DESK.get());
|
||||
})
|
||||
.build());
|
||||
|
||||
|
||||
@@ -7,6 +7,7 @@ import net.dnorberg.rivencraft.item.PageItem;
|
||||
import net.dnorberg.rivencraft.item.NotebookItem;
|
||||
import net.dnorberg.rivencraft.item.InkVialItem;
|
||||
import net.minecraft.world.item.Item;
|
||||
import net.minecraft.world.item.BlockItem;
|
||||
import net.neoforged.bus.api.IEventBus;
|
||||
import net.neoforged.neoforge.registries.DeferredItem;
|
||||
import net.neoforged.neoforge.registries.DeferredRegister;
|
||||
@@ -39,6 +40,7 @@ public final class ModItems {
|
||||
InkVialItem::new,
|
||||
new Item.Properties().stacksTo(16)
|
||||
);
|
||||
public static final DeferredItem<BlockItem> WRITING_DESK = ITEMS.registerSimpleBlockItem(ModBlocks.WRITING_DESK);
|
||||
|
||||
private ModItems() {
|
||||
}
|
||||
|
||||
@@ -2,6 +2,7 @@ package net.dnorberg.rivencraft.registry;
|
||||
|
||||
import net.dnorberg.rivencraft.Rivencraft;
|
||||
import net.dnorberg.rivencraft.menu.NotebookMenu;
|
||||
import net.dnorberg.rivencraft.menu.WritingDeskMenu;
|
||||
import net.minecraft.core.registries.Registries;
|
||||
import net.minecraft.world.inventory.MenuType;
|
||||
import net.neoforged.bus.api.IEventBus;
|
||||
@@ -15,6 +16,8 @@ public final class ModMenus {
|
||||
|
||||
public static final DeferredHolder<MenuType<?>, MenuType<NotebookMenu>> NOTEBOOK =
|
||||
MENUS.register("notebook", () -> IMenuTypeExtension.create(NotebookMenu::new));
|
||||
public static final DeferredHolder<MenuType<?>, MenuType<WritingDeskMenu>> WRITING_DESK =
|
||||
MENUS.register("writing_desk", () -> IMenuTypeExtension.create(WritingDeskMenu::new));
|
||||
|
||||
private ModMenus() {
|
||||
}
|
||||
|
||||
@@ -0,0 +1,8 @@
|
||||
{
|
||||
"variants": {
|
||||
"facing=north": { "model": "rivencraft:block/writing_desk" },
|
||||
"facing=east": { "model": "rivencraft:block/writing_desk", "y": 90 },
|
||||
"facing=south": { "model": "rivencraft:block/writing_desk", "y": 180 },
|
||||
"facing=west": { "model": "rivencraft:block/writing_desk", "y": 270 }
|
||||
}
|
||||
}
|
||||
@@ -16,6 +16,8 @@
|
||||
"item.rivencraft.notebook.pages": "Pages: %s/%s",
|
||||
"item.rivencraft.notebook.unresolved": "Unresolved pages: %s",
|
||||
"item.rivencraft.ink_vial": "Ink Vial",
|
||||
"block.rivencraft.writing_desk": "Writing Desk",
|
||||
"container.rivencraft.writing_desk": "Writing Desk",
|
||||
"item.rivencraft.ink_vial.remaining": "Ink: %s/%s",
|
||||
"item.rivencraft.ink_vial.usage": "Use with a blank Page in the other hand to prepare a Link Panel.",
|
||||
"screen.rivencraft.notebook.search": "Search pages",
|
||||
|
||||
@@ -0,0 +1,8 @@
|
||||
{
|
||||
"parent": "minecraft:block/cube_bottom_top",
|
||||
"textures": {
|
||||
"top": "rivencraft:item/writing_desk",
|
||||
"side": "minecraft:block/oak_planks",
|
||||
"bottom": "minecraft:block/oak_planks"
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,4 @@
|
||||
{
|
||||
"parent": "minecraft:item/generated",
|
||||
"textures": { "layer0": "rivencraft:item/writing_desk" }
|
||||
}
|
||||
Binary file not shown.
|
After Width: | Height: | Size: 208 B |
@@ -0,0 +1,4 @@
|
||||
{
|
||||
"type": "minecraft:block",
|
||||
"pools": [{ "rolls": 1, "entries": [{ "type": "minecraft:item", "name": "rivencraft:writing_desk" }] }]
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
{
|
||||
"type": "minecraft:crafting_shaped",
|
||||
"category": "misc",
|
||||
"pattern": ["V F", "PPP", "P P"],
|
||||
"key": {
|
||||
"V": { "item": "minecraft:glass_bottle" },
|
||||
"F": { "item": "minecraft:feather" },
|
||||
"P": { "tag": "minecraft:planks" }
|
||||
},
|
||||
"result": { "id": "rivencraft:writing_desk", "count": 1 }
|
||||
}
|
||||
Reference in new issue
Block a user