2018-10-26 15:01:48 +02:00
|
|
|
package de.ellpeck.naturesaura.blocks;
|
|
|
|
|
2018-11-11 13:26:19 +01:00
|
|
|
import de.ellpeck.naturesaura.api.NaturesAuraAPI;
|
2021-12-04 15:40:09 +01:00
|
|
|
import de.ellpeck.naturesaura.blocks.tiles.BlockEntityFurnaceHeater;
|
2020-01-29 00:40:28 +01:00
|
|
|
import de.ellpeck.naturesaura.data.BlockStateGenerator;
|
|
|
|
import de.ellpeck.naturesaura.reg.ICustomBlockState;
|
2021-12-15 14:26:42 +01:00
|
|
|
import net.minecraft.core.BlockPos;
|
|
|
|
import net.minecraft.core.Direction;
|
2022-06-27 15:24:04 +02:00
|
|
|
import net.minecraft.util.RandomSource;
|
2021-12-15 14:26:42 +01:00
|
|
|
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.state.BlockState;
|
|
|
|
import net.minecraft.world.level.block.state.StateDefinition;
|
|
|
|
import net.minecraft.world.level.block.state.properties.BlockStateProperties;
|
|
|
|
import net.minecraft.world.level.block.state.properties.DirectionProperty;
|
|
|
|
import net.minecraft.world.phys.shapes.CollisionContext;
|
|
|
|
import net.minecraft.world.phys.shapes.VoxelShape;
|
2024-02-03 14:56:07 +01:00
|
|
|
import net.neoforged.api.distmarker.Dist;
|
|
|
|
import net.neoforged.api.distmarker.OnlyIn;
|
2018-10-26 15:01:48 +02:00
|
|
|
|
2019-11-04 19:08:49 +01:00
|
|
|
import javax.annotation.Nullable;
|
2018-10-26 15:01:48 +02:00
|
|
|
|
2020-01-29 00:40:28 +01:00
|
|
|
public class BlockFurnaceHeater extends BlockContainerImpl implements ICustomBlockState {
|
2021-12-15 14:26:42 +01:00
|
|
|
|
2019-11-04 19:08:49 +01:00
|
|
|
public static final DirectionProperty FACING = BlockStateProperties.FACING;
|
2018-10-26 15:01:48 +02:00
|
|
|
|
2023-02-15 23:45:50 +01:00
|
|
|
private static final VoxelShape[] SHAPES = {
|
2022-06-27 15:24:04 +02:00
|
|
|
Block.box(2, 12, 2, 14, 16, 14), // Down
|
|
|
|
Block.box(2, 0, 2, 14, 4, 14), // Up
|
|
|
|
Block.box(2, 2, 12, 14, 14, 16), // North
|
|
|
|
Block.box(2, 2, 0, 14, 14, 4), // South
|
|
|
|
Block.box(12, 2, 2, 16, 14, 14), // West
|
|
|
|
Block.box(0, 2, 2, 4, 14, 14) // East
|
2019-11-04 19:08:49 +01:00
|
|
|
};
|
2018-10-26 15:01:48 +02:00
|
|
|
|
|
|
|
public BlockFurnaceHeater() {
|
2023-07-08 12:32:27 +02:00
|
|
|
super("furnace_heater", BlockEntityFurnaceHeater.class, Properties.of().strength(3F));
|
2018-10-26 15:01:48 +02:00
|
|
|
}
|
|
|
|
|
2020-02-05 14:30:17 +01:00
|
|
|
@Override
|
|
|
|
protected boolean hasWaterlogging() {
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2018-10-26 15:01:48 +02:00
|
|
|
@Override
|
2019-10-20 22:30:49 +02:00
|
|
|
@OnlyIn(Dist.CLIENT)
|
2022-06-27 15:24:04 +02:00
|
|
|
public void animateTick(BlockState stateIn, Level levelIn, BlockPos pos, RandomSource rand) {
|
2021-12-15 16:30:22 +01:00
|
|
|
var tile = levelIn.getBlockEntity(pos);
|
2021-12-15 14:26:42 +01:00
|
|
|
if (tile instanceof BlockEntityFurnaceHeater heater && heater.isActive) {
|
2022-06-27 15:24:04 +02:00
|
|
|
var facing = stateIn.getValue(BlockFurnaceHeater.FACING);
|
2018-11-12 15:42:56 +01:00
|
|
|
|
|
|
|
float x;
|
|
|
|
float y;
|
|
|
|
float z;
|
2019-10-20 22:30:49 +02:00
|
|
|
if (facing == Direction.UP) {
|
2018-11-12 15:42:56 +01:00
|
|
|
x = 0.35F + rand.nextFloat() * 0.3F;
|
|
|
|
y = 0F;
|
|
|
|
z = 0.35F + rand.nextFloat() * 0.3F;
|
2019-10-20 22:30:49 +02:00
|
|
|
} else if (facing == Direction.DOWN) {
|
2018-11-12 15:42:56 +01:00
|
|
|
x = 0.35F + rand.nextFloat() * 0.3F;
|
|
|
|
y = 1F;
|
|
|
|
z = 0.35F + rand.nextFloat() * 0.3F;
|
|
|
|
} else {
|
2022-06-27 15:24:04 +02:00
|
|
|
x = facing.getStepZ() != 0 ? 0.35F + rand.nextFloat() * 0.3F : facing.getStepX() < 0 ? 1 : 0;
|
2018-11-12 15:42:56 +01:00
|
|
|
y = 0.35F + rand.nextFloat() * 0.3F;
|
2022-06-27 15:24:04 +02:00
|
|
|
z = facing.getStepX() != 0 ? 0.35F + rand.nextFloat() * 0.3F : facing.getStepZ() < 0 ? 1 : 0;
|
2018-11-12 15:42:56 +01:00
|
|
|
}
|
|
|
|
|
2018-11-13 00:36:47 +01:00
|
|
|
NaturesAuraAPI.instance().spawnMagicParticle(
|
2018-11-12 15:42:56 +01:00
|
|
|
pos.getX() + x, pos.getY() + y, pos.getZ() + z,
|
2021-12-15 14:26:42 +01:00
|
|
|
(rand.nextFloat() * 0.016F + 0.01F) * facing.getStepX(),
|
|
|
|
(rand.nextFloat() * 0.016F + 0.01F) * facing.getStepY(),
|
|
|
|
(rand.nextFloat() * 0.016F + 0.01F) * facing.getStepZ(),
|
2018-11-12 15:42:56 +01:00
|
|
|
0xf46e42, rand.nextFloat() + 0.5F, 55, 0F, true, true);
|
2018-10-26 15:01:48 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
2023-02-15 23:45:50 +01:00
|
|
|
@SuppressWarnings("deprecation")
|
2021-12-15 14:26:42 +01:00
|
|
|
public VoxelShape getShape(BlockState state, BlockGetter levelIn, BlockPos pos, CollisionContext context) {
|
2022-06-27 15:24:04 +02:00
|
|
|
return BlockFurnaceHeater.SHAPES[state.getValue(BlockFurnaceHeater.FACING).get3DDataValue()];
|
2018-10-26 15:01:48 +02:00
|
|
|
}
|
|
|
|
|
2018-11-05 20:52:29 +01:00
|
|
|
@Override
|
2021-12-15 14:26:42 +01:00
|
|
|
protected void createBlockStateDefinition(StateDefinition.Builder<Block, BlockState> builder) {
|
|
|
|
super.createBlockStateDefinition(builder);
|
2022-06-27 15:24:04 +02:00
|
|
|
builder.add(BlockFurnaceHeater.FACING);
|
2018-11-12 15:42:56 +01:00
|
|
|
}
|
|
|
|
|
2019-11-04 19:08:49 +01:00
|
|
|
@Nullable
|
2018-11-12 15:42:56 +01:00
|
|
|
@Override
|
2021-12-15 14:26:42 +01:00
|
|
|
public BlockState getStateForPlacement(BlockPlaceContext context) {
|
2022-06-27 15:24:04 +02:00
|
|
|
return super.getStateForPlacement(context).setValue(BlockFurnaceHeater.FACING, context.getClickedFace());
|
2018-11-12 15:42:56 +01:00
|
|
|
}
|
2020-01-29 00:40:28 +01:00
|
|
|
|
|
|
|
@Override
|
|
|
|
public void generateCustomBlockState(BlockStateGenerator generator) {
|
2020-01-29 01:34:58 +01:00
|
|
|
generator.directionalBlock(this, generator.models().getExistingFile(generator.modLoc(this.getBaseName())));
|
|
|
|
}
|
2018-10-26 15:01:48 +02:00
|
|
|
}
|