Port all instances of Block.onBlockActivated

This commit is contained in:
tterrag 2020-03-29 12:05:07 -04:00
parent 53f0524200
commit 11ae3bc820
18 changed files with 88 additions and 86 deletions

View file

@ -42,14 +42,14 @@ public abstract class AbstractChassisBlock extends RotatedPillarBlock {
public ActionResultType onUse(BlockState state, World worldIn, BlockPos pos, PlayerEntity player, Hand handIn,
BlockRayTraceResult hit) {
if (!player.isAllowEdit())
return false;
return ActionResultType.PASS;
ItemStack heldItem = player.getHeldItem(handIn);
boolean isSlimeBall = heldItem.getItem().isIn(Tags.Items.SLIMEBALLS);
BooleanProperty affectedSide = getGlueableSide(state, hit.getFace());
if (affectedSide == null)
return false;
return ActionResultType.PASS;
if (isSlimeBall && state.get(affectedSide)) {
for (Direction face : Direction.values()) {
@ -58,7 +58,7 @@ public abstract class AbstractChassisBlock extends RotatedPillarBlock {
if (worldIn.isRemote) {
Vec3d vec = hit.getHitVec();
worldIn.addParticle(ParticleTypes.ITEM_SLIME, vec.x, vec.y, vec.z, 0, 0, 0);
return true;
return ActionResultType.SUCCESS;
}
worldIn.playSound(null, pos, AllSoundEvents.SLIME_ADDED.get(), SoundCategory.BLOCKS, .5f, 1);
state = state.with(glueableSide, true);
@ -66,22 +66,22 @@ public abstract class AbstractChassisBlock extends RotatedPillarBlock {
}
if (!worldIn.isRemote)
worldIn.setBlockState(pos, state);
return true;
return ActionResultType.SUCCESS;
}
if ((!heldItem.isEmpty() || !player.isSneaking()) && !isSlimeBall)
return false;
return ActionResultType.PASS;
if (state.get(affectedSide) == isSlimeBall)
return false;
return ActionResultType.PASS;
if (worldIn.isRemote) {
Vec3d vec = hit.getHitVec();
worldIn.addParticle(ParticleTypes.ITEM_SLIME, vec.x, vec.y, vec.z, 0, 0, 0);
return true;
return ActionResultType.SUCCESS;
}
worldIn.playSound(null, pos, AllSoundEvents.SLIME_ADDED.get(), SoundCategory.BLOCKS, .5f, 1);
worldIn.setBlockState(pos, state.with(affectedSide, isSlimeBall));
return true;
return ActionResultType.SUCCESS;
}
@Override

View file

@ -55,34 +55,34 @@ public class MechanicalPistonBlock extends DirectionalAxisKineticBlock
public ActionResultType onUse(BlockState state, World worldIn, BlockPos pos, PlayerEntity player, Hand handIn,
BlockRayTraceResult hit) {
if (!player.isAllowEdit())
return false;
return ActionResultType.PASS;
if (player.isSneaking())
return false;
return ActionResultType.PASS;
if (!player.getHeldItem(handIn).getItem().isIn(Tags.Items.SLIMEBALLS)) {
if (player.getHeldItem(handIn).isEmpty()) {
withTileEntityDo(worldIn, pos, te -> te.assembleNextTick = true);
return true;
return ActionResultType.SUCCESS;
}
return false;
return ActionResultType.PASS;
}
if (state.get(STATE) != PistonState.RETRACTED)
return false;
return ActionResultType.PASS;
Direction direction = state.get(FACING);
if (hit.getFace() != direction)
return false;
return ActionResultType.PASS;
if (((MechanicalPistonBlock) state.getBlock()).isSticky)
return false;
return ActionResultType.PASS;
if (worldIn.isRemote) {
Vec3d vec = hit.getHitVec();
worldIn.addParticle(ParticleTypes.ITEM_SLIME, vec.x, vec.y, vec.z, 0, 0, 0);
return true;
return ActionResultType.SUCCESS;
}
worldIn.playSound(null, pos, AllSoundEvents.SLIME_ADDED.get(), SoundCategory.BLOCKS, .5f, 1);
if (!player.isCreative())
player.getHeldItem(handIn).shrink(1);
worldIn.setBlockState(pos, AllBlocks.STICKY_MECHANICAL_PISTON.get().getDefaultState().with(FACING, direction)
.with(AXIS_ALONG_FIRST_COORDINATE, state.get(AXIS_ALONG_FIRST_COORDINATE)));
return true;
return ActionResultType.SUCCESS;
}
@Override

View file

@ -46,14 +46,14 @@ public class PulleyBlock extends HorizontalAxisKineticBlock implements IWithTile
public ActionResultType onUse(BlockState state, World worldIn, BlockPos pos, PlayerEntity player, Hand handIn,
BlockRayTraceResult hit) {
if (!player.isAllowEdit())
return false;
return ActionResultType.PASS;
if (player.isSneaking())
return false;
return ActionResultType.PASS;
if (player.getHeldItem(handIn).isEmpty()) {
withTileEntityDo(worldIn, pos, te -> te.assembleNextTick = true);
return true;
return ActionResultType.SUCCESS;
}
return false;
return ActionResultType.PASS;
}
@Override

View file

@ -166,7 +166,7 @@ public class MechanicalCrafterBlock extends HorizontalKineticBlock
TileEntity te = worldIn.getTileEntity(pos);
if (!(te instanceof MechanicalCrafterTileEntity))
return false;
return ActionResultType.PASS;
MechanicalCrafterTileEntity crafter = (MechanicalCrafterTileEntity) te;
boolean wrenched = AllItems.WRENCH.typeOf(heldItem);
@ -174,59 +174,59 @@ public class MechanicalCrafterBlock extends HorizontalKineticBlock
if (crafter.phase != Phase.IDLE && !wrenched) {
crafter.ejectWholeGrid();
return true;
return ActionResultType.SUCCESS;
}
if (crafter.phase == Phase.IDLE && !isHand && !wrenched) {
if (worldIn.isRemote)
return true;
return ActionResultType.SUCCESS;
if (AllItems.SLOT_COVER.typeOf(heldItem)) {
if (crafter.covered)
return false;
return ActionResultType.PASS;
crafter.covered = true;
crafter.markDirty();
crafter.sendData();
if (!player.isCreative())
heldItem.shrink(1);
return true;
return ActionResultType.SUCCESS;
}
LazyOptional<IItemHandler> capability =
crafter.getCapability(CapabilityItemHandler.ITEM_HANDLER_CAPABILITY);
if (!capability.isPresent())
return false;
return ActionResultType.PASS;
ItemStack remainder =
ItemHandlerHelper.insertItem(capability.orElse(new ItemStackHandler()), heldItem.copy(), false);
if (remainder.getCount() != heldItem.getCount())
player.setHeldItem(handIn, remainder);
return true;
return ActionResultType.SUCCESS;
}
ItemStack inSlot = crafter.inventory.getStackInSlot(0);
if (inSlot.isEmpty()) {
if (crafter.covered && !wrenched) {
if (worldIn.isRemote)
return true;
return ActionResultType.SUCCESS;
crafter.covered = false;
crafter.markDirty();
crafter.sendData();
if (!player.isCreative())
player.inventory.placeItemBackInInventory(worldIn, AllItems.SLOT_COVER.asStack());
return true;
return ActionResultType.SUCCESS;
}
return false;
return ActionResultType.PASS;
}
if (!isHand && !ItemHandlerHelper.canItemStacksStack(heldItem, inSlot))
return false;
return ActionResultType.PASS;
if (worldIn.isRemote)
return true;
return ActionResultType.SUCCESS;
player.inventory.placeItemBackInInventory(worldIn, inSlot);
crafter.inventory.setStackInSlot(0, ItemStack.EMPTY);
return true;
return ActionResultType.SUCCESS;
}
return false;
return ActionResultType.PASS;
}
// @Override // TODO 1.15 register layer

View file

@ -39,10 +39,10 @@ public class HandCrankBlock extends DirectionalKineticBlock implements IWithTile
boolean handEmpty = player.getHeldItem(handIn).isEmpty();
if (!handEmpty && player.isSneaking())
return false;
return ActionResultType.PASS;
withTileEntityDo(worldIn, pos, te -> te.turn(player.isSneaking()));
return true;
return ActionResultType.SUCCESS;
}
@Override

