Fabric port in progress
This commit is contained in:
@@ -32,7 +32,7 @@ import net.minecraft.util.math.Direction;
|
||||
import net.minecraft.util.Hand;
|
||||
import net.minecraft.util.math.Box;
|
||||
import net.minecraft.util.math.BlockPos;
|
||||
import net.minecraft.util.math.BlockRayTraceResult;
|
||||
import net.minecraft.util.hit.BlockHitResult;
|
||||
import net.minecraft.block.ShapeContext;
|
||||
import net.minecraft.util.shape.VoxelShape;
|
||||
import net.minecraft.util.shape.VoxelShapes;
|
||||
@@ -45,24 +45,24 @@ import net.minecraftforge.common.util.FakePlayer;
|
||||
import appeng.api.implementations.tiles.ICrankable;
|
||||
import appeng.block.AEBaseTileBlock;
|
||||
import appeng.core.stats.AeStats;
|
||||
import appeng.tile.AEBaseTileEntity;
|
||||
import appeng.tile.grindstone.CrankTileEntity;
|
||||
import appeng.tile.AEBaseBlockEntity;
|
||||
import appeng.tile.grindstone.CrankBlockEntity;
|
||||
|
||||
public class CrankBlock extends AEBaseTileBlock<CrankTileEntity> {
|
||||
public class CrankBlock extends AEBaseTileBlock<CrankBlockEntity> {
|
||||
|
||||
public CrankBlock(Properties props) {
|
||||
public CrankBlock(Settings props) {
|
||||
super(props);
|
||||
}
|
||||
|
||||
@Override
|
||||
public ActionResult onActivated(final World w, final BlockPos pos, final PlayerEntity player, final Hand hand,
|
||||
final @Nullable ItemStack heldItem, final BlockRayTraceResult hit) {
|
||||
final @Nullable ItemStack heldItem, final BlockHitResult hit) {
|
||||
if (player instanceof FakePlayer || player == null) {
|
||||
this.dropCrank(w, pos);
|
||||
return ActionResult.SUCCESS;
|
||||
}
|
||||
|
||||
final CrankTileEntity tile = this.getTileEntity(w, pos);
|
||||
final CrankBlockEntity tile = this.getBlockEntity(w, pos);
|
||||
if (tile != null) {
|
||||
if (tile.power()) {
|
||||
AeStats.TurnedCranks.addToPlayer(player, 1);
|
||||
@@ -74,14 +74,14 @@ public class CrankBlock extends AEBaseTileBlock<CrankTileEntity> {
|
||||
}
|
||||
|
||||
private void dropCrank(final World world, final BlockPos pos) {
|
||||
world.destroyBlock(pos, true);
|
||||
world.notifyBlockUpdate(pos, this.getDefaultState(), world.getBlockState(pos), 3);
|
||||
world.breakBlock(pos, true);
|
||||
world.updateListeners(pos, this.getDefaultState(), world.getBlockState(pos), 3);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onBlockPlacedBy(final World world, final BlockPos pos, final BlockState state,
|
||||
public void onPlaced(final World world, final BlockPos pos, final BlockState state,
|
||||
final LivingEntity placer, final ItemStack stack) {
|
||||
final AEBaseTileEntity tile = this.getTileEntity(world, pos);
|
||||
final AEBaseBlockEntity tile = this.getBlockEntity(world, pos);
|
||||
if (tile != null) {
|
||||
final Direction mnt = this.findCrankable(world, pos);
|
||||
Direction forward = Direction.UP;
|
||||
@@ -96,8 +96,8 @@ public class CrankBlock extends AEBaseTileBlock<CrankTileEntity> {
|
||||
|
||||
@Override
|
||||
public boolean isValidOrientation(final WorldAccess w, final BlockPos pos, final Direction forward, final Direction up) {
|
||||
final BlockEntity te = w.getTileEntity(pos);
|
||||
return !(te instanceof CrankTileEntity) || this.isCrankable(w, pos, up.getOpposite());
|
||||
final BlockEntity te = w.getBlockEntity(pos);
|
||||
return !(te instanceof CrankBlockEntity) || this.isCrankable(w, pos, up.getOpposite());
|
||||
}
|
||||
|
||||
private Direction findCrankable(final BlockView world, final BlockPos pos) {
|
||||
@@ -111,7 +111,7 @@ public class CrankBlock extends AEBaseTileBlock<CrankTileEntity> {
|
||||
|
||||
private boolean isCrankable(final BlockView world, final BlockPos pos, final Direction offset) {
|
||||
final BlockPos o = pos.offset(offset);
|
||||
final BlockEntity te = world.getTileEntity(o);
|
||||
final BlockEntity te = world.getBlockEntity(o);
|
||||
|
||||
return te instanceof ICrankable && ((ICrankable) te).canCrankAttach(offset.getOpposite());
|
||||
}
|
||||
@@ -124,7 +124,7 @@ public class CrankBlock extends AEBaseTileBlock<CrankTileEntity> {
|
||||
@Override
|
||||
public void neighborChanged(BlockState state, World world, BlockPos pos, Block blockIn, BlockPos fromPos,
|
||||
boolean isMoving) {
|
||||
final AEBaseTileEntity tile = this.getTileEntity(world, pos);
|
||||
final AEBaseBlockEntity tile = this.getBlockEntity(world, pos);
|
||||
if (tile != null) {
|
||||
if (!this.isCrankable(world, pos, tile.getUp().getOpposite())) {
|
||||
this.dropCrank(world, pos);
|
||||
@@ -140,7 +140,7 @@ public class CrankBlock extends AEBaseTileBlock<CrankTileEntity> {
|
||||
}
|
||||
|
||||
private Direction getUp(BlockView world, BlockPos pos) {
|
||||
CrankTileEntity crank = getTileEntity(world, pos);
|
||||
CrankBlockEntity crank = getBlockEntity(world, pos);
|
||||
return crank != null ? crank.getUp() : null;
|
||||
}
|
||||
|
||||
@@ -152,9 +152,9 @@ public class CrankBlock extends AEBaseTileBlock<CrankTileEntity> {
|
||||
return VoxelShapes.empty();
|
||||
} else {
|
||||
// FIXME: Cache per direction, and build it 'precise', not just from AABB
|
||||
final double xOff = -0.15 * up.getXOffset();
|
||||
final double yOff = -0.15 * up.getYOffset();
|
||||
final double zOff = -0.15 * up.getZOffset();
|
||||
final double xOff = -0.15 * up.getOffsetX();
|
||||
final double yOff = -0.15 * up.getOffsetY();
|
||||
final double zOff = -0.15 * up.getOffsetZ();
|
||||
return VoxelShapes.create(
|
||||
new Box(xOff + 0.15, yOff + 0.15, zOff + 0.15, xOff + 0.85, yOff + 0.85, zOff + 0.85));
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user