diff options
Diffstat (limited to 'src/main')
15 files changed, 366 insertions, 210 deletions
diff --git a/src/main/java/lv/enes/mc/eris_alchemy/EMC.java b/src/main/java/lv/enes/mc/eris_alchemy/EMC.java index b8d5557..e34d28f 100644 --- a/src/main/java/lv/enes/mc/eris_alchemy/EMC.java +++ b/src/main/java/lv/enes/mc/eris_alchemy/EMC.java | |||
| @@ -154,7 +154,11 @@ public class EMC { | |||
| 154 | return res; | 154 | return res; |
| 155 | } | 155 | } |
| 156 | 156 | ||
| 157 | private OptionalDouble calculateEmcForRecipe(List<SimplifiedRecipe> recipes, Set<Item> configured, SimplifiedRecipe recipe) { | 157 | private OptionalDouble calculateEmcForRecipe( |
| 158 | List<SimplifiedRecipe> recipes, | ||
| 159 | Set<Item> configured, | ||
| 160 | SimplifiedRecipe recipe | ||
| 161 | ) { | ||
| 158 | try { | 162 | try { |
| 159 | if (recipe.inputs.isEmpty()) { | 163 | if (recipe.inputs.isEmpty()) { |
| 160 | return OptionalDouble.empty(); | 164 | return OptionalDouble.empty(); |
| @@ -191,7 +195,11 @@ public class EMC { | |||
| 191 | } | 195 | } |
| 192 | } | 196 | } |
| 193 | 197 | ||
| 194 | private OptionalDouble calculateEmcForIngredient(List<SimplifiedRecipe> recipes, Set<Item> configured, Ingredient ingredient) { | 198 | private OptionalDouble calculateEmcForIngredient( |
| 199 | List<SimplifiedRecipe> recipes, | ||
| 200 | Set<Item> configured, | ||
| 201 | Ingredient ingredient | ||
| 202 | ) { | ||
| 195 | return Arrays.stream(ingredient.getItems()) | 203 | return Arrays.stream(ingredient.getItems()) |
| 196 | .map(stack -> configEmc(recipes, configured, stack.getItem()).stream() | 204 | .map(stack -> configEmc(recipes, configured, stack.getItem()).stream() |
| 197 | .map(x -> x * stack.getCount()) | 205 | .map(x -> x * stack.getCount()) |
diff --git a/src/main/java/lv/enes/mc/eris_alchemy/ErisAlchemy.java b/src/main/java/lv/enes/mc/eris_alchemy/ErisAlchemy.java index 83cef8c..bb804b3 100644 --- a/src/main/java/lv/enes/mc/eris_alchemy/ErisAlchemy.java +++ b/src/main/java/lv/enes/mc/eris_alchemy/ErisAlchemy.java | |||
| @@ -1,9 +1,5 @@ | |||
| 1 | package lv.enes.mc.eris_alchemy; | 1 | package lv.enes.mc.eris_alchemy; |
| 2 | 2 | ||
| 3 | import lv.enes.mc.eris_alchemy.block.ErisAlchemyBlocks; | ||
| 4 | import lv.enes.mc.eris_alchemy.block.entity.ErisAlchemyBlockEntities; | ||
| 5 | import lv.enes.mc.eris_alchemy.menu.ErisAlchemyMenus; | ||
| 6 | import lv.enes.mc.eris_alchemy.recipe.ErisAlchemyRecipeSerializers; | ||
| 7 | import net.fabricmc.fabric.api.itemgroup.v1.FabricItemGroup; | 3 | import net.fabricmc.fabric.api.itemgroup.v1.FabricItemGroup; |
| 8 | import net.minecraft.core.Registry; | 4 | import net.minecraft.core.Registry; |
| 9 | import net.minecraft.core.registries.BuiltInRegistries; | 5 | import net.minecraft.core.registries.BuiltInRegistries; |
| @@ -21,9 +17,11 @@ public class ErisAlchemy implements ModInitializer { | |||
| 21 | public static final Logger LOGGER = LoggerFactory.getLogger(ID); | 17 | public static final Logger LOGGER = LoggerFactory.getLogger(ID); |
| 22 | 18 | ||
| 23 | public static final CreativeModeTab ITEM_GROUP = FabricItemGroup.builder() | 19 | public static final CreativeModeTab ITEM_GROUP = FabricItemGroup.builder() |
| 24 | .icon(() -> new ItemStack(ErisAlchemyItems.LOW_COVALENCE_DUST)) | 20 | .icon(() -> new ItemStack(ErisAlchemyRegistry.Items.LOW_COVALENCE_DUST)) |
| 25 | .title(Component.translatable("itemGroup.eris_alchemy.item_group")) | 21 | .title(Component.translatable("itemGroup.eris_alchemy.item_group")) |
| 26 | .displayItems((context, entries) -> ErisAlchemyItems.consumeItems((id, item) -> entries.accept(item))) | 22 | .displayItems( |
| 23 | (context, entries) -> ErisAlchemyRegistry.Items.consume((id, item) -> entries.accept(item)) | ||
| 24 | ) | ||
| 27 | .build(); | 25 | .build(); |
| 28 | 26 | ||
| 29 | @Override | 27 | @Override |
| @@ -35,10 +33,14 @@ public class ErisAlchemy implements ModInitializer { | |||
| 35 | 33 | ||
| 36 | Registry.register(BuiltInRegistries.CREATIVE_MODE_TAB, new ResourceLocation(ID, "item_group"), ITEM_GROUP); | 34 | Registry.register(BuiltInRegistries.CREATIVE_MODE_TAB, new ResourceLocation(ID, "item_group"), ITEM_GROUP); |
| 37 | 35 | ||
| 38 | ErisAlchemyBlocks.consumeBlocks((id, block) -> Registry.register(BuiltInRegistries.BLOCK, id, block)); | 36 | ErisAlchemyRegistry.BlockEntities.consume( |
| 39 | ErisAlchemyBlockEntities.consumeBlockEntities((id, block) -> Registry.register(BuiltInRegistries.BLOCK_ENTITY_TYPE, id, block)); | 37 | (id, block) -> Registry.register(BuiltInRegistries.BLOCK_ENTITY_TYPE, id, block) |
| 40 | ErisAlchemyItems.consumeItems((id, item) -> Registry.register(BuiltInRegistries.ITEM, id, item)); | 38 | ); |
| 41 | ErisAlchemyMenus.consumeMenus((id, menu) -> Registry.register(BuiltInRegistries.MENU, id, menu)); | 39 | ErisAlchemyRegistry.Blocks.consume((id, block) -> Registry.register(BuiltInRegistries.BLOCK, id, block)); |
| 42 | ErisAlchemyRecipeSerializers.consumeSerializers((id, serializer) -> Registry.register(BuiltInRegistries.RECIPE_SERIALIZER, id, serializer)); | 40 | ErisAlchemyRegistry.Items.consume((id, item) -> Registry.register(BuiltInRegistries.ITEM, id, item)); |
| 41 | ErisAlchemyRegistry.Menus.consume((id, menu) -> Registry.register(BuiltInRegistries.MENU, id, menu)); | ||
| 42 | ErisAlchemyRegistry.RecipeSerializers.consume( | ||
| 43 | (id, serializer) -> Registry.register(BuiltInRegistries.RECIPE_SERIALIZER, id, serializer) | ||
| 44 | ); | ||
| 43 | } | 45 | } |
| 44 | } | 46 | } |
diff --git a/src/main/java/lv/enes/mc/eris_alchemy/ErisAlchemyItems.java b/src/main/java/lv/enes/mc/eris_alchemy/ErisAlchemyItems.java deleted file mode 100644 index 21bcc7f..0000000 --- a/src/main/java/lv/enes/mc/eris_alchemy/ErisAlchemyItems.java +++ /dev/null | |||
| @@ -1,44 +0,0 @@ | |||
| 1 | package lv.enes.mc.eris_alchemy; | ||
| 2 | |||
| 3 | import lv.enes.mc.eris_alchemy.block.ErisAlchemyBlocks; | ||
| 4 | import net.minecraft.core.registries.BuiltInRegistries; | ||
| 5 | import net.minecraft.resources.ResourceLocation; | ||
| 6 | import net.minecraft.world.item.BlockItem; | ||
| 7 | import net.minecraft.world.item.Item; | ||
| 8 | import net.minecraft.world.item.Rarity; | ||
| 9 | import net.minecraft.world.level.block.Block; | ||
| 10 | import org.quiltmc.qsl.item.setting.api.QuiltItemSettings; | ||
| 11 | |||
| 12 | import java.util.LinkedHashMap; | ||
| 13 | import java.util.Map; | ||
| 14 | import java.util.function.BiConsumer; | ||
| 15 | |||
| 16 | public final class ErisAlchemyItems { | ||
| 17 | private static final Map<ResourceLocation, Item> items = new LinkedHashMap<>(); | ||
| 18 | |||
| 19 | public static final Item ALCHEMICAL_CHEST = register(ErisAlchemyBlocks.ALCHEMICAL_CHEST, new QuiltItemSettings().rarity(Rarity.RARE)); | ||
| 20 | public static final Item LOW_COVALENCE_DUST = register("low_covalence_dust", new Item(new QuiltItemSettings().rarity(Rarity.COMMON))); | ||
| 21 | @SuppressWarnings("unused") | ||
| 22 | public static final Item MEDIUM_COVALENCE_DUST = register("medium_covalence_dust", new Item(new QuiltItemSettings().rarity(Rarity.UNCOMMON))); | ||
| 23 | @SuppressWarnings("unused") | ||
| 24 | public static final Item HIGH_COVALENCE_DUST = register("high_covalence_dust", new Item(new QuiltItemSettings().rarity(Rarity.RARE))); | ||
| 25 | |||
| 26 | public static void consumeItems(BiConsumer<? super ResourceLocation, ? super Item> consumer) { | ||
| 27 | items.forEach(consumer); | ||
| 28 | } | ||
| 29 | |||
| 30 | private static BlockItem register(Block block, QuiltItemSettings settings) { | ||
| 31 | return register(BuiltInRegistries.BLOCK.getKey(block), new BlockItem(block, settings)); | ||
| 32 | } | ||
| 33 | |||
| 34 | private static <T extends Item> T register(String id, T item) { | ||
| 35 | return register(new ResourceLocation(ErisAlchemy.ID, id), item); | ||
| 36 | } | ||
| 37 | |||
| 38 | private static <T extends Item> T register(ResourceLocation id, T item) { | ||
| 39 | items.putIfAbsent(id, item); | ||
| 40 | return item; | ||
| 41 | } | ||
| 42 | |||
| 43 | private ErisAlchemyItems() {} | ||
| 44 | } | ||
diff --git a/src/main/java/lv/enes/mc/eris_alchemy/ErisAlchemyRegistry.java b/src/main/java/lv/enes/mc/eris_alchemy/ErisAlchemyRegistry.java new file mode 100644 index 0000000..c02a1e6 --- /dev/null +++ b/src/main/java/lv/enes/mc/eris_alchemy/ErisAlchemyRegistry.java | |||
| @@ -0,0 +1,147 @@ | |||
| 1 | package lv.enes.mc.eris_alchemy; | ||
| 2 | |||
| 3 | import lv.enes.mc.eris_alchemy.block.AlchemicalChestBlock; | ||
| 4 | import lv.enes.mc.eris_alchemy.block.entity.AlchemicalChestBlockEntity; | ||
| 5 | import lv.enes.mc.eris_alchemy.menu.AlchemicalChestMenu; | ||
| 6 | import lv.enes.mc.eris_alchemy.recipe.CovalenceRepair; | ||
| 7 | import net.minecraft.core.registries.BuiltInRegistries; | ||
| 8 | import net.minecraft.resources.ResourceLocation; | ||
| 9 | import net.minecraft.world.flag.FeatureFlags; | ||
| 10 | import net.minecraft.world.inventory.AbstractContainerMenu; | ||
| 11 | import net.minecraft.world.inventory.MenuType; | ||
| 12 | import net.minecraft.world.item.BlockItem; | ||
| 13 | import net.minecraft.world.item.Item; | ||
| 14 | import net.minecraft.world.item.Rarity; | ||
| 15 | import net.minecraft.world.item.crafting.Recipe; | ||
| 16 | import net.minecraft.world.item.crafting.RecipeSerializer; | ||
| 17 | import net.minecraft.world.level.block.Block; | ||
| 18 | import net.minecraft.world.level.block.entity.BlockEntity; | ||
| 19 | import net.minecraft.world.level.block.entity.BlockEntityType; | ||
| 20 | import org.quiltmc.qsl.block.entity.api.QuiltBlockEntityTypeBuilder; | ||
| 21 | import org.quiltmc.qsl.block.extensions.api.QuiltBlockSettings; | ||
| 22 | import org.quiltmc.qsl.item.setting.api.QuiltItemSettings; | ||
| 23 | |||
| 24 | import java.util.LinkedHashMap; | ||
| 25 | import java.util.Map; | ||
| 26 | import java.util.function.BiConsumer; | ||
| 27 | |||
| 28 | import static net.minecraft.world.level.block.Blocks.ENDER_CHEST; | ||
| 29 | |||
| 30 | public final class ErisAlchemyRegistry { | ||
| 31 | private ErisAlchemyRegistry() {} | ||
| 32 | |||
| 33 | public static final class BlockEntities { | ||
| 34 | private BlockEntities() {} | ||
| 35 | |||
| 36 | private static final Map<ResourceLocation, BlockEntityType<?>> data = new LinkedHashMap<>(); | ||
| 37 | |||
| 38 | public static final BlockEntityType<AlchemicalChestBlockEntity> ALCHEMICAL_CHEST = register( | ||
| 39 | "alchemical_chest", | ||
| 40 | QuiltBlockEntityTypeBuilder.create(AlchemicalChestBlockEntity::new, Blocks.ALCHEMICAL_CHEST) | ||
| 41 | .build() | ||
| 42 | ); | ||
| 43 | |||
| 44 | public static void consume(BiConsumer<? super ResourceLocation, ? super BlockEntityType<?>> consumer) { | ||
| 45 | data.forEach(consumer); | ||
| 46 | } | ||
| 47 | |||
| 48 | private static <T extends BlockEntity> BlockEntityType<T> register(String id, BlockEntityType<T> type) { | ||
| 49 | data.put(new ResourceLocation(ErisAlchemy.ID, id), type); | ||
| 50 | return type; | ||
| 51 | } | ||
| 52 | } | ||
| 53 | |||
| 54 | public static final class Blocks { | ||
| 55 | private Blocks() {} | ||
| 56 | |||
| 57 | private static final Map<ResourceLocation, Block> data = new LinkedHashMap<>(); | ||
| 58 | |||
| 59 | public static final AlchemicalChestBlock ALCHEMICAL_CHEST = register( | ||
| 60 | "alchemical_chest", | ||
| 61 | new AlchemicalChestBlock(QuiltBlockSettings.copy(ENDER_CHEST)) | ||
| 62 | ); | ||
| 63 | |||
| 64 | public static void consume(BiConsumer<? super ResourceLocation, ? super Block> consumer) { | ||
| 65 | data.forEach(consumer); | ||
| 66 | } | ||
| 67 | |||
| 68 | private static <T extends Block> T register(String id, T block) { | ||
| 69 | data.put(new ResourceLocation(ErisAlchemy.ID, id), block); | ||
| 70 | return block; | ||
| 71 | } | ||
| 72 | } | ||
| 73 | |||
| 74 | public static final class Items { | ||
| 75 | private Items() {} | ||
| 76 | |||
| 77 | private static final Map<ResourceLocation, Item> data = new LinkedHashMap<>(); | ||
| 78 | |||
| 79 | public static final Item ALCHEMICAL_CHEST = | ||
| 80 | register(Blocks.ALCHEMICAL_CHEST, new QuiltItemSettings().rarity(Rarity.RARE)); | ||
| 81 | public static final Item LOW_COVALENCE_DUST = | ||
| 82 | register("low_covalence_dust", new Item(new QuiltItemSettings().rarity(Rarity.COMMON))); | ||
| 83 | @SuppressWarnings("unused") | ||
| 84 | public static final Item MEDIUM_COVALENCE_DUST = | ||
| 85 | register("medium_covalence_dust", new Item(new QuiltItemSettings().rarity(Rarity.UNCOMMON))); | ||
| 86 | @SuppressWarnings("unused") | ||
| 87 | public static final Item HIGH_COVALENCE_DUST = | ||
| 88 | register("high_covalence_dust", new Item(new QuiltItemSettings().rarity(Rarity.RARE))); | ||
| 89 | |||
| 90 | public static void consume(BiConsumer<? super ResourceLocation, ? super Item> consumer) { | ||
| 91 | data.forEach(consumer); | ||
| 92 | } | ||
| 93 | |||
| 94 | private static BlockItem register(Block block, QuiltItemSettings settings) { | ||
| 95 | return register(BuiltInRegistries.BLOCK.getKey(block), new BlockItem(block, settings)); | ||
| 96 | } | ||
| 97 | |||
| 98 | private static <T extends Item> T register(String id, T item) { | ||
| 99 | return register(new ResourceLocation(ErisAlchemy.ID, id), item); | ||
| 100 | } | ||
| 101 | |||
| 102 | private static <T extends Item> T register(ResourceLocation id, T item) { | ||
| 103 | data.put(id, item); | ||
| 104 | return item; | ||
| 105 | } | ||
| 106 | } | ||
| 107 | |||
| 108 | public static final class Menus { | ||
| 109 | private Menus() {} | ||
| 110 | |||
| 111 | private static final Map<ResourceLocation, MenuType<?>> data = new LinkedHashMap<>(); | ||
| 112 | |||
| 113 | public static final MenuType<AlchemicalChestMenu> ALCHEMICAL_CHEST = | ||
| 114 | register("alchemy_chest", AlchemicalChestMenu::new); | ||
| 115 | |||
| 116 | public static void consume(BiConsumer<? super ResourceLocation, ? super MenuType<?>> consumer) { | ||
| 117 | data.forEach(consumer); | ||
| 118 | } | ||
| 119 | |||
| 120 | private static <T extends AbstractContainerMenu> MenuType<T> register( | ||
| 121 | String id, | ||
| 122 | MenuType.MenuSupplier<T> supplier | ||
| 123 | ) { | ||
| 124 | var menuType = new MenuType<>(supplier, FeatureFlags.VANILLA_SET); | ||
| 125 | data.put(new ResourceLocation(ErisAlchemy.ID, id), menuType); | ||
| 126 | return menuType; | ||
| 127 | } | ||
| 128 | } | ||
| 129 | |||
| 130 | public static final class RecipeSerializers { | ||
| 131 | private RecipeSerializers() {} | ||
| 132 | |||
| 133 | private static final Map<ResourceLocation, RecipeSerializer<?>> data = new LinkedHashMap<>(); | ||
| 134 | |||
| 135 | public static final RecipeSerializer<CovalenceRepair> COVALENCE_REPAIR = | ||
| 136 | register("covalence_repair", new CovalenceRepair.Serializer()); | ||
| 137 | |||
| 138 | public static void consume(BiConsumer<? super ResourceLocation, ? super RecipeSerializer<?>> consumer) { | ||
| 139 | data.forEach(consumer); | ||
| 140 | } | ||
| 141 | |||
| 142 | private static <T extends Recipe<?>> RecipeSerializer<T> register(String id, RecipeSerializer<T> serializer) { | ||
| 143 | data.put(new ResourceLocation(ErisAlchemy.ID, id), serializer); | ||
| 144 | return serializer; | ||
| 145 | } | ||
| 146 | } | ||
| 147 | } | ||
diff --git a/src/main/java/lv/enes/mc/eris_alchemy/block/AlchemicalChestBlock.java b/src/main/java/lv/enes/mc/eris_alchemy/block/AlchemicalChestBlock.java index 9a3b413..1d8698a 100644 --- a/src/main/java/lv/enes/mc/eris_alchemy/block/AlchemicalChestBlock.java +++ b/src/main/java/lv/enes/mc/eris_alchemy/block/AlchemicalChestBlock.java | |||
| @@ -2,8 +2,8 @@ package lv.enes.mc.eris_alchemy.block; | |||
| 2 | 2 | ||
| 3 | import jakarta.annotation.Nonnull; | 3 | import jakarta.annotation.Nonnull; |
| 4 | import jakarta.annotation.Nullable; | 4 | import jakarta.annotation.Nullable; |
| 5 | import lv.enes.mc.eris_alchemy.ErisAlchemyRegistry; | ||
| 5 | import lv.enes.mc.eris_alchemy.block.entity.AlchemicalChestBlockEntity; | 6 | import lv.enes.mc.eris_alchemy.block.entity.AlchemicalChestBlockEntity; |
| 6 | import lv.enes.mc.eris_alchemy.block.entity.ErisAlchemyBlockEntities; | ||
| 7 | import lv.enes.mc.eris_alchemy.menu.AlchemicalChestMenu; | 7 | import lv.enes.mc.eris_alchemy.menu.AlchemicalChestMenu; |
| 8 | import net.minecraft.core.BlockPos; | 8 | import net.minecraft.core.BlockPos; |
| 9 | import net.minecraft.core.Direction; | 9 | import net.minecraft.core.Direction; |
| @@ -32,12 +32,18 @@ import net.minecraft.world.phys.BlockHitResult; | |||
| 32 | import net.minecraft.world.phys.shapes.CollisionContext; | 32 | import net.minecraft.world.phys.shapes.CollisionContext; |
| 33 | import net.minecraft.world.phys.shapes.VoxelShape; | 33 | import net.minecraft.world.phys.shapes.VoxelShape; |
| 34 | 34 | ||
| 35 | public class AlchemicalChestBlock extends AbstractChestBlock<AlchemicalChestBlockEntity> implements SimpleWaterloggedBlock { | 35 | public class AlchemicalChestBlock |
| 36 | extends AbstractChestBlock<AlchemicalChestBlockEntity> | ||
| 37 | implements SimpleWaterloggedBlock | ||
| 38 | { | ||
| 36 | public static final DirectionProperty FACING = BlockStateProperties.HORIZONTAL_FACING; | 39 | public static final DirectionProperty FACING = BlockStateProperties.HORIZONTAL_FACING; |
| 37 | public static final BooleanProperty WATERLOGGED = BlockStateProperties.WATERLOGGED; | 40 | public static final BooleanProperty WATERLOGGED = BlockStateProperties.WATERLOGGED; |
| 38 | 41 | ||
| 39 | public static final Component CONTAINER_TITLE = Component.translatable("container.eris_alchemy.alchemical_chest"); | 42 | public static final Component CONTAINER_TITLE = Component.translatable("container.eris_alchemy.alchemical_chest"); |
| 40 | public static final VoxelShape SHAPE = Block.box(1.0, 0.0, 1.0, 15.0, 14.0, 15.0); | 43 | public static final VoxelShape SHAPE = Block.box( |
| 44 | 1.0, 0.0, 1.0, | ||
| 45 | 15.0, 14.0, 15.0 | ||
| 46 | ); | ||
| 41 | 47 | ||
| 42 | public static Container getContainer(Level world, BlockPos pos) { | 48 | public static Container getContainer(Level world, BlockPos pos) { |
| 43 | if (world.getBlockEntity(pos) instanceof AlchemicalChestBlockEntity container) { | 49 | if (world.getBlockEntity(pos) instanceof AlchemicalChestBlockEntity container) { |
| @@ -47,7 +53,7 @@ public class AlchemicalChestBlock extends AbstractChestBlock<AlchemicalChestBloc | |||
| 47 | } | 53 | } |
| 48 | 54 | ||
| 49 | public AlchemicalChestBlock(Properties properties) { | 55 | public AlchemicalChestBlock(Properties properties) { |
| 50 | super(properties, () -> ErisAlchemyBlockEntities.ALCHEMICAL_CHEST); | 56 | super(properties, () -> ErisAlchemyRegistry.BlockEntities.ALCHEMICAL_CHEST); |
| 51 | registerDefaultState(getStateDefinition().any() | 57 | registerDefaultState(getStateDefinition().any() |
| 52 | .setValue(FACING, Direction.NORTH) | 58 | .setValue(FACING, Direction.NORTH) |
| 53 | .setValue(WATERLOGGED, false) | 59 | .setValue(WATERLOGGED, false) |
| @@ -56,7 +62,12 @@ public class AlchemicalChestBlock extends AbstractChestBlock<AlchemicalChestBloc | |||
| 56 | 62 | ||
| 57 | @Nonnull | 63 | @Nonnull |
| 58 | @Override | 64 | @Override |
| 59 | public DoubleBlockCombiner.NeighborCombineResult<? extends ChestBlockEntity> combine(BlockState state, Level world, BlockPos pos, boolean ignoreBlocked) { | 65 | public DoubleBlockCombiner.NeighborCombineResult<? extends ChestBlockEntity> combine( |
| 66 | BlockState state, | ||
| 67 | Level world, | ||
| 68 | BlockPos pos, | ||
| 69 | boolean ignoreBlocked | ||
| 70 | ) { | ||
| 60 | return DoubleBlockCombiner.Combiner::acceptNone; | 71 | return DoubleBlockCombiner.Combiner::acceptNone; |
| 61 | } | 72 | } |
| 62 | 73 | ||
| @@ -102,8 +113,16 @@ public class AlchemicalChestBlock extends AbstractChestBlock<AlchemicalChestBloc | |||
| 102 | } | 113 | } |
| 103 | 114 | ||
| 104 | @Override | 115 | @Override |
| 105 | public <T extends BlockEntity> BlockEntityTicker<T> getTicker(Level ignoredWorld, BlockState ignoredState, BlockEntityType<T> type) { | 116 | public <T extends BlockEntity> BlockEntityTicker<T> getTicker( |
| 106 | return createTickerHelper(type, blockEntityType.get(), (world, pos, state, entity) -> entity.tick(world, pos, state)); | 117 | Level ignoredWorld, |
| 118 | BlockState ignoredState, | ||
| 119 | BlockEntityType<T> type | ||
| 120 | ) { | ||
| 121 | return createTickerHelper( | ||
| 122 | type, | ||
| 123 | blockEntityType.get(), | ||
| 124 | (world, pos, state, entity) -> entity.tick(world, pos, state) | ||
| 125 | ); | ||
| 107 | } | 126 | } |
| 108 | 127 | ||
| 109 | @SuppressWarnings("deprecation") | 128 | @SuppressWarnings("deprecation") |
| @@ -155,7 +174,14 @@ public class AlchemicalChestBlock extends AbstractChestBlock<AlchemicalChestBloc | |||
| 155 | @SuppressWarnings("deprecation") | 174 | @SuppressWarnings("deprecation") |
| 156 | @Nonnull | 175 | @Nonnull |
| 157 | @Override | 176 | @Override |
| 158 | public BlockState updateShape(BlockState state, Direction direction, BlockState neighborState, LevelAccessor world, BlockPos pos, BlockPos neighborPos) { | 177 | public BlockState updateShape( |
| 178 | BlockState state, | ||
| 179 | Direction direction, | ||
| 180 | BlockState neighborState, | ||
| 181 | LevelAccessor world, | ||
| 182 | BlockPos pos, | ||
| 183 | BlockPos neighborPos | ||
| 184 | ) { | ||
| 159 | if (state.getValue(WATERLOGGED)) { | 185 | if (state.getValue(WATERLOGGED)) { |
| 160 | world.scheduleTick(pos, Fluids.WATER, Fluids.WATER.getTickDelay(world)); | 186 | world.scheduleTick(pos, Fluids.WATER, Fluids.WATER.getTickDelay(world)); |
| 161 | } | 187 | } |
| @@ -166,7 +192,14 @@ public class AlchemicalChestBlock extends AbstractChestBlock<AlchemicalChestBloc | |||
| 166 | @SuppressWarnings("deprecation") | 192 | @SuppressWarnings("deprecation") |
| 167 | @Nonnull | 193 | @Nonnull |
| 168 | @Override | 194 | @Override |
| 169 | public InteractionResult use(BlockState state, Level world, BlockPos pos, Player player, InteractionHand hand, BlockHitResult hit) { | 195 | public InteractionResult use( |
| 196 | BlockState state, | ||
| 197 | Level world, | ||
| 198 | BlockPos pos, | ||
| 199 | Player player, | ||
| 200 | InteractionHand hand, | ||
| 201 | BlockHitResult hit | ||
| 202 | ) { | ||
| 170 | if (world.isClientSide) { | 203 | if (world.isClientSide) { |
| 171 | return InteractionResult.SUCCESS; | 204 | return InteractionResult.SUCCESS; |
| 172 | } | 205 | } |
| @@ -174,7 +207,7 @@ public class AlchemicalChestBlock extends AbstractChestBlock<AlchemicalChestBloc | |||
| 174 | var provider = getMenuProvider(state, world, pos); | 207 | var provider = getMenuProvider(state, world, pos); |
| 175 | if (provider != null) { | 208 | if (provider != null) { |
| 176 | player.openMenu(provider); | 209 | player.openMenu(provider); |
| 177 | // player.awardStat(getOpenChestStat); | 210 | // TODO: player.awardStat(getOpenChestStat); |
| 178 | PiglinAi.angerNearbyPiglins(player, true); | 211 | PiglinAi.angerNearbyPiglins(player, true); |
| 179 | } | 212 | } |
| 180 | 213 | ||
diff --git a/src/main/java/lv/enes/mc/eris_alchemy/block/ErisAlchemyBlocks.java b/src/main/java/lv/enes/mc/eris_alchemy/block/ErisAlchemyBlocks.java deleted file mode 100644 index 6966681..0000000 --- a/src/main/java/lv/enes/mc/eris_alchemy/block/ErisAlchemyBlocks.java +++ /dev/null | |||
| @@ -1,29 +0,0 @@ | |||
| 1 | package lv.enes.mc.eris_alchemy.block; | ||
| 2 | |||
| 3 | import lv.enes.mc.eris_alchemy.ErisAlchemy; | ||
| 4 | import net.minecraft.resources.ResourceLocation; | ||
| 5 | import net.minecraft.world.level.block.Block; | ||
| 6 | import net.minecraft.world.level.block.Blocks; | ||
| 7 | import org.quiltmc.qsl.block.extensions.api.QuiltBlockSettings; | ||
| 8 | |||
| 9 | import java.util.LinkedHashMap; | ||
| 10 | import java.util.Map; | ||
| 11 | import java.util.function.BiConsumer; | ||
| 12 | |||
| 13 | public final class ErisAlchemyBlocks { | ||
| 14 | private static final Map<ResourceLocation, Block> blocks = new LinkedHashMap<>(); | ||
| 15 | |||
| 16 | public static final AlchemicalChestBlock ALCHEMICAL_CHEST = register("alchemical_chest", new AlchemicalChestBlock(QuiltBlockSettings.copy(Blocks.ENDER_CHEST))); | ||
| 17 | |||
| 18 | public static void consumeBlocks(BiConsumer<? super ResourceLocation, ? super Block> consumer) { | ||
| 19 | blocks.forEach(consumer); | ||
| 20 | } | ||
| 21 | |||
| 22 | private static <T extends Block> T register(String id, T block) { | ||
| 23 | blocks.putIfAbsent(new ResourceLocation(ErisAlchemy.ID, id), block); | ||
| 24 | return block; | ||
| 25 | } | ||
| 26 | |||
| 27 | private ErisAlchemyBlocks() {} | ||
| 28 | |||
| 29 | } | ||
diff --git a/src/main/java/lv/enes/mc/eris_alchemy/block/entity/AlchemicalChestBlockEntity.java b/src/main/java/lv/enes/mc/eris_alchemy/block/entity/AlchemicalChestBlockEntity.java index 9c9942f..1e881f8 100644 --- a/src/main/java/lv/enes/mc/eris_alchemy/block/entity/AlchemicalChestBlockEntity.java +++ b/src/main/java/lv/enes/mc/eris_alchemy/block/entity/AlchemicalChestBlockEntity.java | |||
| @@ -1,7 +1,7 @@ | |||
| 1 | package lv.enes.mc.eris_alchemy.block.entity; | 1 | package lv.enes.mc.eris_alchemy.block.entity; |
| 2 | 2 | ||
| 3 | import jakarta.annotation.Nonnull; | 3 | import jakarta.annotation.Nonnull; |
| 4 | import lv.enes.mc.eris_alchemy.block.ErisAlchemyBlocks; | 4 | import lv.enes.mc.eris_alchemy.ErisAlchemyRegistry; |
| 5 | import lv.enes.mc.eris_alchemy.menu.AlchemicalChestMenu; | 5 | import lv.enes.mc.eris_alchemy.menu.AlchemicalChestMenu; |
| 6 | import net.minecraft.core.BlockPos; | 6 | import net.minecraft.core.BlockPos; |
| 7 | import net.minecraft.core.NonNullList; | 7 | import net.minecraft.core.NonNullList; |
| @@ -62,8 +62,14 @@ public class AlchemicalChestBlockEntity extends BaseContainerBlockEntity impleme | |||
| 62 | } | 62 | } |
| 63 | 63 | ||
| 64 | @Override | 64 | @Override |
| 65 | protected void openerCountChanged(Level world, BlockPos pos, BlockState state, int oldViewerCount, int newViewerCount) { | 65 | protected void openerCountChanged( |
| 66 | world.blockEvent(worldPosition, ErisAlchemyBlocks.ALCHEMICAL_CHEST, EVENT, newViewerCount); | 66 | Level world, |
| 67 | BlockPos pos, | ||
| 68 | BlockState state, | ||
| 69 | int oldViewerCount, | ||
| 70 | int newViewerCount | ||
| 71 | ) { | ||
| 72 | world.blockEvent(worldPosition, ErisAlchemyRegistry.Blocks.ALCHEMICAL_CHEST, EVENT, newViewerCount); | ||
| 67 | } | 73 | } |
| 68 | 74 | ||
| 69 | @Override | 75 | @Override |
| @@ -76,7 +82,7 @@ public class AlchemicalChestBlockEntity extends BaseContainerBlockEntity impleme | |||
| 76 | }; | 82 | }; |
| 77 | 83 | ||
| 78 | public AlchemicalChestBlockEntity(BlockPos pos, BlockState state) { | 84 | public AlchemicalChestBlockEntity(BlockPos pos, BlockState state) { |
| 79 | super(ErisAlchemyBlockEntities.ALCHEMICAL_CHEST, pos, state); | 85 | super(ErisAlchemyRegistry.BlockEntities.ALCHEMICAL_CHEST, pos, state); |
| 80 | } | 86 | } |
| 81 | 87 | ||
| 82 | @Override | 88 | @Override |
diff --git a/src/main/java/lv/enes/mc/eris_alchemy/block/entity/ErisAlchemyBlockEntities.java b/src/main/java/lv/enes/mc/eris_alchemy/block/entity/ErisAlchemyBlockEntities.java deleted file mode 100644 index a95ac58..0000000 --- a/src/main/java/lv/enes/mc/eris_alchemy/block/entity/ErisAlchemyBlockEntities.java +++ /dev/null | |||
| @@ -1,33 +0,0 @@ | |||
| 1 | package lv.enes.mc.eris_alchemy.block.entity; | ||
| 2 | |||
| 3 | import lv.enes.mc.eris_alchemy.ErisAlchemy; | ||
| 4 | import lv.enes.mc.eris_alchemy.block.ErisAlchemyBlocks; | ||
| 5 | import net.minecraft.resources.ResourceLocation; | ||
| 6 | import net.minecraft.world.level.block.entity.BlockEntity; | ||
| 7 | import net.minecraft.world.level.block.entity.BlockEntityType; | ||
| 8 | import org.quiltmc.qsl.block.entity.api.QuiltBlockEntityTypeBuilder; | ||
| 9 | |||
| 10 | import java.util.LinkedHashMap; | ||
| 11 | import java.util.Map; | ||
| 12 | import java.util.function.BiConsumer; | ||
| 13 | |||
| 14 | public final class ErisAlchemyBlockEntities { | ||
| 15 | private static final Map<ResourceLocation, BlockEntityType<?>> entities = new LinkedHashMap<>(); | ||
| 16 | |||
| 17 | public static final BlockEntityType<AlchemicalChestBlockEntity> ALCHEMICAL_CHEST = register( | ||
| 18 | "alchemical_chest", | ||
| 19 | QuiltBlockEntityTypeBuilder.create(AlchemicalChestBlockEntity::new, ErisAlchemyBlocks.ALCHEMICAL_CHEST) | ||
| 20 | .build() | ||
| 21 | ); | ||
| 22 | |||
| 23 | public static void consumeBlockEntities(BiConsumer<? super ResourceLocation, ? super BlockEntityType<?>> consumer) { | ||
| 24 | entities.forEach(consumer); | ||
| 25 | } | ||
| 26 | |||
| 27 | private static <T extends BlockEntity> BlockEntityType<T> register(String id, BlockEntityType<T> type) { | ||
| 28 | entities.putIfAbsent(new ResourceLocation(ErisAlchemy.ID, id), type); | ||
| 29 | return type; | ||
| 30 | } | ||
| 31 | |||
| 32 | private ErisAlchemyBlockEntities() {} | ||
| 33 | } | ||
diff --git a/src/main/java/lv/enes/mc/eris_alchemy/client/ErisAlchemyClient.java b/src/main/java/lv/enes/mc/eris_alchemy/client/ErisAlchemyClient.java index bb5de4f..86cc467 100644 --- a/src/main/java/lv/enes/mc/eris_alchemy/client/ErisAlchemyClient.java +++ b/src/main/java/lv/enes/mc/eris_alchemy/client/ErisAlchemyClient.java | |||
| @@ -1,15 +1,9 @@ | |||
| 1 | package lv.enes.mc.eris_alchemy.client; | 1 | package lv.enes.mc.eris_alchemy.client; |
| 2 | 2 | ||
| 3 | import lv.enes.mc.eris_alchemy.EMC; | 3 | import lv.enes.mc.eris_alchemy.EMC; |
| 4 | import lv.enes.mc.eris_alchemy.ErisAlchemyItems; | ||
| 5 | import lv.enes.mc.eris_alchemy.block.ErisAlchemyBlocks; | ||
| 6 | import lv.enes.mc.eris_alchemy.block.entity.AlchemicalChestBlockEntity; | ||
| 7 | import lv.enes.mc.eris_alchemy.block.entity.ErisAlchemyBlockEntities; | ||
| 8 | import lv.enes.mc.eris_alchemy.menu.ErisAlchemyMenus; | ||
| 9 | import net.fabricmc.fabric.api.client.rendering.v1.BuiltinItemRendererRegistry; | 4 | import net.fabricmc.fabric.api.client.rendering.v1.BuiltinItemRendererRegistry; |
| 10 | import net.minecraft.client.gui.screens.MenuScreens; | 5 | import net.minecraft.client.gui.screens.MenuScreens; |
| 11 | import net.minecraft.client.renderer.blockentity.BlockEntityRenderers; | 6 | import net.minecraft.client.renderer.blockentity.BlockEntityRenderers; |
| 12 | import net.minecraft.client.renderer.blockentity.ChestRenderer; | ||
| 13 | import net.minecraft.network.chat.Component; | 7 | import net.minecraft.network.chat.Component; |
| 14 | import org.quiltmc.loader.api.ModContainer; | 8 | import org.quiltmc.loader.api.ModContainer; |
| 15 | import org.quiltmc.qsl.base.api.entrypoint.client.ClientModInitializer; | 9 | import org.quiltmc.qsl.base.api.entrypoint.client.ClientModInitializer; |
| @@ -21,14 +15,11 @@ import java.text.DecimalFormat; | |||
| 21 | public class ErisAlchemyClient implements ClientModInitializer { | 15 | public class ErisAlchemyClient implements ClientModInitializer { |
| 22 | @Override | 16 | @Override |
| 23 | public void onInitializeClient(ModContainer mod) { | 17 | public void onInitializeClient(ModContainer mod) { |
| 24 | BlockEntityRenderers.register(ErisAlchemyBlockEntities.ALCHEMICAL_CHEST, ChestRenderer::new); | 18 | ErisAlchemyClientRegistry.BlockEntityRenderers.consume(BlockEntityRenderers::register); |
| 19 | ErisAlchemyClientRegistry.ItemRenderers.consume(BuiltinItemRendererRegistry.INSTANCE::register); | ||
| 20 | ErisAlchemyClientRegistry.MenuScreens.consume(MenuScreens::register); | ||
| 25 | 21 | ||
| 26 | BuiltinItemRendererRegistry.INSTANCE.register( | 22 | // MenuScreens.register(ErisAlchemyRegistry.Menus.ALCHEMICAL_CHEST, AlchemicalChestScreen::new); |
| 27 | ErisAlchemyItems.ALCHEMICAL_CHEST, | ||
| 28 | new ChestItemRenderer<>(ErisAlchemyBlocks.ALCHEMICAL_CHEST, AlchemicalChestBlockEntity::new)::renderByItem | ||
| 29 | ); | ||
| 30 | |||
| 31 | MenuScreens.register(ErisAlchemyMenus.ALCHEMICAL_CHEST, AlchemicalChestScreen::new); | ||
| 32 | 23 | ||
| 33 | var doubleFormat = new DecimalFormat("0"); | 24 | var doubleFormat = new DecimalFormat("0"); |
| 34 | doubleFormat.setMaximumFractionDigits(1); | 25 | doubleFormat.setMaximumFractionDigits(1); |
diff --git a/src/main/java/lv/enes/mc/eris_alchemy/client/ErisAlchemyClientRegistry.java b/src/main/java/lv/enes/mc/eris_alchemy/client/ErisAlchemyClientRegistry.java new file mode 100644 index 0000000..3680fd5 --- /dev/null +++ b/src/main/java/lv/enes/mc/eris_alchemy/client/ErisAlchemyClientRegistry.java | |||
| @@ -0,0 +1,116 @@ | |||
| 1 | package lv.enes.mc.eris_alchemy.client; | ||
| 2 | |||
| 3 | import lv.enes.mc.eris_alchemy.block.entity.AlchemicalChestBlockEntity; | ||
| 4 | import net.fabricmc.fabric.api.client.rendering.v1.BuiltinItemRendererRegistry.DynamicItemRenderer; | ||
| 5 | import net.minecraft.client.gui.screens.MenuScreens.ScreenConstructor; | ||
| 6 | import net.minecraft.client.gui.screens.Screen; | ||
| 7 | import net.minecraft.client.gui.screens.inventory.MenuAccess; | ||
| 8 | import net.minecraft.client.renderer.blockentity.BlockEntityRendererProvider; | ||
| 9 | import net.minecraft.client.renderer.blockentity.ChestRenderer; | ||
| 10 | import net.minecraft.world.inventory.AbstractContainerMenu; | ||
| 11 | import net.minecraft.world.inventory.MenuType; | ||
| 12 | import net.minecraft.world.level.ItemLike; | ||
| 13 | import net.minecraft.world.level.block.entity.BlockEntity; | ||
| 14 | import net.minecraft.world.level.block.entity.BlockEntityType; | ||
| 15 | |||
| 16 | import java.util.LinkedHashMap; | ||
| 17 | import java.util.Map; | ||
| 18 | import java.util.function.BiConsumer; | ||
| 19 | |||
| 20 | import static lv.enes.mc.eris_alchemy.ErisAlchemyRegistry.*; | ||
| 21 | |||
| 22 | public final class ErisAlchemyClientRegistry { | ||
| 23 | private ErisAlchemyClientRegistry() {} | ||
| 24 | |||
| 25 | public static final class BlockEntityRenderers { | ||
| 26 | private BlockEntityRenderers() {} | ||
| 27 | |||
| 28 | @FunctionalInterface | ||
| 29 | public interface Consumer { | ||
| 30 | <T extends BlockEntity> void consume(BlockEntityType<? extends T> type, BlockEntityRendererProvider<T> provider); | ||
| 31 | } | ||
| 32 | |||
| 33 | public static void consume(Consumer consumer) { | ||
| 34 | data.values().forEach(pair -> pair.beConsumed(consumer)); | ||
| 35 | } | ||
| 36 | |||
| 37 | private record Pair<T extends BlockEntity>( | ||
| 38 | BlockEntityType<? extends T> type, | ||
| 39 | BlockEntityRendererProvider<T> provider | ||
| 40 | ) { | ||
| 41 | public void beConsumed(Consumer consumer) { | ||
| 42 | consumer.consume(type, provider); | ||
| 43 | } | ||
| 44 | } | ||
| 45 | |||
| 46 | private static final Map<BlockEntityType<?>, Pair<?>> data = new LinkedHashMap<>(); | ||
| 47 | |||
| 48 | private static <T extends BlockEntity> void register( | ||
| 49 | BlockEntityType<? extends T> type, | ||
| 50 | BlockEntityRendererProvider<T> provider | ||
| 51 | ) { | ||
| 52 | data.put(type, new Pair<>(type, provider)); | ||
| 53 | } | ||
| 54 | |||
| 55 | static { | ||
| 56 | register(BlockEntities.ALCHEMICAL_CHEST, ChestRenderer::new); | ||
| 57 | } | ||
| 58 | } | ||
| 59 | |||
| 60 | public static final class ItemRenderers { | ||
| 61 | private ItemRenderers() {} | ||
| 62 | |||
| 63 | public static void consume(BiConsumer<? super ItemLike, ? super DynamicItemRenderer> consumer) { | ||
| 64 | data.forEach(consumer); | ||
| 65 | } | ||
| 66 | |||
| 67 | private static final Map<ItemLike, DynamicItemRenderer> data = new LinkedHashMap<>(); | ||
| 68 | |||
| 69 | private static void register(ItemLike item, DynamicItemRenderer renderer) { | ||
| 70 | data.put(item, renderer); | ||
| 71 | } | ||
| 72 | |||
| 73 | static { | ||
| 74 | register( | ||
| 75 | Items.ALCHEMICAL_CHEST, | ||
| 76 | new ChestItemRenderer<>(Blocks.ALCHEMICAL_CHEST, AlchemicalChestBlockEntity::new)::renderByItem | ||
| 77 | ); | ||
| 78 | } | ||
| 79 | } | ||
| 80 | |||
| 81 | public static final class MenuScreens { | ||
| 82 | private MenuScreens() {} | ||
| 83 | |||
| 84 | @FunctionalInterface | ||
| 85 | public interface Consumer { | ||
| 86 | <M extends AbstractContainerMenu, S extends Screen & MenuAccess<M>> | ||
| 87 | void consume(MenuType<? extends M> menu, ScreenConstructor<M, S> constructor); | ||
| 88 | } | ||
| 89 | |||
| 90 | public static void consume(Consumer consumer) { | ||
| 91 | data.values().forEach(pair -> pair.beConsumed(consumer)); | ||
| 92 | } | ||
| 93 | |||
| 94 | private record Pair<M extends AbstractContainerMenu, S extends Screen & MenuAccess<M>>( | ||
| 95 | MenuType<? extends M> menu, | ||
| 96 | ScreenConstructor<M, S> constructor | ||
| 97 | ) { | ||
| 98 | public void beConsumed(Consumer consumer) { | ||
| 99 | consumer.consume(menu, constructor); | ||
| 100 | } | ||
| 101 | } | ||
| 102 | |||
| 103 | private static final Map<MenuType<?>, Pair<?, ?>> data = new LinkedHashMap<>(); | ||
| 104 | |||
| 105 | private static <M extends AbstractContainerMenu, S extends Screen & MenuAccess<M>> void register( | ||
| 106 | MenuType<? extends M> menu, | ||
| 107 | ScreenConstructor<M, S> constructor | ||
| 108 | ) { | ||
| 109 | data.put(menu, new Pair<>(menu, constructor)); | ||
| 110 | } | ||
| 111 | |||
| 112 | static { | ||
| 113 | register(Menus.ALCHEMICAL_CHEST, AlchemicalChestScreen::new); | ||
| 114 | } | ||
| 115 | } | ||
| 116 | } | ||
diff --git a/src/main/java/lv/enes/mc/eris_alchemy/menu/AlchemicalChestMenu.java b/src/main/java/lv/enes/mc/eris_alchemy/menu/AlchemicalChestMenu.java index e4135c9..a464f3f 100644 --- a/src/main/java/lv/enes/mc/eris_alchemy/menu/AlchemicalChestMenu.java +++ b/src/main/java/lv/enes/mc/eris_alchemy/menu/AlchemicalChestMenu.java | |||
| @@ -1,6 +1,7 @@ | |||
| 1 | package lv.enes.mc.eris_alchemy.menu; | 1 | package lv.enes.mc.eris_alchemy.menu; |
| 2 | 2 | ||
| 3 | import jakarta.annotation.Nonnull; | 3 | import jakarta.annotation.Nonnull; |
| 4 | import lv.enes.mc.eris_alchemy.ErisAlchemyRegistry; | ||
| 4 | import net.minecraft.world.Container; | 5 | import net.minecraft.world.Container; |
| 5 | import net.minecraft.world.SimpleContainer; | 6 | import net.minecraft.world.SimpleContainer; |
| 6 | import net.minecraft.world.entity.player.Inventory; | 7 | import net.minecraft.world.entity.player.Inventory; |
| @@ -20,7 +21,7 @@ public class AlchemicalChestMenu extends AbstractContainerMenu { | |||
| 20 | } | 21 | } |
| 21 | 22 | ||
| 22 | public AlchemicalChestMenu(int syncId, Inventory playerInventory, Container inventory) { | 23 | public AlchemicalChestMenu(int syncId, Inventory playerInventory, Container inventory) { |
| 23 | super(ErisAlchemyMenus.ALCHEMICAL_CHEST, syncId); | 24 | super(ErisAlchemyRegistry.Menus.ALCHEMICAL_CHEST, syncId); |
| 24 | checkContainerSize(inventory, WIDTH * HEIGHT); | 25 | checkContainerSize(inventory, WIDTH * HEIGHT); |
| 25 | 26 | ||
| 26 | this.container = inventory; | 27 | this.container = inventory; |
diff --git a/src/main/java/lv/enes/mc/eris_alchemy/menu/ErisAlchemyMenus.java b/src/main/java/lv/enes/mc/eris_alchemy/menu/ErisAlchemyMenus.java deleted file mode 100644 index 5e3b54a..0000000 --- a/src/main/java/lv/enes/mc/eris_alchemy/menu/ErisAlchemyMenus.java +++ /dev/null | |||
| @@ -1,29 +0,0 @@ | |||
| 1 | package lv.enes.mc.eris_alchemy.menu; | ||
| 2 | |||
| 3 | import lv.enes.mc.eris_alchemy.ErisAlchemy; | ||
| 4 | import net.minecraft.resources.ResourceLocation; | ||
| 5 | import net.minecraft.world.flag.FeatureFlags; | ||
| 6 | import net.minecraft.world.inventory.AbstractContainerMenu; | ||
| 7 | import net.minecraft.world.inventory.MenuType; | ||
| 8 | |||
| 9 | import java.util.LinkedHashMap; | ||
| 10 | import java.util.Map; | ||
| 11 | import java.util.function.BiConsumer; | ||
| 12 | |||
| 13 | public final class ErisAlchemyMenus { | ||
| 14 | private static final Map<ResourceLocation, MenuType<?>> menus = new LinkedHashMap<>(); | ||
| 15 | |||
| 16 | public static final MenuType<AlchemicalChestMenu> ALCHEMICAL_CHEST = register("alchemy_chest", AlchemicalChestMenu::new); | ||
| 17 | |||
| 18 | public static void consumeMenus(BiConsumer<? super ResourceLocation, ? super MenuType<?>> consumer) { | ||
| 19 | menus.forEach(consumer); | ||
| 20 | } | ||
| 21 | |||
| 22 | private static <T extends AbstractContainerMenu> MenuType<T> register(String id, MenuType.MenuSupplier<T> supplier) { | ||
| 23 | var menuType = new MenuType<>(supplier, FeatureFlags.VANILLA_SET); | ||
| 24 | menus.putIfAbsent(new ResourceLocation(ErisAlchemy.ID, id), menuType); | ||
| 25 | return menuType; | ||
| 26 | } | ||
| 27 | |||
| 28 | private ErisAlchemyMenus() {} | ||
| 29 | } | ||
diff --git a/src/main/java/lv/enes/mc/eris_alchemy/mixin/client/SheetsMixin.java b/src/main/java/lv/enes/mc/eris_alchemy/mixin/client/SheetsMixin.java index 544dcef..46f7720 100644 --- a/src/main/java/lv/enes/mc/eris_alchemy/mixin/client/SheetsMixin.java +++ b/src/main/java/lv/enes/mc/eris_alchemy/mixin/client/SheetsMixin.java | |||
| @@ -13,8 +13,17 @@ import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable; | |||
| 13 | 13 | ||
| 14 | @Mixin(Sheets.class) | 14 | @Mixin(Sheets.class) |
| 15 | public abstract class SheetsMixin { | 15 | public abstract class SheetsMixin { |
| 16 | @Inject(method = "chooseMaterial(Lnet/minecraft/world/level/block/entity/BlockEntity;Lnet/minecraft/world/level/block/state/properties/ChestType;Z)Lnet/minecraft/client/resources/model/Material;", at = @At("RETURN"), cancellable = true) | 16 | @Inject( |
| 17 | private static void chooseMaterial(BlockEntity entity, ChestType type, boolean christmas, CallbackInfoReturnable<Material> cir) { | 17 | method = "chooseMaterial(Lnet/minecraft/world/level/block/entity/BlockEntity;Lnet/minecraft/world/level/block/state/properties/ChestType;Z)Lnet/minecraft/client/resources/model/Material;", |
| 18 | at = @At("RETURN"), | ||
| 19 | cancellable = true | ||
| 20 | ) | ||
| 21 | private static void chooseMaterial( | ||
| 22 | BlockEntity entity, | ||
| 23 | ChestType type, | ||
| 24 | boolean christmas, | ||
| 25 | CallbackInfoReturnable<Material> cir | ||
| 26 | ) { | ||
| 18 | if (entity instanceof AlchemicalChestBlockEntity) { | 27 | if (entity instanceof AlchemicalChestBlockEntity) { |
| 19 | cir.setReturnValue(ErisAlchemyMaterials.ALCHEMICAL_CHEST); | 28 | cir.setReturnValue(ErisAlchemyMaterials.ALCHEMICAL_CHEST); |
| 20 | } | 29 | } |
diff --git a/src/main/java/lv/enes/mc/eris_alchemy/recipe/CovalenceRepair.java b/src/main/java/lv/enes/mc/eris_alchemy/recipe/CovalenceRepair.java index dca464a..7fbdc17 100644 --- a/src/main/java/lv/enes/mc/eris_alchemy/recipe/CovalenceRepair.java +++ b/src/main/java/lv/enes/mc/eris_alchemy/recipe/CovalenceRepair.java | |||
| @@ -5,6 +5,7 @@ import com.google.gson.JsonElement; | |||
| 5 | import com.google.gson.JsonObject; | 5 | import com.google.gson.JsonObject; |
| 6 | import com.google.gson.JsonSyntaxException; | 6 | import com.google.gson.JsonSyntaxException; |
| 7 | import jakarta.annotation.Nonnull; | 7 | import jakarta.annotation.Nonnull; |
| 8 | import lv.enes.mc.eris_alchemy.ErisAlchemyRegistry; | ||
| 8 | import net.minecraft.core.RegistryAccess; | 9 | import net.minecraft.core.RegistryAccess; |
| 9 | import net.minecraft.network.FriendlyByteBuf; | 10 | import net.minecraft.network.FriendlyByteBuf; |
| 10 | import net.minecraft.resources.ResourceLocation; | 11 | import net.minecraft.resources.ResourceLocation; |
| @@ -21,7 +22,7 @@ import java.util.ArrayList; | |||
| 21 | import java.util.Arrays; | 22 | import java.util.Arrays; |
| 22 | 23 | ||
| 23 | public class CovalenceRepair extends CustomRecipe { | 24 | public class CovalenceRepair extends CustomRecipe { |
| 24 | static class Serializer implements QuiltRecipeSerializer<CovalenceRepair> { | 25 | public static class Serializer implements QuiltRecipeSerializer<CovalenceRepair> { |
| 25 | private static class Json { | 26 | private static class Json { |
| 26 | CraftingBookCategory category = CraftingBookCategory.MISC; | 27 | CraftingBookCategory category = CraftingBookCategory.MISC; |
| 27 | JsonElement dust; | 28 | JsonElement dust; |
| @@ -29,8 +30,6 @@ public class CovalenceRepair extends CustomRecipe { | |||
| 29 | JsonElement tools = new JsonObject(); | 30 | JsonElement tools = new JsonObject(); |
| 30 | } | 31 | } |
| 31 | 32 | ||
| 32 | Serializer() {} | ||
| 33 | |||
| 34 | @Override | 33 | @Override |
| 35 | public JsonObject toJson(CovalenceRepair recipe) { | 34 | public JsonObject toJson(CovalenceRepair recipe) { |
| 36 | var res = new JsonObject(); | 35 | var res = new JsonObject(); |
| @@ -86,7 +85,13 @@ public class CovalenceRepair extends CustomRecipe { | |||
| 86 | /** What tools can this dust repair. */ | 85 | /** What tools can this dust repair. */ |
| 87 | private final Ingredient tools; | 86 | private final Ingredient tools; |
| 88 | 87 | ||
| 89 | public CovalenceRepair(ResourceLocation id, CraftingBookCategory category, Ingredient dust, Ingredient materials, Ingredient tools) { | 88 | public CovalenceRepair( |
| 89 | ResourceLocation id, | ||
| 90 | CraftingBookCategory category, | ||
| 91 | Ingredient dust, | ||
| 92 | Ingredient materials, | ||
| 93 | Ingredient tools | ||
| 94 | ) { | ||
| 90 | super(id, category); | 95 | super(id, category); |
| 91 | 96 | ||
| 92 | this.dust = dust; | 97 | this.dust = dust; |
| @@ -121,7 +126,7 @@ public class CovalenceRepair extends CustomRecipe { | |||
| 121 | @Nonnull | 126 | @Nonnull |
| 122 | @Override | 127 | @Override |
| 123 | public RecipeSerializer<CovalenceRepair> getSerializer() { | 128 | public RecipeSerializer<CovalenceRepair> getSerializer() { |
| 124 | return ErisAlchemyRecipeSerializers.COVALENCE_REPAIR; | 129 | return ErisAlchemyRegistry.RecipeSerializers.COVALENCE_REPAIR; |
| 125 | } | 130 | } |
| 126 | 131 | ||
| 127 | private boolean isTool(ItemStack stack) { | 132 | private boolean isTool(ItemStack stack) { |
diff --git a/src/main/java/lv/enes/mc/eris_alchemy/recipe/ErisAlchemyRecipeSerializers.java b/src/main/java/lv/enes/mc/eris_alchemy/recipe/ErisAlchemyRecipeSerializers.java deleted file mode 100644 index c5a6676..0000000 --- a/src/main/java/lv/enes/mc/eris_alchemy/recipe/ErisAlchemyRecipeSerializers.java +++ /dev/null | |||
| @@ -1,27 +0,0 @@ | |||
| 1 | package lv.enes.mc.eris_alchemy.recipe; | ||
| 2 | |||
| 3 | import lv.enes.mc.eris_alchemy.ErisAlchemy; | ||
| 4 | import net.minecraft.resources.ResourceLocation; | ||
| 5 | import net.minecraft.world.item.crafting.Recipe; | ||
| 6 | import net.minecraft.world.item.crafting.RecipeSerializer; | ||
| 7 | |||
| 8 | import java.util.LinkedHashMap; | ||
| 9 | import java.util.Map; | ||
| 10 | import java.util.function.BiConsumer; | ||
| 11 | |||
| 12 | public final class ErisAlchemyRecipeSerializers { | ||
| 13 | private static final Map<ResourceLocation, RecipeSerializer<?>> serializers = new LinkedHashMap<>(); | ||
| 14 | |||
| 15 | public static final RecipeSerializer<CovalenceRepair> COVALENCE_REPAIR = register("covalence_repair", new CovalenceRepair.Serializer()); | ||
| 16 | |||
| 17 | public static void consumeSerializers(BiConsumer<? super ResourceLocation, ? super RecipeSerializer<?>> consumer) { | ||
| 18 | serializers.forEach(consumer); | ||
| 19 | } | ||
| 20 | |||
| 21 | private static <T extends Recipe<?>> RecipeSerializer<T> register(String id, RecipeSerializer<T> serializer) { | ||
| 22 | serializers.putIfAbsent(new ResourceLocation(ErisAlchemy.ID, id), serializer); | ||
| 23 | return serializer; | ||
| 24 | } | ||
| 25 | |||
| 26 | private ErisAlchemyRecipeSerializers() {} | ||
| 27 | } | ||