View file

@ -86,12 +86,12 @@ public class DeployerBlock extends DirectionalAxisKineticBlock
BlockRayTraceResult hit) {
ItemStack heldByPlayer = player.getHeldItem(handIn).copy();
if (AllItems.WRENCH.typeOf(heldByPlayer))
return false;
return ActionResultType.PASS;
if (hit.getFace() != state.get(FACING))
return false;
return ActionResultType.PASS;
if (worldIn.isRemote)
return true;
return ActionResultType.SUCCESS;
withTileEntityDo(worldIn, pos, te -> {
ItemStack heldByDeployer = te.player.getHeldItemMainhand().copy();
@ -103,7 +103,7 @@ public class DeployerBlock extends DirectionalAxisKineticBlock
te.sendData();
});
return true;
return ActionResultType.SUCCESS;
}
@Override

View file

@ -58,15 +58,15 @@ public class MillstoneBlock extends KineticBlock {
public ActionResultType onUse(BlockState state, World worldIn, BlockPos pos, PlayerEntity player, Hand handIn,
BlockRayTraceResult hit) {
if (!player.getHeldItem(handIn).isEmpty())
return false;
return ActionResultType.PASS;
if (worldIn.getTileEntity(pos) == null)
return false;
return ActionResultType.PASS;
if (worldIn.isRemote)
return true;
return ActionResultType.SUCCESS;
TileEntity tileEntity = worldIn.getTileEntity(pos);
if (!(tileEntity instanceof MillstoneTileEntity))
return false;
return ActionResultType.PASS;
MillstoneTileEntity millstone = (MillstoneTileEntity) tileEntity;
IItemHandlerModifiable inv = millstone.outputInv;
@ -76,7 +76,7 @@ public class MillstoneBlock extends KineticBlock {
}
millstone.markDirty();
millstone.sendData();
return true;
return ActionResultType.SUCCESS;
}
@Override

View file

@ -52,9 +52,9 @@ public class BasinBlock extends Block implements IWithTileEntity<BasinTileEntity
public ActionResultType onUse(BlockState state, World worldIn, BlockPos pos, PlayerEntity player, Hand handIn,
BlockRayTraceResult hit) {
if (!player.getHeldItem(handIn).isEmpty())
return false;
return ActionResultType.PASS;
if (worldIn.getTileEntity(pos) == null)
return false;
return ActionResultType.PASS;
BasinTileEntity te = (BasinTileEntity) worldIn.getTileEntity(pos);
IItemHandlerModifiable inv = te.inventory.orElse(new ItemStackHandler(1));
@ -64,7 +64,7 @@ public class BasinBlock extends Block implements IWithTileEntity<BasinTileEntity
}
te.onEmptied();
return true;
return ActionResultType.SUCCESS;
}
@Override

