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;
|
2018-10-26 15:01:48 +02:00
|
|
|
import de.ellpeck.naturesaura.blocks.tiles.TileEntityFurnaceHeater;
|
2020-01-29 00:40:28 +01:00
|
|
|
import de.ellpeck.naturesaura.data.BlockStateGenerator;
|
|
|
|
import de.ellpeck.naturesaura.reg.ICustomBlockState;
|
2019-11-04 19:08:49 +01:00
|
|
|
import net.minecraft.block.Block;
|
2019-10-20 22:30:49 +02:00
|
|
|
import net.minecraft.block.BlockState;
|
2019-11-04 19:08:49 +01:00
|
|
|
import net.minecraft.block.material.Material;
|
|
|
|
import net.minecraft.item.BlockItemUseContext;
|
|
|
|
import net.minecraft.state.DirectionProperty;
|
|
|
|
import net.minecraft.state.StateContainer;
|
|
|
|
import net.minecraft.state.properties.BlockStateProperties;
|
2018-10-26 15:01:48 +02:00
|
|
|
import net.minecraft.tileentity.TileEntity;
|
2019-10-20 22:30:49 +02:00
|
|
|
import net.minecraft.util.Direction;
|
2018-10-26 15:01:48 +02:00
|
|
|
import net.minecraft.util.math.BlockPos;
|
2019-11-04 19:08:49 +01:00
|
|
|
import net.minecraft.util.math.shapes.ISelectionContext;
|
|
|
|
import net.minecraft.util.math.shapes.VoxelShape;
|
|
|
|
import net.minecraft.world.IBlockReader;
|
2018-10-26 15:01:48 +02:00
|
|
|
import net.minecraft.world.World;
|
2019-10-20 22:30:49 +02:00
|
|
|
import net.minecraftforge.api.distmarker.Dist;
|
|
|
|
import net.minecraftforge.api.distmarker.OnlyIn;
|
2019-11-04 19:08:49 +01:00
|
|
|
import net.minecraftforge.common.ToolType;
|
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
|
|
|
import java.util.Random;
|
|
|
|
|
2020-01-29 00:40:28 +01:00
|
|
|
public class BlockFurnaceHeater extends BlockContainerImpl implements ICustomBlockState {
|
2019-11-04 19:08:49 +01:00
|
|
|
public static final DirectionProperty FACING = BlockStateProperties.FACING;
|
2018-10-26 15:01:48 +02:00
|
|
|
|
2019-11-04 19:08:49 +01:00
|
|
|
private static final VoxelShape[] SHAPES = new VoxelShape[]{
|
2020-04-03 23:25:41 +02:00
|
|
|
Block.makeCuboidShape(2, 12, 2, 14, 16, 14), // Down
|
2019-11-04 19:08:49 +01:00
|
|
|
Block.makeCuboidShape(2, 0, 2, 14, 4, 14), // Up
|
2020-04-03 23:25:41 +02:00
|
|
|
Block.makeCuboidShape(2, 2, 12, 14, 14, 16), // North
|
2019-11-04 19:08:49 +01:00
|
|
|
Block.makeCuboidShape(2, 2, 0, 14, 14, 4), // South
|
2020-04-03 23:25:41 +02:00
|
|
|
Block.makeCuboidShape(12, 2, 2, 16, 14, 14), // West
|
2019-11-04 19:08:49 +01:00
|
|
|
Block.makeCuboidShape(0, 2, 2, 4, 14, 14) // East
|
|
|
|
};
|
2018-10-26 15:01:48 +02:00
|
|
|
|
|
|
|
public BlockFurnaceHeater() {
|
2020-10-17 21:13:45 +02:00
|
|
|
super("furnace_heater", TileEntityFurnaceHeater::new, Properties.create(Material.ROCK).hardnessAndResistance(3F).harvestLevel(1).harvestTool(ToolType.PICKAXE));
|
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)
|
2019-11-04 19:08:49 +01:00
|
|
|
public void animateTick(BlockState stateIn, World worldIn, BlockPos pos, Random rand) {
|
2018-10-26 15:01:48 +02:00
|
|
|
TileEntity tile = worldIn.getTileEntity(pos);
|
|
|
|
if (tile instanceof TileEntityFurnaceHeater && ((TileEntityFurnaceHeater) tile).isActive) {
|
2019-11-04 19:08:49 +01:00
|
|
|
Direction facing = stateIn.get(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 {
|
|
|
|
x = facing.getZOffset() != 0 ? (0.35F + rand.nextFloat() * 0.3F) : facing.getXOffset() < 0 ? 1 : 0;
|
|
|
|
y = 0.35F + rand.nextFloat() * 0.3F;
|
|
|
|
z = facing.getXOffset() != 0 ? (0.35F + rand.nextFloat() * 0.3F) : facing.getZOffset() < 0 ? 1 : 0;
|
|
|
|
}
|
|
|
|
|
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,
|
|
|
|
(rand.nextFloat() * 0.016F + 0.01F) * facing.getXOffset(),
|
|
|
|
(rand.nextFloat() * 0.016F + 0.01F) * facing.getYOffset(),
|
|
|
|
(rand.nextFloat() * 0.016F + 0.01F) * facing.getZOffset(),
|
|
|
|
0xf46e42, rand.nextFloat() + 0.5F, 55, 0F, true, true);
|
2018-10-26 15:01:48 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
2019-11-04 19:08:49 +01:00
|
|
|
public VoxelShape getShape(BlockState state, IBlockReader worldIn, BlockPos pos, ISelectionContext context) {
|
|
|
|
return SHAPES[state.get(FACING).getIndex()];
|
2018-10-26 15:01:48 +02:00
|
|
|
}
|
|
|
|
|
2018-11-05 20:52:29 +01:00
|
|
|
@Override
|
2019-11-04 19:08:49 +01:00
|
|
|
protected void fillStateContainer(StateContainer.Builder<Block, BlockState> builder) {
|
2020-02-05 14:30:17 +01:00
|
|
|
super.fillStateContainer(builder);
|
2019-11-04 19:08:49 +01:00
|
|
|
builder.add(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
|
2019-11-04 19:08:49 +01:00
|
|
|
public BlockState getStateForPlacement(BlockItemUseContext context) {
|
2020-02-05 14:30:17 +01:00
|
|
|
return super.getStateForPlacement(context).with(FACING, context.getFace());
|
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
|
|
|
}
|