Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Sdev/javadocs #2674

Open
wants to merge 16 commits into
base: 1.20.1
Choose a base branch
from
45 changes: 40 additions & 5 deletions src/main/java/com/gregtechceu/gtceu/api/block/ActiveBlock.java
Original file line number Diff line number Diff line change
Expand Up @@ -11,37 +11,72 @@

import javax.annotation.ParametersAreNonnullByDefault;

/**
* ActiveBlock extends AppearanceBlock with the property ACTIVE.
* This is useful for blocks that have different appearances when active.
* For example, a block that changes appearance when powered by redstone.
* @see AppearanceBlock
*/
@ParametersAreNonnullByDefault
@MethodsReturnNonnullByDefault
public class ActiveBlock extends AppearanceBlock {

public static final BooleanProperty ACTIVE = BooleanProperty.create("active");

/**
* Constructor for ActiveBlock that adds the ACTIVE property to the block state
* Also registers the default block state and properties
* @param properties the properties of the block
*/
public ActiveBlock(Properties properties) {
super(properties);
registerDefaultState(defaultBlockState().setValue(ACTIVE, false));
}

/**
* Adds the ACTIVE property to the block state
* Overrides the createBlockStateDefinition method in AppearanceBlock
* @param builder the block state builder
*/
@Override
protected void createBlockStateDefinition(StateDefinition.Builder<Block, BlockState> builder) {
super.createBlockStateDefinition(builder);
builder.add(ACTIVE);
}

/**
* Changes the active state of the block
* @param state the block state
* @param active whether the block is active or not
* @return the new block state
*/
public BlockState changeActive(BlockState state, boolean active) {
if (state.is(this)) {
return state.setValue(ACTIVE, active);
}
if (state.is(this)) return state.setValue(ACTIVE, active);
return state;
}

/**
* Gets the active state of the block
* @param state the block state
* @return whether the block is active or not
*/
public boolean isActive(BlockState state) {
return state.getValue(ACTIVE);
}

/**
* Gets the block appearance based on the active state
* Overrides the getBlockAppearance method in AppearanceBlock
* @param state the block state
* @param level the block and tint getter
* @param pos the block position
* @param side the direction of the block
* @param sourceState the source block state
* @param sourcePos the source block position
* @return the block state
*/
@Override
public BlockState getBlockAppearance(BlockState state, BlockAndTintGetter level, BlockPos pos, Direction side,
BlockState sourceState, BlockPos sourcePos) {
return defaultBlockState();
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -9,20 +9,36 @@
import org.jetbrains.annotations.Nullable;

/**
* @author KilaBash
* @date 2023/3/27
* @implNote AppearanceBlock
* AppearanceBlock is an abstract class that implements IAppearance.
* This is useful for blocks that have different appearances based on context.
* For example, a block that changes appearance based on the block it is facing.
* @see IAppearance
* @see Block
*/
public class AppearanceBlock extends Block implements IAppearance {

/**
* Constructor for AppearanceBlock that sets the properties of the block
* @param properties the properties of the block
*/
public AppearanceBlock(Properties properties) {
super(properties);
}

/**
* Gets the appearance of the block based on the context
* Overrides the getAppearance method in IAppearance
* @param state the block state
* @param level the block and tint getter
* @param pos the block position
* @param side the direction of the block
* @param queryState the block state of the query
* @param queryPos the block position of the query
* @return the block state of the appearance
*/
@Override
public BlockState getAppearance(BlockState state, BlockAndTintGetter level, BlockPos pos, Direction side,
@Nullable BlockState queryState, @Nullable BlockPos queryPos) {
var appearance = this.getBlockAppearance(state, level, pos, side, queryState, queryPos);
return appearance == null ? state : appearance;
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,11 @@
import net.minecraft.world.level.block.state.properties.BooleanProperty;

/**
* @author KilaBash
* @date 2023/3/12
* @implNote BlockProperties
* BlockProperties is a utility class that contains custom block properties.
* This is useful for blocks that have custom properties that are not included in the default properties.
* For example, a block that has a property that determines whether the block should tick on the server.
* @see BooleanProperty
*/
public final class BlockProperties {

public static final BooleanProperty SERVER_TICK = BooleanProperty.create("server_tick");
}
}
20 changes: 14 additions & 6 deletions src/main/java/com/gregtechceu/gtceu/api/block/IAppearance.java
Original file line number Diff line number Diff line change
Expand Up @@ -8,18 +8,26 @@
import org.jetbrains.annotations.Nullable;

/**
* @author KilaBash
* @date 2023/3/27
* @implNote IAppearanceBlock
* IAppearance is an interface that provides a method to get the appearance of a block.
* This is useful for blocks that have different appearances based on context.
* For example, a block that changes appearance based on the block it is facing.
* @see BlockState
*/
public interface IAppearance {

/**
* get Appearance. same as IForgeBlock.getAppearance() / IFabricBlock.getAppearance()
* Gets the appearance of the block based on the context
* @inheritDoc IForgeBlock#getAppearance(BlockState, BlockAndTintGetter, BlockPos, Direction, BlockState, BlockPos)
* @param state the block state
* @param level the block and tint getter
* @param pos the block position
* @param side the direction of the block
* @param sourceState the block state of the source
* @param sourcePos the block position of the source
* @return the block state of the appearance
*/
@Nullable
default BlockState getBlockAppearance(BlockState state, BlockAndTintGetter level, BlockPos pos, Direction side,
BlockState sourceState, BlockPos sourcePos) {
return state;
}
}
}
43 changes: 33 additions & 10 deletions src/main/java/com/gregtechceu/gtceu/api/block/ICoilType.java
Original file line number Diff line number Diff line change
Expand Up @@ -12,55 +12,78 @@
import java.util.Arrays;
import java.util.Comparator;

public interface ICoilType {

/**
* ICoilType is an interface that provides methods to get the properties of Heating Coils.
* This is useful for Heating Coils that have different properties based on the type of coil.
* For example, a Heating Coil that provides different temperatures based on the level of the coil.
* @see Material
*/
public interface ICoilType {
/**
* @return The Unique Name of the Heating Coil
* TODO: Rename to getRegistryName() or getUniqueName()
* This is used for the registry name of the Heating Coil
* @implNote This should be unique for each Heating Coil
* @return the name of the Heating Coil
*/
@NotNull
String getName();

/**
* @return the temperature the Heating Coil provides
* TODO: Rename to getTemperature()
* This is used for the temperature of the Heating Coil
* @return the temperature of the Heating Coil
*/
int getCoilTemperature();

/**
* TODO: Rename to getParallelizationTier()
* This is used for the parallelization tier of the Heating Coil
* This is used for the amount of parallel recipes in the multi smelter
*
* @return the level of the Heating Coil
* @return the parallelization tier of the Heating Coil
*/
int getLevel();

/**
* This is used for the energy discount in the multi smelter
*
* This is used for the energy discount when used in the multi smelter
* @return the energy discount of the Heating Coil
*/
int getEnergyDiscount();

/**
* This is used for the energy discount in the cracking unit and pyrolyse oven
*
* @return the tier of the coil
* TODO: Rename to getEnergyDiscountTier()
* This is used for the energy discount tier when used in the cracking unit and pyrolyse oven
* @return the energy discount tier of the Heating Coil
*/
int getTier();

/**
* This is used for the material of the Heating Coil
* @implNote This can be {@code null} if the Heating Coil does not have a material
* @return the {@link Material} of the Heating Coil if it has one, otherwise {@code null}
*/
@Nullable
Material getMaterial();

/**
* This is used for the texture of the Heating Coil
* @return the {@link ResourceLocation} defining the base texture of the coil
*/
ResourceLocation getTexture();

/**
* This is used to make a list of all Heating Coils sorted by temperature
* @implNote This is a lazy-loaded list of Heating Coils sorted by temperature
*/
Lazy<ICoilType[]> ALL_COILS_TEMPERATURE_SORTED = Lazy.of(() -> GTCEuAPI.HEATING_COILS.keySet().stream()
.sorted(Comparator.comparing(ICoilType::getCoilTemperature))
.toArray(ICoilType[]::new));

/**
* This is used to get the Heating Coil with the minimum-required temperature
* @param requiredTemperature the minimum-required temperature
* @return the Heating Coil with the minimum-required temperature, otherwise {@code null}
*/
@Nullable
static ICoilType getMinRequiredType(int requiredTemperature) {
return Arrays.stream(ALL_COILS_TEMPERATURE_SORTED.get())
Expand Down
10 changes: 8 additions & 2 deletions src/main/java/com/gregtechceu/gtceu/api/block/IFilterType.java
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,17 @@

import org.jetbrains.annotations.NotNull;

/**
* IFilterType is an interface that provides methods to get the properties of Filters.
* This is useful for Filters that have different properties based on the type of filter.
* For example, a Filter that provides different cleanroom types based on the level of the filter.
* @see CleanroomType
*/
public interface IFilterType extends StringRepresentable {

/**
* Get the cleanroom type of this filter.
* @return The cleanroom type of this filter.
*/
@NotNull
CleanroomType getCleanroomType();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,22 @@
import net.minecraft.resources.ResourceLocation;
import net.minecraft.util.StringRepresentable;

/**
* IFusionCasingType is an interface that provides methods to get the properties of Fusion Casings.
* This is useful for Fusion Casings that have different properties based on the type of casing.
* For example, a Fusion Casing that provides different textures based on the level of the casing.
*/
public interface IFusionCasingType extends StringRepresentable {

/**
* @return the {@link ResourceLocation} defining the base texture of the coil
* Get the texture of the fusing casing.
* @return the {@link ResourceLocation} defining the base texture of the casing
*/
ResourceLocation getTexture();

/**
* Get the harvest level of the casing.
* @return the Harvest level of this casing as an integer
* @see net.minecraft.world.item.Tier
*/
int getHarvestLevel();
}
Loading
Loading