Merge remote-tracking branch 'origin/mc1.15/dev' into mc1.15/dev

This commit is contained in:
JozsefA 2021-03-27 16:38:36 -07:00
commit d28e60a059
17 changed files with 167 additions and 166 deletions

View file

@ -1,6 +1,5 @@
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 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.SpeedControllerTileEntity;
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.EncasedBeltBlock;
import com.simibubi.create.content.contraptions.relays.encased.SplitShaftTileEntity;
@ -66,8 +66,8 @@ public class RotationPropagator {
alignedAxes && definitionFrom.hasShaftTowards(world, from.getPos(), stateFrom, direction)
&& definitionTo.hasShaftTowards(world, to.getPos(), stateTo, direction.getOpposite());
boolean connectedByGears = definitionFrom.hasIntegratedCogwheel(world, from.getPos(), stateFrom)
&& definitionTo.hasIntegratedCogwheel(world, to.getPos(), stateTo);
boolean connectedByGears = ICogWheel.isSmallCog(stateFrom)
&& ICogWheel.isSmallCog(stateTo);
float custom = from.propagateRotationTo(to, stateFrom, stateTo, diff, connectedByAxis, connectedByGears);
if (custom != 0)
@ -98,10 +98,10 @@ public class RotationPropagator {
}
// 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))
return -2f;
if (isLargeCog(stateTo) && definitionFrom.hasIntegratedCogwheel(world, from.getPos(), stateFrom))
if (ICogWheel.isLargeCog(stateTo) && ICogWheel.isSmallCog(stateFrom))
if (isLargeToSmallCog(stateTo, stateFrom, definitionFrom, diff))
return -.5f;
@ -109,7 +109,7 @@ public class RotationPropagator {
if (connectedByGears) {
if (diff.manhattanDistance(BlockPos.ZERO) != 1)
return 0;
if (isLargeCog(stateTo))
if (ICogWheel.isLargeCog(stateTo))
return 0;
if (direction.getAxis() == definitionFrom.getRotationAxis(stateFrom))
return 0;
@ -137,7 +137,7 @@ public class RotationPropagator {
}
private static boolean isLargeToLargeGear(BlockState from, BlockState to, BlockPos diff) {
if (!isLargeCog(from) || !isLargeCog(to))
if (!ICogWheel.isLargeCog(from) || !ICogWheel.isLargeCog(to))
return false;
Axis fromAxis = from.get(AXIS);
Axis toAxis = to.get(AXIS);
@ -186,7 +186,7 @@ public class RotationPropagator {
}
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;
if (!diff.equals(BlockPos.ZERO.down()))
return false;

View file

@ -118,8 +118,6 @@ public interface IRotate extends IWrenchable {
}
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);

View file

@ -72,11 +72,6 @@ public abstract class KineticBlock extends Block implements IRotate {
return false;
}
@Override
public boolean hasIntegratedCogwheel(IWorldReader world, BlockPos pos, BlockState state) {
return false;
}
@Override
public boolean hasTileEntity(BlockState state) {
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.goggles.IHaveGoggleInformation;
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.item.TooltipHelper;
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) {
return block.hasIntegratedCogwheel(world, pos, state);
return ICogWheel.isSmallCog(state);
}
@Override

View file

@ -6,6 +6,7 @@ import com.simibubi.create.AllBlocks;
import com.simibubi.create.CreateClient;
import com.simibubi.create.content.contraptions.KineticDebugger;
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.SuperByteBuffer;
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) {
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())
+ ((axis == Axis.Z) ? 0 : pos.getZ())) % 2;
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.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.foundation.render.backend.instancing.*;
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) {
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())
+ ((axis == Direction.Axis.Z) ? 0 : pos.getZ())) % 2;
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.components.crafter.ConnectedInputHandler.ConnectedInput;
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.tileEntity.TileEntityBehaviour;
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.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);
@ -60,11 +61,6 @@ public class MechanicalCrafterBlock extends HorizontalKineticBlock implements IT
return AllTileEntities.MECHANICAL_CRAFTER.create();
}
@Override
public boolean hasIntegratedCogwheel(IWorldReader world, BlockPos pos, BlockState state) {
return true;
}
@Override
public Axis getRotationAxis(BlockState state) {
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.AllTileEntities;
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.item.ItemHelper;
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.ItemStackHandler;
public class MillstoneBlock extends KineticBlock implements ITE<MillstoneTileEntity> {
public class MillstoneBlock extends KineticBlock implements ITE<MillstoneTileEntity>, ICogWheel {
public MillstoneBlock(Properties 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
public Axis getRotationAxis(BlockState state) {
return Axis.Y;

View file

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

View file

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

View file

@ -1,5 +1,16 @@
package com.simibubi.create.content.contraptions.relays.advanced;
import com.simibubi.create.AllBlocks;
import com.simibubi.create.AllShapes;
import com.simibubi.create.AllTileEntities;
import com.simibubi.create.content.contraptions.base.HorizontalAxisKineticBlock;
import com.simibubi.create.content.contraptions.relays.elementary.CogWheelBlock;
import com.simibubi.create.content.contraptions.relays.elementary.CogwheelBlockItem;
import com.simibubi.create.content.contraptions.relays.elementary.ICogWheel;
import com.simibubi.create.foundation.block.ITE;
import com.simibubi.create.foundation.utility.placement.IPlacementHelper;
import com.simibubi.create.foundation.utility.placement.PlacementHelpers;
import com.simibubi.create.foundation.utility.placement.PlacementOffset;
import mcp.MethodsReturnNonnullByDefault;
import net.minecraft.block.Block;
import net.minecraft.block.BlockState;
@ -18,18 +29,11 @@ import net.minecraft.util.math.shapes.VoxelShape;
import net.minecraft.world.IBlockReader;
import net.minecraft.world.World;
import javax.annotation.ParametersAreNonnullByDefault;
import java.util.function.Predicate;
import com.simibubi.create.AllBlocks;
import com.simibubi.create.AllShapes;
import com.simibubi.create.AllTileEntities;
import com.simibubi.create.content.contraptions.base.HorizontalAxisKineticBlock;
import com.simibubi.create.content.contraptions.relays.elementary.CogWheelBlock;
import com.simibubi.create.content.contraptions.relays.elementary.CogwheelBlockItem;
import com.simibubi.create.foundation.block.ITE;
import com.simibubi.create.foundation.utility.placement.IPlacementHelper;
import com.simibubi.create.foundation.utility.placement.PlacementHelpers;
import com.simibubi.create.foundation.utility.placement.PlacementOffset;
@ParametersAreNonnullByDefault
@MethodsReturnNonnullByDefault
public class SpeedControllerBlock extends HorizontalAxisKineticBlock implements ITE<SpeedControllerTileEntity> {
private static final int placementHelperId = PlacementHelpers.register(new PlacementHelper());
@ -48,7 +52,7 @@ public class SpeedControllerBlock extends HorizontalAxisKineticBlock implements
BlockState above = context.getWorld()
.getBlockState(context.getPos()
.up());
if (CogWheelBlock.isLargeCog(above) && above.get(CogWheelBlock.AXIS)
if (ICogWheel.isLargeCog(above) && above.get(CogWheelBlock.AXIS)
.isHorizontal())
return getDefaultState().with(HORIZONTAL_AXIS, above.get(CogWheelBlock.AXIS) == Axis.X ? Axis.Z : Axis.X);
return super.getStateForPlacement(context);
@ -82,7 +86,7 @@ public class SpeedControllerBlock extends HorizontalAxisKineticBlock implements
private static class PlacementHelper implements IPlacementHelper {
@Override
public Predicate<ItemStack> getItemPredicate() {
return AllBlocks.LARGE_COGWHEEL::isIn;
return ((Predicate<ItemStack>) ICogWheel::isLargeCogItem).and(ICogWheel::isDedicatedCogItem);
}
@Override
@ -100,8 +104,7 @@ public class SpeedControllerBlock extends HorizontalAxisKineticBlock implements
Axis newAxis = state.get(HORIZONTAL_AXIS) == Axis.X ? Axis.Z : Axis.X;
if (CogwheelBlockItem.hasLargeCogwheelNeighbor(world, newPos, newAxis)
|| CogwheelBlockItem.hasSmallCogwheelNeighbor(world, newPos, newAxis))
if (!CogWheelBlock.isValidCogwheelPosition(true, world, newPos, newAxis))
return PlacementOffset.fail();
return PlacementOffset.success(newPos, s -> s.with(CogWheelBlock.AXIS, newAxis));

View file

@ -7,6 +7,7 @@ import com.simibubi.create.content.contraptions.RotationPropagator;
import com.simibubi.create.content.contraptions.base.KineticTileEntity;
import com.simibubi.create.content.contraptions.components.motor.CreativeMotorTileEntity;
import com.simibubi.create.content.contraptions.relays.elementary.CogWheelBlock;
import com.simibubi.create.content.contraptions.relays.elementary.ICogWheel;
import com.simibubi.create.foundation.config.AllConfigs;
import com.simibubi.create.foundation.tileEntity.TileEntityBehaviour;
import com.simibubi.create.foundation.tileEntity.behaviour.ValueBoxTransform;
@ -118,8 +119,8 @@ public class SpeedControllerTileEntity extends KineticTileEntity {
if (world == null || !world.isRemote)
return;
BlockState stateAbove = world.getBlockState(pos.up());
hasBracket = AllBlocks.LARGE_COGWHEEL.has(stateAbove) && stateAbove.get(CogWheelBlock.AXIS)
.isHorizontal();
hasBracket = ICogWheel.isDedicatedCogWheel(stateAbove.getBlock()) && ICogWheel.isLargeCog(stateAbove)
&& stateAbove.get(CogWheelBlock.AXIS).isHorizontal();
}
@Override

View file

@ -5,18 +5,14 @@ import com.simibubi.create.AllShapes;
import com.simibubi.create.content.contraptions.base.IRotate;
import com.simibubi.create.content.contraptions.relays.advanced.SpeedControllerBlock;
import com.simibubi.create.foundation.utility.Iterate;
import mcp.MethodsReturnNonnullByDefault;
import net.minecraft.block.Block;
import net.minecraft.block.BlockState;
import net.minecraft.fluid.Fluids;
import net.minecraft.fluid.IFluidState;
import net.minecraft.item.BlockItemUseContext;
import net.minecraft.item.ItemGroup;
import net.minecraft.item.ItemStack;
import net.minecraft.state.properties.BlockStateProperties;
import net.minecraft.util.Direction;
import net.minecraft.util.Direction.Axis;
import net.minecraft.util.NonNullList;
import net.minecraft.util.math.BlockPos;
import net.minecraft.util.math.shapes.ISelectionContext;
import net.minecraft.util.math.shapes.VoxelShape;
@ -24,11 +20,16 @@ import net.minecraft.world.IBlockReader;
import net.minecraft.world.IWorldReader;
import net.minecraft.world.World;
public class CogWheelBlock extends AbstractShaftBlock {
import javax.annotation.ParametersAreNonnullByDefault;
@ParametersAreNonnullByDefault
@MethodsReturnNonnullByDefault
@SuppressWarnings("deprecation")
public class CogWheelBlock extends AbstractShaftBlock implements ICogWheel {
boolean isLarge;
private CogWheelBlock(boolean large, Properties properties) {
protected CogWheelBlock(boolean large, Properties properties) {
super(properties);
isLarge = large;
}
@ -41,12 +42,14 @@ public class CogWheelBlock extends AbstractShaftBlock {
return new CogWheelBlock(true, properties);
}
public static boolean isSmallCog(BlockState state) {
return AllBlocks.COGWHEEL.has(state);
@Override
public boolean isLargeCog() {
return isLarge;
}
public static boolean isLargeCog(BlockState state) {
return AllBlocks.LARGE_COGWHEEL.has(state);
@Override
public boolean isSmallCog() {
return !isLarge;
}
@Override
@ -56,8 +59,12 @@ public class CogWheelBlock extends AbstractShaftBlock {
@Override
public boolean isValidPosition(BlockState state, IWorldReader worldIn, BlockPos pos) {
return isValidCogwheelPosition(ICogWheel.isLargeCog(state), worldIn, pos, state.get(AXIS));
}
public static boolean isValidCogwheelPosition(boolean large, IWorldReader worldIn, BlockPos pos, Axis cogAxis) {
for (Direction facing : Iterate.directions) {
if (facing.getAxis() == state.get(AXIS))
if (facing.getAxis() == cogAxis)
continue;
BlockPos offsetPos = pos.offset(facing);
@ -65,75 +72,53 @@ public class CogWheelBlock extends AbstractShaftBlock {
if (blockState.has(AXIS) && facing.getAxis() == blockState.get(AXIS))
continue;
boolean smallCog = 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) || large && ICogWheel.isSmallCog(blockState))
return false;
}
return true;
}
protected Axis getAxisForPlacement(BlockItemUseContext context) {
if (context.getPlayer() != null && context.getPlayer().isSneaking())
return context.getFace().getAxis();
World world = context.getWorld();
BlockState stateBelow = world.getBlockState(context.getPos().down());
if (AllBlocks.ROTATION_SPEED_CONTROLLER.has(stateBelow) && isLargeCog())
return stateBelow.get(SpeedControllerBlock.HORIZONTAL_AXIS) == Axis.X ? Axis.Z : Axis.X;
BlockPos placedOnPos = context.getPos().offset(context.getFace().getOpposite());
BlockState placedAgainst = world.getBlockState(placedOnPos);
Block block = placedAgainst.getBlock();
if (ICogWheel.isSmallCog(placedAgainst))
return ((IRotate) block).getRotationAxis(placedAgainst);
Axis preferredAxis = getPreferredAxis(context);
return preferredAxis != null ? preferredAxis : context.getFace().getAxis();
}
@Override
public BlockState getStateForPlacement(BlockItemUseContext context) {
BlockPos placedOnPos = context.getPos()
.offset(context.getFace()
.getOpposite());
World world = context.getWorld();
BlockState placedAgainst = world.getBlockState(placedOnPos);
Block block = placedAgainst.getBlock();
if (context.getPlayer() != null && context.getPlayer()
.isSneaking())
return this.getDefaultState()
.with(AXIS, context.getFace()
.getAxis());
BlockState stateBelow = world.getBlockState(context.getPos()
.down());
IFluidState ifluidstate = context.getWorld()
.getFluidState(context.getPos());
if (AllBlocks.ROTATION_SPEED_CONTROLLER.has(stateBelow) && isLarge) {
return this.getDefaultState()
.with(BlockStateProperties.WATERLOGGED, ifluidstate.getFluid() == Fluids.WATER)
.with(AXIS, stateBelow.get(SpeedControllerBlock.HORIZONTAL_AXIS) == Axis.X ? Axis.Z : Axis.X);
}
if (!(block instanceof IRotate)
|| !(((IRotate) block).hasIntegratedCogwheel(world, placedOnPos, placedAgainst))) {
Axis preferredAxis = getPreferredAxis(context);
if (preferredAxis != null)
return this.getDefaultState()
.with(AXIS, preferredAxis)
.with(BlockStateProperties.WATERLOGGED, ifluidstate.getFluid() == Fluids.WATER);
return this.getDefaultState()
.with(AXIS, context.getFace()
.getAxis())
.with(BlockStateProperties.WATERLOGGED, ifluidstate.getFluid() == Fluids.WATER);
}
return getDefaultState().with(AXIS, ((IRotate) block).getRotationAxis(placedAgainst));
boolean shouldWaterlog = context.getWorld().getFluidState(context.getPos()).getFluid() == Fluids.WATER;
return this.getDefaultState()
.with(AXIS, getAxisForPlacement(context))
.with(BlockStateProperties.WATERLOGGED, shouldWaterlog);
}
@Override
public float getParticleTargetRadius() {
return isLarge ? 1.125f : .65f;
return isLargeCog() ? 1.125f : .65f;
}
@Override
public float getParticleInitialRadius() {
return isLarge ? 1f : .75f;
return isLargeCog() ? 1f : .75f;
}
public void fillItemGroup(ItemGroup group, NonNullList<ItemStack> items) {
items.add(new ItemStack(this));
}
// IRotate
@Override
public boolean hasIntegratedCogwheel(IWorldReader world, BlockPos pos, BlockState state) {
return !isLarge;
public boolean isDedicatedCogWheel() {
return true;
}
}

View file

@ -17,11 +17,9 @@ import net.minecraft.world.World;
import java.util.List;
import java.util.function.Predicate;
import com.simibubi.create.AllBlocks;
import com.simibubi.create.AllShapes;
import com.simibubi.create.content.contraptions.base.DirectionalKineticBlock;
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.utility.Iterate;
import com.simibubi.create.foundation.utility.placement.IPlacementHelper;
@ -100,7 +98,7 @@ public class CogwheelBlockItem extends BlockItem {
continue;
if (blockState.get(CogWheelBlock.AXIS) != axis)
continue;
if (AllBlocks.LARGE_COGWHEEL.has(blockState) == large)
if (ICogWheel.isLargeCog(blockState) == large)
continue;
AllTriggers.triggerFor(AllTriggers.SHIFTING_GEARS, player);
}
@ -114,7 +112,7 @@ public class CogwheelBlockItem extends BlockItem {
@Override
public Predicate<ItemStack> getItemPredicate() {
return AllBlocks.COGWHEEL::isIn;
return ((Predicate<ItemStack>) ICogWheel::isSmallCogItem).and(ICogWheel::isDedicatedCogItem);
}
@Override
@ -129,7 +127,7 @@ public class CogwheelBlockItem extends BlockItem {
for (Direction dir : directions) {
BlockPos newPos = pos.offset(dir);
if (hasLargeCogwheelNeighbor(world, newPos, state.get(AXIS)))
if (!CogWheelBlock.isValidCogwheelPosition(false, world, newPos, state.get(AXIS)))
continue;
if (!world.getBlockState(newPos)
@ -153,7 +151,7 @@ public class CogwheelBlockItem extends BlockItem {
@Override
public Predicate<ItemStack> getItemPredicate() {
return AllBlocks.LARGE_COGWHEEL::isIn;
return ((Predicate<ItemStack>) ICogWheel::isLargeCogItem).and(ICogWheel::isDedicatedCogItem);
}
@Override
@ -170,7 +168,7 @@ public class CogwheelBlockItem extends BlockItem {
BlockPos newPos = pos.offset(dir)
.offset(side);
if (hasLargeCogwheelNeighbor(world, newPos, dir.getAxis()) || hasSmallCogwheelNeighbor(world, newPos, dir.getAxis()))
if (!CogWheelBlock.isValidCogwheelPosition(true, world, newPos, dir.getAxis()))
continue;
if (!world.getBlockState(newPos)
@ -212,7 +210,7 @@ public class CogwheelBlockItem extends BlockItem {
.isReplaceable())
continue;
if (AllBlocks.COGWHEEL.has(state) && hasSmallCogwheelNeighbor(world, newPos, state.get(AXIS)))
if (!CogWheelBlock.isValidCogwheelPosition(ICogWheel.isLargeCog(state), world, newPos, state.get(AXIS)))
continue;
return PlacementOffset.success(newPos, s -> s.with(AXIS, state.get(AXIS)));
@ -236,13 +234,12 @@ public class CogwheelBlockItem extends BlockItem {
@Override
public Predicate<ItemStack> getItemPredicate() {
return AllBlocks.LARGE_COGWHEEL::isIn;
return ((Predicate<ItemStack>) ICogWheel::isLargeCogItem).and(ICogWheel::isDedicatedCogItem);
}
@Override
public Predicate<BlockState> getStatePredicate() {
return s -> !AllBlocks.COGWHEEL.has(s) && s.getBlock() instanceof IRotate
&& ((IRotate) s.getBlock()).hasIntegratedCogwheel(null, null, null);
return s -> !ICogWheel.isDedicatedCogWheel(s.getBlock()) && ICogWheel.isSmallCog(s);
}
@Override
@ -274,8 +271,7 @@ public class CogwheelBlockItem extends BlockItem {
.isReplaceable())
continue;
if (hasLargeCogwheelNeighbor(world, newPos, newAxis)
|| hasSmallCogwheelNeighbor(world, newPos, newAxis))
if (!CogWheelBlock.isValidCogwheelPosition(false, world, newPos, newAxis))
return PlacementOffset.fail();
return PlacementOffset.success(newPos, s -> s.with(CogWheelBlock.AXIS, newAxis));
@ -285,27 +281,4 @@ public class CogwheelBlockItem extends BlockItem {
}
}
static public boolean hasLargeCogwheelNeighbor(World world, BlockPos pos, Axis axis) {
for (Direction dir : Iterate.directions) {
if (dir.getAxis() == axis)
continue;
if (AllBlocks.LARGE_COGWHEEL.has(world.getBlockState(pos.offset(dir))))
return true;
}
return false;
}
static public boolean hasSmallCogwheelNeighbor(World world, BlockPos pos, Axis axis) {
for (Direction dir : Iterate.directions) {
if (dir.getAxis() == axis)
continue;
if (AllBlocks.COGWHEEL.has(world.getBlockState(pos.offset(dir))))
return true;
}
return false;
}
}

View file

@ -0,0 +1,64 @@
package com.simibubi.create.content.contraptions.relays.elementary;
import com.simibubi.create.content.contraptions.base.IRotate;
import net.minecraft.block.Block;
import net.minecraft.block.BlockState;
import net.minecraft.item.BlockItem;
import net.minecraft.item.Item;
import net.minecraft.item.ItemStack;
public interface ICogWheel extends IRotate {
static boolean isSmallCog(BlockState state) {
return isSmallCog(state.getBlock());
}
static boolean isLargeCog(BlockState state) {
return isLargeCog(state.getBlock());
}
static boolean isSmallCog(Block block) {
return block instanceof ICogWheel && ((ICogWheel) block).isSmallCog();
}
static boolean isLargeCog(Block block) {
return block instanceof ICogWheel && ((ICogWheel) block).isLargeCog();
}
static boolean isDedicatedCogWheel(Block block) {
return block instanceof ICogWheel && ((ICogWheel) block).isDedicatedCogWheel();
}
static boolean isDedicatedCogItem(ItemStack test) {
Item item = test.getItem();
if (!(item instanceof BlockItem))
return false;
return isDedicatedCogWheel(((BlockItem) item).getBlock());
}
static boolean isSmallCogItem(ItemStack test) {
Item item = test.getItem();
if (!(item instanceof BlockItem))
return false;
return isSmallCog(((BlockItem) item).getBlock());
}
static boolean isLargeCogItem(ItemStack test) {
Item item = test.getItem();
if (!(item instanceof BlockItem))
return false;
return isLargeCog(((BlockItem) item).getBlock());
}
default boolean isLargeCog() {
return false;
}
default boolean isSmallCog() {
return !isLargeCog();
}
default boolean isDedicatedCogWheel() {
return false;
}
}

View file

@ -2,7 +2,6 @@ package com.simibubi.create.content.contraptions.relays.elementary;
import java.util.List;
import com.simibubi.create.AllBlocks;
import com.simibubi.create.content.contraptions.base.IRotate;
import com.simibubi.create.content.contraptions.base.KineticTileEntity;
import com.simibubi.create.foundation.advancement.AllTriggers;
@ -34,7 +33,7 @@ public class SimpleKineticTileEntity extends KineticTileEntity {
@Override
public List<BlockPos> addPropagationLocations(IRotate block, BlockState state, List<BlockPos> neighbours) {
if (!AllBlocks.LARGE_COGWHEEL.has(state))
if (!ICogWheel.isLargeCog(state))
return super.addPropagationLocations(block, state, neighbours);
BlockPos.getAllInBox(new BlockPos(-1, -1, -1), new BlockPos(1, 1, 1))

View file

@ -1,5 +1,6 @@
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 com.simibubi.create.AllShapes;
@ -29,7 +30,7 @@ import net.minecraft.world.IBlockReader;
import net.minecraft.world.IWorldReader;
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");
@ -48,11 +49,6 @@ public class ArmBlock extends KineticBlock implements ITE<ArmTileEntity> {
return getDefaultState().with(CEILING, ctx.getFace() == Direction.DOWN);
}
@Override
public boolean hasIntegratedCogwheel(IWorldReader world, BlockPos pos, BlockState state) {
return true;
}
@Override
public VoxelShape getShape(BlockState state, IBlockReader p_220053_2_, BlockPos p_220053_3_,
ISelectionContext p_220053_4_) {