View file

@ -48,18 +48,18 @@ public class AnalogLeverBlock extends HorizontalFaceBlock implements IWithTileEn
BlockRayTraceResult hit) {
if (worldIn.isRemote) {
addParticles(state, worldIn, pos, 1.0F);
return true;
return ActionResultType.SUCCESS;
}
boolean sneak = player.isSneaking();
AnalogLeverTileEntity te = getTileEntity(worldIn, pos);
if (te == null)
return true;
return ActionResultType.SUCCESS;
te.changeState(sneak);
float f = .25f + ((te.state + 5) / 15f) * .5f;
worldIn.playSound(null, pos, SoundEvents.BLOCK_LEVER_CLICK, SoundCategory.BLOCKS, 0.2F, f);
return true;
return ActionResultType.SUCCESS;
}
@Override

View file

@ -81,17 +81,17 @@ public class SequencedGearshiftBlock extends HorizontalAxisKineticBlock
BlockRayTraceResult hit) {
ItemStack held = player.getHeldItemMainhand();
if (AllItems.WRENCH.typeOf(held))
return false;
return ActionResultType.PASS;
if (held.getItem() instanceof BlockItem) {
BlockItem blockItem = (BlockItem) held.getItem();
if (blockItem.getBlock() instanceof KineticBlock && hasShaftTowards(worldIn, pos, state, hit.getFace()))
return false;
return ActionResultType.PASS;
}
DistExecutor.runWhenOn(Dist.CLIENT, () -> () -> {
displayScreen((SequencedGearshiftTileEntity) worldIn.getTileEntity(pos));
});
return true;
return ActionResultType.SUCCESS;
}
@OnlyIn(value = Dist.CLIENT)

