mirror of
https://github.com/RoBaertschi/EnvironmentTech.git
synced 2025-04-19 23:03:28 +00:00
added ui for env collector, WIP
This commit is contained in:
parent
79f3210e23
commit
bd31a84c53
@ -0,0 +1,2 @@
|
|||||||
|
// 1.20.6 2024-06-04T18:17:38.371046381 Item Models: environmenttech
|
||||||
|
7da758340fb853d580031041c9f27152a54ec971 assets/environmenttech/models/item/env_collector.json
|
@ -1,3 +1,3 @@
|
|||||||
// 1.20.6 2024-06-04T08:11:35.3127563 Recipes
|
// 1.20.6 2024-06-04T18:17:38.370569743 Recipes
|
||||||
a8f75064cc52045c05943428b359d7c7ef8967dc data/environmenttech/advancements/recipes/environmental_essence.json
|
375ee3cb8eaf222bd0d5576061d1741b5b3d5cff data/environmenttech/advancements/recipes/environmental_essence.json
|
||||||
d462a41d1b0fda35660ed3e4c807f83f6dc0e0cd data/environmenttech/recipes/environmental_essence.json
|
d462a41d1b0fda35660ed3e4c807f83f6dc0e0cd data/environmenttech/recipes/environmental_essence.json
|
||||||
|
@ -0,0 +1,3 @@
|
|||||||
|
{
|
||||||
|
"parent": "environmenttech:block/env_collector_main"
|
||||||
|
}
|
@ -1,6 +1,16 @@
|
|||||||
{
|
{
|
||||||
"parent": "minecraft:recipes/root",
|
"parent": "minecraft:recipes/root",
|
||||||
"criteria": {
|
"criteria": {
|
||||||
|
"env_collector": {
|
||||||
|
"conditions": {
|
||||||
|
"items": [
|
||||||
|
{
|
||||||
|
"items": "environmenttech:env_collector"
|
||||||
|
}
|
||||||
|
]
|
||||||
|
},
|
||||||
|
"trigger": "minecraft:inventory_changed"
|
||||||
|
},
|
||||||
"has_the_recipe": {
|
"has_the_recipe": {
|
||||||
"conditions": {
|
"conditions": {
|
||||||
"recipe": "environmenttech:environmental_essence"
|
"recipe": "environmenttech:environmental_essence"
|
||||||
@ -21,7 +31,8 @@
|
|||||||
"requirements": [
|
"requirements": [
|
||||||
[
|
[
|
||||||
"has_the_recipe",
|
"has_the_recipe",
|
||||||
"iron_ingot"
|
"iron_ingot",
|
||||||
|
"env_collector"
|
||||||
]
|
]
|
||||||
],
|
],
|
||||||
"rewards": {
|
"rewards": {
|
||||||
|
@ -21,6 +21,7 @@ import robaertschi.environmenttech.data.recipes.ETRecipes;
|
|||||||
import robaertschi.environmenttech.level.block.ETBlocks;
|
import robaertschi.environmenttech.level.block.ETBlocks;
|
||||||
import robaertschi.environmenttech.level.block.entity.ETBlockEntities;
|
import robaertschi.environmenttech.level.block.entity.ETBlockEntities;
|
||||||
import robaertschi.environmenttech.level.item.ETItems;
|
import robaertschi.environmenttech.level.item.ETItems;
|
||||||
|
import robaertschi.environmenttech.menu.ETMenus;
|
||||||
|
|
||||||
@Mod(EnvironmentTech.MODID)
|
@Mod(EnvironmentTech.MODID)
|
||||||
public class EnvironmentTech
|
public class EnvironmentTech
|
||||||
@ -46,6 +47,7 @@ public class EnvironmentTech
|
|||||||
ETRecipes.init(modEventBus);
|
ETRecipes.init(modEventBus);
|
||||||
ETAttachments.init(modEventBus);
|
ETAttachments.init(modEventBus);
|
||||||
ETCapabilities.init(modEventBus);
|
ETCapabilities.init(modEventBus);
|
||||||
|
ETMenus.init(modEventBus);
|
||||||
|
|
||||||
NeoForge.EVENT_BUS.register(this);
|
NeoForge.EVENT_BUS.register(this);
|
||||||
|
|
||||||
@ -71,13 +73,4 @@ public class EnvironmentTech
|
|||||||
// event.getEntity().sendSystemMessage(Component.literal("ENV in chunk: " + env));
|
// event.getEntity().sendSystemMessage(Component.literal("ENV in chunk: " + env));
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@EventBusSubscriber(modid = MODID, bus = EventBusSubscriber.Bus.MOD, value = Dist.CLIENT)
|
|
||||||
public static class ClientModEvents
|
|
||||||
{
|
|
||||||
@SubscribeEvent
|
|
||||||
public static void onClientSetup(FMLClientSetupEvent event)
|
|
||||||
{
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
@ -0,0 +1,20 @@
|
|||||||
|
package robaertschi.environmenttech.client;
|
||||||
|
|
||||||
|
import net.neoforged.bus.api.SubscribeEvent;
|
||||||
|
import net.neoforged.fml.common.EventBusSubscriber;
|
||||||
|
import net.neoforged.fml.event.lifecycle.FMLClientSetupEvent;
|
||||||
|
import net.neoforged.neoforge.client.event.RegisterMenuScreensEvent;
|
||||||
|
import robaertschi.environmenttech.client.screen.EnvCollectorScreen;
|
||||||
|
import robaertschi.environmenttech.menu.ETMenus;
|
||||||
|
|
||||||
|
@EventBusSubscriber(bus = EventBusSubscriber.Bus.MOD)
|
||||||
|
public class ETClient {
|
||||||
|
@SubscribeEvent
|
||||||
|
public static void setup(FMLClientSetupEvent event) {
|
||||||
|
}
|
||||||
|
|
||||||
|
@SubscribeEvent
|
||||||
|
public static void registerMenu(RegisterMenuScreensEvent event) {
|
||||||
|
event.register(ETMenus.ENV_COLLECTOR_MENU.get(), EnvCollectorScreen::new);
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,26 @@
|
|||||||
|
package robaertschi.environmenttech.client.screen;
|
||||||
|
|
||||||
|
import net.minecraft.client.gui.GuiGraphics;
|
||||||
|
import net.minecraft.client.gui.screens.inventory.AbstractContainerScreen;
|
||||||
|
import net.minecraft.network.chat.Component;
|
||||||
|
import net.minecraft.resources.ResourceLocation;
|
||||||
|
import net.minecraft.world.entity.player.Inventory;
|
||||||
|
import org.jetbrains.annotations.NotNull;
|
||||||
|
import robaertschi.environmenttech.EnvironmentTech;
|
||||||
|
import robaertschi.environmenttech.menu.EnvCollectorMenu;
|
||||||
|
|
||||||
|
public class EnvCollectorScreen extends AbstractContainerScreen<EnvCollectorMenu> {
|
||||||
|
private final ResourceLocation GUI = EnvironmentTech.id("textures/gui/container/env_collector.png");
|
||||||
|
|
||||||
|
public EnvCollectorScreen(EnvCollectorMenu pMenu, Inventory pPlayerInventory, Component pTitle) {
|
||||||
|
super(pMenu, pPlayerInventory, pTitle);
|
||||||
|
// this.inventoryLabelY = this.imageHeight - 110;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected void renderBg(@NotNull GuiGraphics pGuiGraphics, float pPartialTick, int pMouseX, int pMouseY) {
|
||||||
|
int relX = (this.width - this.imageWidth) / 2;
|
||||||
|
int relY = (this.height - this.imageHeight) / 2;
|
||||||
|
pGuiGraphics.blit(GUI, relX, relY, 0, 0, this.imageWidth, this.imageHeight);
|
||||||
|
}
|
||||||
|
}
|
@ -30,5 +30,10 @@ public class ETDatagen {
|
|||||||
event.includeClient(),
|
event.includeClient(),
|
||||||
new ETBlockStateProvider(output, existingFileHelper)
|
new ETBlockStateProvider(output, existingFileHelper)
|
||||||
);
|
);
|
||||||
|
|
||||||
|
generator.addProvider(
|
||||||
|
event.includeClient(),
|
||||||
|
new ETItemModelProvider(output, existingFileHelper)
|
||||||
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -0,0 +1,20 @@
|
|||||||
|
package robaertschi.environmenttech.datagen;
|
||||||
|
|
||||||
|
import net.minecraft.data.PackOutput;
|
||||||
|
import net.neoforged.neoforge.client.model.generators.ItemModelProvider;
|
||||||
|
import net.neoforged.neoforge.common.data.ExistingFileHelper;
|
||||||
|
import robaertschi.environmenttech.level.block.ETBlocks;
|
||||||
|
|
||||||
|
import static robaertschi.environmenttech.EnvironmentTech.MODID;
|
||||||
|
|
||||||
|
public class ETItemModelProvider extends ItemModelProvider {
|
||||||
|
public ETItemModelProvider(PackOutput output, ExistingFileHelper existingFileHelper) {
|
||||||
|
super(output, MODID, existingFileHelper);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected void registerModels() {
|
||||||
|
withExistingParent(ETBlocks.ENV_COLLECTOR_BLOCK.getId().getPath(), modLoc("block/" + "env_collector_main"));
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
@ -28,6 +28,7 @@ public class ETRecipeProvider extends RecipeProvider {
|
|||||||
).unlockedBy(
|
).unlockedBy(
|
||||||
"iron_ingot",
|
"iron_ingot",
|
||||||
InventoryChangeTrigger.TriggerInstance.hasItems(Items.IRON_INGOT)
|
InventoryChangeTrigger.TriggerInstance.hasItems(Items.IRON_INGOT)
|
||||||
).save(recipeOutput);
|
).unlockedBy("env_collector", InventoryChangeTrigger.TriggerInstance.hasItems(ETItems.ENV_COLLECTOR_BLOCK_ITEM))
|
||||||
|
.save(recipeOutput);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -13,7 +13,7 @@ public class ETBlocks {
|
|||||||
// Create a Deferred Register to hold Blocks which will all be registered under the "environmenttech" namespace
|
// Create a Deferred Register to hold Blocks which will all be registered under the "environmenttech" namespace
|
||||||
public static final DeferredRegister.Blocks BLOCKS = DeferredRegister.createBlocks(MODID);
|
public static final DeferredRegister.Blocks BLOCKS = DeferredRegister.createBlocks(MODID);
|
||||||
// Creates a new Block with the id "environmenttech:example_block", combining the namespace and path
|
// Creates a new Block with the id "environmenttech:example_block", combining the namespace and path
|
||||||
public static final DeferredBlock<Block> EXAMPLE_BLOCK = BLOCKS.registerSimpleBlock("example_block", BlockBehaviour.Properties.of().mapColor(MapColor.STONE));
|
// public static final DeferredBlock<Block> EXAMPLE_BLOCK = BLOCKS.registerSimpleBlock("example_block", BlockBehaviour.Properties.of().mapColor(MapColor.STONE));
|
||||||
public static final DeferredBlock<EnvCollectorBlock> ENV_COLLECTOR_BLOCK = BLOCKS.registerBlock("env_collector", EnvCollectorBlock::new, BlockBehaviour.Properties.of());
|
public static final DeferredBlock<EnvCollectorBlock> ENV_COLLECTOR_BLOCK = BLOCKS.registerBlock("env_collector", EnvCollectorBlock::new, BlockBehaviour.Properties.of());
|
||||||
|
|
||||||
|
|
||||||
|
@ -3,7 +3,16 @@ package robaertschi.environmenttech.level.block;
|
|||||||
import com.mojang.serialization.MapCodec;
|
import com.mojang.serialization.MapCodec;
|
||||||
import lombok.extern.slf4j.Slf4j;
|
import lombok.extern.slf4j.Slf4j;
|
||||||
import net.minecraft.core.BlockPos;
|
import net.minecraft.core.BlockPos;
|
||||||
|
import net.minecraft.network.chat.Component;
|
||||||
import net.minecraft.server.level.ServerLevel;
|
import net.minecraft.server.level.ServerLevel;
|
||||||
|
import net.minecraft.world.InteractionHand;
|
||||||
|
import net.minecraft.world.InteractionResult;
|
||||||
|
import net.minecraft.world.ItemInteractionResult;
|
||||||
|
import net.minecraft.world.MenuProvider;
|
||||||
|
import net.minecraft.world.entity.player.Inventory;
|
||||||
|
import net.minecraft.world.entity.player.Player;
|
||||||
|
import net.minecraft.world.inventory.AbstractContainerMenu;
|
||||||
|
import net.minecraft.world.item.ItemStack;
|
||||||
import net.minecraft.world.level.Level;
|
import net.minecraft.world.level.Level;
|
||||||
import net.minecraft.world.level.block.BaseEntityBlock;
|
import net.minecraft.world.level.block.BaseEntityBlock;
|
||||||
import net.minecraft.world.level.block.RenderShape;
|
import net.minecraft.world.level.block.RenderShape;
|
||||||
@ -11,13 +20,17 @@ import net.minecraft.world.level.block.entity.BlockEntity;
|
|||||||
import net.minecraft.world.level.block.entity.BlockEntityTicker;
|
import net.minecraft.world.level.block.entity.BlockEntityTicker;
|
||||||
import net.minecraft.world.level.block.entity.BlockEntityType;
|
import net.minecraft.world.level.block.entity.BlockEntityType;
|
||||||
import net.minecraft.world.level.block.state.BlockState;
|
import net.minecraft.world.level.block.state.BlockState;
|
||||||
|
import net.minecraft.world.phys.BlockHitResult;
|
||||||
import org.jetbrains.annotations.NotNull;
|
import org.jetbrains.annotations.NotNull;
|
||||||
import org.jetbrains.annotations.Nullable;
|
import org.jetbrains.annotations.Nullable;
|
||||||
import robaertschi.environmenttech.level.block.entity.ETBlockEntities;
|
import robaertschi.environmenttech.level.block.entity.ETBlockEntities;
|
||||||
import robaertschi.environmenttech.level.block.entity.EnvCollectorBlockEntity;
|
import robaertschi.environmenttech.level.block.entity.EnvCollectorBlockEntity;
|
||||||
|
import robaertschi.environmenttech.menu.EnvCollectorMenu;
|
||||||
|
|
||||||
import javax.annotation.ParametersAreNonnullByDefault;
|
import javax.annotation.ParametersAreNonnullByDefault;
|
||||||
|
|
||||||
|
import static robaertschi.environmenttech.EnvironmentTech.MODID;
|
||||||
|
|
||||||
@ParametersAreNonnullByDefault()
|
@ParametersAreNonnullByDefault()
|
||||||
@Slf4j
|
@Slf4j
|
||||||
public class EnvCollectorBlock extends BaseEntityBlock {
|
public class EnvCollectorBlock extends BaseEntityBlock {
|
||||||
@ -44,6 +57,40 @@ public class EnvCollectorBlock extends BaseEntityBlock {
|
|||||||
return new EnvCollectorBlockEntity(pPos, pState);
|
return new EnvCollectorBlockEntity(pPos, pState);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected @NotNull InteractionResult useWithoutItem(BlockState pState, Level pLevel, BlockPos pPos, Player pPlayer, BlockHitResult pHitResult) {
|
||||||
|
return openMenu(pLevel, pPos, pPlayer);
|
||||||
|
}
|
||||||
|
|
||||||
|
private InteractionResult openMenu(Level pLevel, BlockPos pPos, Player pPlayer) {
|
||||||
|
if (!pLevel.isClientSide) {
|
||||||
|
BlockEntity be = pLevel.getBlockEntity(pPos);
|
||||||
|
if (be instanceof EnvCollectorBlockEntity) {
|
||||||
|
MenuProvider containerProvider = new MenuProvider() {
|
||||||
|
@Override
|
||||||
|
public @NotNull Component getDisplayName() {
|
||||||
|
return Component.translatable("environmenttech.screen.env_collector");
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public @NotNull AbstractContainerMenu createMenu(int pContainerId, Inventory pPlayerInventory, Player pPlayer) {
|
||||||
|
return new EnvCollectorMenu(pContainerId, pPlayer, pPos);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
pPlayer.openMenu(containerProvider, buf -> buf.writeBlockPos(pPos));
|
||||||
|
} else {
|
||||||
|
throw new IllegalStateException("Our named container provider is missing!");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return InteractionResult.SUCCESS;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected @NotNull ItemInteractionResult useItemOn(ItemStack pStack, BlockState pState, Level pLevel, BlockPos pPos, Player pPlayer, InteractionHand pHand, BlockHitResult pHitResult) {
|
||||||
|
InteractionResult result = openMenu(pLevel, pPos, pPlayer);
|
||||||
|
return ItemInteractionResult.SUCCESS;
|
||||||
|
}
|
||||||
|
|
||||||
@Nullable
|
@Nullable
|
||||||
@Override
|
@Override
|
||||||
public <T extends BlockEntity> BlockEntityTicker<T> getTicker(Level pLevel, BlockState pState, BlockEntityType<T> pBlockEntityType) {
|
public <T extends BlockEntity> BlockEntityTicker<T> getTicker(Level pLevel, BlockState pState, BlockEntityType<T> pBlockEntityType) {
|
||||||
|
@ -24,6 +24,13 @@ import robaertschi.environmenttech.data.recipes.EnvCollectorRecipe;
|
|||||||
import static robaertschi.environmenttech.EnvironmentTech.MODID;
|
import static robaertschi.environmenttech.EnvironmentTech.MODID;
|
||||||
|
|
||||||
public class EnvCollectorBlockEntity extends BlockEntity {
|
public class EnvCollectorBlockEntity extends BlockEntity {
|
||||||
|
public static final int SLOT_INPUT = 0;
|
||||||
|
public static final int SLOT_INPUT_COUNT = 1;
|
||||||
|
|
||||||
|
public static final int SLOT_OUTPUT = 0;
|
||||||
|
public static final int SLOT_OUTPUT_COUNT = 1;
|
||||||
|
|
||||||
|
public static final int SLOT_COUNT = SLOT_INPUT_COUNT + SLOT_OUTPUT_COUNT;
|
||||||
|
|
||||||
@Getter
|
@Getter
|
||||||
private final ItemStackHandler inventory = new ItemStackHandler(2) {
|
private final ItemStackHandler inventory = new ItemStackHandler(2) {
|
||||||
@ -32,6 +39,11 @@ public class EnvCollectorBlockEntity extends BlockEntity {
|
|||||||
super.onContentsChanged(slot);
|
super.onContentsChanged(slot);
|
||||||
EnvCollectorBlockEntity.this.setChanged();
|
EnvCollectorBlockEntity.this.setChanged();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean isItemValid(int slot, @NotNull ItemStack stack) {
|
||||||
|
return slot < SLOT_INPUT_COUNT;
|
||||||
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
@Getter
|
@Getter
|
||||||
|
@ -13,9 +13,9 @@ import net.neoforged.neoforge.event.BuildCreativeModeTabContentsEvent;
|
|||||||
import net.neoforged.neoforge.registries.DeferredHolder;
|
import net.neoforged.neoforge.registries.DeferredHolder;
|
||||||
import net.neoforged.neoforge.registries.DeferredItem;
|
import net.neoforged.neoforge.registries.DeferredItem;
|
||||||
import net.neoforged.neoforge.registries.DeferredRegister;
|
import net.neoforged.neoforge.registries.DeferredRegister;
|
||||||
|
import robaertschi.environmenttech.level.block.ETBlocks;
|
||||||
|
|
||||||
import static robaertschi.environmenttech.EnvironmentTech.MODID;
|
import static robaertschi.environmenttech.EnvironmentTech.MODID;
|
||||||
import static robaertschi.environmenttech.level.block.ETBlocks.EXAMPLE_BLOCK;
|
|
||||||
|
|
||||||
@EventBusSubscriber(bus = EventBusSubscriber.Bus.MOD)
|
@EventBusSubscriber(bus = EventBusSubscriber.Bus.MOD)
|
||||||
public class ETItems {
|
public class ETItems {
|
||||||
@ -25,7 +25,9 @@ public class ETItems {
|
|||||||
public static final DeferredRegister<CreativeModeTab> CREATIVE_MODE_TABS = DeferredRegister.create(Registries.CREATIVE_MODE_TAB, MODID);
|
public static final DeferredRegister<CreativeModeTab> CREATIVE_MODE_TABS = DeferredRegister.create(Registries.CREATIVE_MODE_TAB, MODID);
|
||||||
|
|
||||||
|
|
||||||
public static final DeferredItem<BlockItem> EXAMPLE_BLOCK_ITEM = ITEMS.registerSimpleBlockItem("example_block", EXAMPLE_BLOCK);
|
// public static final DeferredItem<BlockItem> EXAMPLE_BLOCK_ITEM = ITEMS.registerSimpleBlockItem("example_block", EXAMPLE_BLOCK);
|
||||||
|
|
||||||
|
public static final DeferredItem<BlockItem> ENV_COLLECTOR_BLOCK_ITEM = ITEMS.registerSimpleBlockItem("env_collector", ETBlocks.ENV_COLLECTOR_BLOCK);
|
||||||
|
|
||||||
public static final DeferredItem<EnvDetectorItem> ENV_DETECTOR_ITEM = ITEMS.registerItem("env_detector",
|
public static final DeferredItem<EnvDetectorItem> ENV_DETECTOR_ITEM = ITEMS.registerItem("env_detector",
|
||||||
EnvDetectorItem::new,
|
EnvDetectorItem::new,
|
||||||
@ -41,10 +43,11 @@ public class ETItems {
|
|||||||
public static final DeferredHolder<CreativeModeTab, CreativeModeTab> CREATE_MODE_TAB = CREATIVE_MODE_TABS.register("environmenttech", () -> CreativeModeTab.builder()
|
public static final DeferredHolder<CreativeModeTab, CreativeModeTab> CREATE_MODE_TAB = CREATIVE_MODE_TABS.register("environmenttech", () -> CreativeModeTab.builder()
|
||||||
.title(Component.translatable("itemGroup.environmenttech"))
|
.title(Component.translatable("itemGroup.environmenttech"))
|
||||||
.withTabsBefore(CreativeModeTabs.COMBAT)
|
.withTabsBefore(CreativeModeTabs.COMBAT)
|
||||||
.icon(() -> ENV_DETECTOR_ITEM.get().getDefaultInstance())
|
.icon(() -> ENV_COLLECTOR_BLOCK_ITEM.get().getDefaultInstance())
|
||||||
.displayItems((parameters, output) -> {
|
.displayItems((parameters, output) -> {
|
||||||
|
output.accept(ENV_COLLECTOR_BLOCK_ITEM.get());
|
||||||
output.accept(ENV_DETECTOR_ITEM.get());
|
output.accept(ENV_DETECTOR_ITEM.get());
|
||||||
output.accept(EXAMPLE_BLOCK_ITEM.get());
|
// output.accept(EXAMPLE_BLOCK_ITEM.get());
|
||||||
output.accept(ENVIRONMENTAL_ESSENCE_ITEM.get());
|
output.accept(ENVIRONMENTAL_ESSENCE_ITEM.get());
|
||||||
}).build());
|
}).build());
|
||||||
|
|
||||||
|
21
src/main/java/robaertschi/environmenttech/menu/ETMenus.java
Normal file
21
src/main/java/robaertschi/environmenttech/menu/ETMenus.java
Normal file
@ -0,0 +1,21 @@
|
|||||||
|
package robaertschi.environmenttech.menu;
|
||||||
|
|
||||||
|
import net.minecraft.core.registries.BuiltInRegistries;
|
||||||
|
import net.minecraft.world.inventory.MenuType;
|
||||||
|
import net.neoforged.bus.api.IEventBus;
|
||||||
|
import net.neoforged.neoforge.common.extensions.IMenuTypeExtension;
|
||||||
|
import net.neoforged.neoforge.registries.DeferredHolder;
|
||||||
|
import net.neoforged.neoforge.registries.DeferredRegister;
|
||||||
|
|
||||||
|
import static robaertschi.environmenttech.EnvironmentTech.MODID;
|
||||||
|
|
||||||
|
public class ETMenus {
|
||||||
|
public static final DeferredRegister<MenuType<?>> MENUS = DeferredRegister.create(BuiltInRegistries.MENU, MODID);
|
||||||
|
|
||||||
|
public static final DeferredHolder<MenuType<?>, MenuType<EnvCollectorMenu>> ENV_COLLECTOR_MENU = MENUS.register("env_collector", () ->
|
||||||
|
IMenuTypeExtension.create((windowId, inv, data) -> new EnvCollectorMenu(windowId, inv.player, data.readBlockPos())));
|
||||||
|
|
||||||
|
public static void init(IEventBus modEventBus) {
|
||||||
|
MENUS.register(modEventBus);
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,104 @@
|
|||||||
|
package robaertschi.environmenttech.menu;
|
||||||
|
|
||||||
|
import net.minecraft.core.BlockPos;
|
||||||
|
import net.minecraft.world.Container;
|
||||||
|
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.ContainerLevelAccess;
|
||||||
|
import net.minecraft.world.inventory.MenuType;
|
||||||
|
import net.minecraft.world.inventory.Slot;
|
||||||
|
import net.minecraft.world.item.ItemStack;
|
||||||
|
import net.neoforged.neoforge.items.SlotItemHandler;
|
||||||
|
import org.jetbrains.annotations.NotNull;
|
||||||
|
import org.jetbrains.annotations.Nullable;
|
||||||
|
import robaertschi.environmenttech.level.block.ETBlocks;
|
||||||
|
import robaertschi.environmenttech.level.block.entity.EnvCollectorBlockEntity;
|
||||||
|
|
||||||
|
import static robaertschi.environmenttech.level.block.entity.EnvCollectorBlockEntity.SLOT_COUNT;
|
||||||
|
import static robaertschi.environmenttech.level.block.entity.EnvCollectorBlockEntity.SLOT_INPUT;
|
||||||
|
|
||||||
|
public class EnvCollectorMenu extends AbstractContainerMenu {
|
||||||
|
|
||||||
|
private final BlockPos pos;
|
||||||
|
|
||||||
|
public EnvCollectorMenu(int pContainerId, Player player, BlockPos pos) {
|
||||||
|
super(ETMenus.ENV_COLLECTOR_MENU.get(), pContainerId);
|
||||||
|
this.pos = pos;
|
||||||
|
if (player.level().getBlockEntity(pos) instanceof EnvCollectorBlockEntity envCollector) {
|
||||||
|
addSlot(new SlotItemHandler(envCollector.getInventory(), 0, 55, 35));
|
||||||
|
addSlot(new SlotItemHandler(envCollector.getInventory(), 1, 114, 33));
|
||||||
|
}
|
||||||
|
layoutPlayerInventorySlots(player.getInventory(), 10, 70);
|
||||||
|
}
|
||||||
|
|
||||||
|
private int addSlotRange(Container playerInventory, int index, int x, int y, int amount, int dx) {
|
||||||
|
for (int i = 0 ; i < amount ; i++) {
|
||||||
|
addSlot(new Slot(playerInventory, index, x, y));
|
||||||
|
x += dx;
|
||||||
|
index++;
|
||||||
|
}
|
||||||
|
return index;
|
||||||
|
}
|
||||||
|
|
||||||
|
private int addSlotBox(Container playerInventory, int index, int x, int y, int horAmount, int dx, int verAmount, int dy) {
|
||||||
|
for (int j = 0 ; j < verAmount ; j++) {
|
||||||
|
index = addSlotRange(playerInventory, index, x, y, horAmount, dx);
|
||||||
|
y += dy;
|
||||||
|
}
|
||||||
|
return index;
|
||||||
|
}
|
||||||
|
|
||||||
|
private void layoutPlayerInventorySlots(Container playerInventory, int leftCol, int topRow) {
|
||||||
|
// Player inventory
|
||||||
|
addSlotBox(playerInventory, 9, leftCol, topRow, 9, 18, 3, 18);
|
||||||
|
|
||||||
|
// Hotbar
|
||||||
|
topRow += 58;
|
||||||
|
addSlotRange(playerInventory, 0, leftCol, topRow, 9, 18);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public @NotNull ItemStack quickMoveStack(@NotNull Player pPlayer, int pIndex) {
|
||||||
|
ItemStack itemStack = ItemStack.EMPTY;
|
||||||
|
Slot slot = this.slots.get(pIndex);
|
||||||
|
if (slot.hasItem()) {
|
||||||
|
ItemStack stack = slot.getItem();
|
||||||
|
itemStack = stack.copy();
|
||||||
|
if (pIndex < SLOT_COUNT) {
|
||||||
|
if (!this.moveItemStackTo(stack, SLOT_COUNT, Inventory.INVENTORY_SIZE + SLOT_COUNT, true)) {
|
||||||
|
return ItemStack.EMPTY;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!this.moveItemStackTo(stack, SLOT_INPUT, SLOT_INPUT+1, false)) {
|
||||||
|
if (pIndex < 27 + SLOT_COUNT) {
|
||||||
|
if (!this.moveItemStackTo(stack, 27 + SLOT_COUNT, 36 + SLOT_COUNT, false)) {
|
||||||
|
return ItemStack.EMPTY;
|
||||||
|
}
|
||||||
|
} else if (pIndex < Inventory.INVENTORY_SIZE + SLOT_COUNT && !this.moveItemStackTo(stack, 2, 27 + SLOT_COUNT, false)) {
|
||||||
|
return ItemStack.EMPTY;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (stack.isEmpty()) {
|
||||||
|
slot.set(ItemStack.EMPTY);
|
||||||
|
} else {
|
||||||
|
slot.setChanged();
|
||||||
|
}
|
||||||
|
|
||||||
|
if (stack.getCount() == itemStack.getCount()) {
|
||||||
|
return ItemStack.EMPTY;
|
||||||
|
}
|
||||||
|
|
||||||
|
slot.onTake(pPlayer, stack);
|
||||||
|
}
|
||||||
|
|
||||||
|
return itemStack;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean stillValid(@NotNull Player pPlayer) {
|
||||||
|
return stillValid(ContainerLevelAccess.create(pPlayer.level(), pos), pPlayer, ETBlocks.ENV_COLLECTOR_BLOCK.get());
|
||||||
|
}
|
||||||
|
}
|
Binary file not shown.
After Width: | Height: | Size: 171 B |
Binary file not shown.
After Width: | Height: | Size: 572 B |
Loading…
x
Reference in New Issue
Block a user