Skip to content

Commit

Permalink
Started menus
Browse files Browse the repository at this point in the history
  • Loading branch information
Fureniku committed Jan 21, 2024
1 parent a691351 commit 7d10a43
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 3 deletions.
11 changes: 9 additions & 2 deletions src/main/java/com/fureniku/metropolis/RegistrationBase.java
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
package com.fureniku.metropolis;

import com.fureniku.metropolis.blockentity.MetroBlockEntity;
import com.fureniku.metropolis.test.BlockEntityTest;
import com.fureniku.metropolis.test.RegistrationTest;
import com.fureniku.metropolis.menus.MetroMenu;
import com.fureniku.metropolis.utils.CreativeTabSet;
import com.fureniku.metropolis.utils.Debug;
import net.minecraft.core.registries.Registries;
import net.minecraft.data.DataGenerator;
import net.minecraft.data.PackOutput;
import net.minecraft.world.inventory.MenuType;
import net.minecraft.world.item.*;
import net.minecraft.world.level.block.Block;
import net.minecraft.world.level.block.entity.BlockEntityType;
Expand Down Expand Up @@ -38,6 +38,7 @@ public abstract class RegistrationBase {
protected final DeferredRegister<Item> itemRegistry;
protected final DeferredRegister<CreativeModeTab> creativeTabs;
protected final DeferredRegister<BlockEntityType<?>> blockEntityRegistry;
protected final DeferredRegister<MenuType<?>> menuTypeRegistry;

/**
* Used by registration groups
Expand All @@ -58,6 +59,7 @@ public RegistrationBase(String modid, IEventBus modEventBus) {
itemRegistry = DeferredRegister.create(ForgeRegistries.ITEMS, modid);
creativeTabs = DeferredRegister.create(Registries.CREATIVE_MODE_TAB, modid);
blockEntityRegistry = DeferredRegister.create(ForgeRegistries.BLOCK_ENTITY_TYPES, modid);
menuTypeRegistry = DeferredRegister.create(ForgeRegistries.MENU_TYPES, modid);
modEventBus.addListener(this::common);
modEventBus.addListener(this::client);
modEventBus.addListener(this::buildCreativeTabs);
Expand All @@ -69,6 +71,7 @@ public RegistrationBase(String modid, IEventBus modEventBus) {
itemRegistry.register(modEventBus);
creativeTabs.register(modEventBus);
blockEntityRegistry.register(modEventBus);
menuTypeRegistry.register(modEventBus);
}

/**
Expand Down Expand Up @@ -163,6 +166,10 @@ public <T extends MetroBlockEntity> RegistryObject<BlockEntityType<T>> registerB
return blockEntityRegistry.register(name + "_entity", () -> BlockEntityType.Builder.of(blockEntity, block.get()).build(null));
}

public <T extends MetroMenu> RegistryObject<MenuType<T>> registerMenuType(String name, Supplier<MenuType<T>> menu) {
return menuTypeRegistry.register(name, menu);
}

/**
* Add all your blocks to the created creative tabs in here!
* <p>It may be neater to create a function for each tab, and call those functions from here.</p>
Expand Down
12 changes: 12 additions & 0 deletions src/main/java/com/fureniku/metropolis/menus/MetroMenu.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
package com.fureniku.metropolis.menus;

import net.minecraft.world.inventory.AbstractContainerMenu;
import net.minecraft.world.inventory.MenuType;
import org.jetbrains.annotations.Nullable;

public abstract class MetroMenu extends AbstractContainerMenu {

protected MetroMenu(@Nullable MenuType<?> menuType, int containerId) {
super(menuType, containerId);
}
}
3 changes: 2 additions & 1 deletion src/main/java/com/fureniku/metropolis/utils/ShapeUtils.java
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,8 @@ public class ShapeUtils {
private static final Object2IntMap<BlockState> stateToIndex = new Object2IntOpenHashMap<>();

public static VoxelShape makeShape(float size, float height) {
return Block.box(size, 0, size, 16-size, height, 16-size);
double x = size/2;
return Block.box(8-x, 0, 8-x, 8+x, height, 8+x);
}

public static VoxelShape makeShape(Vec3 shape) {
Expand Down

0 comments on commit 7d10a43

Please sign in to comment.