107 lines
4.3 KiB
Java
107 lines
4.3 KiB
Java
/*
|
|
* Copyright (c) 2021 TeamMoeg
|
|
*
|
|
* This file is part of Steam Powered.
|
|
*
|
|
* Steam Powered is free software: you can redistribute it and/or modify
|
|
* it under the terms of the GNU General Public License as published by
|
|
* the Free Software Foundation, version 3.
|
|
*
|
|
* Steam Powered is distributed in the hope that it will be useful,
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
* GNU General Public License for more details.
|
|
*
|
|
* You should have received a copy of the GNU General Public License
|
|
* along with Steam Powered. If not, see <https://www.gnu.org/licenses/>.
|
|
*/
|
|
|
|
package com.teammoeg.steampowered.content.engine;
|
|
|
|
import com.jozufozu.flywheel.core.PartialModel;
|
|
import com.simibubi.create.AllBlockPartials;
|
|
import com.simibubi.create.AllShapes;
|
|
import com.simibubi.create.content.contraptions.components.flywheel.engine.EngineBlock;
|
|
import com.teammoeg.steampowered.registrate.SPTiles;
|
|
import net.minecraft.block.Block;
|
|
import net.minecraft.block.BlockState;
|
|
import net.minecraft.item.BlockItemUseContext;
|
|
import net.minecraft.particles.ParticleTypes;
|
|
import net.minecraft.state.BooleanProperty;
|
|
import net.minecraft.state.StateContainer;
|
|
import net.minecraft.state.properties.BlockStateProperties;
|
|
import net.minecraft.tileentity.TileEntity;
|
|
import net.minecraft.util.Direction;
|
|
import net.minecraft.util.SoundCategory;
|
|
import net.minecraft.util.SoundEvents;
|
|
import net.minecraft.util.math.BlockPos;
|
|
import net.minecraft.util.math.shapes.ISelectionContext;
|
|
import net.minecraft.util.math.shapes.VoxelShape;
|
|
import net.minecraft.world.IBlockReader;
|
|
import net.minecraft.world.World;
|
|
import net.minecraftforge.api.distmarker.Dist;
|
|
import net.minecraftforge.api.distmarker.OnlyIn;
|
|
|
|
import javax.annotation.Nullable;
|
|
import java.util.Random;
|
|
|
|
public class SteamEngineBlock extends EngineBlock {
|
|
public static final BooleanProperty LIT = BlockStateProperties.LIT;
|
|
|
|
public SteamEngineBlock(Properties builder) {
|
|
super(builder);
|
|
this.registerDefaultState(this.stateDefinition.any().setValue(LIT, Boolean.valueOf(false)));
|
|
}
|
|
|
|
public BlockState getStateForPlacement(BlockItemUseContext context) {
|
|
Direction facing = context.getClickedFace();
|
|
return this.defaultBlockState().setValue(FACING, facing.getAxis().isVertical() ? context.getHorizontalDirection().getOpposite() : facing).setValue(LIT, Boolean.valueOf(false));
|
|
}
|
|
|
|
protected void createBlockStateDefinition(StateContainer.Builder<Block, BlockState> builder) {
|
|
super.createBlockStateDefinition(builder.add(LIT));
|
|
}
|
|
|
|
@Override
|
|
public TileEntity createTileEntity(BlockState state, IBlockReader world) {
|
|
return SPTiles.BRONZE_STEAM_ENGINE.create();
|
|
}
|
|
|
|
@Override
|
|
public VoxelShape getShape(BlockState state, IBlockReader worldIn, BlockPos pos, ISelectionContext context) {
|
|
return AllShapes.FURNACE_ENGINE.get(state.getValue(FACING));
|
|
}
|
|
|
|
@Nullable
|
|
@Override
|
|
public PartialModel getFrameModel() {
|
|
return AllBlockPartials.FURNACE_GENERATOR_FRAME;
|
|
}
|
|
|
|
@Override
|
|
protected boolean isValidBaseBlock(BlockState baseBlock, IBlockReader world, BlockPos pos) {
|
|
return true;
|
|
}
|
|
|
|
@OnlyIn(Dist.CLIENT)
|
|
public void animateTick(BlockState p_180655_1_, World p_180655_2_, BlockPos p_180655_3_, Random p_180655_4_) {
|
|
if (p_180655_1_.getValue(LIT)) {
|
|
double d0 = (double) p_180655_3_.getX() + 0.5D;
|
|
double d1 = (double) p_180655_3_.getY();
|
|
double d2 = (double) p_180655_3_.getZ() + 0.5D;
|
|
if (p_180655_4_.nextDouble() < 0.1D) {
|
|
p_180655_2_.playLocalSound(d0, d1, d2, SoundEvents.BLASTFURNACE_FIRE_CRACKLE, SoundCategory.BLOCKS, 1.0F, 1.0F, false);
|
|
}
|
|
|
|
Direction direction = p_180655_1_.getValue(FACING);
|
|
Direction.Axis direction$axis = direction.getAxis();
|
|
double d3 = 0.52D;
|
|
double d4 = p_180655_4_.nextDouble() * 0.6D - 0.3D;
|
|
double d5 = direction$axis == Direction.Axis.X ? (double) direction.getStepX() * 0.52D : d4;
|
|
double d6 = p_180655_4_.nextDouble() * 9.0D / 16.0D;
|
|
double d7 = direction$axis == Direction.Axis.Z ? (double) direction.getStepZ() * 0.52D : d4;
|
|
p_180655_2_.addParticle(ParticleTypes.LAVA, d0 + d5, d1 + d6, d2 + d7, 0.0D, 0.0D, 0.0D);
|
|
}
|
|
}
|
|
}
|