HexCasting/Common/src/main/java/at/petrak/hexcasting/common/blocks/BlockConjured.java

132 lines
4.8 KiB
Java
Raw Normal View History

2022-01-30 22:44:31 +01:00
package at.petrak.hexcasting.common.blocks;
2022-06-08 01:21:57 +02:00
import at.petrak.hexcasting.annotations.SoftImplement;
import at.petrak.hexcasting.api.pigment.FrozenPigment;
2022-05-05 19:37:52 +02:00
import at.petrak.hexcasting.common.blocks.entity.BlockEntityConjured;
2022-06-07 20:57:16 +02:00
import at.petrak.hexcasting.xplat.IForgeLikeBlock;
2022-01-30 22:44:31 +01:00
import net.minecraft.core.BlockPos;
import net.minecraft.server.level.ServerLevel;
2022-03-21 19:22:56 +01:00
import net.minecraft.sounds.SoundEvents;
2022-01-30 22:44:31 +01:00
import net.minecraft.world.entity.Entity;
import net.minecraft.world.entity.LivingEntity;
import net.minecraft.world.entity.player.Player;
import net.minecraft.world.level.BlockGetter;
import net.minecraft.world.level.Level;
import net.minecraft.world.level.LevelAccessor;
import net.minecraft.world.level.block.Block;
import net.minecraft.world.level.block.EntityBlock;
import net.minecraft.world.level.block.RenderShape;
import net.minecraft.world.level.block.entity.BlockEntity;
import net.minecraft.world.level.block.entity.BlockEntityTicker;
import net.minecraft.world.level.block.entity.BlockEntityType;
2022-01-30 22:44:31 +01:00
import net.minecraft.world.level.block.state.BlockState;
import net.minecraft.world.phys.shapes.CollisionContext;
import net.minecraft.world.phys.shapes.Shapes;
import net.minecraft.world.phys.shapes.VoxelShape;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
2022-06-07 20:57:16 +02:00
public class BlockConjured extends Block implements EntityBlock, IForgeLikeBlock {
2022-01-30 22:44:31 +01:00
public BlockConjured(Properties properties) {
2022-01-30 22:44:31 +01:00
super(properties);
}
2022-03-21 19:22:56 +01:00
@Override
public void playerWillDestroy(Level pLevel, BlockPos pPos, BlockState pState, Player pPlayer) {
super.playerWillDestroy(pLevel, pPos, pState, pPlayer);
// For some reason the block doesn't play breaking noises. So we fix that!
pPlayer.playSound(SoundEvents.AMETHYST_BLOCK_BREAK, 1f, 1f);
2022-03-21 19:22:56 +01:00
}
@Nullable
2022-01-30 22:44:31 +01:00
@Override
public <T extends BlockEntity> BlockEntityTicker<T> getTicker(Level pLevel, BlockState pState,
BlockEntityType<T> pBlockEntityType) {
if (pLevel.isClientSide()) {
return BlockConjured::tick;
} else {
return null;
}
}
private static <T extends BlockEntity> void tick(Level level, BlockPos blockPos, BlockState blockState, T t) {
if (t instanceof BlockEntityConjured conjured) {
conjured.particleEffect();
2022-01-30 22:44:31 +01:00
}
}
@Override
public void stepOn(Level pLevel, @NotNull BlockPos pPos, @NotNull BlockState pState, @NotNull Entity pEntity) {
2022-01-30 22:44:31 +01:00
BlockEntity tile = pLevel.getBlockEntity(pPos);
if (tile instanceof BlockEntityConjured bec) {
bec.walkParticle(pEntity);
2022-01-30 22:44:31 +01:00
}
}
@Nullable
@Override
public BlockEntity newBlockEntity(@NotNull BlockPos pPos, @NotNull BlockState pState) {
return new BlockEntityConjured(pPos, pState);
}
public static void setColor(LevelAccessor pLevel, BlockPos pPos, FrozenPigment colorizer) {
2022-01-30 22:44:31 +01:00
BlockEntity blockentity = pLevel.getBlockEntity(pPos);
if (blockentity instanceof BlockEntityConjured tile) {
tile.setColorizer(colorizer);
2022-01-30 22:44:31 +01:00
}
}
@Override
public void onPlace(@NotNull BlockState pState, Level pLevel, @NotNull BlockPos pPos, @NotNull BlockState pOldState,
boolean pIsMoving) {
2022-01-30 22:44:31 +01:00
pLevel.sendBlockUpdated(pPos, pState, pState, Block.UPDATE_CLIENTS);
super.onPlace(pState, pLevel, pPos, pOldState, pIsMoving);
}
@Override
public boolean propagatesSkylightDown(@NotNull BlockState pState, @NotNull BlockGetter pLevel,
@NotNull BlockPos pPos) {
2022-01-30 22:44:31 +01:00
return true;
}
@Override
2022-05-05 19:37:52 +02:00
public @NotNull VoxelShape getVisualShape(BlockState pState, BlockGetter pLevel, BlockPos pPos,
CollisionContext pContext) {
2022-01-30 22:44:31 +01:00
return Shapes.empty();
}
@Override
public float getShadeBrightness(BlockState pState, BlockGetter pLevel, BlockPos pPos) {
return 1.0F;
}
@Override
public @NotNull RenderShape getRenderShape(@NotNull BlockState state) {
return RenderShape.INVISIBLE;
}
@Override
protected void spawnDestroyParticles(Level pLevel, Player pPlayer, BlockPos pPos, BlockState pState) {
// NO-OP
}
2022-01-30 22:44:31 +01:00
2022-06-08 01:21:57 +02:00
@SoftImplement("forge")
public boolean addLandingEffects(BlockState state1, ServerLevel worldserver, BlockPos pos, BlockState state2,
LivingEntity entity, int numberOfParticles) {
2022-06-08 01:21:57 +02:00
return addLandingEffects(state1, worldserver, pos, entity, numberOfParticles);
}
@Override
public boolean addLandingEffects(BlockState state, ServerLevel worldserver, BlockPos pos,
LivingEntity entity, int numberOfParticles) {
2022-01-30 22:44:31 +01:00
BlockEntity tile = worldserver.getBlockEntity(pos);
if (tile instanceof BlockEntityConjured bec) {
bec.landParticle(entity, numberOfParticles);
2022-01-30 22:44:31 +01:00
}
return true;
}
}