More portable blocks

- Fixed latch hotfix still not making it work properly
- Cocoa pods can now be harvested by harvesters
- Fans, RSCs, basins, stockpile switches, gauges, engines, cranks and other blocks can now be moved in a contraption
- Most of creates technical blocks can now be picked up using a wrench
- Fixed Stockpile switch not reacting to movement.
- Fixed Stockpile switch not reacting to changes to a double container
- Chassis range display no longer shows the overlay for non-sticky directions
This commit is contained in:
simibubi 2020-05-09 12:14:26 +02:00
parent 4cbf424f4d
commit 0bd3a8d880
28 changed files with 167 additions and 69 deletions

View file

@ -10,11 +10,13 @@ import net.minecraft.block.Block;
import net.minecraft.block.BlockState;
import net.minecraft.block.Blocks;
import net.minecraft.entity.player.PlayerEntity;
import net.minecraft.item.ItemUseContext;
import net.minecraft.util.ActionResultType;
import net.minecraft.util.math.BlockPos;
import net.minecraft.world.IBlockReader;
import net.minecraftforge.common.ToolType;
public class CasingBlock extends Block implements IHaveConnectedTextures {
public class CasingBlock extends Block implements IHaveConnectedTextures, IWrenchable {
String textureFrom;
@ -22,6 +24,11 @@ public class CasingBlock extends Block implements IHaveConnectedTextures {
super(Properties.from(Blocks.ANDESITE));
this.textureFrom = textureFrom;
}
@Override
public ActionResultType onWrenched(BlockState state, ItemUseContext context) {
return ActionResultType.FAIL;
}
@Override
public ToolType getHarvestTool(BlockState state) {

View file

@ -27,6 +27,8 @@ public interface IWrenchable {
KineticTileEntity.switchToBlockState(world, context.getPos(), updateAfterWrenched(rotated, context));
TileEntity te = context.getWorld().getTileEntity(context.getPos());
if (te != null)
te.updateContainingBlockInfo();
if (te instanceof GeneratingKineticTileEntity) {
((GeneratingKineticTileEntity) te).updateGeneratedRotation();
}

View file

@ -4,7 +4,6 @@ import com.simibubi.create.foundation.item.ItemDescription.Palette;
import net.minecraft.block.Block;
import net.minecraft.block.BlockState;
import net.minecraft.block.material.PushReaction;
import net.minecraft.entity.LivingEntity;
import net.minecraft.entity.player.PlayerEntity;
import net.minecraft.item.ItemStack;
@ -71,11 +70,6 @@ public abstract class KineticBlock extends Block implements IRotate {
return true;
}
@Override
public PushReaction getPushReaction(BlockState state) {
return PushReaction.BLOCK;
}
@Override
public abstract TileEntity createTileEntity(BlockState state, IBlockReader world);

View file

@ -359,8 +359,12 @@ public abstract class KineticTileEntity extends SmartTileEntity
return;
TileEntity tileEntityIn = world.getTileEntity(pos);
if (!(tileEntityIn instanceof KineticTileEntity))
boolean isKinetic = tileEntityIn instanceof KineticTileEntity;
if (!isKinetic) {
world.setBlockState(pos, state, 3);
return;
}
KineticTileEntity tileEntity = (KineticTileEntity) tileEntityIn;
if (tileEntity.hasNetwork())

View file

@ -1,6 +1,7 @@
package com.simibubi.create.modules.contraptions.components.actors;
import com.simibubi.create.foundation.utility.AllShapes;
import com.simibubi.create.modules.contraptions.IWrenchable;
import com.simibubi.create.modules.contraptions.components.contraptions.IPortableBlock;
import net.minecraft.block.Block;
@ -8,7 +9,9 @@ import net.minecraft.block.BlockState;
import net.minecraft.block.Blocks;
import net.minecraft.block.HorizontalBlock;
import net.minecraft.item.BlockItemUseContext;
import net.minecraft.item.ItemUseContext;
import net.minecraft.state.StateContainer.Builder;
import net.minecraft.util.ActionResultType;
import net.minecraft.util.Direction;
import net.minecraft.util.math.BlockPos;
import net.minecraft.util.math.shapes.ISelectionContext;
@ -16,11 +19,16 @@ import net.minecraft.util.math.shapes.VoxelShape;
import net.minecraft.world.IBlockReader;
import net.minecraft.world.IWorldReader;
public abstract class AttachedActorBlock extends HorizontalBlock implements IPortableBlock {
public abstract class AttachedActorBlock extends HorizontalBlock implements IPortableBlock, IWrenchable {
public AttachedActorBlock() {
super(Properties.from(Blocks.IRON_BLOCK));
}
@Override
public ActionResultType onWrenched(BlockState state, ItemUseContext context) {
return ActionResultType.FAIL;
}
@Override
public VoxelShape getShape(BlockState state, IBlockReader worldIn, BlockPos pos, ISelectionContext context) {

View file

@ -12,6 +12,7 @@ import com.simibubi.create.modules.contraptions.components.contraptions.Movement
import net.minecraft.block.BlockState;
import net.minecraft.block.Blocks;
import net.minecraft.block.CocoaBlock;
import net.minecraft.block.CropsBlock;
import net.minecraft.block.KelpBlock;
import net.minecraft.block.SugarCaneBlock;
@ -81,7 +82,7 @@ public class HarvesterMovementBehaviour extends MovementBehaviour {
return false;
return true;
}
if (state.getCollisionShape(world, pos).isEmpty()) {
if (state.getCollisionShape(world, pos).isEmpty() || state.getBlock() instanceof CocoaBlock) {
for (IProperty<?> property : state.getProperties()) {
if (!(property instanceof IntegerProperty))
continue;
@ -96,14 +97,14 @@ public class HarvesterMovementBehaviour extends MovementBehaviour {
return false;
}
private boolean isValidOther(World world, BlockPos pos, BlockState state) {
if (state.getBlock() instanceof CropsBlock)
return false;
if (state.getBlock() instanceof SugarCaneBlock)
return true;
if (state.getCollisionShape(world, pos).isEmpty()) {
if (state.getCollisionShape(world, pos).isEmpty() || state.getBlock() instanceof CocoaBlock) {
for (IProperty<?> property : state.getProperties()) {
if (!(property instanceof IntegerProperty))
continue;
@ -131,7 +132,7 @@ public class HarvesterMovementBehaviour extends MovementBehaviour {
return Blocks.AIR.getDefaultState();
return state.getFluidState().getBlockState();
}
if (state.getCollisionShape(world, pos).isEmpty()) {
if (state.getCollisionShape(world, pos).isEmpty() || state.getBlock() instanceof CocoaBlock) {
for (IProperty<?> property : state.getProperties()) {
if (!(property instanceof IntegerProperty))
continue;

View file

@ -13,6 +13,9 @@ import com.simibubi.create.modules.contraptions.components.contraptions.piston.M
import com.simibubi.create.modules.contraptions.components.contraptions.piston.MechanicalPistonBlock.PistonState;
import com.simibubi.create.modules.contraptions.components.contraptions.pulley.PulleyBlock;
import com.simibubi.create.modules.contraptions.components.contraptions.pulley.PulleyTileEntity;
import com.simibubi.create.modules.contraptions.components.crank.HandCrankBlock;
import com.simibubi.create.modules.contraptions.components.fan.NozzleBlock;
import com.simibubi.create.modules.contraptions.components.flywheel.engine.EngineBlock;
import com.simibubi.create.modules.contraptions.components.contraptions.pulley.PulleyBlock.MagnetBlock;
import com.simibubi.create.modules.contraptions.components.contraptions.pulley.PulleyBlock.RopeBlock;
import com.simibubi.create.modules.logistics.block.AttachedLogisticalBlock;
@ -105,6 +108,8 @@ public class BlockMovementTraits {
Block block = state.getBlock();
if (state.has(BlockStateProperties.HANGING))
return true;
if (block instanceof HandCrankBlock)
return true;
if (block instanceof LadderBlock)
return true;
if (block instanceof ExtractorBlock)
@ -131,8 +136,12 @@ public class BlockMovementTraits {
return true;
if (block instanceof RopeBlock)
return true;
if (block instanceof NozzleBlock)
return true;
if (block instanceof MagnetBlock)
return true;
if (block instanceof EngineBlock)
return true;
return false;
}
@ -178,6 +187,12 @@ public class BlockMovementTraits {
return direction == Direction.DOWN;
if (block instanceof AttachedActorBlock)
return direction == state.get(HarvesterBlock.HORIZONTAL_FACING).getOpposite();
if (block instanceof HandCrankBlock)
return direction == state.get(HandCrankBlock.FACING).getOpposite();
if (block instanceof NozzleBlock)
return direction == state.get(NozzleBlock.FACING).getOpposite();
if (block instanceof EngineBlock)
return direction == state.get(EngineBlock.HORIZONTAL_FACING).getOpposite();
return false;
}

View file

@ -7,6 +7,7 @@ import com.simibubi.create.AllBlocks;
import com.simibubi.create.modules.contraptions.components.actors.BlockBreakingMovementBehaviour;
import net.minecraft.block.BlockState;
import net.minecraft.block.CocoaBlock;
import net.minecraft.block.material.PushReaction;
import net.minecraft.client.Minecraft;
import net.minecraft.entity.Entity;
@ -272,7 +273,8 @@ public class ContraptionCollider {
if (AllBlocks.PULLEY_MAGNET.typeOf(collidedState) && pos.equals(BlockPos.ZERO)
&& movementDirection == Direction.UP)
continue;
if (collidedState.getBlock() instanceof CocoaBlock)
continue;
if (!collidedState.getMaterial().isReplaceable()
&& !collidedState.getCollisionShape(world, colliderPos).isEmpty()) {
return true;

View file

@ -24,7 +24,7 @@ public abstract class BearingBlock extends DirectionalKineticBlock {
protected boolean hasStaticPart() {
return true;
}
@Override
public Axis getRotationAxis(BlockState state) {
return state.get(FACING).getAxis();

View file

@ -1,6 +1,7 @@
package com.simibubi.create.modules.contraptions.components.contraptions.chassis;
import com.simibubi.create.AllSoundEvents;
import com.simibubi.create.modules.contraptions.IWrenchable;
import net.minecraft.block.BlockState;
import net.minecraft.block.RotatedPillarBlock;
@ -21,7 +22,7 @@ import net.minecraft.world.IBlockReader;
import net.minecraft.world.World;
import net.minecraftforge.common.Tags;
public abstract class AbstractChassisBlock extends RotatedPillarBlock {
public abstract class AbstractChassisBlock extends RotatedPillarBlock implements IWrenchable {
public AbstractChassisBlock(Properties properties) {
super(properties);

View file

@ -46,8 +46,9 @@ public class ChassisTileEntity extends SmartTileEntity {
te -> ((ChassisTileEntity) te).collectChassisGroup());
range.requiresWrench();
range.between(1, max);
range.withClientCallback(
i -> DistExecutor.runWhenOn(Dist.CLIENT, () -> () -> ChassisRangeDisplay.display(this)));
range
.withClientCallback(
i -> DistExecutor.runWhenOn(Dist.CLIENT, () -> () -> ChassisRangeDisplay.display(this)));
range.value = max / 2;
behaviours.add(range);
}
@ -161,7 +162,7 @@ public class ChassisTileEntity extends SmartTileEntity {
BlockPos current = pos.offset(facing, i);
BlockState currentState = world.getBlockState(current);
if (forcedMovement != facing && !visualize && !sticky)
if (forcedMovement != facing && !sticky)
break;
// Ignore replaceable Blocks and Air-like

View file

@ -4,6 +4,7 @@ import com.simibubi.create.AllBlocks;
import com.simibubi.create.foundation.block.ITE;
import com.simibubi.create.foundation.block.RenderUtilityBlock;
import com.simibubi.create.foundation.utility.AllShapes;
import com.simibubi.create.modules.contraptions.IWrenchable;
import com.simibubi.create.modules.contraptions.components.contraptions.ContraptionEntity;
import com.simibubi.create.modules.contraptions.components.contraptions.mounted.CartAssemblerTileEntity.CartMovementMode;
@ -32,7 +33,7 @@ import net.minecraft.util.math.shapes.VoxelShapes;
import net.minecraft.world.IBlockReader;
import net.minecraft.world.World;
public class CartAssemblerBlock extends AbstractRailBlock implements ITE<CartAssemblerTileEntity> {
public class CartAssemblerBlock extends AbstractRailBlock implements ITE<CartAssemblerTileEntity>, IWrenchable {
public static IProperty<RailShape> RAIL_SHAPE =
EnumProperty.create("shape", RailShape.class, RailShape.EAST_WEST, RailShape.NORTH_SOUTH);

View file

@ -3,6 +3,7 @@ package com.simibubi.create.modules.contraptions.components.contraptions.piston;
import com.simibubi.create.AllBlocks;
import com.simibubi.create.foundation.block.ProperDirectionalBlock;
import com.simibubi.create.foundation.utility.AllShapes;
import com.simibubi.create.modules.contraptions.IWrenchable;
import com.simibubi.create.modules.contraptions.components.contraptions.piston.MechanicalPistonBlock.PistonState;
import net.minecraft.block.BlockState;
@ -20,7 +21,7 @@ import net.minecraft.util.math.shapes.VoxelShape;
import net.minecraft.world.IBlockReader;
import net.minecraft.world.World;
public class PistonPoleBlock extends ProperDirectionalBlock {
public class PistonPoleBlock extends ProperDirectionalBlock implements IWrenchable {
public PistonPoleBlock() {
super(Properties.from(Blocks.PISTON_HEAD));

View file

@ -3,11 +3,14 @@ package com.simibubi.create.modules.contraptions.components.fan;
import com.simibubi.create.AllBlocks;
import com.simibubi.create.foundation.block.ProperDirectionalBlock;
import com.simibubi.create.foundation.utility.AllShapes;
import com.simibubi.create.modules.contraptions.IWrenchable;
import net.minecraft.block.Block;
import net.minecraft.block.BlockState;
import net.minecraft.item.BlockItemUseContext;
import net.minecraft.item.ItemUseContext;
import net.minecraft.tileentity.TileEntity;
import net.minecraft.util.ActionResultType;
import net.minecraft.util.BlockRenderLayer;
import net.minecraft.util.Direction;
import net.minecraft.util.math.BlockPos;
@ -17,7 +20,7 @@ import net.minecraft.world.IBlockReader;
import net.minecraft.world.IWorldReader;
import net.minecraft.world.World;
public class NozzleBlock extends ProperDirectionalBlock {
public class NozzleBlock extends ProperDirectionalBlock implements IWrenchable {
public NozzleBlock() {
super(Properties.from(AllBlocks.ENCASED_FAN.get()));
@ -28,6 +31,11 @@ public class NozzleBlock extends ProperDirectionalBlock {
return true;
}
@Override
public ActionResultType onWrenched(BlockState state, ItemUseContext context) {
return ActionResultType.FAIL;
}
@Override
public TileEntity createTileEntity(BlockState state, IBlockReader world) {
return new NozzleTileEntity();

View file

@ -3,14 +3,16 @@ package com.simibubi.create.modules.contraptions.components.flywheel.engine;
import javax.annotation.Nullable;
import com.simibubi.create.AllBlockPartials;
import com.simibubi.create.modules.contraptions.IWrenchable;
import net.minecraft.block.Block;
import net.minecraft.block.BlockState;
import net.minecraft.block.HorizontalBlock;
import net.minecraft.block.material.PushReaction;
import net.minecraft.item.BlockItemUseContext;
import net.minecraft.item.ItemUseContext;
import net.minecraft.state.StateContainer.Builder;
import net.minecraft.tileentity.TileEntity;
import net.minecraft.util.ActionResultType;
import net.minecraft.util.Direction;
import net.minecraft.util.math.BlockPos;
import net.minecraft.world.IBlockReader;
@ -19,7 +21,7 @@ import net.minecraft.world.World;
import net.minecraftforge.api.distmarker.Dist;
import net.minecraftforge.api.distmarker.OnlyIn;
public abstract class EngineBlock extends HorizontalBlock {
public abstract class EngineBlock extends HorizontalBlock implements IWrenchable {
protected EngineBlock(Properties builder) {
super(builder);
@ -36,10 +38,10 @@ public abstract class EngineBlock extends HorizontalBlock {
}
@Override
public PushReaction getPushReaction(BlockState state) {
return PushReaction.BLOCK;
public ActionResultType onWrenched(BlockState state, ItemUseContext context) {
return ActionResultType.FAIL;
}
@Override
public abstract TileEntity createTileEntity(BlockState state, IBlockReader world);

View file

@ -5,16 +5,18 @@ import com.simibubi.create.foundation.advancement.AllTriggers;
import com.simibubi.create.foundation.block.ITE;
import com.simibubi.create.foundation.item.ItemHelper;
import com.simibubi.create.foundation.utility.AllShapes;
import com.simibubi.create.modules.contraptions.IWrenchable;
import net.minecraft.block.Block;
import net.minecraft.block.BlockState;
import net.minecraft.block.Blocks;
import net.minecraft.block.material.PushReaction;
import net.minecraft.entity.Entity;
import net.minecraft.entity.item.ItemEntity;
import net.minecraft.entity.player.PlayerEntity;
import net.minecraft.item.ItemStack;
import net.minecraft.item.ItemUseContext;
import net.minecraft.tileentity.TileEntity;
import net.minecraft.util.ActionResultType;
import net.minecraft.util.Hand;
import net.minecraft.util.math.BlockPos;
import net.minecraft.util.math.BlockRayTraceResult;
@ -26,7 +28,7 @@ import net.minecraftforge.items.IItemHandlerModifiable;
import net.minecraftforge.items.ItemHandlerHelper;
import net.minecraftforge.items.ItemStackHandler;
public class BasinBlock extends Block implements ITE<BasinTileEntity> {
public class BasinBlock extends Block implements ITE<BasinTileEntity>, IWrenchable {
public BasinBlock() {
super(Properties.from(Blocks.ANDESITE));
@ -41,10 +43,10 @@ public class BasinBlock extends Block implements ITE<BasinTileEntity> {
public TileEntity createTileEntity(BlockState state, IBlockReader world) {
return new BasinTileEntity();
}
@Override
public PushReaction getPushReaction(BlockState state) {
return PushReaction.BLOCK;
public ActionResultType onWrenched(BlockState state, ItemUseContext context) {
return ActionResultType.FAIL;
}
@Override

View file

@ -4,6 +4,7 @@ import java.util.Random;
import com.simibubi.create.AllBlocks;
import com.simibubi.create.foundation.block.ProperDirectionalBlock;
import com.simibubi.create.modules.contraptions.IWrenchable;
import com.simibubi.create.modules.contraptions.components.contraptions.IPortableBlock;
import com.simibubi.create.modules.contraptions.components.contraptions.MovementBehaviour;
@ -20,7 +21,7 @@ import net.minecraft.world.IBlockReader;
import net.minecraft.world.IWorld;
import net.minecraft.world.World;
public class ContactBlock extends ProperDirectionalBlock implements IPortableBlock {
public class ContactBlock extends ProperDirectionalBlock implements IPortableBlock, IWrenchable {
public static final BooleanProperty POWERED = BlockStateProperties.POWERED;
public static MovementBehaviour MOVEMENT = new ContactMovementBehaviour();

View file

@ -5,6 +5,7 @@ import java.util.Random;
import com.simibubi.create.foundation.utility.ColorHelper;
import com.simibubi.create.foundation.utility.Lang;
import com.simibubi.create.foundation.utility.VecHelper;
import com.simibubi.create.foundation.utility.WrappedWorld;
import com.simibubi.create.modules.contraptions.base.DirectionalAxisKineticBlock;
import com.simibubi.create.modules.contraptions.base.IRotate;
@ -79,13 +80,16 @@ public class GaugeBlock extends DirectionalAxisKineticBlock {
Direction nearestLookingDirection = context.getNearestLookingDirection();
boolean lookPositive = nearestLookingDirection.getAxisDirection() == AxisDirection.POSITIVE;
if (face.getAxis() == Axis.X) {
toPlace = toPlace.with(FACING, lookPositive ? Direction.NORTH : Direction.SOUTH)
toPlace = toPlace
.with(FACING, lookPositive ? Direction.NORTH : Direction.SOUTH)
.with(AXIS_ALONG_FIRST_COORDINATE, true);
} else if (face.getAxis() == Axis.Y) {
toPlace = toPlace.with(FACING, horizontalFacing.getOpposite()).with(AXIS_ALONG_FIRST_COORDINATE,
horizontalFacing.getAxis() == Axis.X);
toPlace = toPlace
.with(FACING, horizontalFacing.getOpposite())
.with(AXIS_ALONG_FIRST_COORDINATE, horizontalFacing.getAxis() == Axis.X);
} else {
toPlace = toPlace.with(FACING, lookPositive ? Direction.WEST : Direction.EAST)
toPlace = toPlace
.with(FACING, lookPositive ? Direction.WEST : Direction.EAST)
.with(AXIS_ALONG_FIRST_COORDINATE, false);
}
@ -119,8 +123,8 @@ public class GaugeBlock extends DirectionalAxisKineticBlock {
if (getRotationAxis(state) == Axis.Y && face != state.get(FACING))
return false;
BlockState blockState = world.getBlockState(pos.offset(face));
if (Block.hasSolidSide(blockState, world, pos, face.getOpposite())
&& blockState.getMaterial() != Material.GLASS)
if (Block.hasSolidSide(blockState, world, pos, face.getOpposite()) && blockState.getMaterial() != Material.GLASS
&& !(world instanceof WrappedWorld))
return false;
return true;
}
@ -149,11 +153,15 @@ public class GaugeBlock extends DirectionalAxisKineticBlock {
continue;
for (int i = 0; i < particleCount; i++) {
Vec3d mul = VecHelper.offsetRandomly(Vec3d.ZERO, rand, .25f)
.mul(new Vec3d(1, 1, 1).subtract(positiveFaceVec)).normalize().scale(.3f);
Vec3d mul = VecHelper
.offsetRandomly(Vec3d.ZERO, rand, .25f)
.mul(new Vec3d(1, 1, 1).subtract(positiveFaceVec))
.normalize()
.scale(.3f);
Vec3d offset = VecHelper.getCenterOf(pos).add(faceVec.scale(.55)).add(mul);
worldIn.addParticle(new RedstoneParticleData((float) rgb.x, (float) rgb.y, (float) rgb.z, 1), offset.x,
offset.y, offset.z, mul.x, mul.y, mul.z);
worldIn
.addParticle(new RedstoneParticleData((float) rgb.x, (float) rgb.y, (float) rgb.z, 1), offset.x,
offset.y, offset.z, mul.x, mul.y, mul.z);
}
}

View file

@ -2,6 +2,7 @@ package com.simibubi.create.modules.logistics.block;
import com.simibubi.create.AllBlocks;
import com.simibubi.create.foundation.block.IHaveNoBlockItem;
import com.simibubi.create.modules.contraptions.IWrenchable;
import com.simibubi.create.modules.contraptions.relays.belt.BeltBlock;
import com.simibubi.create.modules.logistics.block.transposer.TransposerBlock;
@ -13,8 +14,10 @@ import net.minecraft.block.material.PushReaction;
import net.minecraft.entity.player.PlayerEntity;
import net.minecraft.item.BlockItemUseContext;
import net.minecraft.item.ItemStack;
import net.minecraft.item.ItemUseContext;
import net.minecraft.state.BooleanProperty;
import net.minecraft.state.StateContainer.Builder;
import net.minecraft.util.ActionResultType;
import net.minecraft.util.Direction;
import net.minecraft.util.ResourceLocation;
import net.minecraft.util.math.BlockPos;
@ -23,7 +26,7 @@ import net.minecraft.world.IBlockReader;
import net.minecraft.world.IWorldReader;
import net.minecraft.world.World;
public abstract class AttachedLogisticalBlock extends HorizontalBlock implements IHaveNoBlockItem {
public abstract class AttachedLogisticalBlock extends HorizontalBlock implements IHaveNoBlockItem, IWrenchable {
public static final BooleanProperty UPWARD = BooleanProperty.create("upward");
@ -36,6 +39,11 @@ public abstract class AttachedLogisticalBlock extends HorizontalBlock implements
return !isVertical();
}
@Override
public ActionResultType onWrenched(BlockState state, ItemUseContext context) {
return ActionResultType.FAIL;
}
protected abstract boolean isVertical();
protected abstract BlockState getVerticalDefaultState();

View file

@ -1,13 +1,14 @@
package com.simibubi.create.modules.logistics.block;
import com.simibubi.create.AllItems;
import com.simibubi.create.foundation.block.ITE;
import com.simibubi.create.foundation.gui.ScreenOpener;
import com.simibubi.create.modules.contraptions.IWrenchable;
import net.minecraft.block.Block;
import net.minecraft.block.BlockState;
import net.minecraft.block.Blocks;
import net.minecraft.block.HorizontalBlock;
import net.minecraft.block.material.PushReaction;
import net.minecraft.client.entity.player.ClientPlayerEntity;
import net.minecraft.entity.player.PlayerEntity;
import net.minecraft.item.BlockItemUseContext;
@ -26,7 +27,7 @@ import net.minecraftforge.api.distmarker.OnlyIn;
import net.minecraftforge.fml.DistExecutor;
import net.minecraftforge.items.CapabilityItemHandler;
public class StockswitchBlock extends HorizontalBlock implements ITE<StockswitchTileEntity> {
public class StockswitchBlock extends HorizontalBlock implements ITE<StockswitchTileEntity>, IWrenchable {
public static final IntegerProperty INDICATOR = IntegerProperty.create("indicator", 0, 6);
@ -88,6 +89,8 @@ public class StockswitchBlock extends HorizontalBlock implements ITE<Stockswitch
@Override
public boolean onBlockActivated(BlockState state, World worldIn, BlockPos pos, PlayerEntity player, Hand handIn,
BlockRayTraceResult hit) {
if (player != null && AllItems.WRENCH.typeOf(player.getHeldItem(handIn)))
return false;
DistExecutor.runWhenOn(Dist.CLIENT,
() -> () -> withTileEntityDo(worldIn, pos, te -> this.displayScreen(te, player)));
return true;
@ -139,11 +142,6 @@ public class StockswitchBlock extends HorizontalBlock implements ITE<Stockswitch
return new StockswitchTileEntity();
}
@Override
public PushReaction getPushReaction(BlockState state) {
return PushReaction.BLOCK;
}
@Override
public Class<StockswitchTileEntity> getTileEntityClass() {
return StockswitchTileEntity.class;

View file

@ -1,7 +1,10 @@
package com.simibubi.create.modules.logistics.block;
import java.util.List;
import com.simibubi.create.AllTileEntities;
import com.simibubi.create.foundation.block.SyncedTileEntity;
import com.simibubi.create.foundation.behaviour.base.SmartTileEntity;
import com.simibubi.create.foundation.behaviour.base.TileEntityBehaviour;
import net.minecraft.block.BlockState;
import net.minecraft.item.ItemStack;
@ -15,7 +18,7 @@ import net.minecraftforge.common.util.LazyOptional;
import net.minecraftforge.items.CapabilityItemHandler;
import net.minecraftforge.items.IItemHandler;
public class StockswitchTileEntity extends SyncedTileEntity {
public class StockswitchTileEntity extends SmartTileEntity {
public float onWhenAbove;
public float offWhenBelow;
@ -34,6 +37,7 @@ public class StockswitchTileEntity extends SyncedTileEntity {
currentLevel = -1;
powered = false;
observedInventory = LazyOptional.empty();
setLazyTickRate(10);
}
@Override
@ -107,7 +111,17 @@ public class StockswitchTileEntity extends SyncedTileEntity {
world.notifyNeighbors(pos, getBlockState().getBlock());
}
@Override
public void lazyTick() {
super.lazyTick();
if (world.isRemote)
return;
findNewInventory();
updateCurrentLevel();
}
private boolean findNewInventory() {
observedInventory = LazyOptional.empty();
BlockPos invPos = getPos().offset(getBlockState().get(BlockStateProperties.HORIZONTAL_FACING));
if (!world.isBlockPresent(invPos))
@ -119,14 +133,19 @@ public class StockswitchTileEntity extends SyncedTileEntity {
TileEntity invTE = world.getTileEntity(invPos);
if (invTE == null)
return false;
observedInventory = invTE.getCapability(CapabilityItemHandler.ITEM_HANDLER_CAPABILITY);
if (observedInventory.isPresent()) {
updateCurrentLevel();
return true;
}
return false;
}
@Override
public void addBehaviours(List<TileEntityBehaviour> behaviours) {
}
}

View file

@ -0,0 +1,13 @@
package com.simibubi.create.modules.logistics.block.diodes;
import com.simibubi.create.modules.contraptions.IWrenchable;
import net.minecraft.block.RedstoneDiodeBlock;
public abstract class AbstractDiodeBlock extends RedstoneDiodeBlock implements IWrenchable {
public AbstractDiodeBlock(Properties builder) {
super(builder);
}
}

View file

@ -5,7 +5,6 @@ import com.simibubi.create.AllBlocks;
import net.minecraft.block.Block;
import net.minecraft.block.BlockState;
import net.minecraft.block.Blocks;
import net.minecraft.block.RedstoneDiodeBlock;
import net.minecraft.state.BooleanProperty;
import net.minecraft.state.StateContainer.Builder;
import net.minecraft.tileentity.TileEntity;
@ -13,7 +12,7 @@ import net.minecraft.util.Direction;
import net.minecraft.util.math.BlockPos;
import net.minecraft.world.IBlockReader;
public class FlexpeaterBlock extends RedstoneDiodeBlock {
public class FlexpeaterBlock extends AbstractDiodeBlock {
public static BooleanProperty POWERING = BooleanProperty.create("powering");

View file

@ -57,7 +57,8 @@ public class LatchBlock extends ToggleLatchBlock {
if (i > 0)
return true;
BlockState blockstate = worldIn.getBlockState(blockpos);
return blockstate.getBlock() == Blocks.REDSTONE_WIRE ? blockstate.get(RedstoneWireBlock.POWER) > 0 : false;
if (blockstate.getBlock() == Blocks.REDSTONE_WIRE && blockstate.get(RedstoneWireBlock.POWER) > 0)
return true;
}
return false;
}

View file

@ -5,7 +5,6 @@ import java.util.Random;
import net.minecraft.block.Block;
import net.minecraft.block.BlockState;
import net.minecraft.block.Blocks;
import net.minecraft.block.RedstoneDiodeBlock;
import net.minecraft.state.BooleanProperty;
import net.minecraft.state.StateContainer.Builder;
import net.minecraft.util.Direction;
@ -14,7 +13,7 @@ import net.minecraft.world.IBlockReader;
import net.minecraft.world.TickPriority;
import net.minecraft.world.World;
public class PulseRepeaterBlock extends RedstoneDiodeBlock {
public class PulseRepeaterBlock extends AbstractDiodeBlock {
public static BooleanProperty PULSING = BooleanProperty.create("pulsing");

View file

@ -2,10 +2,11 @@ package com.simibubi.create.modules.logistics.block.diodes;
import java.util.Random;
import com.simibubi.create.AllItems;
import net.minecraft.block.Block;
import net.minecraft.block.BlockState;
import net.minecraft.block.Blocks;
import net.minecraft.block.RedstoneDiodeBlock;
import net.minecraft.entity.player.PlayerEntity;
import net.minecraft.state.BooleanProperty;
import net.minecraft.state.StateContainer.Builder;
@ -16,10 +17,10 @@ import net.minecraft.util.math.BlockRayTraceResult;
import net.minecraft.world.IBlockReader;
import net.minecraft.world.World;
public class ToggleLatchBlock extends RedstoneDiodeBlock {
public class ToggleLatchBlock extends AbstractDiodeBlock {
public static BooleanProperty POWERING = BooleanProperty.create("powering");
public ToggleLatchBlock() {
super(Properties.from(Blocks.REPEATER));
setDefaultState(getDefaultState().with(POWERING, false).with(POWERED, false));
@ -29,17 +30,17 @@ public class ToggleLatchBlock extends RedstoneDiodeBlock {
protected void fillStateContainer(Builder<Block, BlockState> builder) {
builder.add(POWERED, POWERING, HORIZONTAL_FACING);
}
@Override
public int getWeakPower(BlockState blockState, IBlockReader blockAccess, BlockPos pos, Direction side) {
return blockState.get(HORIZONTAL_FACING) == side ? this.getActiveSignal(blockAccess, pos, blockState) : 0;
}
@Override
protected int getDelay(BlockState state) {
return 1;
}
@Override
public boolean onBlockActivated(BlockState state, World worldIn, BlockPos pos, PlayerEntity player, Hand handIn,
BlockRayTraceResult hit) {
@ -47,6 +48,8 @@ public class ToggleLatchBlock extends RedstoneDiodeBlock {
return false;
if (player.isSneaking())
return false;
if (AllItems.WRENCH.typeOf(player.getHeldItem(handIn)))
return false;
return activated(worldIn, pos, state);
}

View file

@ -2,6 +2,7 @@ package com.simibubi.create.modules.logistics.block.inventories;
import com.simibubi.create.foundation.block.ProperDirectionalBlock;
import com.simibubi.create.foundation.utility.AllShapes;
import com.simibubi.create.modules.contraptions.IWrenchable;
import net.minecraft.block.Block;
import net.minecraft.block.BlockState;
@ -16,7 +17,7 @@ import net.minecraft.world.IBlockReader;
import net.minecraft.world.IWorld;
import net.minecraft.world.World;
public class CrateBlock extends ProperDirectionalBlock {
public class CrateBlock extends ProperDirectionalBlock implements IWrenchable {
public static final BooleanProperty DOUBLE = BooleanProperty.create("double");

View file

@ -2,7 +2,6 @@ package com.simibubi.create.modules.logistics.block.transposer;
import com.simibubi.create.AllBlocks;
import com.simibubi.create.foundation.utility.AllShapes;
import com.simibubi.create.modules.contraptions.IWrenchable;
import com.simibubi.create.modules.logistics.block.belts.BeltAttachableLogisticalBlock;
import net.minecraft.block.Block;
@ -23,7 +22,7 @@ import net.minecraft.world.IBlockReader;
import net.minecraft.world.IWorldReader;
import net.minecraft.world.World;
public class TransposerBlock extends BeltAttachableLogisticalBlock implements IWrenchable {
public class TransposerBlock extends BeltAttachableLogisticalBlock {
public static BooleanProperty POWERED = BlockStateProperties.POWERED;