Created
July 29, 2022 23:04
-
-
Save MrKelpy/aba155b55ac2216332cc66c725c19586 to your computer and use it in GitHub Desktop.
What i have now
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package com.mrkelpy.miasmapothecary.blocks.MixingTable; | |
import com.mrkelpy.miasmapothecary.blocks.MixingTable.MixingTableBlockEntity; | |
import net.minecraft.MethodsReturnNonnullByDefault; | |
import net.minecraft.core.BlockPos; | |
import net.minecraft.core.Direction; | |
import net.minecraft.server.level.ServerPlayer; | |
import net.minecraft.world.InteractionHand; | |
import net.minecraft.world.InteractionResult; | |
import net.minecraft.world.entity.player.Player; | |
import net.minecraft.world.item.context.BlockPlaceContext; | |
import net.minecraft.world.level.BlockGetter; | |
import net.minecraft.world.level.Level; | |
import net.minecraft.world.level.block.Block; | |
import net.minecraft.world.level.block.EntityBlock; | |
import net.minecraft.world.level.block.HorizontalDirectionalBlock; | |
import net.minecraft.world.level.block.entity.BlockEntity; | |
import net.minecraft.world.level.block.state.BlockBehaviour; | |
import net.minecraft.world.level.block.state.BlockState; | |
import net.minecraft.world.level.block.state.StateDefinition; | |
import net.minecraft.world.level.block.state.properties.DirectionProperty; | |
import net.minecraft.world.level.material.Material; | |
import net.minecraft.world.level.material.MaterialColor; | |
import net.minecraft.world.phys.BlockHitResult; | |
import net.minecraft.world.phys.shapes.CollisionContext; | |
import net.minecraft.world.phys.shapes.VoxelShape; | |
import org.jetbrains.annotations.Nullable; | |
import javax.annotation.ParametersAreNonnullByDefault; | |
import java.util.Objects; | |
@MethodsReturnNonnullByDefault | |
@ParametersAreNonnullByDefault | |
public class MixingTableBlock extends Block implements EntityBlock { | |
private static final BlockBehaviour.Properties BLOCK_PROPERTIES = buildProperties(); | |
private static final VoxelShape SHAPE = box(0.0D, 0.0D, 0.0D, 16.0D, 15.0D, 16.0D); | |
private static final DirectionProperty FACING = HorizontalDirectionalBlock.FACING; | |
public MixingTableBlock() { | |
super(BLOCK_PROPERTIES); | |
this.registerDefaultState(this.getStateDefinition().any().setValue(FACING, Direction.NORTH)); | |
} | |
/** | |
* Builds the properties for the current block. | |
*/ | |
private static BlockBehaviour.Properties buildProperties() { | |
BlockBehaviour.Properties properties = BlockBehaviour.Properties.of(Material.STONE); | |
properties.color(MaterialColor.COLOR_BROWN); | |
properties.strength(2.5f, 6f); | |
properties.requiresCorrectToolForDrops(); | |
return properties; | |
} | |
@Override | |
public InteractionResult use(BlockState pState, Level pLevel, BlockPos pPos, Player pPlayer, InteractionHand pHand, BlockHitResult pHit) { | |
if (pPlayer instanceof ServerPlayer) | |
MixingTableMenu.openContainer((ServerPlayer) pPlayer, pPos); | |
return InteractionResult.SUCCESS; | |
} | |
@SuppressWarnings("deprecation") | |
@Override | |
public VoxelShape getShape(BlockState pState, BlockGetter pLevel, BlockPos pPos, CollisionContext pContext) { | |
return SHAPE; | |
} | |
@Override | |
public BlockState getStateForPlacement(BlockPlaceContext pContext) { | |
return Objects.requireNonNull(super.getStateForPlacement(pContext)).setValue(FACING, pContext.getHorizontalDirection().getOpposite()); | |
} | |
@Override | |
protected void createBlockStateDefinition(StateDefinition.Builder<Block, BlockState> pBuilder) { | |
pBuilder.add(FACING); | |
} | |
@Nullable | |
@Override | |
public BlockEntity newBlockEntity(BlockPos pPos, BlockState pState) { | |
return new MixingTableBlockEntity(pPos, pState); | |
} | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package com.mrkelpy.miasmapothecary.blocks.MixingTable; | |
import com.mrkelpy.miasmapothecary.setup.Registration; | |
import net.minecraft.MethodsReturnNonnullByDefault; | |
import net.minecraft.core.BlockPos; | |
import net.minecraft.world.level.block.entity.BlockEntity; | |
import net.minecraft.world.level.block.state.BlockState; | |
import net.minecraftforge.api.distmarker.OnlyIn; | |
import javax.annotation.ParametersAreNonnullByDefault; | |
@MethodsReturnNonnullByDefault | |
@ParametersAreNonnullByDefault | |
public class MixingTableBlockEntity extends BlockEntity { | |
public MixingTableBlockEntity(BlockPos pos, BlockState state) { | |
super(Registration.MIXING_TABLE_BLOCK_ENTITY.get(), pos, state); | |
} | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package com.mrkelpy.miasmapothecary.blocks.MixingTable; | |
public class MixingTableBlockScreen { | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package com.mrkelpy.miasmapothecary.setup; | |
import com.mrkelpy.miasmapothecary.MiasmaApothecary; | |
import com.mrkelpy.miasmapothecary.blocks.MixingTable.MixingTableBlock; | |
import com.mrkelpy.miasmapothecary.blocks.MixingTable.MixingTableBlockEntity; | |
import com.mrkelpy.miasmapothecary.blocks.MixingTable.MixingTableMenu; | |
import com.mrkelpy.miasmapothecary.items.MixingTableBlockItem; | |
import com.mrkelpy.miasmapothecary.other.CreativeTabMiasmaApothecary; | |
import net.minecraft.core.Registry; | |
import net.minecraft.world.inventory.AbstractContainerMenu; | |
import net.minecraft.world.inventory.ContainerLevelAccess; | |
import net.minecraft.world.inventory.MenuType; | |
import net.minecraft.world.item.CreativeModeTab; | |
import net.minecraft.world.item.Item; | |
import net.minecraft.world.item.crafting.RecipeSerializer; | |
import net.minecraft.world.item.crafting.RecipeType; | |
import net.minecraft.world.level.block.Block; | |
import net.minecraft.world.level.block.entity.BlockEntityType; | |
import net.minecraftforge.common.extensions.IForgeMenuType; | |
import net.minecraftforge.network.IContainerFactory; | |
import net.minecraftforge.registries.DeferredRegister; | |
import net.minecraftforge.registries.ForgeRegistries; | |
import net.minecraftforge.registries.RegistryObject; | |
/** | |
* This class is responsible for registering every object into the game. | |
*/ | |
public class Registration { | |
/** | |
* DEFERRED REGISTERS | |
*/ | |
public static final DeferredRegister<Item> ITEMS = | |
DeferredRegister.create(ForgeRegistries.ITEMS, MiasmaApothecary.MODID); | |
public static final DeferredRegister<Block> BLOCKS = | |
DeferredRegister.create(ForgeRegistries.BLOCKS, MiasmaApothecary.MODID); | |
public static final DeferredRegister<RecipeSerializer<?>> RECIPE_SERIALIZERS = | |
DeferredRegister.create(ForgeRegistries.RECIPE_SERIALIZERS, MiasmaApothecary.MODID); | |
public static final DeferredRegister<RecipeType<?>> RECIPE_TYPES = | |
DeferredRegister.create(Registry.RECIPE_TYPE_REGISTRY, MiasmaApothecary.MODID); | |
public static final DeferredRegister<BlockEntityType<?>> BLOCK_ENTITY_TYPES = | |
DeferredRegister.create(Registry.BLOCK_ENTITY_TYPE_REGISTRY, MiasmaApothecary.MODID); | |
public static final DeferredRegister<MenuType<?>> MENU_TYPES = | |
DeferredRegister.create(Registry.MENU_REGISTRY, MiasmaApothecary.MODID); | |
/** | |
* This is a helper method for container registration. | |
* Instead of registering the Menu itself, we register a MenuType pointing to the menu. | |
* @param id The registration ID | |
* @param factory The factory for the menu. | |
*/ | |
private static <T extends AbstractContainerMenu> RegistryObject<MenuType<T>> registerContainer(String id, IContainerFactory<T> factory) { | |
return MENU_TYPES.register(id, () -> IForgeMenuType.create(factory)); | |
} | |
/** | |
* BLOCKS REGISTRATION | |
*/ | |
public static final RegistryObject<Block> MIXING_TABLE_BLOCK = BLOCKS.register("mixing_table_block", MixingTableBlock::new); | |
/** | |
* ITEMS REGISTRATION | |
*/ | |
public static final RegistryObject<Item> MIXING_TABLE = ITEMS.register("mixing_table", MixingTableBlockItem::new); | |
/** | |
* CREATIVE TAB REGISTRATION | |
*/ | |
public static final CreativeModeTab CustomModTab = new CreativeTabMiasmaApothecary(); | |
/** | |
* BLOCK ENTITY TYPE REGISTRATION | |
*/ | |
public static final RegistryObject<BlockEntityType<?>> MIXING_TABLE_BLOCK_ENTITY = | |
BLOCK_ENTITY_TYPES.register("mixing_table_block_entity", () -> BlockEntityType.Builder.of(MixingTableBlockEntity::new, MIXING_TABLE_BLOCK.get()).build(null)); | |
/** | |
* MENU TYPE REGISTRATION | |
*/ | |
public static final RegistryObject<MenuType<MixingTableMenu>> MIXING_TABLE_CONTAINER = | |
registerContainer("mixing_table", (id, inventory, buff) -> new MixingTableMenu(id, ContainerLevelAccess.create(inventory.player.getLevel(), buff.readBlockPos()))); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment