Skip to content
This repository has been archived by the owner on Apr 22, 2024. It is now read-only.

Commit

Permalink
blocks javadoc done
Browse files Browse the repository at this point in the history
  • Loading branch information
TheRealEmissions committed Mar 27, 2024
1 parent 7d4708f commit 0e38ecc
Show file tree
Hide file tree
Showing 9 changed files with 276 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,18 @@
import net.minecraft.util.valueproviders.IntProvider;
import net.minecraft.world.level.block.DropExperienceBlock;

/**
* This abstract class is used to ensure consistency throughout the project.
* You should always extend our abstract classes or implement our interfaces when creating new types (in this case
* blocks) to ensure that the project is easier to maintain and understand.
*/
public abstract class DumbDropExperienceBlock extends DropExperienceBlock implements IDumbBlock {
/**
* Constructor for the {@link DumbDropExperienceBlock} class.
*
* @param experience An instance of {@link IntProvider} that represents the experience provided by the block. Must not be null.
* @param properties An instance of {@link Properties} that represents the properties of the block. Must not be null.
*/
protected DumbDropExperienceBlock(IntProvider experience, Properties properties) {
super(experience, properties);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,16 +8,38 @@

import java.util.function.UnaryOperator;

/**
* It provides methods to create an item from a block.
* It also ensures that any blocks created using our abstract classes (as you should be doing) will be added to the creative tab.
* In your block classes, you can override {@link ICreativeTabElement#getCreativeTabs()} to add your block to a different creative tab (or multiple).
*/
public interface IDumbBlock extends ICreativeTabElement {

/**
* Creates an {@link Item} from the block with the given {@link Item.Properties}.
*
* @param properties An instance of {@link Item.Properties} that represents the properties of the item. Must not be null.
* @return a new instance of {@link BlockItem} with the given properties.
*/
default Item createItem(Item.Properties properties) {
return new BlockItem((Block) this, properties);
}

/**
* Creates an {@link Item} from the block with default {@link Item.Properties}.
*
* @return a new instance of {@link BlockItem} with default properties.
*/
default Item createItem() {
return createItem(new Item.Properties());
}

/**
* Creates an {@link Item} from the block with properties obtained by applying the given {@link UnaryOperator} to the default {@link Item.Properties}.
*
* @param properties A {@link UnaryOperator} that takes an instance of {@link Item.Properties} and returns an instance of {@link Item.Properties}. Must not be null.
* @return a new instance of {@link BlockItem} with properties obtained by applying the given unary operator to the default properties.
*/
default Item createItem(@NotNull UnaryOperator<Item.Properties> properties) {
return createItem(properties.apply(new Item.Properties()));
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,12 @@
package net.dumbcode.projectnublar.core.blocks.entity;

import net.dumbcode.projectnublar.ProjectNublar;
import net.dumbcode.projectnublar.core.blocks.entity.elements.TestBlockEntity;
import net.dumbcode.projectnublar.core.registry.Registrar;
import net.minecraft.client.renderer.blockentity.BlockEntityRenderer;
import net.minecraft.client.renderer.blockentity.BlockEntityRendererProvider;
import net.minecraft.core.BlockPos;
import net.minecraft.resources.ResourceKey;
import net.minecraft.resources.ResourceLocation;
import net.minecraft.world.level.block.entity.BlockEntityType;
import net.minecraft.world.level.block.state.BlockState;
Expand All @@ -18,47 +21,147 @@

import static net.dumbcode.projectnublar.ProjectNublar.MOD_ID;

/**
* This class represents the block entities in the mod {@link ProjectNublar}
* It contains an enumeration of the different types of entities and a record for the registry.
* Each entity type has its own block entity constructor, renderer, registry, and model.
* The registry record is used to refer to the block entity type in the registry.
*/
public class DumbBlockEntities {
/**
* Each enum constant represents a different type of block entity.
* Each enum constant has its own block entity constructor, renderer, registry, and model.
* The block entity constructor is a function that creates a new instance of the block entity.
* The renderer is a function that creates a new instance of the block entity renderer.
* The registry is a record that contains a reference to the block entity type in the registry.
* The model is a defaulted block geo model that represents the 3D model of the block entity.
*/
public enum Entities {
/**
* TEST_BLOCK is an enum constant of the {@link Entities} enum.
* It is used to showcase how to create a block entity with a custom renderer.
* <p>
* The first argument, {@code TestBlockEntity::new}, is a method reference to the constructor of {@link TestBlockEntity}.
* This serves as the block entity constructor for TEST_BLOCK, which creates a new instance of {@link TestBlockEntity}.
* <p>
* The second argument, {@code TestBlockEntity.Renderer::new}, is a method reference to the constructor of the {@link TestBlockEntity.Renderer} class embedded in {@link TestBlockEntity}.
* You should follow this pattern when creating a custom renderer for a block entity.
* This serves as the renderer for TEST_BLOCK, which creates a new instance of the block entity renderer.
*/
TEST_BLOCK(
TestBlockEntity::new,
TestBlockEntity.Renderer::new
);

/**
* Supplier function that creates a new instance of a {@link DumbBlockEntity}.
* It is a functional interface that takes a {@link BlockPos} and a {@link BlockState} as arguments and returns a new {@link DumbBlockEntity}.
*/
private final BlockEntityType.BlockEntitySupplier<DumbBlockEntity> blockEntityConstructor;

/**
* The renderer is a provider function that creates a new instance of a {@link BlockEntityRenderer} for a {@link DumbBlockEntity}.
* It is a functional interface that takes a {@link BlockEntityRendererProvider.Context} as an argument and returns a new {@link BlockEntityRenderer}.
*/
private final BlockEntityRendererProvider<DumbBlockEntity> renderer;

/**
* The registry is an instance of the {@link Registry} record, created using the static method {@link Registry#of(RegistryObject)}
* It contains a {@link RegistryObject} that represents the block entity type in the registry.
* The {@link RegistryObject} is created using the static method {@link RegistryObject#create(ResourceLocation, ResourceKey, String)}.
*/
private final Registry registry = Registry.of(
RegistryObject.create(new ResourceLocation(MOD_ID, getRegisterName()), Registrar.BLOCK_ENTITY_TYPES.getRegistryKey(), MOD_ID)
);

/**
* The model is an instance of the {@link DefaultedBlockGeoModel} class, created using its constructor.
* It represents the 3D model of the block entity.
* The {@link DefaultedBlockGeoModel} is created using a {@link ResourceLocation} that represents the location of the model in the mod's resources.
*/
private final DefaultedBlockGeoModel<DumbBlockEntity> model = new DefaultedBlockGeoModel<>(new ResourceLocation(MOD_ID, getRegisterName()));

/**
* This is the constructor for the {@link Entities} enum.
* It takes two arguments: a blockEntityConstructor and a renderer.
*
* @param blockEntityConstructor A {@link TriFunction} that takes an {@link Entities} enum constant, a {@link BlockPos}, and a {@link BlockState} as arguments, and returns a new instance of a {@link DumbBlockEntity}.
* @param renderer A {@link BiFunction} that takes an {@link Entities} enum constant and a {@link BlockEntityRendererProvider.Context} as arguments, and returns a new instance of a {@link GeoBlockRenderer} for a {@link DumbBlockEntity}.
*
* The blockEntityConstructor is stored as a lambda function that takes a {@link BlockPos} and a {@link BlockState} as arguments (a {@link BlockEntityType.BlockEntitySupplier}).
* The renderer is stored as a lambda function that takes a {@link BlockEntityRendererProvider.Context} as an argument (a {@link BlockEntityRendererProvider}).
*/
Entities(TriFunction<Entities, BlockPos, BlockState, DumbBlockEntity> blockEntityConstructor, BiFunction<Entities, BlockEntityRendererProvider.Context, ? extends GeoBlockRenderer<DumbBlockEntity>> renderer) {
this.blockEntityConstructor = (pos, state) -> blockEntityConstructor.apply(this, pos, state);
this.renderer = context -> renderer.apply(this, context);
}

/**
* Returns the registry of the block entity type.
* The registry is an instance of the {@link Registry} record, which contains a {@link RegistryObject} that represents the block entity type in the registry.
*
* @return the registry of the block entity type
*/
public Registry getRegistry() {
return this.registry;
}

/**
* Returns the 3D model of the block entity.
* The model is an instance of the {@link DefaultedBlockGeoModel} class, which represents the 3D model of the block entity.
*
* @return the 3D model of the block entity
*/
public DefaultedBlockGeoModel<DumbBlockEntity> getModel() {
return this.model;
}

/**
* Returns the renderer of the block entity.
* The renderer is a provider function that creates a new instance of a {@link BlockEntityRenderer} for a {@link DumbBlockEntity}.
*
* @return the renderer of the block entity
*/
public BlockEntityRendererProvider<DumbBlockEntity> getRenderer() {
return this.renderer;
}

/**
* Returns the block entity constructor of the block entity.
* The block entity constructor is a supplier function that creates a new instance of a {@link DumbBlockEntity}.
*
* @return the block entity constructor of the block entity
*/
public BlockEntityType.BlockEntitySupplier<DumbBlockEntity> getBlockEntityConstructor() {
return this.blockEntityConstructor;
}

/**
* Returns the name of the enum constant, converted to lower case.
* This is used as the register name for the block entity type in the registry.
*
* @return the register name of the block entity type
*/
public @NotNull String getRegisterName() {
return this.name().toLowerCase();
}
}

/**
* Holds a single field, {@link #blockEntityType()}, which is a {@link RegistryObject} of {@link BlockEntityType} for {@link DumbBlockEntity}.
* This record is used to encapsulate the blockEntityType as a record component.
*
* @param blockEntityType A {@link RegistryObject} that represents the block entity type in the registry.
*/
public record Registry(RegistryObject<BlockEntityType<DumbBlockEntity>> blockEntityType) {

/**
* This is a static factory method for creating a new instance of the {@link Registry} record.
* It takes a {@link RegistryObject} of {@link BlockEntityType} for {@link DumbBlockEntity} as an argument and returns a new {@link Registry} record with the given blockEntityType.
*
* @param blockEntityType A {@link RegistryObject} that represents the block entity type in the registry.
* @return a new {@link Registry} record with the given blockEntityType.
*/
@Contract("_ -> new")
public static @NotNull Registry of(RegistryObject<BlockEntityType<DumbBlockEntity>> blockEntityType) {
return new Registry(blockEntityType);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,33 @@
import software.bernie.geckolib.core.animatable.instance.AnimatableInstanceCache;
import software.bernie.geckolib.util.GeckoLibUtil;

/**
* It represents a block entity that can be animated via GeckoLib.
*/
public abstract class DumbBlockEntity extends BlockEntity implements GeoBlockEntity {

/**
* An instance of {@link AnimatableInstanceCache} that represents the cache of animatable instances.
* This cache is used to store the animation data for the block entity.
*/
protected final AnimatableInstanceCache instanceCache = GeckoLibUtil.createInstanceCache(this);

/**
* Constructor for the {@link DumbBlockEntity} class.
*
* @param entity An instance of {@link DumbBlockEntities.Entities} that represents the entity associated with the block entity. Must not be null.
* @param pPos An instance of {@link BlockPos} that represents the position of the block entity. Must not be null.
* @param pBlockState An instance of {@link BlockState} that represents the state of the block entity. Must not be null.
*/
protected DumbBlockEntity(DumbBlockEntities.Entities entity, BlockPos pPos, BlockState pBlockState) {
super(entity.getRegistry().blockEntityType().get(), pPos, pBlockState);
}

/**
* Returns the cache of animatable instances.
*
* @return the cache of animatable instances.
*/
@Override
public AnimatableInstanceCache getAnimatableInstanceCache() {
return instanceCache;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package net.dumbcode.projectnublar.core.blocks.entity;

import net.dumbcode.projectnublar.core.blocks.DumbBlock;
import net.dumbcode.projectnublar.core.blocks.DumbBlocks;

Check warning on line 4 in src/main/java/net/dumbcode/projectnublar/core/blocks/entity/DumbEntityBlock.java

View workflow job for this annotation

GitHub Actions / Qodana Community for JVM

Unused import

Unused import `import net.dumbcode.projectnublar.core.blocks.DumbBlocks;`
import net.minecraft.core.BlockPos;
import net.minecraft.world.level.block.EntityBlock;
import net.minecraft.world.level.block.RenderShape;
Expand All @@ -9,22 +10,51 @@
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;

/**
* This class is used as a parent class for entity blocks.
* You should ensure any entity block classes extend this class to ensure consistency throughout the project.
* Any block entities should be added to {@link DumbBlockEntities.Entities} to ensure they are registered correctly.
*/
public abstract class DumbEntityBlock extends DumbBlock implements EntityBlock {
/**
* An instance of {@link DumbBlockEntities.Entities} that is pretty much a circular reference to this.
* This also allows access to its registry via {@link DumbBlockEntities.Entities#getRegistry()} for creating block entities with {@link #newBlockEntity(BlockPos, BlockState)}
*/
private final DumbBlockEntities.Entities entity;

/**
* Constructor for the {@link DumbEntityBlock} class.
*
* @param entity An instance of {@link DumbBlockEntities.Entities} that represents this. Must not be null.
* @param properties An instance of {@link Properties} that represents the properties of the block. Must not be null.
*/
protected DumbEntityBlock(DumbBlockEntities.Entities entity, Properties properties) {
super(properties);
this.entity = entity;
}

/**
* Returns the render shape of the block.
*
* @param pState An instance of {@link BlockState} that represents the state of the block. Must not be null.
* @return the render shape of the block.
*/
@Override
@SuppressWarnings("deprecation")
public @NotNull RenderShape getRenderShape(@NotNull BlockState pState) {
return RenderShape.ENTITYBLOCK_ANIMATED;
}

/**
* Creates a new block entity at the given position with the given state.
*
* @param pPos An instance of {@link BlockPos} that represents the position of the block. Must not be null.
* @param pState An instance of {@link BlockState} that represents the state of the block. Must not be null.
* @return a new instance of {@link BlockEntity} at the given position with the given state.
*/
@Nullable
@Override
public BlockEntity newBlockEntity(@NotNull BlockPos pPos, @NotNull BlockState pState) {
return entity.getRegistry().blockEntityType().get().create(pPos, pState);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -9,19 +9,47 @@
import software.bernie.geckolib.core.animation.AnimatableManager;
import software.bernie.geckolib.renderer.GeoBlockRenderer;

/**
* This is a test block entity to showcase how creating one works.
*/
public class TestBlockEntity extends DumbBlockEntity {

/**
* This is a nested class {@link Renderer} that extends {@link GeoBlockRenderer}.
* It is used to render the {@link TestBlockEntity} in the game.
* It is advised you follow this pattern when creating a custom renderer for a block entity as
* it ensures consistency throughout the project. Furthermore, it is highly unlikely that you will need to
* use this renderer for other block entities.
*
* @param entity The {@link DumbBlockEntities.Entities} enum constant that represents the type of the block entity.

Check warning on line 24 in src/main/java/net/dumbcode/projectnublar/core/blocks/entity/elements/TestBlockEntity.java

View workflow job for this annotation

GitHub Actions / Qodana Community for JVM

Declaration has problems in Javadoc references

Cannot resolve symbol `entity`
* @param context The context for the block entity renderer provider.

Check warning on line 25 in src/main/java/net/dumbcode/projectnublar/core/blocks/entity/elements/TestBlockEntity.java

View workflow job for this annotation

GitHub Actions / Qodana Community for JVM

Declaration has problems in Javadoc references

Cannot resolve symbol `context`
*/
public static class Renderer extends GeoBlockRenderer<DumbBlockEntity> {
public Renderer(DumbBlockEntities.@NotNull Entities entity, BlockEntityRendererProvider.Context context) {
super(entity.getModel());
}
}

/**
* This is the constructor for the {@link TestBlockEntity} class.
* It takes three arguments: an {@link DumbBlockEntities.Entities} enum constant, a {@link BlockPos}, and a {@link BlockState}.
*
* @param entity The {@link DumbBlockEntities.Entities} enum constant that represents the type of the block entity.
* @param pPos The position of the block entity in the world.
* @param pBlockState The state of the block in the world.
*/
public TestBlockEntity(DumbBlockEntities.Entities entity, BlockPos pPos, BlockState pBlockState) {
super(entity, pPos, pBlockState);
}

/**
* This method is used to register the animation controllers for the block entity.
* It takes a {@link AnimatableManager.ControllerRegistrar} as an argument, which is used to register the animation controllers.
*
* @param controllers The registrar for the animation controllers.
*/
@Override
public void registerControllers(AnimatableManager.ControllerRegistrar controllers) {

}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
package net.dumbcode.projectnublar.core.mobs;

public interface DumbEntity {
}
Loading

0 comments on commit 0e38ecc

Please sign in to comment.