diff --git a/src/main/java/ru/dbotthepony/mc/otm/OverdriveThatMatters.java b/src/main/java/ru/dbotthepony/mc/otm/OverdriveThatMatters.java index 1ddf1485c..d812e4a5f 100644 --- a/src/main/java/ru/dbotthepony/mc/otm/OverdriveThatMatters.java +++ b/src/main/java/ru/dbotthepony/mc/otm/OverdriveThatMatters.java @@ -1,9 +1,12 @@ package ru.dbotthepony.mc.otm; +import net.minecraft.client.gui.screens.MenuScreens; +import net.minecraft.client.gui.screens.inventory.ContainerScreen; import net.minecraft.resources.ResourceLocation; import net.minecraft.server.level.ServerPlayer; import net.minecraft.world.entity.Entity; import net.minecraft.world.entity.player.Player; +import net.minecraft.world.inventory.MenuType; import net.minecraft.world.item.BlockItem; import net.minecraft.world.item.CreativeModeTab; import net.minecraft.world.item.Item; @@ -42,6 +45,11 @@ public class OverdriveThatMatters { public static BlockEntityType.Builder ANDROID_STATION_BUILDER = BlockEntityType.Builder.of(BlockAndroidStation.BlockAndroidStationEntity::new, ANDROID_STATION); public static BlockEntityType ANDROID_STATION_FACTORY = null; public static Item ANDROID_STATION_ITEM = new BlockItem(ANDROID_STATION, new Item.Properties().stacksTo(64).tab(CreativeModeTab.TAB_MISC)).setRegistryName(BlockAndroidStation.REGISTRY_NAME); + public static MenuType ANDROID_STATION_MENU_TYPE = new MenuType<>(BlockAndroidStation.BlockAndroidStationEntity.AndroidStationMenu::new); + + static { + ANDROID_STATION_MENU_TYPE.setRegistryName(BlockAndroidStation.REGISTRY_NAME); + } // public static final Block STONE = register("stone", new Block(BlockBehaviour.Properties.of(Material.STONE, MaterialColor.STONE).requiresCorrectToolForDrops().strength(1.5F, 6.0F))); @@ -59,8 +67,7 @@ public class OverdriveThatMatters { private void setup(final FMLCommonSetupEvent event) { // some preinit code - LOGGER.info("HELLO FROM PREINIT"); - LOGGER.info("DIRT BLOCK >> {}", Blocks.DIRT.getRegistryName()); + LOGGER.info("setup called"); } private void enqueueIMC(final InterModEnqueueEvent event) { @@ -79,7 +86,7 @@ public class OverdriveThatMatters { @SubscribeEvent public void onServerStarting(FMLServerStartingEvent event) { // do something when the server starts - LOGGER.info("HELLO from server starting"); + LOGGER.info("server starting called"); } private final ResourceLocation android_cap_location = new ResourceLocation(OverdriveThatMatters.MOD_ID, "android_capability"); @@ -114,25 +121,33 @@ public class OverdriveThatMatters { @SubscribeEvent public static void onBlocksRegistry(final RegistryEvent.Register blockRegistryEvent) { // регистрация блоков - LOGGER.info("HELLO from Register Block"); + LOGGER.info("Register Block called"); blockRegistryEvent.getRegistry().register(ANDROID_STATION); } @SubscribeEvent public static void onItemRegistry(final RegistryEvent.Register blockRegistryEvent) { // регистрация предметов - LOGGER.info("HELLO from Register Item"); + LOGGER.info("Register Item called"); blockRegistryEvent.getRegistry().register(ANDROID_STATION_ITEM); } @SubscribeEvent public static void onBlockEntityRegistry(final RegistryEvent.Register> blockRegistryEvent) { // регистрация tile entity - LOGGER.info("HELLO from Register BlockEntity"); + LOGGER.info("Register BlockEntity called"); // build(data_fixer) ANDROID_STATION_FACTORY = ANDROID_STATION_BUILDER.build(null); ANDROID_STATION_FACTORY.setRegistryName(BlockAndroidStation.REGISTRY_NAME); blockRegistryEvent.getRegistry().register(ANDROID_STATION_FACTORY); } + + @SubscribeEvent + public static void onMenuTypeRegistry(final RegistryEvent.Register> blockRegistryEvent) { + // регистрация tile entity + LOGGER.info("Register MenuType called"); + blockRegistryEvent.getRegistry().register(ANDROID_STATION_MENU_TYPE); + MenuScreens.register(ANDROID_STATION_MENU_TYPE, BlockAndroidStation.BlockAndroidStationEntity.AndroidStationScreen::new); + } } } diff --git a/src/main/java/ru/dbotthepony/mc/otm/block/BlockAndroidStation.java b/src/main/java/ru/dbotthepony/mc/otm/block/BlockAndroidStation.java index fea3ed8c1..0cf1f911b 100644 --- a/src/main/java/ru/dbotthepony/mc/otm/block/BlockAndroidStation.java +++ b/src/main/java/ru/dbotthepony/mc/otm/block/BlockAndroidStation.java @@ -1,11 +1,24 @@ package ru.dbotthepony.mc.otm.block; +import com.mojang.blaze3d.systems.RenderSystem; +import com.mojang.blaze3d.vertex.PoseStack; +import net.minecraft.client.gui.screens.inventory.AbstractContainerScreen; +import net.minecraft.client.renderer.GameRenderer; import net.minecraft.core.BlockPos; import net.minecraft.core.Direction; import net.minecraft.nbt.CompoundTag; +import net.minecraft.network.chat.Component; +import net.minecraft.network.chat.TranslatableComponent; import net.minecraft.resources.ResourceLocation; import net.minecraft.server.level.ServerPlayer; +import net.minecraft.world.InteractionHand; +import net.minecraft.world.InteractionResult; +import net.minecraft.world.MenuProvider; import net.minecraft.world.entity.LivingEntity; +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.MenuType; import net.minecraft.world.level.BlockGetter; import net.minecraft.world.level.Level; import net.minecraft.world.level.block.Block; @@ -18,6 +31,7 @@ import net.minecraft.world.level.block.state.BlockState; import net.minecraft.world.level.material.Material; import net.minecraft.world.level.material.MaterialColor; import net.minecraft.world.phys.AABB; +import net.minecraft.world.phys.BlockHitResult; import net.minecraft.world.phys.shapes.CollisionContext; import net.minecraft.world.phys.shapes.Shapes; import net.minecraft.world.phys.shapes.VoxelShape; @@ -61,7 +75,62 @@ public class BlockAndroidStation extends Block implements EntityBlock { return level.isClientSide || type != OverdriveThatMatters.ANDROID_STATION_FACTORY ? null : BlockAndroidStationEntity::tick; } - public static class BlockAndroidStationEntity extends BlockEntity { + @Override + public InteractionResult use(BlockState p_60503_, Level level, BlockPos pos, Player ply, InteractionHand p_60507_, BlockHitResult p_60508_) { + if (!level.isClientSide && level.getBlockEntity(pos) instanceof BlockAndroidStationEntity tile) { + ply.openMenu(tile); + return InteractionResult.CONSUME; + } + + return InteractionResult.SUCCESS; + } + + public static class BlockAndroidStationEntity extends BlockEntity implements MenuProvider { + @Override + public Component getDisplayName() { + return new TranslatableComponent("container.android_station"); + } + + @Nullable + @Override + public AbstractContainerMenu createMenu(int containerID, Inventory inventory, Player ply) { + new Exception().printStackTrace(); + return new AndroidStationMenu(containerID, this); + } + + public static class AndroidStationMenu extends AbstractContainerMenu { + private BlockAndroidStationEntity tile; + private Inventory inventory; + + public AndroidStationMenu(int containerID, Inventory inventory) { + super(OverdriveThatMatters.ANDROID_STATION_MENU_TYPE, containerID); + new Exception().printStackTrace(); + this.inventory = inventory; + } + + public AndroidStationMenu(int containerID, BlockAndroidStationEntity tile) { + super(OverdriveThatMatters.ANDROID_STATION_MENU_TYPE, containerID); + new Exception().printStackTrace(); + this.tile = tile; + } + + @Override + public boolean stillValid(Player p_38874_) { + return !tile.isRemoved(); + } + } + + public static class AndroidStationScreen extends AbstractContainerScreen { + public AndroidStationScreen(AndroidStationMenu p_97741_, Inventory p_97742_, Component p_97743_) { + super(p_97741_, p_97742_, p_97743_); + } + + @Override + protected void renderBg(PoseStack p_97787_, float p_97788_, int p_97789_, int p_97790_) { + + } + } + private static class AndroidStationEnergyStorage extends EnergyStorage { public AndroidStationEnergyStorage(int capacity, int maxReceive, int maxExtract) { super(capacity, maxReceive, maxExtract);