Cogwheel refactor Part I

- Moved hasIntegratedCogWheel and isSmallCog to ICogWheel
This commit is contained in:
grimmauld 2021-03-27 22:42:27 +01:00
parent 213711ce77
commit 4ff20b4217
15 changed files with 62 additions and 73 deletions

View file

@ -1,6 +1,5 @@
package com.simibubi.create.content.contraptions; package com.simibubi.create.content.contraptions;
import static com.simibubi.create.content.contraptions.relays.elementary.CogWheelBlock.isLargeCog;
import static net.minecraft.state.properties.BlockStateProperties.AXIS; import static net.minecraft.state.properties.BlockStateProperties.AXIS;
import java.util.LinkedList; import java.util.LinkedList;
@ -12,6 +11,7 @@ import com.simibubi.create.content.contraptions.base.KineticTileEntity;
import com.simibubi.create.content.contraptions.relays.advanced.SpeedControllerBlock; import com.simibubi.create.content.contraptions.relays.advanced.SpeedControllerBlock;
import com.simibubi.create.content.contraptions.relays.advanced.SpeedControllerTileEntity; import com.simibubi.create.content.contraptions.relays.advanced.SpeedControllerTileEntity;
import com.simibubi.create.content.contraptions.relays.elementary.CogWheelBlock; import com.simibubi.create.content.contraptions.relays.elementary.CogWheelBlock;
import com.simibubi.create.content.contraptions.relays.elementary.ICogWheel;
import com.simibubi.create.content.contraptions.relays.encased.DirectionalShaftHalvesTileEntity; import com.simibubi.create.content.contraptions.relays.encased.DirectionalShaftHalvesTileEntity;
import com.simibubi.create.content.contraptions.relays.encased.EncasedBeltBlock; import com.simibubi.create.content.contraptions.relays.encased.EncasedBeltBlock;
import com.simibubi.create.content.contraptions.relays.encased.SplitShaftTileEntity; import com.simibubi.create.content.contraptions.relays.encased.SplitShaftTileEntity;
@ -66,8 +66,8 @@ public class RotationPropagator {
alignedAxes && definitionFrom.hasShaftTowards(world, from.getPos(), stateFrom, direction) alignedAxes && definitionFrom.hasShaftTowards(world, from.getPos(), stateFrom, direction)
&& definitionTo.hasShaftTowards(world, to.getPos(), stateTo, direction.getOpposite()); && definitionTo.hasShaftTowards(world, to.getPos(), stateTo, direction.getOpposite());
boolean connectedByGears = definitionFrom.hasIntegratedCogwheel(world, from.getPos(), stateFrom) boolean connectedByGears = ICogWheel.isSmallCog(stateFrom)
&& definitionTo.hasIntegratedCogwheel(world, to.getPos(), stateTo); && ICogWheel.isSmallCog(stateTo);
float custom = from.propagateRotationTo(to, stateFrom, stateTo, diff, connectedByAxis, connectedByGears); float custom = from.propagateRotationTo(to, stateFrom, stateTo, diff, connectedByAxis, connectedByGears);
if (custom != 0) if (custom != 0)
@ -98,10 +98,10 @@ public class RotationPropagator {
} }
// Gear <-> Large Gear // Gear <-> Large Gear
if (isLargeCog(stateFrom) && definitionTo.hasIntegratedCogwheel(world, to.getPos(), stateTo)) if (ICogWheel.isLargeCog(stateFrom) && ICogWheel.isSmallCog(stateTo))
if (isLargeToSmallCog(stateFrom, stateTo, definitionTo, diff)) if (isLargeToSmallCog(stateFrom, stateTo, definitionTo, diff))
return -2f; return -2f;
if (isLargeCog(stateTo) && definitionFrom.hasIntegratedCogwheel(world, from.getPos(), stateFrom)) if (ICogWheel.isLargeCog(stateTo) && ICogWheel.isSmallCog(stateFrom))
if (isLargeToSmallCog(stateTo, stateFrom, definitionFrom, diff)) if (isLargeToSmallCog(stateTo, stateFrom, definitionFrom, diff))
return -.5f; return -.5f;
@ -109,7 +109,7 @@ public class RotationPropagator {
if (connectedByGears) { if (connectedByGears) {
if (diff.manhattanDistance(BlockPos.ZERO) != 1) if (diff.manhattanDistance(BlockPos.ZERO) != 1)
return 0; return 0;
if (isLargeCog(stateTo)) if (ICogWheel.isLargeCog(stateTo))
return 0; return 0;
if (direction.getAxis() == definitionFrom.getRotationAxis(stateFrom)) if (direction.getAxis() == definitionFrom.getRotationAxis(stateFrom))
return 0; return 0;
@ -137,7 +137,7 @@ public class RotationPropagator {
} }
private static boolean isLargeToLargeGear(BlockState from, BlockState to, BlockPos diff) { private static boolean isLargeToLargeGear(BlockState from, BlockState to, BlockPos diff) {
if (!isLargeCog(from) || !isLargeCog(to)) if (!ICogWheel.isLargeCog(from) || !ICogWheel.isLargeCog(to))
return false; return false;
Axis fromAxis = from.get(AXIS); Axis fromAxis = from.get(AXIS);
Axis toAxis = to.get(AXIS); Axis toAxis = to.get(AXIS);
@ -186,7 +186,7 @@ public class RotationPropagator {
} }
private static boolean isLargeCogToSpeedController(BlockState from, BlockState to, BlockPos diff) { private static boolean isLargeCogToSpeedController(BlockState from, BlockState to, BlockPos diff) {
if (!isLargeCog(from) || !AllBlocks.ROTATION_SPEED_CONTROLLER.has(to)) if (!ICogWheel.isLargeCog(from) || !AllBlocks.ROTATION_SPEED_CONTROLLER.has(to))
return false; return false;
if (!diff.equals(BlockPos.ZERO.down())) if (!diff.equals(BlockPos.ZERO.down()))
return false; return false;

View file

@ -119,8 +119,6 @@ public interface IRotate extends IWrenchable {
public boolean hasShaftTowards(IWorldReader world, BlockPos pos, BlockState state, Direction face); public boolean hasShaftTowards(IWorldReader world, BlockPos pos, BlockState state, Direction face);
public boolean hasIntegratedCogwheel(IWorldReader world, BlockPos pos, BlockState state);
public Axis getRotationAxis(BlockState state); public Axis getRotationAxis(BlockState state);
public default SpeedLevel getMinimumRequiredSpeedLevel() { public default SpeedLevel getMinimumRequiredSpeedLevel() {

View file

@ -72,11 +72,6 @@ public abstract class KineticBlock extends Block implements IRotate {
return false; return false;
} }
@Override
public boolean hasIntegratedCogwheel(IWorldReader world, BlockPos pos, BlockState state) {
return false;
}
@Override @Override
public boolean hasTileEntity(BlockState state) { public boolean hasTileEntity(BlockState state) {
return true; return true;

View file

@ -14,6 +14,7 @@ import com.simibubi.create.content.contraptions.base.IRotate.SpeedLevel;
import com.simibubi.create.content.contraptions.base.IRotate.StressImpact; import com.simibubi.create.content.contraptions.base.IRotate.StressImpact;
import com.simibubi.create.content.contraptions.goggles.IHaveGoggleInformation; import com.simibubi.create.content.contraptions.goggles.IHaveGoggleInformation;
import com.simibubi.create.content.contraptions.goggles.IHaveHoveringInformation; import com.simibubi.create.content.contraptions.goggles.IHaveHoveringInformation;
import com.simibubi.create.content.contraptions.relays.elementary.ICogWheel;
import com.simibubi.create.foundation.config.AllConfigs; import com.simibubi.create.foundation.config.AllConfigs;
import com.simibubi.create.foundation.item.TooltipHelper; import com.simibubi.create.foundation.item.TooltipHelper;
import com.simibubi.create.foundation.render.backend.FastRenderDispatcher; import com.simibubi.create.foundation.render.backend.FastRenderDispatcher;
@ -529,7 +530,7 @@ public abstract class KineticTileEntity extends SmartTileEntity
} }
protected boolean canPropagateDiagonally(IRotate block, BlockState state) { protected boolean canPropagateDiagonally(IRotate block, BlockState state) {
return block.hasIntegratedCogwheel(world, pos, state); return ICogWheel.isSmallCog(state);
} }
@Override @Override

View file

@ -6,6 +6,7 @@ import com.simibubi.create.AllBlocks;
import com.simibubi.create.CreateClient; import com.simibubi.create.CreateClient;
import com.simibubi.create.content.contraptions.KineticDebugger; import com.simibubi.create.content.contraptions.KineticDebugger;
import com.simibubi.create.content.contraptions.relays.elementary.CogWheelBlock; import com.simibubi.create.content.contraptions.relays.elementary.CogWheelBlock;
import com.simibubi.create.content.contraptions.relays.elementary.ICogWheel;
import com.simibubi.create.foundation.render.Compartment; import com.simibubi.create.foundation.render.Compartment;
import com.simibubi.create.foundation.render.SuperByteBuffer; import com.simibubi.create.foundation.render.SuperByteBuffer;
import com.simibubi.create.foundation.render.backend.FastRenderDispatcher; import com.simibubi.create.foundation.render.backend.FastRenderDispatcher;
@ -96,7 +97,7 @@ public class KineticTileEntityRenderer extends SafeTileEntityRenderer<KineticTil
} }
protected static float getRotationOffsetForPosition(KineticTileEntity te, final BlockPos pos, final Axis axis) { protected static float getRotationOffsetForPosition(KineticTileEntity te, final BlockPos pos, final Axis axis) {
float offset = CogWheelBlock.isLargeCog(te.getBlockState()) ? 11.25f : 0; float offset = ICogWheel.isLargeCog(te.getBlockState()) ? 11.25f : 0;
double d = (((axis == Axis.X) ? 0 : pos.getX()) + ((axis == Axis.Y) ? 0 : pos.getY()) double d = (((axis == Axis.X) ? 0 : pos.getX()) + ((axis == Axis.Y) ? 0 : pos.getY())
+ ((axis == Axis.Z) ? 0 : pos.getZ())) % 2; + ((axis == Axis.Z) ? 0 : pos.getZ())) % 2;
if (d == 0) { if (d == 0) {

View file

@ -2,6 +2,7 @@ package com.simibubi.create.content.contraptions.base;
import com.simibubi.create.AllBlocks; import com.simibubi.create.AllBlocks;
import com.simibubi.create.content.contraptions.relays.elementary.CogWheelBlock; import com.simibubi.create.content.contraptions.relays.elementary.CogWheelBlock;
import com.simibubi.create.content.contraptions.relays.elementary.ICogWheel;
import com.simibubi.create.content.contraptions.relays.elementary.ShaftBlock; import com.simibubi.create.content.contraptions.relays.elementary.ShaftBlock;
import com.simibubi.create.foundation.render.backend.instancing.*; import com.simibubi.create.foundation.render.backend.instancing.*;
import com.simibubi.create.foundation.render.backend.instancing.InstancedModel; import com.simibubi.create.foundation.render.backend.instancing.InstancedModel;
@ -62,7 +63,7 @@ public abstract class KineticTileInstance<T extends KineticTileEntity> extends T
} }
protected float getRotationOffset(final Direction.Axis axis) { protected float getRotationOffset(final Direction.Axis axis) {
float offset = CogWheelBlock.isLargeCog(blockState) ? 11.25f : 0; float offset = ICogWheel.isLargeCog(blockState) ? 11.25f : 0;
double d = (((axis == Direction.Axis.X) ? 0 : pos.getX()) + ((axis == Direction.Axis.Y) ? 0 : pos.getY()) double d = (((axis == Direction.Axis.X) ? 0 : pos.getX()) + ((axis == Direction.Axis.Y) ? 0 : pos.getY())
+ ((axis == Direction.Axis.Z) ? 0 : pos.getZ())) % 2; + ((axis == Direction.Axis.Z) ? 0 : pos.getZ())) % 2;
if (d == 0) { if (d == 0) {

View file

@ -7,6 +7,7 @@ import com.simibubi.create.content.contraptions.base.HorizontalKineticBlock;
import com.simibubi.create.content.contraptions.base.KineticTileEntity; import com.simibubi.create.content.contraptions.base.KineticTileEntity;
import com.simibubi.create.content.contraptions.components.crafter.ConnectedInputHandler.ConnectedInput; import com.simibubi.create.content.contraptions.components.crafter.ConnectedInputHandler.ConnectedInput;
import com.simibubi.create.content.contraptions.components.crafter.MechanicalCrafterTileEntity.Phase; import com.simibubi.create.content.contraptions.components.crafter.MechanicalCrafterTileEntity.Phase;
import com.simibubi.create.content.contraptions.relays.elementary.ICogWheel;
import com.simibubi.create.foundation.block.ITE; import com.simibubi.create.foundation.block.ITE;
import com.simibubi.create.foundation.tileEntity.TileEntityBehaviour; import com.simibubi.create.foundation.tileEntity.TileEntityBehaviour;
import com.simibubi.create.foundation.tileEntity.behaviour.inventory.InvManipulationBehaviour; import com.simibubi.create.foundation.tileEntity.behaviour.inventory.InvManipulationBehaviour;
@ -41,7 +42,7 @@ import net.minecraftforge.items.IItemHandler;
import net.minecraftforge.items.ItemHandlerHelper; import net.minecraftforge.items.ItemHandlerHelper;
import net.minecraftforge.items.ItemStackHandler; import net.minecraftforge.items.ItemStackHandler;
public class MechanicalCrafterBlock extends HorizontalKineticBlock implements ITE<MechanicalCrafterTileEntity> { public class MechanicalCrafterBlock extends HorizontalKineticBlock implements ITE<MechanicalCrafterTileEntity>, ICogWheel {
public static final EnumProperty<Pointing> POINTING = EnumProperty.create("pointing", Pointing.class); public static final EnumProperty<Pointing> POINTING = EnumProperty.create("pointing", Pointing.class);
@ -60,11 +61,6 @@ public class MechanicalCrafterBlock extends HorizontalKineticBlock implements IT
return AllTileEntities.MECHANICAL_CRAFTER.create(); return AllTileEntities.MECHANICAL_CRAFTER.create();
} }
@Override
public boolean hasIntegratedCogwheel(IWorldReader world, BlockPos pos, BlockState state) {
return true;
}
@Override @Override
public Axis getRotationAxis(BlockState state) { public Axis getRotationAxis(BlockState state) {
return state.get(HORIZONTAL_FACING) return state.get(HORIZONTAL_FACING)

View file

@ -3,6 +3,7 @@ package com.simibubi.create.content.contraptions.components.millstone;
import com.simibubi.create.AllShapes; import com.simibubi.create.AllShapes;
import com.simibubi.create.AllTileEntities; import com.simibubi.create.AllTileEntities;
import com.simibubi.create.content.contraptions.base.KineticBlock; import com.simibubi.create.content.contraptions.base.KineticBlock;
import com.simibubi.create.content.contraptions.relays.elementary.ICogWheel;
import com.simibubi.create.foundation.block.ITE; import com.simibubi.create.foundation.block.ITE;
import com.simibubi.create.foundation.item.ItemHelper; import com.simibubi.create.foundation.item.ItemHelper;
import com.simibubi.create.foundation.utility.Iterate; import com.simibubi.create.foundation.utility.Iterate;
@ -30,7 +31,7 @@ import net.minecraftforge.items.IItemHandler;
import net.minecraftforge.items.IItemHandlerModifiable; import net.minecraftforge.items.IItemHandlerModifiable;
import net.minecraftforge.items.ItemStackHandler; import net.minecraftforge.items.ItemStackHandler;
public class MillstoneBlock extends KineticBlock implements ITE<MillstoneTileEntity> { public class MillstoneBlock extends KineticBlock implements ITE<MillstoneTileEntity>, ICogWheel {
public MillstoneBlock(Properties properties) { public MillstoneBlock(Properties properties) {
super(properties); super(properties);
@ -131,11 +132,6 @@ public class MillstoneBlock extends KineticBlock implements ITE<MillstoneTileEnt
} }
} }
@Override
public boolean hasIntegratedCogwheel(IWorldReader world, BlockPos pos, BlockState state) {
return true;
}
@Override @Override
public Axis getRotationAxis(BlockState state) { public Axis getRotationAxis(BlockState state) {
return Axis.Y; return Axis.Y;

View file

@ -4,6 +4,7 @@ import com.simibubi.create.AllBlocks;
import com.simibubi.create.AllShapes; import com.simibubi.create.AllShapes;
import com.simibubi.create.AllTileEntities; import com.simibubi.create.AllTileEntities;
import com.simibubi.create.content.contraptions.base.KineticBlock; import com.simibubi.create.content.contraptions.base.KineticBlock;
import com.simibubi.create.content.contraptions.relays.elementary.ICogWheel;
import com.simibubi.create.foundation.block.ITE; import com.simibubi.create.foundation.block.ITE;
import net.minecraft.block.BlockState; import net.minecraft.block.BlockState;
@ -17,7 +18,7 @@ import net.minecraft.util.math.shapes.VoxelShape;
import net.minecraft.world.IBlockReader; import net.minecraft.world.IBlockReader;
import net.minecraft.world.IWorldReader; import net.minecraft.world.IWorldReader;
public class MechanicalMixerBlock extends KineticBlock implements ITE<MechanicalMixerTileEntity> { public class MechanicalMixerBlock extends KineticBlock implements ITE<MechanicalMixerTileEntity>, ICogWheel {
public MechanicalMixerBlock(Properties properties) { public MechanicalMixerBlock(Properties properties) {
super(properties); super(properties);
@ -51,11 +52,6 @@ public class MechanicalMixerBlock extends KineticBlock implements ITE<Mechanical
return false; return false;
} }
@Override
public boolean hasIntegratedCogwheel(IWorldReader world, BlockPos pos, BlockState state) {
return true;
}
@Override @Override
public float getParticleTargetRadius() { public float getParticleTargetRadius() {
return .85f; return .85f;

View file

@ -2,6 +2,7 @@ package com.simibubi.create.content.contraptions.fluids;
import java.util.Random; import java.util.Random;
import com.simibubi.create.content.contraptions.relays.elementary.ICogWheel;
import org.apache.commons.lang3.mutable.MutableBoolean; import org.apache.commons.lang3.mutable.MutableBoolean;
import com.simibubi.create.AllShapes; import com.simibubi.create.AllShapes;
@ -31,7 +32,7 @@ import net.minecraft.world.TickPriority;
import net.minecraft.world.World; import net.minecraft.world.World;
import net.minecraft.world.server.ServerWorld; import net.minecraft.world.server.ServerWorld;
public class PumpBlock extends DirectionalKineticBlock implements IWaterLoggable { public class PumpBlock extends DirectionalKineticBlock implements IWaterLoggable, ICogWheel {
public PumpBlock(Properties p_i48415_1_) { public PumpBlock(Properties p_i48415_1_) {
super(p_i48415_1_); super(p_i48415_1_);
@ -82,11 +83,6 @@ public class PumpBlock extends DirectionalKineticBlock implements IWaterLoggable
return AllShapes.PUMP.get(state.get(FACING)); return AllShapes.PUMP.get(state.get(FACING));
} }
@Override
public boolean hasIntegratedCogwheel(IWorldReader world, BlockPos pos, BlockState state) {
return true;
}
@Override @Override
public void neighborChanged(BlockState state, World world, BlockPos pos, Block otherBlock, BlockPos neighborPos, public void neighborChanged(BlockState state, World world, BlockPos pos, Block otherBlock, BlockPos neighborPos,
boolean isMoving) { boolean isMoving) {

View file

@ -1,5 +1,6 @@
package com.simibubi.create.content.contraptions.relays.advanced; package com.simibubi.create.content.contraptions.relays.advanced;
import com.simibubi.create.content.contraptions.relays.elementary.ICogWheel;
import mcp.MethodsReturnNonnullByDefault; import mcp.MethodsReturnNonnullByDefault;
import net.minecraft.block.Block; import net.minecraft.block.Block;
import net.minecraft.block.BlockState; import net.minecraft.block.BlockState;
@ -48,7 +49,7 @@ public class SpeedControllerBlock extends HorizontalAxisKineticBlock implements
BlockState above = context.getWorld() BlockState above = context.getWorld()
.getBlockState(context.getPos() .getBlockState(context.getPos()
.up()); .up());
if (CogWheelBlock.isLargeCog(above) && above.get(CogWheelBlock.AXIS) if (ICogWheel.isLargeCog(above) && above.get(CogWheelBlock.AXIS)
.isHorizontal()) .isHorizontal())
return getDefaultState().with(HORIZONTAL_AXIS, above.get(CogWheelBlock.AXIS) == Axis.X ? Axis.Z : Axis.X); return getDefaultState().with(HORIZONTAL_AXIS, above.get(CogWheelBlock.AXIS) == Axis.X ? Axis.Z : Axis.X);
return super.getStateForPlacement(context); return super.getStateForPlacement(context);

View file

@ -24,11 +24,11 @@ import net.minecraft.world.IBlockReader;
import net.minecraft.world.IWorldReader; import net.minecraft.world.IWorldReader;
import net.minecraft.world.World; import net.minecraft.world.World;
public class CogWheelBlock extends AbstractShaftBlock { public class CogWheelBlock extends AbstractShaftBlock implements ICogWheel{
boolean isLarge; boolean isLarge;
private CogWheelBlock(boolean large, Properties properties) { protected CogWheelBlock(boolean large, Properties properties) {
super(properties); super(properties);
isLarge = large; isLarge = large;
} }
@ -41,12 +41,14 @@ public class CogWheelBlock extends AbstractShaftBlock {
return new CogWheelBlock(true, properties); return new CogWheelBlock(true, properties);
} }
public static boolean isSmallCog(BlockState state) { @Override
return AllBlocks.COGWHEEL.has(state); public boolean isLargeCog() {
return isLarge;
} }
public static boolean isLargeCog(BlockState state) { @Override
return AllBlocks.LARGE_COGWHEEL.has(state); public boolean isSmallCog() {
return !isLarge;
} }
@Override @Override
@ -65,11 +67,9 @@ public class CogWheelBlock extends AbstractShaftBlock {
if (blockState.has(AXIS) && facing.getAxis() == blockState.get(AXIS)) if (blockState.has(AXIS) && facing.getAxis() == blockState.get(AXIS))
continue; continue;
boolean smallCog = isSmallCog(blockState); boolean smallCog = ICogWheel.isSmallCog(blockState);
if (!smallCog && blockState.getBlock() instanceof IRotate)
smallCog = ((IRotate) blockState.getBlock()).hasIntegratedCogwheel(worldIn, offsetPos, blockState);
if (isLargeCog(blockState) || isLarge && smallCog) if (ICogWheel.isLargeCog(blockState) || isLarge && smallCog)
return false; return false;
} }
return true; return true;
@ -100,8 +100,7 @@ public class CogWheelBlock extends AbstractShaftBlock {
.with(AXIS, stateBelow.get(SpeedControllerBlock.HORIZONTAL_AXIS) == Axis.X ? Axis.Z : Axis.X); .with(AXIS, stateBelow.get(SpeedControllerBlock.HORIZONTAL_AXIS) == Axis.X ? Axis.Z : Axis.X);
} }
if (!(block instanceof IRotate) if (!ICogWheel.isSmallCog(placedAgainst)) {
|| !(((IRotate) block).hasIntegratedCogwheel(world, placedOnPos, placedAgainst))) {
Axis preferredAxis = getPreferredAxis(context); Axis preferredAxis = getPreferredAxis(context);
if (preferredAxis != null) if (preferredAxis != null)
return this.getDefaultState() return this.getDefaultState()
@ -129,11 +128,4 @@ public class CogWheelBlock extends AbstractShaftBlock {
public void fillItemGroup(ItemGroup group, NonNullList<ItemStack> items) { public void fillItemGroup(ItemGroup group, NonNullList<ItemStack> items) {
items.add(new ItemStack(this)); items.add(new ItemStack(this));
} }
// IRotate
@Override
public boolean hasIntegratedCogwheel(IWorldReader world, BlockPos pos, BlockState state) {
return !isLarge;
}
} }

View file

@ -21,7 +21,6 @@ import com.simibubi.create.AllBlocks;
import com.simibubi.create.AllShapes; import com.simibubi.create.AllShapes;
import com.simibubi.create.content.contraptions.base.DirectionalKineticBlock; import com.simibubi.create.content.contraptions.base.DirectionalKineticBlock;
import com.simibubi.create.content.contraptions.base.HorizontalKineticBlock; import com.simibubi.create.content.contraptions.base.HorizontalKineticBlock;
import com.simibubi.create.content.contraptions.base.IRotate;
import com.simibubi.create.foundation.advancement.AllTriggers; import com.simibubi.create.foundation.advancement.AllTriggers;
import com.simibubi.create.foundation.utility.Iterate; import com.simibubi.create.foundation.utility.Iterate;
import com.simibubi.create.foundation.utility.placement.IPlacementHelper; import com.simibubi.create.foundation.utility.placement.IPlacementHelper;
@ -241,8 +240,7 @@ public class CogwheelBlockItem extends BlockItem {
@Override @Override
public Predicate<BlockState> getStatePredicate() { public Predicate<BlockState> getStatePredicate() {
return s -> !AllBlocks.COGWHEEL.has(s) && s.getBlock() instanceof IRotate return s -> !AllBlocks.COGWHEEL.has(s) && ICogWheel.isSmallCog(s);
&& ((IRotate) s.getBlock()).hasIntegratedCogwheel(null, null, null);
} }
@Override @Override
@ -285,7 +283,7 @@ public class CogwheelBlockItem extends BlockItem {
} }
} }
static public boolean hasLargeCogwheelNeighbor(World world, BlockPos pos, Axis axis) { public static boolean hasLargeCogwheelNeighbor(World world, BlockPos pos, Axis axis) {
for (Direction dir : Iterate.directions) { for (Direction dir : Iterate.directions) {
if (dir.getAxis() == axis) if (dir.getAxis() == axis)
continue; continue;
@ -297,7 +295,7 @@ public class CogwheelBlockItem extends BlockItem {
return false; return false;
} }
static public boolean hasSmallCogwheelNeighbor(World world, BlockPos pos, Axis axis) { public static boolean hasSmallCogwheelNeighbor(World world, BlockPos pos, Axis axis) {
for (Direction dir : Iterate.directions) { for (Direction dir : Iterate.directions) {
if (dir.getAxis() == axis) if (dir.getAxis() == axis)
continue; continue;

View file

@ -0,0 +1,22 @@
package com.simibubi.create.content.contraptions.relays.elementary;
import com.simibubi.create.content.contraptions.base.IRotate;
import net.minecraft.block.BlockState;
public interface ICogWheel extends IRotate {
static boolean isSmallCog(BlockState state) {
return state.getBlock() instanceof ICogWheel && ((ICogWheel) state.getBlock()).isSmallCog();
}
static boolean isLargeCog(BlockState state) {
return state.getBlock() instanceof ICogWheel && ((ICogWheel) state.getBlock()).isLargeCog();
}
default boolean isLargeCog() {
return false;
}
default boolean isSmallCog() {
return !isLargeCog();
}
}

View file

@ -1,5 +1,6 @@
package com.simibubi.create.content.logistics.block.mechanicalArm; package com.simibubi.create.content.logistics.block.mechanicalArm;
import com.simibubi.create.content.contraptions.relays.elementary.ICogWheel;
import org.apache.commons.lang3.mutable.MutableBoolean; import org.apache.commons.lang3.mutable.MutableBoolean;
import com.simibubi.create.AllShapes; import com.simibubi.create.AllShapes;
@ -29,7 +30,7 @@ import net.minecraft.world.IBlockReader;
import net.minecraft.world.IWorldReader; import net.minecraft.world.IWorldReader;
import net.minecraft.world.World; import net.minecraft.world.World;
public class ArmBlock extends KineticBlock implements ITE<ArmTileEntity> { public class ArmBlock extends KineticBlock implements ITE<ArmTileEntity>, ICogWheel {
public static final BooleanProperty CEILING = BooleanProperty.create("ceiling"); public static final BooleanProperty CEILING = BooleanProperty.create("ceiling");
@ -48,11 +49,6 @@ public class ArmBlock extends KineticBlock implements ITE<ArmTileEntity> {
return getDefaultState().with(CEILING, ctx.getFace() == Direction.DOWN); return getDefaultState().with(CEILING, ctx.getFace() == Direction.DOWN);
} }
@Override
public boolean hasIntegratedCogwheel(IWorldReader world, BlockPos pos, BlockState state) {
return true;
}
@Override @Override
public VoxelShape getShape(BlockState state, IBlockReader p_220053_2_, BlockPos p_220053_3_, public VoxelShape getShape(BlockState state, IBlockReader p_220053_2_, BlockPos p_220053_3_,
ISelectionContext p_220053_4_) { ISelectionContext p_220053_4_) {