Framework for ARC
Initial framework for the ARC block, including GUI, Container, Tile Entity, and Block.
This commit is contained in:
parent
2a8143844a
commit
ec1b0644cb
32 changed files with 847 additions and 70 deletions
|
@ -0,0 +1,162 @@
|
|||
package wayoftime.bloodmagic.common.block;
|
||||
|
||||
import net.minecraft.block.Block;
|
||||
import net.minecraft.block.BlockState;
|
||||
import net.minecraft.block.HorizontalBlock;
|
||||
import net.minecraft.block.SoundType;
|
||||
import net.minecraft.block.material.Material;
|
||||
import net.minecraft.entity.LivingEntity;
|
||||
import net.minecraft.entity.player.PlayerEntity;
|
||||
import net.minecraft.entity.player.ServerPlayerEntity;
|
||||
import net.minecraft.inventory.container.INamedContainerProvider;
|
||||
import net.minecraft.item.BlockItemUseContext;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.state.BooleanProperty;
|
||||
import net.minecraft.state.DirectionProperty;
|
||||
import net.minecraft.state.StateContainer;
|
||||
import net.minecraft.state.properties.BlockStateProperties;
|
||||
import net.minecraft.tileentity.AbstractFurnaceTileEntity;
|
||||
import net.minecraft.tileentity.TileEntity;
|
||||
import net.minecraft.util.ActionResultType;
|
||||
import net.minecraft.util.Direction;
|
||||
import net.minecraft.util.Hand;
|
||||
import net.minecraft.util.Mirror;
|
||||
import net.minecraft.util.Rotation;
|
||||
import net.minecraft.util.math.BlockPos;
|
||||
import net.minecraft.util.math.BlockRayTraceResult;
|
||||
import net.minecraft.world.IBlockReader;
|
||||
import net.minecraft.world.IWorld;
|
||||
import net.minecraft.world.World;
|
||||
import net.minecraftforge.common.ToolType;
|
||||
import net.minecraftforge.fml.network.NetworkHooks;
|
||||
import wayoftime.bloodmagic.tile.TileAlchemicalReactionChamber;
|
||||
|
||||
public class BlockAlchemicalReactionChamber extends Block
|
||||
{
|
||||
public static final DirectionProperty FACING = HorizontalBlock.HORIZONTAL_FACING;
|
||||
public static final BooleanProperty LIT = BlockStateProperties.LIT;
|
||||
|
||||
public BlockAlchemicalReactionChamber()
|
||||
{
|
||||
super(Properties.create(Material.ROCK).hardnessAndResistance(2.0F, 5.0F).harvestTool(ToolType.PICKAXE).harvestLevel(2).sound(SoundType.STONE));
|
||||
this.setDefaultState(this.stateContainer.getBaseState().with(FACING, Direction.NORTH).with(LIT, Boolean.valueOf(false)));
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean hasTileEntity(BlockState state)
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public TileEntity createTileEntity(BlockState state, IBlockReader world)
|
||||
{
|
||||
return new TileAlchemicalReactionChamber();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onPlayerDestroy(IWorld world, BlockPos blockPos, BlockState blockState)
|
||||
{
|
||||
TileAlchemicalReactionChamber arc = (TileAlchemicalReactionChamber) world.getTileEntity(blockPos);
|
||||
if (arc != null)
|
||||
arc.dropItems();
|
||||
|
||||
super.onPlayerDestroy(world, blockPos, blockState);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onReplaced(BlockState state, World worldIn, BlockPos pos, BlockState newState, boolean isMoving)
|
||||
{
|
||||
if (!state.isIn(newState.getBlock()))
|
||||
{
|
||||
TileEntity tileentity = worldIn.getTileEntity(pos);
|
||||
if (tileentity instanceof TileAlchemicalReactionChamber)
|
||||
{
|
||||
((TileAlchemicalReactionChamber) tileentity).dropItems();
|
||||
worldIn.updateComparatorOutputLevel(pos, this);
|
||||
}
|
||||
|
||||
super.onReplaced(state, worldIn, pos, newState, isMoving);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public ActionResultType onBlockActivated(BlockState state, World world, BlockPos pos, PlayerEntity player, Hand hand, BlockRayTraceResult blockRayTraceResult)
|
||||
{
|
||||
if (world.isRemote)
|
||||
return ActionResultType.SUCCESS;
|
||||
|
||||
TileEntity tile = world.getTileEntity(pos);
|
||||
if (!(tile instanceof TileAlchemicalReactionChamber))
|
||||
return ActionResultType.FAIL;
|
||||
|
||||
NetworkHooks.openGui((ServerPlayerEntity) player, (INamedContainerProvider) tile, pos);
|
||||
// player.openGui(BloodMagic.instance, Constants.Gui.SOUL_FORGE_GUI, world, pos.getX(), pos.getY(), pos.getZ());
|
||||
|
||||
return ActionResultType.SUCCESS;
|
||||
}
|
||||
|
||||
@Override
|
||||
public BlockState getStateForPlacement(BlockItemUseContext context)
|
||||
{
|
||||
return this.getDefaultState().with(FACING, context.getPlacementHorizontalFacing().getOpposite());
|
||||
}
|
||||
|
||||
/**
|
||||
* Called by ItemBlocks after a block is set in the world, to allow post-place
|
||||
* logic
|
||||
*/
|
||||
@Override
|
||||
public void onBlockPlacedBy(World worldIn, BlockPos pos, BlockState state, LivingEntity placer, ItemStack stack)
|
||||
{
|
||||
if (stack.hasDisplayName())
|
||||
{
|
||||
TileEntity tileentity = worldIn.getTileEntity(pos);
|
||||
if (tileentity instanceof AbstractFurnaceTileEntity)
|
||||
{
|
||||
((AbstractFurnaceTileEntity) tileentity).setCustomName(stack.getDisplayName());
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the blockstate with the given rotation from the passed blockstate. If
|
||||
* inapplicable, returns the passed blockstate.
|
||||
*
|
||||
* @deprecated call via {@link IBlockState#withRotation(Rotation)} whenever
|
||||
* possible. Implementing/overriding is fine.
|
||||
*/
|
||||
@Override
|
||||
public BlockState rotate(BlockState state, Rotation rot)
|
||||
{
|
||||
return state.with(FACING, rot.rotate(state.get(FACING)));
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the blockstate with the given mirror of the passed blockstate. If
|
||||
* inapplicable, returns the passed blockstate.
|
||||
*
|
||||
* @deprecated call via {@link IBlockState#withMirror(Mirror)} whenever
|
||||
* possible. Implementing/overriding is fine.
|
||||
*/
|
||||
@Override
|
||||
public BlockState mirror(BlockState state, Mirror mirrorIn)
|
||||
{
|
||||
return state.rotate(mirrorIn.toRotation(state.get(FACING)));
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void fillStateContainer(StateContainer.Builder<Block, BlockState> builder)
|
||||
{
|
||||
builder.add(FACING, LIT);
|
||||
}
|
||||
|
||||
public boolean eventReceived(BlockState state, World worldIn, BlockPos pos, int id, int param)
|
||||
{
|
||||
super.eventReceived(state, worldIn, pos, id, param);
|
||||
TileEntity tileentity = worldIn.getTileEntity(pos);
|
||||
return tileentity == null ? false : tileentity.receiveClientEvent(id, param);
|
||||
}
|
||||
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue