Adds a block imitator
This commit is contained in:
parent
46c7478aa7
commit
95405f9e5a
2 changed files with 94 additions and 1 deletions
|
@ -53,7 +53,7 @@ mod_name=Zontreck Library Mod
|
||||||
# The license of the mod. Review your options at https://choosealicense.com/. All Rights Reserved is the default.
|
# The license of the mod. Review your options at https://choosealicense.com/. All Rights Reserved is the default.
|
||||||
mod_license=GPLv3
|
mod_license=GPLv3
|
||||||
# The mod version. See https://semver.org/
|
# The mod version. See https://semver.org/
|
||||||
mod_version=1.10.011024.0312
|
mod_version=1.10.011224.2203
|
||||||
# The group ID for the mod. It is only important when publishing as an artifact to a Maven repository.
|
# The group ID for the mod. It is only important when publishing as an artifact to a Maven repository.
|
||||||
# This should match the base package used for the mod sources.
|
# This should match the base package used for the mod sources.
|
||||||
# See https://maven.apache.org/guides/mini/guide-naming-conventions.html
|
# See https://maven.apache.org/guides/mini/guide-naming-conventions.html
|
||||||
|
|
|
@ -0,0 +1,93 @@
|
||||||
|
package dev.zontreck.libzontreck.blocks;
|
||||||
|
|
||||||
|
import net.minecraft.core.BlockPos;
|
||||||
|
import net.minecraft.core.Direction;
|
||||||
|
import net.minecraft.server.level.ServerLevel;
|
||||||
|
import net.minecraft.util.RandomSource;
|
||||||
|
import net.minecraft.world.entity.Entity;
|
||||||
|
import net.minecraft.world.item.ItemStack;
|
||||||
|
import net.minecraft.world.level.BlockGetter;
|
||||||
|
import net.minecraft.world.level.Level;
|
||||||
|
import net.minecraft.world.level.biome.Biome;
|
||||||
|
import net.minecraft.world.level.block.Block;
|
||||||
|
import net.minecraft.world.level.block.state.BlockState;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Code partially taken from HT's TreeChop
|
||||||
|
* <p>
|
||||||
|
* <a href="https://github.com/hammertater/treechop/blob/main/shared/src/main/java/ht/treechop/common/block/BlockImitator.java">Source Material</a>
|
||||||
|
*/
|
||||||
|
public abstract class BlockImitation extends Block
|
||||||
|
{
|
||||||
|
public BlockImitation(Properties pProperties) {
|
||||||
|
super(pProperties);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
public abstract BlockState getImitatedBlockState(BlockGetter level, BlockPos pos);
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void animateTick(BlockState blockState, Level level, BlockPos pos, RandomSource random) {
|
||||||
|
BlockState imitatedBlockState = getImitatedBlockState(level, pos);
|
||||||
|
imitatedBlockState.getBlock().animateTick(imitatedBlockState, level, pos, random);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void stepOn(Level level, BlockPos pos, BlockState blockState, Entity entity) {
|
||||||
|
BlockState imitatedBlockState = getImitatedBlockState(level, pos);
|
||||||
|
imitatedBlockState.getBlock().stepOn(level, pos, imitatedBlockState, entity);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void fallOn(Level level, BlockState blockState, BlockPos pos, Entity entity, float speed) {
|
||||||
|
BlockState imitatedBlockState = getImitatedBlockState(level, pos);
|
||||||
|
imitatedBlockState.getBlock().fallOn(level, imitatedBlockState, pos, entity, speed);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public ItemStack getCloneItemStack(BlockGetter level, BlockPos pos, BlockState blockState) {
|
||||||
|
BlockState imitatedBlockState = getImitatedBlockState(level, pos);
|
||||||
|
return imitatedBlockState.getBlock().getCloneItemStack(level, pos, imitatedBlockState);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void handlePrecipitation(BlockState blockState, Level level, BlockPos pos, Biome.Precipitation precipitation) {
|
||||||
|
BlockState imitatedBlockState = getImitatedBlockState(level, pos);
|
||||||
|
imitatedBlockState.getBlock().handlePrecipitation(imitatedBlockState, level, pos, precipitation);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public int getLightBlock(BlockState blockState, BlockGetter level, BlockPos pos) {
|
||||||
|
return super.getLightBlock(blockState, level, pos);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public float getShadeBrightness(BlockState blockState, BlockGetter level, BlockPos pos) {
|
||||||
|
return super.getShadeBrightness(blockState, level, pos);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public int getAnalogOutputSignal(BlockState blockState, Level level, BlockPos pos) {
|
||||||
|
return getImitatedBlockState(level, pos).getAnalogOutputSignal(level, pos);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void randomTick(BlockState blockState, ServerLevel level, BlockPos pos, RandomSource random) {
|
||||||
|
getImitatedBlockState(level, pos).randomTick(level, pos, random);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void tick(BlockState blockState, ServerLevel level, BlockPos pos, RandomSource random) {
|
||||||
|
getImitatedBlockState(level, pos).tick(level, pos, random);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public int getSignal(BlockState blockState, BlockGetter level, BlockPos pos, Direction direction) {
|
||||||
|
return getImitatedBlockState(level, pos).getSignal(level, pos, direction);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public int getDirectSignal(BlockState blockState, BlockGetter level, BlockPos pos, Direction direction) {
|
||||||
|
return getImitatedBlockState(level, pos).getDirectSignal(level, pos, direction);
|
||||||
|
}
|
||||||
|
}
|
Reference in a new issue