View file

@ -202,7 +202,7 @@ public class BeltBlock extends HorizontalKineticBlock
public ActionResultType onUse(BlockState state, World worldIn, BlockPos pos, PlayerEntity player, Hand handIn,
BlockRayTraceResult hit) {
if (player.isSneaking() || !player.isAllowEdit())
return false;
return ActionResultType.PASS;
ItemStack heldItem = player.getHeldItem(handIn);
boolean isShaft = heldItem.getItem() == AllBlocks.SHAFT.get().asItem();
boolean isCasing = heldItem.getItem() == AllBlocks.BRASS_CASING.get().asItem();
@ -211,7 +211,7 @@ public class BeltBlock extends HorizontalKineticBlock
if (isDye) {
if (worldIn.isRemote)
return true;
return ActionResultType.SUCCESS;
withTileEntityDo(worldIn, pos, te -> {
DyeColor dyeColor = DyeColor.getColor(heldItem);
if (dyeColor == null)
@ -220,20 +220,20 @@ public class BeltBlock extends HorizontalKineticBlock
});
if (!player.isCreative())
heldItem.shrink(1);
return true;
return ActionResultType.SUCCESS;
}
TileEntity te = worldIn.getTileEntity(pos);
if (te == null || !(te instanceof BeltTileEntity))
return false;
return ActionResultType.PASS;
BeltTileEntity belt = (BeltTileEntity) te;
if (isHand) {
BeltTileEntity controllerBelt = belt.getControllerTE();
if (controllerBelt == null)
return false;
return ActionResultType.PASS;
if (worldIn.isRemote)
return true;
return ActionResultType.SUCCESS;
controllerBelt.getInventory().forEachWithin(belt.index + .5f, .55f, (transportedItemStack) -> {
player.inventory.placeItemBackInInventory(worldIn, transportedItemStack.stack);
return Collections.emptyList();
@ -242,28 +242,28 @@ public class BeltBlock extends HorizontalKineticBlock
if (isShaft) {
if (state.get(PART) != Part.MIDDLE)
return false;
return ActionResultType.PASS;
if (worldIn.isRemote)
return true;
return ActionResultType.SUCCESS;
if (!player.isCreative())
heldItem.shrink(1);
worldIn.setBlockState(pos, state.with(PART, Part.PULLEY), 2);
belt.attachKinetics();
return true;
return ActionResultType.SUCCESS;
}
if (isCasing) {
if (state.get(CASING))
return false;
return ActionResultType.PASS;
if (state.get(SLOPE) == Slope.VERTICAL)
return false;
return ActionResultType.PASS;
if (!player.isCreative())
heldItem.shrink(1);
worldIn.setBlockState(pos, state.with(CASING, true), 2);
return true;
return ActionResultType.SUCCESS;
}
return false;
return ActionResultType.PASS;
}
@Override

View file

@ -122,7 +122,7 @@ public class RedstoneLinkBlock extends ProperDirectionalBlock {
if (player.isSneaking()) {
RedstoneLinkTileEntity te = (RedstoneLinkTileEntity) worldIn.getTileEntity(pos);
if (te == null)
return false;
return ActionResultType.PASS;
if (!worldIn.isRemote) {
Boolean wasReceiver = state.get(RECEIVER);
@ -133,10 +133,10 @@ public class RedstoneLinkBlock extends ProperDirectionalBlock {
} else
te.transmit(false);
}
return true;
return ActionResultType.SUCCESS;
}
return false;
return ActionResultType.PASS;
}
@Override

View file

@ -192,10 +192,10 @@ public class FunnelBlock extends AttachedLogisticalBlock implements IBeltAttachm
if (!ItemStack.areItemStacksEqual(remainder, heldItem))
player.setHeldItem(handIn, remainder);
});
return true;
return ActionResultType.SUCCESS;
}
return false;
return ActionResultType.PASS;
}
public boolean process(BeltTileEntity belt, TransportedItemStack transported, BeltAttachmentState state) {

View file

@ -6,6 +6,8 @@ import net.minecraft.block.Block;
import net.minecraft.block.BlockState;
import net.minecraft.state.BooleanProperty;
import net.minecraft.state.StateContainer.Builder;
import net.minecraft.util.ActionResult;
import net.minecraft.util.ActionResultType;
import net.minecraft.util.Direction;
import net.minecraft.util.math.BlockPos;
import net.minecraft.world.IBlockReader;
@ -81,12 +83,12 @@ public class LatchBlock extends ToggleLatchBlock {
}
@Override
protected boolean activated(World worldIn, BlockPos pos, BlockState state) {
protected ActionResultType activated(World worldIn, BlockPos pos, BlockState state) {
if (state.get(POWERED) != state.get(POWERED_SIDE))
return false;
return ActionResultType.PASS;
if (!worldIn.isRemote)
worldIn.setBlockState(pos, state.cycle(POWERING), 2);
return true;
return ActionResultType.SUCCESS;
}
@Override

View file

@ -46,9 +46,9 @@ public class ToggleLatchBlock extends RedstoneDiodeBlock {
public ActionResultType onUse(BlockState state, World worldIn, BlockPos pos, PlayerEntity player, Hand handIn,
BlockRayTraceResult hit) {
if (!player.isAllowEdit())
return false;
return ActionResultType.PASS;
if (player.isSneaking())
return false;
return ActionResultType.PASS;
return activated(worldIn, pos, state);
}
@ -66,10 +66,10 @@ public class ToggleLatchBlock extends RedstoneDiodeBlock {
worldIn.setBlockState(pos, newState.cycle(POWERING), 2);
}
protected boolean activated(World worldIn, BlockPos pos, BlockState state) {
protected ActionResultType activated(World worldIn, BlockPos pos, BlockState state) {
if (!worldIn.isRemote)
worldIn.setBlockState(pos, state.cycle(POWERING), 2);
return true;
return ActionResultType.SUCCESS;
}
@Override

View file

@ -117,7 +117,7 @@ public class FlexcrateBlock extends ProperDirectionalBlock {
BlockRayTraceResult hit) {
if (worldIn.isRemote) {
return true;
return ActionResultType.SUCCESS;
} else {
TileEntity te = worldIn.getTileEntity(pos);
if (te instanceof FlexcrateTileEntity) {
@ -125,7 +125,7 @@ public class FlexcrateBlock extends ProperDirectionalBlock {
fte = fte.getMainCrate();
NetworkHooks.openGui((ServerPlayerEntity) player, fte, fte::sendToContainer);
}
return true;
return ActionResultType.SUCCESS;
}
}

View file

@ -65,12 +65,12 @@ public class SchematicTableBlock extends HorizontalBlock {
BlockRayTraceResult hit) {
if (worldIn.isRemote) {
return true;
return ActionResultType.SUCCESS;
} else {
SchematicTableTileEntity te = (SchematicTableTileEntity) worldIn.getTileEntity(pos);
if (te != null)
NetworkHooks.openGui((ServerPlayerEntity) player, te, te::sendToContainer);
return true;
return ActionResultType.SUCCESS;
}
}

View file

@ -60,7 +60,7 @@ public class SchematicannonBlock extends Block {
BlockRayTraceResult hit) {
if (worldIn.isRemote) {
return true;
return ActionResultType.SUCCESS;
} else {
SchematicannonTileEntity te = (SchematicannonTileEntity) worldIn.getTileEntity(pos);
if (te != null)
@ -70,7 +70,7 @@ public class SchematicannonBlock extends Block {
player.inventory.setInventorySlotContents(player.inventory.currentItem, ItemStack.EMPTY);
}
NetworkHooks.openGui((ServerPlayerEntity) player, te, te::sendToContainer);
return true;
return ActionResultType.SUCCESS;
}
}