mirror of
https://github.com/Creators-of-Create/Create.git
synced 2025-02-11 21:05:03 +01:00
Everything
This commit is contained in:
parent
3f7fbef9d6
commit
2768123b52
84 changed files with 1030 additions and 996 deletions
|
@ -2,6 +2,8 @@ package com.simibubi.create;
|
||||||
|
|
||||||
import java.util.Random;
|
import java.util.Random;
|
||||||
|
|
||||||
|
import com.simibubi.create.content.contraptions.solver.AllConnections;
|
||||||
|
|
||||||
import org.apache.logging.log4j.LogManager;
|
import org.apache.logging.log4j.LogManager;
|
||||||
import org.apache.logging.log4j.Logger;
|
import org.apache.logging.log4j.Logger;
|
||||||
|
|
||||||
|
@ -83,6 +85,7 @@ public class Create {
|
||||||
ModLoadingContext modLoadingContext = ModLoadingContext.get();
|
ModLoadingContext modLoadingContext = ModLoadingContext.get();
|
||||||
|
|
||||||
AllSoundEvents.prepare();
|
AllSoundEvents.prepare();
|
||||||
|
AllConnections.register();
|
||||||
AllBlocks.register();
|
AllBlocks.register();
|
||||||
AllItems.register();
|
AllItems.register();
|
||||||
AllFluids.register();
|
AllFluids.register();
|
||||||
|
|
|
@ -38,16 +38,20 @@ public class KineticDebugger {
|
||||||
return;
|
return;
|
||||||
|
|
||||||
Level world = Minecraft.getInstance().level;
|
Level world = Minecraft.getInstance().level;
|
||||||
BlockPos toOutline = te.hasSource() ? te.source : te.getBlockPos();
|
BlockPos toOutline = te.getSpeedSource().orElse(te.getBlockPos());
|
||||||
BlockState state = te.getBlockState();
|
BlockState state = te.getBlockState();
|
||||||
VoxelShape shape = world.getBlockState(toOutline)
|
VoxelShape shape = world.getBlockState(toOutline)
|
||||||
.getBlockSupportShape(world, toOutline);
|
.getBlockSupportShape(world, toOutline);
|
||||||
|
|
||||||
if (te.getTheoreticalSpeed() != 0 && !shape.isEmpty())
|
if (te.getTheoreticalSpeed() != 0 && !shape.isEmpty()) {
|
||||||
|
int color = te.getSpeedSource().flatMap($ -> te.getNetworkID())
|
||||||
|
.map(id -> Color.generateFromLong(id).getRGB())
|
||||||
|
.orElse(0xffcc00);
|
||||||
CreateClient.OUTLINER.chaseAABB("kineticSource", shape.bounds()
|
CreateClient.OUTLINER.chaseAABB("kineticSource", shape.bounds()
|
||||||
.move(toOutline))
|
.move(toOutline))
|
||||||
.lineWidth(1 / 16f)
|
.lineWidth(1 / 16f)
|
||||||
.colored(te.hasSource() ? Color.generateFromLong(te.network).getRGB() : 0xffcc00);
|
.colored(color);
|
||||||
|
}
|
||||||
|
|
||||||
if (state.getBlock() instanceof IRotate) {
|
if (state.getBlock() instanceof IRotate) {
|
||||||
Axis axis = ((IRotate) state.getBlock()).getRotationAxis(state);
|
Axis axis = ((IRotate) state.getBlock()).getRotationAxis(state);
|
||||||
|
|
|
@ -95,23 +95,20 @@ public abstract class DirectionalAxisKineticBlock extends DirectionalKineticBloc
|
||||||
BlockState blockState = reader.getBlockState(neighbourPos);
|
BlockState blockState = reader.getBlockState(neighbourPos);
|
||||||
Block block = blockState.getBlock();
|
Block block = blockState.getBlock();
|
||||||
return block instanceof IRotate
|
return block instanceof IRotate
|
||||||
&& ((IRotate) block).hasShaftTowards(reader, neighbourPos, blockState, facing.getOpposite());
|
&& ((IRotate) block).hasShaftTowards(blockState, facing.getOpposite(), reader, pos);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static Axis getRotationAxis(Axis facing, boolean alongFirstCoordinate) {
|
||||||
|
return switch (facing) {
|
||||||
|
case X -> alongFirstCoordinate ? Axis.Y : Axis.Z;
|
||||||
|
case Y -> alongFirstCoordinate ? Axis.X : Axis.Z;
|
||||||
|
case Z -> alongFirstCoordinate ? Axis.X : Axis.Y;
|
||||||
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Axis getRotationAxis(BlockState state) {
|
public Axis getRotationAxis(BlockState state) {
|
||||||
Axis pistonAxis = state.getValue(FACING)
|
return getRotationAxis(state.getValue(FACING).getAxis(), state.getValue(AXIS_ALONG_FIRST_COORDINATE));
|
||||||
.getAxis();
|
|
||||||
boolean alongFirst = state.getValue(AXIS_ALONG_FIRST_COORDINATE);
|
|
||||||
|
|
||||||
if (pistonAxis == Axis.X)
|
|
||||||
return alongFirst ? Axis.Y : Axis.Z;
|
|
||||||
if (pistonAxis == Axis.Y)
|
|
||||||
return alongFirst ? Axis.X : Axis.Z;
|
|
||||||
if (pistonAxis == Axis.Z)
|
|
||||||
return alongFirst ? Axis.X : Axis.Y;
|
|
||||||
|
|
||||||
throw new IllegalStateException("Unknown axis??");
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -122,7 +119,7 @@ public abstract class DirectionalAxisKineticBlock extends DirectionalKineticBloc
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean hasShaftTowards(LevelReader world, BlockPos pos, BlockState state, Direction face) {
|
public boolean hasShaftTowards(BlockState state, Direction face) {
|
||||||
return face.getAxis() == getRotationAxis(state);
|
return face.getAxis() == getRotationAxis(state);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -26,24 +26,24 @@ public abstract class DirectionalKineticBlock extends KineticBlock {
|
||||||
super.createBlockStateDefinition(builder);
|
super.createBlockStateDefinition(builder);
|
||||||
}
|
}
|
||||||
|
|
||||||
public Direction getPreferredFacing(BlockPlaceContext context) {
|
public static Direction getPreferredFacing(BlockPlaceContext context) {
|
||||||
Direction prefferedSide = null;
|
Direction preferredSide = null;
|
||||||
for (Direction side : Iterate.directions) {
|
for (Direction side : Iterate.directions) {
|
||||||
BlockState blockState = context.getLevel()
|
BlockState blockState = context.getLevel()
|
||||||
.getBlockState(context.getClickedPos()
|
.getBlockState(context.getClickedPos()
|
||||||
.relative(side));
|
.relative(side));
|
||||||
if (blockState.getBlock() instanceof IRotate) {
|
if (blockState.getBlock() instanceof IRotate) {
|
||||||
if (((IRotate) blockState.getBlock()).hasShaftTowards(context.getLevel(), context.getClickedPos()
|
if (((IRotate) blockState.getBlock()).hasShaftTowards(
|
||||||
.relative(side), blockState, side.getOpposite()))
|
blockState, side.getOpposite(), context.getLevel(), context.getClickedPos()))
|
||||||
if (prefferedSide != null && prefferedSide.getAxis() != side.getAxis()) {
|
if (preferredSide != null && preferredSide.getAxis() != side.getAxis()) {
|
||||||
prefferedSide = null;
|
preferredSide = null;
|
||||||
break;
|
break;
|
||||||
} else {
|
} else {
|
||||||
prefferedSide = side;
|
preferredSide = side;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return prefferedSide;
|
return preferredSide;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|
|
@ -1,89 +0,0 @@
|
||||||
package com.simibubi.create.content.contraptions.base;
|
|
||||||
|
|
||||||
import java.util.List;
|
|
||||||
|
|
||||||
import net.minecraft.core.BlockPos;
|
|
||||||
import net.minecraft.network.chat.Component;
|
|
||||||
import net.minecraft.world.level.block.entity.BlockEntityType;
|
|
||||||
import net.minecraft.world.level.block.state.BlockState;
|
|
||||||
|
|
||||||
public abstract class GeneratingKineticTileEntity extends KineticTileEntity {
|
|
||||||
|
|
||||||
public boolean reActivateSource;
|
|
||||||
|
|
||||||
public GeneratingKineticTileEntity(BlockEntityType<?> typeIn, BlockPos pos, BlockState state) {
|
|
||||||
super(typeIn, pos, state);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void tick() {
|
|
||||||
super.tick();
|
|
||||||
if (reActivateSource) {
|
|
||||||
updateGeneratedRotation();
|
|
||||||
reActivateSource = false;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public boolean addToGoggleTooltip(List<Component> tooltip, boolean isPlayerSneaking) {
|
|
||||||
boolean added = super.addToGoggleTooltip(tooltip, isPlayerSneaking);
|
|
||||||
|
|
||||||
// float stressBase = calculateAddedStressCapacity();
|
|
||||||
// if (stressBase != 0 && IRotate.StressImpact.isEnabled()) {
|
|
||||||
// tooltip.add(componentSpacing.plainCopy().append(Lang.translate("gui.goggles.generator_stats")));
|
|
||||||
// tooltip.add(componentSpacing.plainCopy().append(Lang.translate("tooltip.capacityProvided").withStyle(ChatFormatting.GRAY)));
|
|
||||||
//
|
|
||||||
// float speed = getTheoreticalSpeed();
|
|
||||||
// if (speed != getGeneratedSpeed() && speed != 0)
|
|
||||||
// stressBase *= getGeneratedSpeed() / speed;
|
|
||||||
//
|
|
||||||
// speed = Math.abs(speed);
|
|
||||||
// float stressTotal = stressBase * speed;
|
|
||||||
//
|
|
||||||
// tooltip.add(
|
|
||||||
// componentSpacing.plainCopy()
|
|
||||||
// .append(new TextComponent(" " + IHaveGoggleInformation.format(stressTotal))
|
|
||||||
// .append(Lang.translate("generic.unit.stress"))
|
|
||||||
// .withStyle(ChatFormatting.AQUA))
|
|
||||||
// .append(" ")
|
|
||||||
// .append(Lang.translate("gui.goggles.at_current_speed").withStyle(ChatFormatting.DARK_GRAY)));
|
|
||||||
//
|
|
||||||
// added = true;
|
|
||||||
// }
|
|
||||||
|
|
||||||
return added;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void updateGeneratedRotation() {
|
|
||||||
// float speed = getGeneratedSpeed();
|
|
||||||
// float prevSpeed = this.speed;
|
|
||||||
//
|
|
||||||
// if (level.isClientSide)
|
|
||||||
// return;
|
|
||||||
//
|
|
||||||
// if (prevSpeed != speed) {
|
|
||||||
// if (!hasSource()) {
|
|
||||||
// SpeedLevel levelBefore = SpeedLevel.of(this.speed);
|
|
||||||
// SpeedLevel levelafter = SpeedLevel.of(speed);
|
|
||||||
// if (levelBefore != levelafter)
|
|
||||||
// effects.queueRotationIndicators();
|
|
||||||
// }
|
|
||||||
//
|
|
||||||
// applyNewSpeed(prevSpeed, speed);
|
|
||||||
// }
|
|
||||||
//
|
|
||||||
// if (hasNetwork() && speed != 0) {
|
|
||||||
// KineticNetwork network = getOrCreateNetwork();
|
|
||||||
// notifyStressCapacityChange(calculateAddedStressCapacity());
|
|
||||||
// getOrCreateNetwork().updateStressFor(this, calculateStressApplied());
|
|
||||||
// network.updateStress();
|
|
||||||
// }
|
|
||||||
//
|
|
||||||
// onSpeedChanged(prevSpeed);
|
|
||||||
// sendData();
|
|
||||||
}
|
|
||||||
|
|
||||||
public Long createNetworkId() {
|
|
||||||
return worldPosition.asLong();
|
|
||||||
}
|
|
||||||
}
|
|
|
@ -1,15 +1,11 @@
|
||||||
package com.simibubi.create.content.contraptions.base;
|
package com.simibubi.create.content.contraptions.base;
|
||||||
|
|
||||||
import com.simibubi.create.content.contraptions.solver.AllConnections;
|
|
||||||
import com.simibubi.create.content.contraptions.solver.KineticConnections;
|
|
||||||
import com.simibubi.create.foundation.utility.Iterate;
|
import com.simibubi.create.foundation.utility.Iterate;
|
||||||
|
|
||||||
import net.minecraft.core.BlockPos;
|
|
||||||
import net.minecraft.core.Direction;
|
import net.minecraft.core.Direction;
|
||||||
import net.minecraft.core.Direction.Axis;
|
import net.minecraft.core.Direction.Axis;
|
||||||
import net.minecraft.core.Direction.AxisDirection;
|
import net.minecraft.core.Direction.AxisDirection;
|
||||||
import net.minecraft.world.item.context.BlockPlaceContext;
|
import net.minecraft.world.item.context.BlockPlaceContext;
|
||||||
import net.minecraft.world.level.LevelReader;
|
|
||||||
import net.minecraft.world.level.block.Block;
|
import net.minecraft.world.level.block.Block;
|
||||||
import net.minecraft.world.level.block.Mirror;
|
import net.minecraft.world.level.block.Mirror;
|
||||||
import net.minecraft.world.level.block.Rotation;
|
import net.minecraft.world.level.block.Rotation;
|
||||||
|
@ -41,21 +37,21 @@ public abstract class HorizontalAxisKineticBlock extends KineticBlock {
|
||||||
}
|
}
|
||||||
|
|
||||||
public static Axis getPreferredHorizontalAxis(BlockPlaceContext context) {
|
public static Axis getPreferredHorizontalAxis(BlockPlaceContext context) {
|
||||||
Direction prefferedSide = null;
|
Direction preferredSide = null;
|
||||||
for (Direction side : Iterate.horizontalDirections) {
|
for (Direction side : Iterate.horizontalDirections) {
|
||||||
BlockState blockState = context.getLevel().getBlockState(context.getClickedPos().relative(side));
|
BlockState blockState = context.getLevel().getBlockState(context.getClickedPos().relative(side));
|
||||||
if (blockState.getBlock() instanceof IRotate) {
|
if (blockState.getBlock() instanceof IRotate) {
|
||||||
if (((IRotate) blockState.getBlock()).hasShaftTowards(context.getLevel(), context.getClickedPos().relative(side),
|
if (((IRotate) blockState.getBlock()).hasShaftTowards(
|
||||||
blockState, side.getOpposite()))
|
blockState, side.getOpposite(), context.getLevel(), context.getClickedPos()))
|
||||||
if (prefferedSide != null && prefferedSide.getAxis() != side.getAxis()) {
|
if (preferredSide != null && preferredSide.getAxis() != side.getAxis()) {
|
||||||
prefferedSide = null;
|
preferredSide = null;
|
||||||
break;
|
break;
|
||||||
} else {
|
} else {
|
||||||
prefferedSide = side;
|
preferredSide = side;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return prefferedSide == null ? null : prefferedSide.getAxis();
|
return preferredSide == null ? null : preferredSide.getAxis();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -64,12 +60,7 @@ public abstract class HorizontalAxisKineticBlock extends KineticBlock {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public KineticConnections getInitialConnections(BlockState state) {
|
public boolean hasShaftTowards(BlockState state, Direction face) {
|
||||||
return AllConnections.FULL_SHAFT.apply(state.getValue(HORIZONTAL_AXIS));
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public boolean hasShaftTowards(LevelReader world, BlockPos pos, BlockState state, Direction face) {
|
|
||||||
return face.getAxis() == state.getValue(HORIZONTAL_AXIS);
|
return face.getAxis() == state.getValue(HORIZONTAL_AXIS);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -34,23 +34,23 @@ public abstract class HorizontalKineticBlock extends KineticBlock {
|
||||||
}
|
}
|
||||||
|
|
||||||
public Direction getPreferredHorizontalFacing(BlockPlaceContext context) {
|
public Direction getPreferredHorizontalFacing(BlockPlaceContext context) {
|
||||||
Direction prefferedSide = null;
|
Direction preferredSide = null;
|
||||||
for (Direction side : Iterate.horizontalDirections) {
|
for (Direction side : Iterate.horizontalDirections) {
|
||||||
BlockState blockState = context.getLevel()
|
BlockState blockState = context.getLevel()
|
||||||
.getBlockState(context.getClickedPos()
|
.getBlockState(context.getClickedPos()
|
||||||
.relative(side));
|
.relative(side));
|
||||||
if (blockState.getBlock() instanceof IRotate) {
|
if (blockState.getBlock() instanceof IRotate) {
|
||||||
if (((IRotate) blockState.getBlock()).hasShaftTowards(context.getLevel(), context.getClickedPos()
|
if (((IRotate) blockState.getBlock()).hasShaftTowards(
|
||||||
.relative(side), blockState, side.getOpposite()))
|
blockState, side.getOpposite(), context.getLevel(), context.getClickedPos()))
|
||||||
if (prefferedSide != null && prefferedSide.getAxis() != side.getAxis()) {
|
if (preferredSide != null && preferredSide.getAxis() != side.getAxis()) {
|
||||||
prefferedSide = null;
|
preferredSide = null;
|
||||||
break;
|
break;
|
||||||
} else {
|
} else {
|
||||||
prefferedSide = side;
|
preferredSide = side;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return prefferedSide;
|
return preferredSide;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|
|
@ -1,11 +1,12 @@
|
||||||
package com.simibubi.create.content.contraptions.base;
|
package com.simibubi.create.content.contraptions.base;
|
||||||
|
|
||||||
import com.simibubi.create.content.contraptions.goggles.IHaveGoggleInformation;
|
import com.simibubi.create.content.contraptions.goggles.IHaveGoggleInformation;
|
||||||
import com.simibubi.create.content.contraptions.solver.AllConnections;
|
import com.simibubi.create.content.contraptions.relays.elementary.ICogWheel;
|
||||||
import com.simibubi.create.content.contraptions.solver.KineticConnections;
|
import com.simibubi.create.content.contraptions.solver.ConnectionsBuilder;
|
||||||
import com.simibubi.create.content.contraptions.wrench.IWrenchable;
|
import com.simibubi.create.content.contraptions.wrench.IWrenchable;
|
||||||
import com.simibubi.create.foundation.config.AllConfigs;
|
import com.simibubi.create.foundation.config.AllConfigs;
|
||||||
import com.simibubi.create.foundation.item.ItemDescription;
|
import com.simibubi.create.foundation.item.ItemDescription;
|
||||||
|
import com.simibubi.create.foundation.utility.Iterate;
|
||||||
import com.simibubi.create.foundation.utility.Lang;
|
import com.simibubi.create.foundation.utility.Lang;
|
||||||
|
|
||||||
import net.minecraft.ChatFormatting;
|
import net.minecraft.ChatFormatting;
|
||||||
|
@ -15,6 +16,7 @@ import net.minecraft.core.Direction.Axis;
|
||||||
import net.minecraft.network.chat.Component;
|
import net.minecraft.network.chat.Component;
|
||||||
import net.minecraft.network.chat.MutableComponent;
|
import net.minecraft.network.chat.MutableComponent;
|
||||||
import net.minecraft.network.chat.TextComponent;
|
import net.minecraft.network.chat.TextComponent;
|
||||||
|
import net.minecraft.world.level.Level;
|
||||||
import net.minecraft.world.level.LevelReader;
|
import net.minecraft.world.level.LevelReader;
|
||||||
import net.minecraft.world.level.block.state.BlockState;
|
import net.minecraft.world.level.block.state.BlockState;
|
||||||
|
|
||||||
|
@ -121,12 +123,26 @@ public interface IRotate extends IWrenchable {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
boolean hasShaftTowards(LevelReader world, BlockPos pos, BlockState state, Direction face);
|
boolean hasShaftTowards(BlockState state, Direction face);
|
||||||
|
|
||||||
|
default boolean hasShaftTowards(BlockState state, Direction face, LevelReader level, BlockPos pos) {
|
||||||
|
return hasShaftTowards(state, face);
|
||||||
|
}
|
||||||
|
|
||||||
Axis getRotationAxis(BlockState state);
|
Axis getRotationAxis(BlockState state);
|
||||||
|
|
||||||
default KineticConnections getInitialConnections(BlockState state) {
|
default ConnectionsBuilder buildInitialConnections(ConnectionsBuilder builder, BlockState state) {
|
||||||
return AllConnections.EMPTY;
|
for (Direction face : Iterate.directions) {
|
||||||
|
if (hasShaftTowards(state, face))
|
||||||
|
builder = builder.withHalfShaft(face);
|
||||||
|
}
|
||||||
|
if (state.getBlock() instanceof ICogWheel cog) {
|
||||||
|
if (cog.isLargeCog())
|
||||||
|
builder = builder.withLargeCog(getRotationAxis(state));
|
||||||
|
if (cog.isSmallCog())
|
||||||
|
builder = builder.withSmallCog(getRotationAxis(state));
|
||||||
|
}
|
||||||
|
return builder;
|
||||||
}
|
}
|
||||||
|
|
||||||
default SpeedLevel getMinimumRequiredSpeedLevel() {
|
default SpeedLevel getMinimumRequiredSpeedLevel() {
|
||||||
|
|
|
@ -8,7 +8,6 @@ import net.minecraft.world.entity.LivingEntity;
|
||||||
import net.minecraft.world.item.ItemStack;
|
import net.minecraft.world.item.ItemStack;
|
||||||
import net.minecraft.world.level.Level;
|
import net.minecraft.world.level.Level;
|
||||||
import net.minecraft.world.level.LevelAccessor;
|
import net.minecraft.world.level.LevelAccessor;
|
||||||
import net.minecraft.world.level.LevelReader;
|
|
||||||
import net.minecraft.world.level.block.Block;
|
import net.minecraft.world.level.block.Block;
|
||||||
import net.minecraft.world.level.block.entity.BlockEntity;
|
import net.minecraft.world.level.block.entity.BlockEntity;
|
||||||
import net.minecraft.world.level.block.state.BlockState;
|
import net.minecraft.world.level.block.state.BlockState;
|
||||||
|
@ -22,7 +21,7 @@ public abstract class KineticBlock extends Block implements IRotate {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean hasShaftTowards(LevelReader world, BlockPos pos, BlockState state, Direction face) {
|
public boolean hasShaftTowards(BlockState state, Direction face) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -17,7 +17,7 @@ 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.content.contraptions.relays.elementary.ICogWheel;
|
||||||
import com.simibubi.create.content.contraptions.relays.gearbox.GearboxBlock;
|
import com.simibubi.create.content.contraptions.relays.gearbox.GearboxBlock;
|
||||||
import com.simibubi.create.content.contraptions.solver.AllConnections;
|
import com.simibubi.create.content.contraptions.solver.ConnectionsBuilder;
|
||||||
import com.simibubi.create.content.contraptions.solver.IKineticController;
|
import com.simibubi.create.content.contraptions.solver.IKineticController;
|
||||||
import com.simibubi.create.content.contraptions.solver.KineticConnections;
|
import com.simibubi.create.content.contraptions.solver.KineticConnections;
|
||||||
import com.simibubi.create.content.contraptions.solver.KineticSolver;
|
import com.simibubi.create.content.contraptions.solver.KineticSolver;
|
||||||
|
@ -35,7 +35,6 @@ import net.minecraft.client.resources.language.I18n;
|
||||||
import net.minecraft.core.BlockPos;
|
import net.minecraft.core.BlockPos;
|
||||||
import net.minecraft.core.Direction;
|
import net.minecraft.core.Direction;
|
||||||
import net.minecraft.core.Direction.AxisDirection;
|
import net.minecraft.core.Direction.AxisDirection;
|
||||||
import net.minecraft.core.Vec3i;
|
|
||||||
import net.minecraft.nbt.CompoundTag;
|
import net.minecraft.nbt.CompoundTag;
|
||||||
import net.minecraft.nbt.NbtUtils;
|
import net.minecraft.nbt.NbtUtils;
|
||||||
import net.minecraft.network.chat.Component;
|
import net.minecraft.network.chat.Component;
|
||||||
|
@ -53,37 +52,41 @@ import net.minecraftforge.fml.DistExecutor;
|
||||||
public class KineticTileEntity extends SmartTileEntity
|
public class KineticTileEntity extends SmartTileEntity
|
||||||
implements IHaveGoggleInformation, IHaveHoveringInformation, FlywheelRendered, IKineticController {
|
implements IHaveGoggleInformation, IHaveHoveringInformation, FlywheelRendered, IKineticController {
|
||||||
|
|
||||||
public @Nullable Long network = null;
|
|
||||||
public @Nullable BlockPos source = null;
|
|
||||||
|
|
||||||
protected KineticEffectHandler effects;
|
protected KineticEffectHandler effects;
|
||||||
protected float theoreticalSpeed;
|
|
||||||
protected KineticConnections clientConnections;
|
|
||||||
protected @Nullable BlockPos speedSource;
|
|
||||||
protected boolean overstressed;
|
|
||||||
protected float networkImpact;
|
|
||||||
protected float networkCapacity;
|
|
||||||
|
|
||||||
|
private float theoreticalSpeed;
|
||||||
|
private long networkID;
|
||||||
|
private @Nullable BlockPos speedSource;
|
||||||
|
private boolean overstressed;
|
||||||
|
private float networkImpact;
|
||||||
|
private float networkCapacity;
|
||||||
|
|
||||||
|
private boolean kineticsInit;
|
||||||
protected boolean wasMoved;
|
protected boolean wasMoved;
|
||||||
private int flickerTally;
|
private int flickerTally;
|
||||||
private int validationCountdown;
|
private int validationCountdown;
|
||||||
|
|
||||||
private final KineticConnections connections;
|
private KineticConnections initialConnections;
|
||||||
|
private boolean initialConnectionsChanged;
|
||||||
|
|
||||||
public KineticTileEntity(BlockEntityType<?> typeIn, BlockPos pos, BlockState state) {
|
public KineticTileEntity(BlockEntityType<?> typeIn, BlockPos pos, BlockState state) {
|
||||||
super(typeIn, pos, state);
|
super(typeIn, pos, state);
|
||||||
|
|
||||||
effects = new KineticEffectHandler(this);
|
effects = new KineticEffectHandler(this);
|
||||||
|
updateInitialConnections(state);
|
||||||
if (state.getBlock() instanceof IRotate rotate) {
|
|
||||||
connections = rotate.getInitialConnections(state);
|
|
||||||
} else {
|
|
||||||
connections = AllConnections.EMPTY;
|
|
||||||
}
|
|
||||||
clientConnections = connections;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override public KineticConnections getConnections() { return connections; }
|
protected void updateInitialConnections(BlockState state) {
|
||||||
|
if (state.getBlock() instanceof IRotate rotate) {
|
||||||
|
initialConnections = rotate.buildInitialConnections(ConnectionsBuilder.builder(), state).build();
|
||||||
|
if (getLevel() != null && !getLevel().isClientSide) {
|
||||||
|
initialConnectionsChanged = true;
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
initialConnections = KineticConnections.empty();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override public KineticConnections getConnections() { return initialConnections; }
|
||||||
|
|
||||||
@Override public float getStressImpact() { return getDefaultStressImpact(); }
|
@Override public float getStressImpact() { return getDefaultStressImpact(); }
|
||||||
|
|
||||||
|
@ -102,13 +105,8 @@ public class KineticTileEntity extends SmartTileEntity
|
||||||
return (float) BlockStressValues.getCapacity(getStressConfigKey());
|
return (float) BlockStressValues.getCapacity(getStressConfigKey());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public float getShaftSpeed(Direction face) {
|
||||||
public float getRotationSpeedModifier(Vec3i offset) {
|
return getSpeed() * getConnections().getShaftSpeedModifier(face);
|
||||||
return getClientConnections().checkConnection(offset).orElse(0f);
|
|
||||||
}
|
|
||||||
|
|
||||||
public float getRotationSpeedModifier(Direction face) {
|
|
||||||
return getRotationSpeedModifier(face.getNormal());
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -127,7 +125,7 @@ public class KineticTileEntity extends SmartTileEntity
|
||||||
|
|
||||||
if (level.isClientSide) {
|
if (level.isClientSide) {
|
||||||
cachedBoundingBox = null; // cache the bounding box for every frame between ticks
|
cachedBoundingBox = null; // cache the bounding box for every frame between ticks
|
||||||
DistExecutor.unsafeRunWhenOn(Dist.CLIENT, () -> () -> this.tickAudio());
|
DistExecutor.unsafeRunWhenOn(Dist.CLIENT, () -> this::tickAudio);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -165,6 +163,11 @@ public class KineticTileEntity extends SmartTileEntity
|
||||||
}
|
}
|
||||||
|
|
||||||
public void onSpeedChanged(float previousSpeed) {
|
public void onSpeedChanged(float previousSpeed) {
|
||||||
|
if (!level.isClientSide && getSpeedSource().isEmpty()) {
|
||||||
|
if (SpeedLevel.of(previousSpeed) != SpeedLevel.of(getSpeed()))
|
||||||
|
effects.queueRotationIndicators();
|
||||||
|
}
|
||||||
|
|
||||||
boolean fromOrToZero = (previousSpeed == 0) != (getSpeed() == 0);
|
boolean fromOrToZero = (previousSpeed == 0) != (getSpeed() == 0);
|
||||||
boolean directionSwap = !fromOrToZero && Math.signum(previousSpeed) != Math.signum(getSpeed());
|
boolean directionSwap = !fromOrToZero && Math.signum(previousSpeed) != Math.signum(getSpeed());
|
||||||
if (fromOrToZero || directionSwap)
|
if (fromOrToZero || directionSwap)
|
||||||
|
@ -179,13 +182,19 @@ public class KineticTileEntity extends SmartTileEntity
|
||||||
@Override
|
@Override
|
||||||
protected void write(CompoundTag compound, boolean clientPacket) {
|
protected void write(CompoundTag compound, boolean clientPacket) {
|
||||||
if (clientPacket) {
|
if (clientPacket) {
|
||||||
compound.putFloat("Speed", theoreticalSpeed);
|
if (initialConnectionsChanged) {
|
||||||
compound.put("Connections", clientConnections.save(new CompoundTag()));
|
compound.putBoolean("UpdateConnections", true);
|
||||||
compound.putBoolean("Overstressed", overstressed);
|
initialConnectionsChanged = false;
|
||||||
compound.putFloat("Impact", networkImpact);
|
}
|
||||||
compound.putFloat("Capacity", networkCapacity);
|
compound.putFloat("Speed", getTheoreticalSpeed());
|
||||||
if (speedSource != null)
|
getNetworkID().ifPresent(id -> compound.putLong("Network", id));
|
||||||
compound.put("Source", NbtUtils.writeBlockPos(speedSource));
|
if (isOverstressed())
|
||||||
|
compound.putBoolean("Overstressed", isOverstressed());
|
||||||
|
if (getNetworkImpact() > 0)
|
||||||
|
compound.putFloat("Impact", getNetworkImpact());
|
||||||
|
if (getNetworkCapacity() > 0)
|
||||||
|
compound.putFloat("Capacity", getNetworkCapacity());
|
||||||
|
getSpeedSource().ifPresent(source -> compound.put("Source", NbtUtils.writeBlockPos(source)));
|
||||||
}
|
}
|
||||||
|
|
||||||
super.write(compound, clientPacket);
|
super.write(compound, clientPacket);
|
||||||
|
@ -194,9 +203,11 @@ public class KineticTileEntity extends SmartTileEntity
|
||||||
@Override
|
@Override
|
||||||
protected void read(CompoundTag tag, boolean clientPacket) {
|
protected void read(CompoundTag tag, boolean clientPacket) {
|
||||||
if (clientPacket) {
|
if (clientPacket) {
|
||||||
|
if (tag.getBoolean("UpdateConnections"))
|
||||||
|
updateInitialConnections(getBlockState());
|
||||||
updateFromSolver(tag.getFloat("Speed"),
|
updateFromSolver(tag.getFloat("Speed"),
|
||||||
tag.contains("Source") ? NbtUtils.readBlockPos(tag.getCompound("Source")) : null,
|
tag.contains("Source") ? NbtUtils.readBlockPos(tag.getCompound("Source")) : null,
|
||||||
KineticConnections.load(tag.getCompound("Connections")),
|
tag.getLong("Network"),
|
||||||
tag.getBoolean("Overstressed"),
|
tag.getBoolean("Overstressed"),
|
||||||
tag.getFloat("Impact"),
|
tag.getFloat("Impact"),
|
||||||
tag.getFloat("Capacity"));
|
tag.getFloat("Capacity"));
|
||||||
|
@ -221,8 +232,8 @@ public class KineticTileEntity extends SmartTileEntity
|
||||||
return Optional.ofNullable(speedSource);
|
return Optional.ofNullable(speedSource);
|
||||||
}
|
}
|
||||||
|
|
||||||
public KineticConnections getClientConnections() {
|
public Optional<Long> getNetworkID() {
|
||||||
return clientConnections;
|
return networkID == 0 ? Optional.empty() : Optional.of(networkID);
|
||||||
}
|
}
|
||||||
|
|
||||||
public boolean isOverstressed() {
|
public boolean isOverstressed() {
|
||||||
|
@ -237,52 +248,41 @@ public class KineticTileEntity extends SmartTileEntity
|
||||||
return networkCapacity;
|
return networkCapacity;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void updateFromSolver(float theoreticalSpeed, @Nullable BlockPos speedSource, KineticConnections connections,
|
public void updateFromSolver(float theoreticalSpeed, @Nullable BlockPos speedSource, long networkID,
|
||||||
boolean overstressed, float networkImpact, float networkCapacity) {
|
boolean overstressed, float networkImpact, float networkCapacity) {
|
||||||
float prevSpeed = getSpeed();
|
float prevSpeed = getSpeed();
|
||||||
BlockPos prevSpeedSource = getSpeedSource().orElse(null);
|
BlockPos prevSpeedSource = this.speedSource;
|
||||||
KineticConnections prevConnections = getClientConnections();
|
long prevNetworkID = this.networkID;
|
||||||
boolean prevOverstressed = isOverstressed();
|
boolean prevOverstressed = isOverstressed();
|
||||||
float prevNetworkImpact = getNetworkImpact();
|
float prevNetworkImpact = getNetworkImpact();
|
||||||
float prevNetworkCapacity = getNetworkCapacity();
|
float prevNetworkCapacity = getNetworkCapacity();
|
||||||
|
|
||||||
this.theoreticalSpeed = theoreticalSpeed;
|
this.theoreticalSpeed = theoreticalSpeed;
|
||||||
this.speedSource = speedSource;
|
this.speedSource = speedSource;
|
||||||
this.clientConnections = connections;
|
this.networkID = networkID;
|
||||||
this.overstressed = overstressed;
|
this.overstressed = overstressed;
|
||||||
this.networkImpact = networkImpact;
|
this.networkImpact = networkImpact;
|
||||||
this.networkCapacity = networkCapacity;
|
this.networkCapacity = networkCapacity;
|
||||||
|
|
||||||
boolean send = false;
|
boolean changed = initialConnectionsChanged;
|
||||||
|
|
||||||
if (prevOverstressed != overstressed || prevNetworkImpact != networkImpact || prevNetworkCapacity != networkCapacity) {
|
if (!kineticsInit || prevOverstressed != overstressed || prevNetworkImpact != networkImpact
|
||||||
|
|| prevNetworkCapacity != networkCapacity) {
|
||||||
onStressChanged(prevNetworkImpact, prevNetworkCapacity, prevOverstressed);
|
onStressChanged(prevNetworkImpact, prevNetworkCapacity, prevOverstressed);
|
||||||
send = true;
|
changed = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (getSpeed() != prevSpeed) {
|
if (!kineticsInit || getSpeed() != prevSpeed) {
|
||||||
onSpeedChanged(prevSpeed);
|
onSpeedChanged(prevSpeed);
|
||||||
send = true;
|
changed = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
kineticsInit = true;
|
||||||
if (level.isClientSide) return;
|
if (level.isClientSide) return;
|
||||||
|
if (changed || networkID != prevNetworkID || !Objects.equal(speedSource, prevSpeedSource))
|
||||||
if (!connections.equals(prevConnections))
|
|
||||||
send = true;
|
|
||||||
if (!Objects.equal(speedSource, prevSpeedSource))
|
|
||||||
send = true;
|
|
||||||
if (send)
|
|
||||||
sendData();
|
sendData();
|
||||||
}
|
}
|
||||||
|
|
||||||
public boolean hasSource() {
|
|
||||||
return source != null;
|
|
||||||
}
|
|
||||||
|
|
||||||
public boolean hasNetwork() {
|
|
||||||
return network != null;
|
|
||||||
}
|
|
||||||
|
|
||||||
public boolean isSpeedRequirementFulfilled() {
|
public boolean isSpeedRequirementFulfilled() {
|
||||||
BlockState state = getBlockState();
|
BlockState state = getBlockState();
|
||||||
if (!(getBlockState().getBlock() instanceof IRotate))
|
if (!(getBlockState().getBlock() instanceof IRotate))
|
||||||
|
@ -299,8 +299,12 @@ public class KineticTileEntity extends SmartTileEntity
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void switchToBlockState(Level world, BlockPos pos, BlockState state) {
|
public static void switchToBlockState(Level world, BlockPos pos, BlockState state) {
|
||||||
if (!world.isClientSide)
|
if (!world.isClientSide) {
|
||||||
world.setBlock(pos, state, 3);
|
world.setBlockAndUpdate(pos, state);
|
||||||
|
if (world.getBlockEntity(pos) instanceof KineticTileEntity kte) {
|
||||||
|
kte.updateInitialConnections(state);
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -341,16 +345,17 @@ public class KineticTileEntity extends SmartTileEntity
|
||||||
@Override
|
@Override
|
||||||
public boolean addToGoggleTooltip(List<Component> tooltip, boolean isPlayerSneaking) {
|
public boolean addToGoggleTooltip(List<Component> tooltip, boolean isPlayerSneaking) {
|
||||||
boolean added = false;
|
boolean added = false;
|
||||||
float stressAtBase = getStressImpact();
|
|
||||||
|
|
||||||
if (stressAtBase != 0 && StressImpact.isEnabled()) {
|
// stress impact info
|
||||||
|
float impact = getStressImpact();
|
||||||
|
if (impact != 0 && StressImpact.isEnabled()) {
|
||||||
tooltip.add(componentSpacing.plainCopy()
|
tooltip.add(componentSpacing.plainCopy()
|
||||||
.append(Lang.translate("gui.goggles.kinetic_stats")));
|
.append(Lang.translate("gui.goggles.kinetic_stats")));
|
||||||
tooltip.add(componentSpacing.plainCopy()
|
tooltip.add(componentSpacing.plainCopy()
|
||||||
.append(Lang.translate("tooltip.stressImpact")
|
.append(Lang.translate("tooltip.stressImpact")
|
||||||
.withStyle(ChatFormatting.GRAY)));
|
.withStyle(ChatFormatting.GRAY)));
|
||||||
|
|
||||||
float stressTotal = stressAtBase * Math.abs(getTheoreticalSpeed());
|
float stressTotal = impact * Math.abs(getTheoreticalSpeed());
|
||||||
|
|
||||||
tooltip.add(componentSpacing.plainCopy()
|
tooltip.add(componentSpacing.plainCopy()
|
||||||
.append(new TextComponent(" " + IHaveGoggleInformation.format(stressTotal))
|
.append(new TextComponent(" " + IHaveGoggleInformation.format(stressTotal))
|
||||||
|
@ -363,8 +368,31 @@ public class KineticTileEntity extends SmartTileEntity
|
||||||
added = true;
|
added = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
return added;
|
// stress capacity info
|
||||||
|
float capacity = getStressCapacity();
|
||||||
|
if (capacity != 0 && IRotate.StressImpact.isEnabled()) {
|
||||||
|
tooltip.add(componentSpacing.plainCopy().append(Lang.translate("gui.goggles.generator_stats")));
|
||||||
|
tooltip.add(componentSpacing.plainCopy().append(Lang.translate("tooltip.capacityProvided").withStyle(ChatFormatting.GRAY)));
|
||||||
|
|
||||||
|
float speed = getTheoreticalSpeed();
|
||||||
|
if (speed != getGeneratedSpeed() && speed != 0)
|
||||||
|
capacity *= getGeneratedSpeed() / speed;
|
||||||
|
|
||||||
|
speed = Math.abs(speed);
|
||||||
|
float stressTotal = capacity * speed;
|
||||||
|
|
||||||
|
tooltip.add(
|
||||||
|
componentSpacing.plainCopy()
|
||||||
|
.append(new TextComponent(" " + IHaveGoggleInformation.format(stressTotal))
|
||||||
|
.append(Lang.translate("generic.unit.stress"))
|
||||||
|
.withStyle(ChatFormatting.AQUA))
|
||||||
|
.append(" ")
|
||||||
|
.append(Lang.translate("gui.goggles.at_current_speed").withStyle(ChatFormatting.DARK_GRAY)));
|
||||||
|
|
||||||
|
added = true;
|
||||||
|
}
|
||||||
|
|
||||||
|
return added;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void clearKineticInformation() {
|
public void clearKineticInformation() {
|
||||||
|
|
|
@ -98,7 +98,7 @@ public class KineticTileEntityRenderer extends SafeTileEntityRenderer<KineticTil
|
||||||
|
|
||||||
if (KineticDebugger.isActive()) {
|
if (KineticDebugger.isActive()) {
|
||||||
rainbowMode = true;
|
rainbowMode = true;
|
||||||
buffer.color(te.hasNetwork() ? Color.generateFromLong(te.network) : Color.WHITE);
|
buffer.color(te.getNetworkID().map(Color::generateFromLong).orElse(Color.WHITE));
|
||||||
} else {
|
} else {
|
||||||
float overStressedEffect = te.effects.overStressedEffect;
|
float overStressedEffect = te.effects.overStressedEffect;
|
||||||
if (overStressedEffect != 0)
|
if (overStressedEffect != 0)
|
||||||
|
|
|
@ -24,40 +24,34 @@ public abstract class RotatedPillarKineticBlock extends KineticBlock {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public BlockState rotate(BlockState state, Rotation rot) {
|
public BlockState rotate(BlockState state, Rotation rot) {
|
||||||
switch (rot) {
|
return switch (rot) {
|
||||||
case COUNTERCLOCKWISE_90:
|
case COUNTERCLOCKWISE_90, CLOCKWISE_90 -> switch (state.getValue(AXIS)) {
|
||||||
case CLOCKWISE_90:
|
case X -> state.setValue(AXIS, Axis.Z);
|
||||||
switch (state.getValue(AXIS)) {
|
case Z -> state.setValue(AXIS, Axis.X);
|
||||||
case X:
|
default -> state;
|
||||||
return state.setValue(AXIS, Direction.Axis.Z);
|
};
|
||||||
case Z:
|
default -> state;
|
||||||
return state.setValue(AXIS, Direction.Axis.X);
|
};
|
||||||
default:
|
|
||||||
return state;
|
|
||||||
}
|
|
||||||
default:
|
|
||||||
return state;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public static Axis getPreferredAxis(BlockPlaceContext context) {
|
public static Axis getPreferredAxis(BlockPlaceContext context) {
|
||||||
Axis prefferedAxis = null;
|
Axis preferredAxis = null;
|
||||||
for (Direction side : Iterate.directions) {
|
for (Direction side : Iterate.directions) {
|
||||||
BlockState blockState = context.getLevel()
|
BlockState blockState = context.getLevel()
|
||||||
.getBlockState(context.getClickedPos()
|
.getBlockState(context.getClickedPos()
|
||||||
.relative(side));
|
.relative(side));
|
||||||
if (blockState.getBlock() instanceof IRotate) {
|
if (blockState.getBlock() instanceof IRotate) {
|
||||||
if (((IRotate) blockState.getBlock()).hasShaftTowards(context.getLevel(), context.getClickedPos()
|
if (((IRotate) blockState.getBlock()).hasShaftTowards(
|
||||||
.relative(side), blockState, side.getOpposite()))
|
blockState, side.getOpposite(), context.getLevel(), context.getClickedPos()))
|
||||||
if (prefferedAxis != null && prefferedAxis != side.getAxis()) {
|
if (preferredAxis != null && preferredAxis != side.getAxis()) {
|
||||||
prefferedAxis = null;
|
preferredAxis = null;
|
||||||
break;
|
break;
|
||||||
} else {
|
} else {
|
||||||
prefferedAxis = side.getAxis();
|
preferredAxis = side.getAxis();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return prefferedAxis;
|
return preferredAxis;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|
|
@ -39,11 +39,7 @@ public class KineticData extends BasicData {
|
||||||
}
|
}
|
||||||
|
|
||||||
public KineticData setColor(KineticTileEntity te) {
|
public KineticData setColor(KineticTileEntity te) {
|
||||||
if (te.hasNetwork()) {
|
setColor(te.getNetworkID().map(Color::generateFromLong).orElse(Color.WHITE));
|
||||||
setColor(Color.generateFromLong(te.network));
|
|
||||||
}else {
|
|
||||||
setColor(0xFF, 0xFF, 0xFF);
|
|
||||||
}
|
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -17,7 +17,6 @@ import net.minecraft.world.entity.Entity;
|
||||||
import net.minecraft.world.entity.item.ItemEntity;
|
import net.minecraft.world.entity.item.ItemEntity;
|
||||||
import net.minecraft.world.level.BlockGetter;
|
import net.minecraft.world.level.BlockGetter;
|
||||||
import net.minecraft.world.level.Level;
|
import net.minecraft.world.level.Level;
|
||||||
import net.minecraft.world.level.LevelReader;
|
|
||||||
import net.minecraft.world.level.block.Block;
|
import net.minecraft.world.level.block.Block;
|
||||||
import net.minecraft.world.level.block.entity.BlockEntityType;
|
import net.minecraft.world.level.block.entity.BlockEntityType;
|
||||||
import net.minecraft.world.level.block.state.BlockState;
|
import net.minecraft.world.level.block.state.BlockState;
|
||||||
|
@ -68,7 +67,7 @@ public class DrillBlock extends DirectionalKineticBlock implements ITE<DrillTile
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean hasShaftTowards(LevelReader world, BlockPos pos, BlockState state, Direction face) {
|
public boolean hasShaftTowards(BlockState state, Direction face) {
|
||||||
return face == state.getValue(FACING)
|
return face == state.getValue(FACING)
|
||||||
.getOpposite();
|
.getOpposite();
|
||||||
}
|
}
|
||||||
|
|
|
@ -13,7 +13,6 @@ import net.minecraft.world.item.CreativeModeTab;
|
||||||
import net.minecraft.world.item.ItemStack;
|
import net.minecraft.world.item.ItemStack;
|
||||||
import net.minecraft.world.item.context.BlockPlaceContext;
|
import net.minecraft.world.item.context.BlockPlaceContext;
|
||||||
import net.minecraft.world.level.BlockGetter;
|
import net.minecraft.world.level.BlockGetter;
|
||||||
import net.minecraft.world.level.LevelReader;
|
|
||||||
import net.minecraft.world.level.block.Block;
|
import net.minecraft.world.level.block.Block;
|
||||||
import net.minecraft.world.level.block.entity.BlockEntityType;
|
import net.minecraft.world.level.block.entity.BlockEntityType;
|
||||||
import net.minecraft.world.level.block.state.BlockState;
|
import net.minecraft.world.level.block.state.BlockState;
|
||||||
|
@ -59,7 +58,7 @@ public class CuckooClockBlock extends HorizontalKineticBlock implements ITE<Cuck
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean hasShaftTowards(LevelReader world, BlockPos pos, BlockState state, Direction face) {
|
public boolean hasShaftTowards(BlockState state, Direction face) {
|
||||||
return face == state.getValue(HORIZONTAL_FACING).getOpposite();
|
return face == state.getValue(HORIZONTAL_FACING).getOpposite();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -98,15 +98,13 @@ public class HandCrankBlock extends DirectionalKineticBlock implements ITE<HandC
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean hasShaftTowards(LevelReader world, BlockPos pos, BlockState state, Direction face) {
|
public boolean hasShaftTowards(BlockState state, Direction face) {
|
||||||
return face == state.getValue(FACING)
|
return face == state.getValue(FACING).getOpposite();
|
||||||
.getOpposite();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Axis getRotationAxis(BlockState state) {
|
public Axis getRotationAxis(BlockState state) {
|
||||||
return state.getValue(FACING)
|
return state.getValue(FACING).getAxis();
|
||||||
.getAxis();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|
|
@ -2,7 +2,7 @@ package com.simibubi.create.content.contraptions.components.crank;
|
||||||
|
|
||||||
import com.simibubi.create.AllBlocks;
|
import com.simibubi.create.AllBlocks;
|
||||||
import com.simibubi.create.AllSoundEvents;
|
import com.simibubi.create.AllSoundEvents;
|
||||||
import com.simibubi.create.content.contraptions.base.GeneratingKineticTileEntity;
|
import com.simibubi.create.content.contraptions.base.KineticTileEntity;
|
||||||
import com.simibubi.create.foundation.utility.AnimationTickHolder;
|
import com.simibubi.create.foundation.utility.AnimationTickHolder;
|
||||||
|
|
||||||
import net.minecraft.core.BlockPos;
|
import net.minecraft.core.BlockPos;
|
||||||
|
@ -13,7 +13,7 @@ import net.minecraft.world.level.block.state.BlockState;
|
||||||
import net.minecraftforge.api.distmarker.Dist;
|
import net.minecraftforge.api.distmarker.Dist;
|
||||||
import net.minecraftforge.api.distmarker.OnlyIn;
|
import net.minecraftforge.api.distmarker.OnlyIn;
|
||||||
|
|
||||||
public class HandCrankTileEntity extends GeneratingKineticTileEntity {
|
public class HandCrankTileEntity extends KineticTileEntity {
|
||||||
|
|
||||||
public int inUse;
|
public int inUse;
|
||||||
public boolean backwards;
|
public boolean backwards;
|
||||||
|
@ -25,23 +25,16 @@ public class HandCrankTileEntity extends GeneratingKineticTileEntity {
|
||||||
}
|
}
|
||||||
|
|
||||||
public void turn(boolean back) {
|
public void turn(boolean back) {
|
||||||
boolean update = false;
|
|
||||||
|
|
||||||
if (getGeneratedSpeed() == 0 || back != backwards)
|
|
||||||
update = true;
|
|
||||||
|
|
||||||
inUse = 10;
|
inUse = 10;
|
||||||
this.backwards = back;
|
backwards = back;
|
||||||
if (update && !level.isClientSide)
|
|
||||||
updateGeneratedRotation();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public float getGeneratedSpeed() {
|
public float getGeneratedSpeed() {
|
||||||
|
if (isRemoved()) return 0;
|
||||||
Block block = getBlockState().getBlock();
|
Block block = getBlockState().getBlock();
|
||||||
if (!(block instanceof HandCrankBlock))
|
if (!(block instanceof HandCrankBlock crank))
|
||||||
return 0;
|
return 0;
|
||||||
HandCrankBlock crank = (HandCrankBlock) block;
|
|
||||||
int speed = (inUse == 0 ? 0 : backwards ? -1 : 1) * crank.getRotationSpeed();
|
int speed = (inUse == 0 ? 0 : backwards ? -1 : 1) * crank.getRotationSpeed();
|
||||||
return convertToDirection(speed, getBlockState().getValue(HandCrankBlock.FACING));
|
return convertToDirection(speed, getBlockState().getValue(HandCrankBlock.FACING));
|
||||||
}
|
}
|
||||||
|
@ -66,12 +59,8 @@ public class HandCrankTileEntity extends GeneratingKineticTileEntity {
|
||||||
chasingVelocity += ((actualSpeed * 10 / 3f) - chasingVelocity) * .25f;
|
chasingVelocity += ((actualSpeed * 10 / 3f) - chasingVelocity) * .25f;
|
||||||
independentAngle += chasingVelocity;
|
independentAngle += chasingVelocity;
|
||||||
|
|
||||||
if (inUse > 0) {
|
if (inUse > 0)
|
||||||
inUse--;
|
inUse--;
|
||||||
|
|
||||||
if (inUse == 0 && !level.isClientSide)
|
|
||||||
updateGeneratedRotation();
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|
|
@ -171,7 +171,7 @@ public class CrushingWheelBlock extends RotatedPillarKineticBlock implements ITE
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean hasShaftTowards(LevelReader world, BlockPos pos, BlockState state, Direction face) {
|
public boolean hasShaftTowards(BlockState state, Direction face) {
|
||||||
return face.getAxis() == state.getValue(AXIS);
|
return face.getAxis() == state.getValue(AXIS);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -13,7 +13,6 @@ import net.minecraft.world.item.context.BlockPlaceContext;
|
||||||
import net.minecraft.world.item.context.UseOnContext;
|
import net.minecraft.world.item.context.UseOnContext;
|
||||||
import net.minecraft.world.level.Level;
|
import net.minecraft.world.level.Level;
|
||||||
import net.minecraft.world.level.LevelAccessor;
|
import net.minecraft.world.level.LevelAccessor;
|
||||||
import net.minecraft.world.level.LevelReader;
|
|
||||||
import net.minecraft.world.level.block.Block;
|
import net.minecraft.world.level.block.Block;
|
||||||
import net.minecraft.world.level.block.entity.BlockEntityType;
|
import net.minecraft.world.level.block.entity.BlockEntityType;
|
||||||
import net.minecraft.world.level.block.state.BlockState;
|
import net.minecraft.world.level.block.state.BlockState;
|
||||||
|
@ -96,7 +95,7 @@ public class EncasedFanBlock extends DirectionalKineticBlock implements ITE<Enca
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean hasShaftTowards(LevelReader world, BlockPos pos, BlockState state, Direction face) {
|
public boolean hasShaftTowards(BlockState state, Direction face) {
|
||||||
return face == state.getValue(FACING)
|
return face == state.getValue(FACING)
|
||||||
.getOpposite();
|
.getOpposite();
|
||||||
}
|
}
|
||||||
|
|
|
@ -4,7 +4,7 @@ import javax.annotation.Nullable;
|
||||||
|
|
||||||
import com.simibubi.create.AllBlocks;
|
import com.simibubi.create.AllBlocks;
|
||||||
import com.simibubi.create.AllTags.AllBlockTags;
|
import com.simibubi.create.AllTags.AllBlockTags;
|
||||||
import com.simibubi.create.content.contraptions.base.GeneratingKineticTileEntity;
|
import com.simibubi.create.content.contraptions.base.KineticTileEntity;
|
||||||
import com.simibubi.create.content.contraptions.processing.burner.BlazeBurnerBlock;
|
import com.simibubi.create.content.contraptions.processing.burner.BlazeBurnerBlock;
|
||||||
import com.simibubi.create.content.logistics.block.chute.ChuteTileEntity;
|
import com.simibubi.create.content.logistics.block.chute.ChuteTileEntity;
|
||||||
import com.simibubi.create.foundation.config.AllConfigs;
|
import com.simibubi.create.foundation.config.AllConfigs;
|
||||||
|
@ -20,7 +20,7 @@ import net.minecraft.world.level.block.state.BlockState;
|
||||||
import net.minecraft.world.level.block.state.properties.BlockStateProperties;
|
import net.minecraft.world.level.block.state.properties.BlockStateProperties;
|
||||||
|
|
||||||
@MethodsReturnNonnullByDefault
|
@MethodsReturnNonnullByDefault
|
||||||
public class EncasedFanTileEntity extends GeneratingKineticTileEntity implements IAirCurrentSource {
|
public class EncasedFanTileEntity extends KineticTileEntity implements IAirCurrentSource {
|
||||||
|
|
||||||
public AirCurrent airCurrent;
|
public AirCurrent airCurrent;
|
||||||
protected int airCurrentUpdateCooldown;
|
protected int airCurrentUpdateCooldown;
|
||||||
|
@ -52,21 +52,21 @@ public class EncasedFanTileEntity extends GeneratingKineticTileEntity implements
|
||||||
super.write(compound, clientPacket);
|
super.write(compound, clientPacket);
|
||||||
}
|
}
|
||||||
|
|
||||||
public float calculateAddedStressCapacity() {
|
|
||||||
//return lastCapacityProvided = (isGenerator ? super.calculateAddedStressCapacity() : 0);
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
public float calculateStressApplied() {
|
|
||||||
//return isGenerator ? 0 : super.calculateStressApplied();
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public float getGeneratedSpeed() {
|
public float getGeneratedSpeed() {
|
||||||
return isGenerator ? AllConfigs.SERVER.kinetics.generatingFanSpeed.get() : 0;
|
return isGenerator ? AllConfigs.SERVER.kinetics.generatingFanSpeed.get() : 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public float getStressCapacity() {
|
||||||
|
return isGenerator ? super.getStressCapacity() : 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public float getStressImpact() {
|
||||||
|
return isGenerator ? 0 : super.getStressImpact();
|
||||||
|
}
|
||||||
|
|
||||||
public void queueGeneratorUpdate() {
|
public void queueGeneratorUpdate() {
|
||||||
updateGenerator = true;
|
updateGenerator = true;
|
||||||
}
|
}
|
||||||
|
@ -88,7 +88,6 @@ public class EncasedFanTileEntity extends GeneratingKineticTileEntity implements
|
||||||
if (shouldGenerate == isGenerator)
|
if (shouldGenerate == isGenerator)
|
||||||
return;
|
return;
|
||||||
isGenerator = shouldGenerate;
|
isGenerator = shouldGenerate;
|
||||||
updateGeneratedRotation();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public boolean blockBelowIsHot() {
|
public boolean blockBelowIsHot() {
|
||||||
|
|
|
@ -16,7 +16,6 @@ import net.minecraft.world.InteractionResult;
|
||||||
import net.minecraft.world.item.context.BlockPlaceContext;
|
import net.minecraft.world.item.context.BlockPlaceContext;
|
||||||
import net.minecraft.world.item.context.UseOnContext;
|
import net.minecraft.world.item.context.UseOnContext;
|
||||||
import net.minecraft.world.level.Level;
|
import net.minecraft.world.level.Level;
|
||||||
import net.minecraft.world.level.LevelReader;
|
|
||||||
import net.minecraft.world.level.block.Block;
|
import net.minecraft.world.level.block.Block;
|
||||||
import net.minecraft.world.level.block.entity.BlockEntityType;
|
import net.minecraft.world.level.block.entity.BlockEntityType;
|
||||||
import net.minecraft.world.level.block.state.BlockState;
|
import net.minecraft.world.level.block.state.BlockState;
|
||||||
|
@ -74,7 +73,7 @@ public class FlywheelBlock extends HorizontalKineticBlock implements ITE<Flywhee
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean hasShaftTowards(LevelReader world, BlockPos pos, BlockState state, Direction face) {
|
public boolean hasShaftTowards(BlockState state, Direction face) {
|
||||||
return face == state.getValue(HORIZONTAL_FACING).getOpposite();
|
return face == state.getValue(HORIZONTAL_FACING).getOpposite();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
package com.simibubi.create.content.contraptions.components.flywheel;
|
package com.simibubi.create.content.contraptions.components.flywheel;
|
||||||
|
|
||||||
import com.simibubi.create.content.contraptions.base.GeneratingKineticTileEntity;
|
import com.simibubi.create.content.contraptions.base.KineticTileEntity;
|
||||||
import com.simibubi.create.foundation.utility.animation.InterpolatedChasingValue;
|
import com.simibubi.create.foundation.utility.animation.InterpolatedChasingValue;
|
||||||
|
|
||||||
import net.minecraft.core.BlockPos;
|
import net.minecraft.core.BlockPos;
|
||||||
|
@ -9,7 +9,7 @@ import net.minecraft.world.level.block.entity.BlockEntityType;
|
||||||
import net.minecraft.world.level.block.state.BlockState;
|
import net.minecraft.world.level.block.state.BlockState;
|
||||||
import net.minecraft.world.phys.AABB;
|
import net.minecraft.world.phys.AABB;
|
||||||
|
|
||||||
public class FlywheelTileEntity extends GeneratingKineticTileEntity {
|
public class FlywheelTileEntity extends KineticTileEntity {
|
||||||
|
|
||||||
private float generatedCapacity;
|
private float generatedCapacity;
|
||||||
private float generatedSpeed;
|
private float generatedSpeed;
|
||||||
|
@ -25,7 +25,6 @@ public class FlywheelTileEntity extends GeneratingKineticTileEntity {
|
||||||
|
|
||||||
public void setRotation(float speed, float capacity) {
|
public void setRotation(float speed, float capacity) {
|
||||||
if (generatedSpeed != speed || generatedCapacity != capacity) {
|
if (generatedSpeed != speed || generatedCapacity != capacity) {
|
||||||
|
|
||||||
if (speed == 0) {
|
if (speed == 0) {
|
||||||
if (stoppingCooldown == 0)
|
if (stoppingCooldown == 0)
|
||||||
stoppingCooldown = 40;
|
stoppingCooldown = 40;
|
||||||
|
@ -35,20 +34,15 @@ public class FlywheelTileEntity extends GeneratingKineticTileEntity {
|
||||||
stoppingCooldown = 0;
|
stoppingCooldown = 0;
|
||||||
generatedSpeed = speed;
|
generatedSpeed = speed;
|
||||||
generatedCapacity = capacity;
|
generatedCapacity = capacity;
|
||||||
updateGeneratedRotation();
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public float getGeneratedSpeed() {
|
public float getGeneratedSpeed() {
|
||||||
|
if (isRemoved()) return 0;
|
||||||
return convertToDirection(generatedSpeed, getBlockState().getValue(FlywheelBlock.HORIZONTAL_FACING));
|
return convertToDirection(generatedSpeed, getBlockState().getValue(FlywheelBlock.HORIZONTAL_FACING));
|
||||||
}
|
}
|
||||||
|
|
||||||
public float calculateAddedStressCapacity() {
|
|
||||||
//return lastCapacityProvided = generatedCapacity;
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public AABB makeRenderBoundingBox() {
|
public AABB makeRenderBoundingBox() {
|
||||||
return super.makeRenderBoundingBox().inflate(2);
|
return super.makeRenderBoundingBox().inflate(2);
|
||||||
|
@ -78,7 +72,7 @@ public class FlywheelTileEntity extends GeneratingKineticTileEntity {
|
||||||
super.tick();
|
super.tick();
|
||||||
|
|
||||||
if (level.isClientSide) {
|
if (level.isClientSide) {
|
||||||
float targetSpeed = isVirtual() ? theoreticalSpeed : getGeneratedSpeed();
|
float targetSpeed = isVirtual() ? getTheoreticalSpeed() : getGeneratedSpeed();
|
||||||
visualSpeed.target(targetSpeed);
|
visualSpeed.target(targetSpeed);
|
||||||
visualSpeed.tick();
|
visualSpeed.tick();
|
||||||
angle += visualSpeed.value * 3 / 10f;
|
angle += visualSpeed.value * 3 / 10f;
|
||||||
|
@ -86,13 +80,6 @@ public class FlywheelTileEntity extends GeneratingKineticTileEntity {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
|
||||||
* After getting moved by pistons the generatedSpeed attribute reads 16 but the
|
|
||||||
* actual speed stays at 0, if it happens update rotation
|
|
||||||
*/
|
|
||||||
if (getGeneratedSpeed() != 0 && getSpeed() == 0)
|
|
||||||
updateGeneratedRotation();
|
|
||||||
|
|
||||||
if (stoppingCooldown == 0)
|
if (stoppingCooldown == 0)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
|
@ -100,7 +87,6 @@ public class FlywheelTileEntity extends GeneratingKineticTileEntity {
|
||||||
if (stoppingCooldown == 0) {
|
if (stoppingCooldown == 0) {
|
||||||
generatedCapacity = 0;
|
generatedCapacity = 0;
|
||||||
generatedSpeed = 0;
|
generatedSpeed = 0;
|
||||||
updateGeneratedRotation();
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -19,7 +19,6 @@ import net.minecraft.world.entity.player.Player;
|
||||||
import net.minecraft.world.item.ItemStack;
|
import net.minecraft.world.item.ItemStack;
|
||||||
import net.minecraft.world.level.BlockGetter;
|
import net.minecraft.world.level.BlockGetter;
|
||||||
import net.minecraft.world.level.Level;
|
import net.minecraft.world.level.Level;
|
||||||
import net.minecraft.world.level.LevelReader;
|
|
||||||
import net.minecraft.world.level.block.entity.BlockEntityType;
|
import net.minecraft.world.level.block.entity.BlockEntityType;
|
||||||
import net.minecraft.world.level.block.state.BlockState;
|
import net.minecraft.world.level.block.state.BlockState;
|
||||||
import net.minecraft.world.level.pathfinder.PathComputationType;
|
import net.minecraft.world.level.pathfinder.PathComputationType;
|
||||||
|
@ -44,7 +43,7 @@ public class MillstoneBlock extends KineticBlock implements ITE<MillstoneTileEnt
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean hasShaftTowards(LevelReader world, BlockPos pos, BlockState state, Direction face) {
|
public boolean hasShaftTowards(BlockState state, Direction face) {
|
||||||
return face == Direction.DOWN;
|
return face == Direction.DOWN;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -46,7 +46,7 @@ public class MechanicalMixerBlock extends KineticBlock implements ITE<Mechanical
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean hasShaftTowards(LevelReader world, BlockPos pos, BlockState state, Direction face) {
|
public boolean hasShaftTowards(BlockState state, Direction face) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -3,9 +3,6 @@ package com.simibubi.create.content.contraptions.components.motor;
|
||||||
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.DirectionalKineticBlock;
|
import com.simibubi.create.content.contraptions.base.DirectionalKineticBlock;
|
||||||
import com.simibubi.create.content.contraptions.solver.AllConnections;
|
|
||||||
import com.simibubi.create.content.contraptions.solver.KineticConnections;
|
|
||||||
import com.simibubi.create.content.contraptions.solver.KineticSolver;
|
|
||||||
import com.simibubi.create.foundation.block.ITE;
|
import com.simibubi.create.foundation.block.ITE;
|
||||||
|
|
||||||
import net.minecraft.core.BlockPos;
|
import net.minecraft.core.BlockPos;
|
||||||
|
@ -13,8 +10,6 @@ import net.minecraft.core.Direction;
|
||||||
import net.minecraft.core.Direction.Axis;
|
import net.minecraft.core.Direction.Axis;
|
||||||
import net.minecraft.world.item.context.BlockPlaceContext;
|
import net.minecraft.world.item.context.BlockPlaceContext;
|
||||||
import net.minecraft.world.level.BlockGetter;
|
import net.minecraft.world.level.BlockGetter;
|
||||||
import net.minecraft.world.level.Level;
|
|
||||||
import net.minecraft.world.level.LevelReader;
|
|
||||||
import net.minecraft.world.level.block.entity.BlockEntityType;
|
import net.minecraft.world.level.block.entity.BlockEntityType;
|
||||||
import net.minecraft.world.level.block.state.BlockState;
|
import net.minecraft.world.level.block.state.BlockState;
|
||||||
import net.minecraft.world.level.pathfinder.PathComputationType;
|
import net.minecraft.world.level.pathfinder.PathComputationType;
|
||||||
|
@ -44,7 +39,7 @@ public class CreativeMotorBlock extends DirectionalKineticBlock implements ITE<C
|
||||||
// IRotate:
|
// IRotate:
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean hasShaftTowards(LevelReader world, BlockPos pos, BlockState state, Direction face) {
|
public boolean hasShaftTowards(BlockState state, Direction face) {
|
||||||
return face == state.getValue(FACING);
|
return face == state.getValue(FACING);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -54,11 +49,6 @@ public class CreativeMotorBlock extends DirectionalKineticBlock implements ITE<C
|
||||||
.getAxis();
|
.getAxis();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
|
||||||
public KineticConnections getInitialConnections(BlockState state) {
|
|
||||||
return AllConnections.HALF_SHAFT.apply(state.getValue(FACING));
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean hideStressImpact() {
|
public boolean hideStressImpact() {
|
||||||
return true;
|
return true;
|
||||||
|
|
|
@ -3,7 +3,7 @@ package com.simibubi.create.content.contraptions.components.motor;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
import com.simibubi.create.AllBlocks;
|
import com.simibubi.create.AllBlocks;
|
||||||
import com.simibubi.create.content.contraptions.base.GeneratingKineticTileEntity;
|
import com.simibubi.create.content.contraptions.base.KineticTileEntity;
|
||||||
import com.simibubi.create.foundation.config.AllConfigs;
|
import com.simibubi.create.foundation.config.AllConfigs;
|
||||||
import com.simibubi.create.foundation.tileEntity.TileEntityBehaviour;
|
import com.simibubi.create.foundation.tileEntity.TileEntityBehaviour;
|
||||||
import com.simibubi.create.foundation.tileEntity.behaviour.CenteredSideValueBoxTransform;
|
import com.simibubi.create.foundation.tileEntity.behaviour.CenteredSideValueBoxTransform;
|
||||||
|
@ -15,7 +15,7 @@ import net.minecraft.core.BlockPos;
|
||||||
import net.minecraft.world.level.block.entity.BlockEntityType;
|
import net.minecraft.world.level.block.entity.BlockEntityType;
|
||||||
import net.minecraft.world.level.block.state.BlockState;
|
import net.minecraft.world.level.block.state.BlockState;
|
||||||
|
|
||||||
public class CreativeMotorTileEntity extends GeneratingKineticTileEntity {
|
public class CreativeMotorTileEntity extends KineticTileEntity {
|
||||||
|
|
||||||
public static final int DEFAULT_SPEED = 16;
|
public static final int DEFAULT_SPEED = 16;
|
||||||
protected ScrollValueBehaviour generatedSpeed;
|
protected ScrollValueBehaviour generatedSpeed;
|
||||||
|
@ -63,7 +63,7 @@ public class CreativeMotorTileEntity extends GeneratingKineticTileEntity {
|
||||||
step *= 4;
|
step *= 4;
|
||||||
}
|
}
|
||||||
|
|
||||||
return (int) (current + (context.forward ? step : -step) == 0 ? step + 1 : step);
|
return current + (context.forward ? step : -step) == 0 ? step + 1 : step;
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -55,7 +55,7 @@ public class MechanicalPressBlock extends HorizontalKineticBlock implements ITE<
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean hasShaftTowards(LevelReader world, BlockPos pos, BlockState state, Direction face) {
|
public boolean hasShaftTowards(BlockState state, Direction face) {
|
||||||
return face.getAxis() == state.getValue(HORIZONTAL_FACING)
|
return face.getAxis() == state.getValue(HORIZONTAL_FACING)
|
||||||
.getAxis();
|
.getAxis();
|
||||||
}
|
}
|
||||||
|
|
|
@ -21,7 +21,6 @@ import net.minecraft.world.entity.item.ItemEntity;
|
||||||
import net.minecraft.world.item.context.BlockPlaceContext;
|
import net.minecraft.world.item.context.BlockPlaceContext;
|
||||||
import net.minecraft.world.level.BlockGetter;
|
import net.minecraft.world.level.BlockGetter;
|
||||||
import net.minecraft.world.level.Level;
|
import net.minecraft.world.level.Level;
|
||||||
import net.minecraft.world.level.LevelReader;
|
|
||||||
import net.minecraft.world.level.block.entity.BlockEntityType;
|
import net.minecraft.world.level.block.entity.BlockEntityType;
|
||||||
import net.minecraft.world.level.block.state.BlockState;
|
import net.minecraft.world.level.block.state.BlockState;
|
||||||
import net.minecraft.world.level.material.PushReaction;
|
import net.minecraft.world.level.material.PushReaction;
|
||||||
|
@ -97,9 +96,9 @@ public class SawBlock extends DirectionalAxisKineticBlock implements ITE<SawTile
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean hasShaftTowards(LevelReader world, BlockPos pos, BlockState state, Direction face) {
|
public boolean hasShaftTowards(BlockState state, Direction face) {
|
||||||
return isHorizontal(state) ? face == state.getValue(FACING).getOpposite()
|
return isHorizontal(state) ? face == state.getValue(FACING).getOpposite()
|
||||||
: super.hasShaftTowards(world, pos, state, face);
|
: super.hasShaftTowards(state, face);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|
|
@ -2,12 +2,10 @@ package com.simibubi.create.content.contraptions.components.structureMovement.be
|
||||||
|
|
||||||
import com.simibubi.create.content.contraptions.base.DirectionalKineticBlock;
|
import com.simibubi.create.content.contraptions.base.DirectionalKineticBlock;
|
||||||
|
|
||||||
import net.minecraft.core.BlockPos;
|
|
||||||
import net.minecraft.core.Direction;
|
import net.minecraft.core.Direction;
|
||||||
import net.minecraft.core.Direction.Axis;
|
import net.minecraft.core.Direction.Axis;
|
||||||
import net.minecraft.world.InteractionResult;
|
import net.minecraft.world.InteractionResult;
|
||||||
import net.minecraft.world.item.context.UseOnContext;
|
import net.minecraft.world.item.context.UseOnContext;
|
||||||
import net.minecraft.world.level.LevelReader;
|
|
||||||
import net.minecraft.world.level.block.entity.BlockEntity;
|
import net.minecraft.world.level.block.entity.BlockEntity;
|
||||||
import net.minecraft.world.level.block.state.BlockState;
|
import net.minecraft.world.level.block.state.BlockState;
|
||||||
|
|
||||||
|
@ -18,7 +16,7 @@ public abstract class BearingBlock extends DirectionalKineticBlock {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean hasShaftTowards(LevelReader world, BlockPos pos, BlockState state, Direction face) {
|
public boolean hasShaftTowards(BlockState state, Direction face) {
|
||||||
return face == state.getValue(FACING).getOpposite();
|
return face == state.getValue(FACING).getOpposite();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -77,10 +77,7 @@ public class ClockworkBearingTileEntity extends KineticTileEntity
|
||||||
if (!level.isClientSide && assembleNextTick) {
|
if (!level.isClientSide && assembleNextTick) {
|
||||||
assembleNextTick = false;
|
assembleNextTick = false;
|
||||||
if (running) {
|
if (running) {
|
||||||
boolean canDisassemble = true;
|
if (getTheoreticalSpeed() == 0) {
|
||||||
if (theoreticalSpeed == 0 && (canDisassemble || hourHand == null || hourHand.getContraption()
|
|
||||||
.getBlocks()
|
|
||||||
.isEmpty())) {
|
|
||||||
if (hourHand != null)
|
if (hourHand != null)
|
||||||
hourHand.getContraption()
|
hourHand.getContraption()
|
||||||
.stop(level);
|
.stop(level);
|
||||||
|
|
|
@ -3,7 +3,7 @@ package com.simibubi.create.content.contraptions.components.structureMovement.be
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
import com.simibubi.create.AllSoundEvents;
|
import com.simibubi.create.AllSoundEvents;
|
||||||
import com.simibubi.create.content.contraptions.base.GeneratingKineticTileEntity;
|
import com.simibubi.create.content.contraptions.base.KineticTileEntity;
|
||||||
import com.simibubi.create.content.contraptions.components.structureMovement.AbstractContraptionEntity;
|
import com.simibubi.create.content.contraptions.components.structureMovement.AbstractContraptionEntity;
|
||||||
import com.simibubi.create.content.contraptions.components.structureMovement.AssemblyException;
|
import com.simibubi.create.content.contraptions.components.structureMovement.AssemblyException;
|
||||||
import com.simibubi.create.content.contraptions.components.structureMovement.ControlledContraptionEntity;
|
import com.simibubi.create.content.contraptions.components.structureMovement.ControlledContraptionEntity;
|
||||||
|
@ -25,7 +25,7 @@ import net.minecraft.world.level.block.entity.BlockEntityType;
|
||||||
import net.minecraft.world.level.block.state.BlockState;
|
import net.minecraft.world.level.block.state.BlockState;
|
||||||
import net.minecraft.world.level.block.state.properties.BlockStateProperties;
|
import net.minecraft.world.level.block.state.properties.BlockStateProperties;
|
||||||
|
|
||||||
public class MechanicalBearingTileEntity extends GeneratingKineticTileEntity
|
public class MechanicalBearingTileEntity extends KineticTileEntity
|
||||||
implements IBearingTileEntity, IDisplayAssemblyExceptions {
|
implements IBearingTileEntity, IDisplayAssemblyExceptions {
|
||||||
|
|
||||||
protected ScrollOptionBehaviour<RotationMode> movementMode;
|
protected ScrollOptionBehaviour<RotationMode> movementMode;
|
||||||
|
@ -178,7 +178,6 @@ public class MechanicalBearingTileEntity extends GeneratingKineticTileEntity
|
||||||
running = true;
|
running = true;
|
||||||
angle = 0;
|
angle = 0;
|
||||||
sendData();
|
sendData();
|
||||||
updateGeneratedRotation();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public void disassemble() {
|
public void disassemble() {
|
||||||
|
@ -194,7 +193,6 @@ public class MechanicalBearingTileEntity extends GeneratingKineticTileEntity
|
||||||
|
|
||||||
movedContraption = null;
|
movedContraption = null;
|
||||||
running = false;
|
running = false;
|
||||||
updateGeneratedRotation();
|
|
||||||
assembleNextTick = false;
|
assembleNextTick = false;
|
||||||
sendData();
|
sendData();
|
||||||
}
|
}
|
||||||
|
@ -212,9 +210,8 @@ public class MechanicalBearingTileEntity extends GeneratingKineticTileEntity
|
||||||
if (running) {
|
if (running) {
|
||||||
boolean canDisassemble = movementMode.get() == RotationMode.ROTATE_PLACE
|
boolean canDisassemble = movementMode.get() == RotationMode.ROTATE_PLACE
|
||||||
|| (isNearInitialAngle() && movementMode.get() == RotationMode.ROTATE_PLACE_RETURNED);
|
|| (isNearInitialAngle() && movementMode.get() == RotationMode.ROTATE_PLACE_RETURNED);
|
||||||
if (theoreticalSpeed == 0 && (canDisassemble || movedContraption == null || movedContraption.getContraption()
|
if (getTheoreticalSpeed() == 0 && (canDisassemble || movedContraption == null
|
||||||
.getBlocks()
|
|| movedContraption.getContraption().getBlocks().isEmpty())) {
|
||||||
.isEmpty())) {
|
|
||||||
if (movedContraption != null)
|
if (movedContraption != null)
|
||||||
movedContraption.getContraption()
|
movedContraption.getContraption()
|
||||||
.stop(level);
|
.stop(level);
|
||||||
|
@ -222,7 +219,7 @@ public class MechanicalBearingTileEntity extends GeneratingKineticTileEntity
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
if (theoreticalSpeed == 0 && !isWindmill())
|
if (getTheoreticalSpeed() == 0 && !isWindmill())
|
||||||
return;
|
return;
|
||||||
assemble();
|
assemble();
|
||||||
}
|
}
|
||||||
|
|
|
@ -18,16 +18,38 @@ import net.minecraft.world.level.block.state.BlockState;
|
||||||
public class WindmillBearingTileEntity extends MechanicalBearingTileEntity {
|
public class WindmillBearingTileEntity extends MechanicalBearingTileEntity {
|
||||||
|
|
||||||
protected ScrollOptionBehaviour<RotationDirection> movementDirection;
|
protected ScrollOptionBehaviour<RotationDirection> movementDirection;
|
||||||
protected float lastGeneratedSpeed;
|
protected float generated;
|
||||||
|
|
||||||
public WindmillBearingTileEntity(BlockEntityType<?> type, BlockPos pos, BlockState state) {
|
public WindmillBearingTileEntity(BlockEntityType<?> type, BlockPos pos, BlockState state) {
|
||||||
super(type, pos, state);
|
super(type, pos, state);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void updateGeneratedRotation() {
|
public void initialize() {
|
||||||
super.updateGeneratedRotation();
|
updateGeneratedSpeed();
|
||||||
lastGeneratedSpeed = getGeneratedSpeed();
|
super.initialize();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void assemble() {
|
||||||
|
super.assemble();
|
||||||
|
updateGeneratedSpeed();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void disassemble() {
|
||||||
|
super.disassemble();
|
||||||
|
updateGeneratedSpeed();
|
||||||
|
}
|
||||||
|
|
||||||
|
public void updateGeneratedSpeed() {
|
||||||
|
if (!running) {
|
||||||
|
generated = 0;
|
||||||
|
} else if (movedContraption != null) {
|
||||||
|
int sails = ((BearingContraption) movedContraption.getContraption()).getSailBlocks()
|
||||||
|
/ AllConfigs.SERVER.kinetics.windmillSailsPerRPM.get();
|
||||||
|
generated = Mth.clamp(sails, 1, 16) * getAngleSpeedDirection();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -39,13 +61,7 @@ public class WindmillBearingTileEntity extends MechanicalBearingTileEntity {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public float getGeneratedSpeed() {
|
public float getGeneratedSpeed() {
|
||||||
if (!running)
|
return generated;
|
||||||
return 0;
|
|
||||||
if (movedContraption == null)
|
|
||||||
return lastGeneratedSpeed;
|
|
||||||
int sails = ((BearingContraption) movedContraption.getContraption()).getSailBlocks()
|
|
||||||
/ AllConfigs.SERVER.kinetics.windmillSailsPerRPM.get();
|
|
||||||
return Mth.clamp(sails, 1, 16) * getAngleSpeedDirection();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -60,14 +76,14 @@ public class WindmillBearingTileEntity extends MechanicalBearingTileEntity {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void write(CompoundTag compound, boolean clientPacket) {
|
public void write(CompoundTag compound, boolean clientPacket) {
|
||||||
compound.putFloat("LastGenerated", lastGeneratedSpeed);
|
compound.putFloat("LastGenerated", generated);
|
||||||
super.write(compound, clientPacket);
|
super.write(compound, clientPacket);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected void read(CompoundTag compound, boolean clientPacket) {
|
protected void read(CompoundTag compound, boolean clientPacket) {
|
||||||
if (!wasMoved)
|
if (!wasMoved)
|
||||||
lastGeneratedSpeed = compound.getFloat("LastGenerated");
|
generated = compound.getFloat("LastGenerated");
|
||||||
super.read(compound, clientPacket);
|
super.read(compound, clientPacket);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -86,7 +102,7 @@ public class WindmillBearingTileEntity extends MechanicalBearingTileEntity {
|
||||||
if (!running)
|
if (!running)
|
||||||
return;
|
return;
|
||||||
if (!level.isClientSide)
|
if (!level.isClientSide)
|
||||||
updateGeneratedRotation();
|
updateGeneratedSpeed();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -94,16 +110,14 @@ public class WindmillBearingTileEntity extends MechanicalBearingTileEntity {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
static enum RotationDirection implements INamedIconOptions {
|
enum RotationDirection implements INamedIconOptions {
|
||||||
|
|
||||||
CLOCKWISE(AllIcons.I_REFRESH), COUNTER_CLOCKWISE(AllIcons.I_ROTATE_CCW),
|
CLOCKWISE(AllIcons.I_REFRESH), COUNTER_CLOCKWISE(AllIcons.I_ROTATE_CCW),;
|
||||||
|
|
||||||
;
|
private final String translationKey;
|
||||||
|
private final AllIcons icon;
|
||||||
|
|
||||||
private String translationKey;
|
RotationDirection(AllIcons icon) {
|
||||||
private AllIcons icon;
|
|
||||||
|
|
||||||
private RotationDirection(AllIcons icon) {
|
|
||||||
this.icon = icon;
|
this.icon = icon;
|
||||||
translationKey = "generic." + Lang.asId(name());
|
translationKey = "generic." + Lang.asId(name());
|
||||||
}
|
}
|
||||||
|
|
|
@ -5,6 +5,8 @@ import com.simibubi.create.AllTileEntities;
|
||||||
import com.simibubi.create.content.contraptions.base.DirectionalAxisKineticBlock;
|
import com.simibubi.create.content.contraptions.base.DirectionalAxisKineticBlock;
|
||||||
import com.simibubi.create.content.contraptions.base.IRotate;
|
import com.simibubi.create.content.contraptions.base.IRotate;
|
||||||
import com.simibubi.create.content.contraptions.relays.advanced.GantryShaftBlock;
|
import com.simibubi.create.content.contraptions.relays.advanced.GantryShaftBlock;
|
||||||
|
import com.simibubi.create.content.contraptions.solver.AllConnections;
|
||||||
|
import com.simibubi.create.content.contraptions.solver.ConnectionsBuilder;
|
||||||
import com.simibubi.create.foundation.block.ITE;
|
import com.simibubi.create.foundation.block.ITE;
|
||||||
import com.simibubi.create.foundation.utility.Iterate;
|
import com.simibubi.create.foundation.utility.Iterate;
|
||||||
|
|
||||||
|
@ -29,6 +31,15 @@ public class GantryCarriageBlock extends DirectionalAxisKineticBlock implements
|
||||||
super(properties);
|
super(properties);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public ConnectionsBuilder buildInitialConnections(ConnectionsBuilder builder, BlockState state) {
|
||||||
|
return super.buildInitialConnections(builder, state).withDirAxial(
|
||||||
|
AllConnections.DirAxial.GANTRY_PINION,
|
||||||
|
state.getValue(FACING),
|
||||||
|
state.getValue(AXIS_ALONG_FIRST_COORDINATE)
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean canSurvive(BlockState state, LevelReader world, BlockPos pos) {
|
public boolean canSurvive(BlockState state, LevelReader world, BlockPos pos) {
|
||||||
Direction direction = state.getValue(FACING);
|
Direction direction = state.getValue(FACING);
|
||||||
|
@ -59,7 +70,7 @@ public class GantryCarriageBlock extends DirectionalAxisKineticBlock implements
|
||||||
return InteractionResult.PASS;
|
return InteractionResult.PASS;
|
||||||
if (player.getItemInHand(handIn)
|
if (player.getItemInHand(handIn)
|
||||||
.isEmpty()) {
|
.isEmpty()) {
|
||||||
withTileEntityDo(worldIn, pos, te -> te.checkValidGantryShaft());
|
withTileEntityDo(worldIn, pos, GantryCarriageTileEntity::checkValidGantryShaft);
|
||||||
return InteractionResult.SUCCESS;
|
return InteractionResult.SUCCESS;
|
||||||
}
|
}
|
||||||
return InteractionResult.PASS;
|
return InteractionResult.PASS;
|
||||||
|
@ -103,8 +114,7 @@ public class GantryCarriageBlock extends DirectionalAxisKineticBlock implements
|
||||||
}
|
}
|
||||||
|
|
||||||
public static boolean isValidGantryShaftAxis(BlockState pinionState, BlockState gantryState) {
|
public static boolean isValidGantryShaftAxis(BlockState pinionState, BlockState gantryState) {
|
||||||
return getValidGantryShaftAxis(pinionState) == gantryState.getValue(GantryShaftBlock.FACING)
|
return getValidGantryShaftAxis(pinionState) == gantryState.getValue(GantryShaftBlock.FACING).getAxis();
|
||||||
.getAxis();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public static Axis getValidGantryShaftAxis(BlockState state) {
|
public static Axis getValidGantryShaftAxis(BlockState state) {
|
||||||
|
|
|
@ -122,25 +122,6 @@ public class GantryCarriageTileEntity extends KineticTileEntity implements IDisp
|
||||||
super.read(compound, clientPacket);
|
super.read(compound, clientPacket);
|
||||||
}
|
}
|
||||||
|
|
||||||
public float propagateRotationTo(KineticTileEntity target, BlockState stateFrom, BlockState stateTo, BlockPos diff,
|
|
||||||
boolean connectedViaAxes, boolean connectedViaCogs) {
|
|
||||||
//float defaultModifier =
|
|
||||||
//super.propagateRotationTo(target, stateFrom, stateTo, diff, connectedViaAxes, connectedViaCogs);
|
|
||||||
float defaultModifier = 1;
|
|
||||||
|
|
||||||
if (connectedViaAxes)
|
|
||||||
return defaultModifier;
|
|
||||||
if (!AllBlocks.GANTRY_SHAFT.has(stateTo))
|
|
||||||
return defaultModifier;
|
|
||||||
if (!stateTo.getValue(GantryShaftBlock.POWERED))
|
|
||||||
return defaultModifier;
|
|
||||||
|
|
||||||
Direction direction = Direction.getNearest(diff.getX(), diff.getY(), diff.getZ());
|
|
||||||
if (stateFrom.getValue(GantryCarriageBlock.FACING) != direction.getOpposite())
|
|
||||||
return defaultModifier;
|
|
||||||
return getGantryPinionModifier(stateTo.getValue(GantryShaftBlock.FACING), stateFrom.getValue(GantryCarriageBlock.FACING));
|
|
||||||
}
|
|
||||||
|
|
||||||
public static float getGantryPinionModifier(Direction shaft, Direction pinionDirection) {
|
public static float getGantryPinionModifier(Direction shaft, Direction pinionDirection) {
|
||||||
Axis shaftAxis = shaft.getAxis();
|
Axis shaftAxis = shaft.getAxis();
|
||||||
float directionModifier = shaft.getAxisDirection()
|
float directionModifier = shaft.getAxisDirection()
|
||||||
|
|
|
@ -50,7 +50,7 @@ public class PulleyTileEntity extends LinearActuatorTileEntity {
|
||||||
if (!(level.getBlockState(worldPosition)
|
if (!(level.getBlockState(worldPosition)
|
||||||
.getBlock() instanceof PulleyBlock))
|
.getBlock() instanceof PulleyBlock))
|
||||||
return;
|
return;
|
||||||
if (theoreticalSpeed == 0)
|
if (getTheoreticalSpeed() == 0)
|
||||||
return;
|
return;
|
||||||
int maxLength = AllConfigs.SERVER.kinetics.maxRopeLength.get();
|
int maxLength = AllConfigs.SERVER.kinetics.maxRopeLength.get();
|
||||||
int i = 1;
|
int i = 1;
|
||||||
|
|
|
@ -4,8 +4,6 @@ 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.base.KineticTileEntity;
|
import com.simibubi.create.content.contraptions.base.KineticTileEntity;
|
||||||
import com.simibubi.create.content.contraptions.solver.AllConnections;
|
|
||||||
import com.simibubi.create.content.contraptions.solver.KineticConnections;
|
|
||||||
import com.simibubi.create.foundation.block.ITE;
|
import com.simibubi.create.foundation.block.ITE;
|
||||||
import com.simibubi.create.foundation.utility.VecHelper;
|
import com.simibubi.create.foundation.utility.VecHelper;
|
||||||
|
|
||||||
|
@ -18,7 +16,6 @@ import net.minecraft.world.entity.LivingEntity;
|
||||||
import net.minecraft.world.entity.player.Player;
|
import net.minecraft.world.entity.player.Player;
|
||||||
import net.minecraft.world.level.BlockGetter;
|
import net.minecraft.world.level.BlockGetter;
|
||||||
import net.minecraft.world.level.Level;
|
import net.minecraft.world.level.Level;
|
||||||
import net.minecraft.world.level.LevelReader;
|
|
||||||
import net.minecraft.world.level.block.RenderShape;
|
import net.minecraft.world.level.block.RenderShape;
|
||||||
import net.minecraft.world.level.block.entity.BlockEntityType;
|
import net.minecraft.world.level.block.entity.BlockEntityType;
|
||||||
import net.minecraft.world.level.block.state.BlockState;
|
import net.minecraft.world.level.block.state.BlockState;
|
||||||
|
@ -91,7 +88,7 @@ public class TurntableBlock extends KineticBlock implements ITE<TurntableTileEnt
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean hasShaftTowards(LevelReader world, BlockPos pos, BlockState state, Direction face) {
|
public boolean hasShaftTowards(BlockState state, Direction face) {
|
||||||
return face == Direction.DOWN;
|
return face == Direction.DOWN;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -100,11 +97,6 @@ public class TurntableBlock extends KineticBlock implements ITE<TurntableTileEnt
|
||||||
return Axis.Y;
|
return Axis.Y;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
|
||||||
public KineticConnections getInitialConnections(BlockState state) {
|
|
||||||
return AllConnections.HALF_SHAFT.apply(Direction.DOWN);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Class<TurntableTileEntity> getTileEntityClass() {
|
public Class<TurntableTileEntity> getTileEntityClass() {
|
||||||
return TurntableTileEntity.class;
|
return TurntableTileEntity.class;
|
||||||
|
|
|
@ -146,7 +146,7 @@ public class WaterWheelBlock extends DirectionalKineticBlock implements ITE<Wate
|
||||||
}
|
}
|
||||||
|
|
||||||
private void updateWheelSpeed(LevelAccessor world, BlockPos pos) {
|
private void updateWheelSpeed(LevelAccessor world, BlockPos pos) {
|
||||||
withTileEntityDo(world, pos, WaterWheelTileEntity::updateGeneratedRotation);
|
withTileEntityDo(world, pos, WaterWheelTileEntity::updateGeneratedSpeed);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -185,7 +185,7 @@ public class WaterWheelBlock extends DirectionalKineticBlock implements ITE<Wate
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean hasShaftTowards(LevelReader world, BlockPos pos, BlockState state, Direction face) {
|
public boolean hasShaftTowards(BlockState state, Direction face) {
|
||||||
return state.getValue(FACING)
|
return state.getValue(FACING)
|
||||||
.getAxis() == face.getAxis();
|
.getAxis() == face.getAxis();
|
||||||
}
|
}
|
||||||
|
|
|
@ -4,7 +4,7 @@ import java.util.HashMap;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
|
|
||||||
import com.simibubi.create.AllBlocks;
|
import com.simibubi.create.AllBlocks;
|
||||||
import com.simibubi.create.content.contraptions.base.GeneratingKineticTileEntity;
|
import com.simibubi.create.content.contraptions.base.KineticTileEntity;
|
||||||
import com.simibubi.create.foundation.config.AllConfigs;
|
import com.simibubi.create.foundation.config.AllConfigs;
|
||||||
import com.simibubi.create.foundation.utility.Iterate;
|
import com.simibubi.create.foundation.utility.Iterate;
|
||||||
|
|
||||||
|
@ -15,9 +15,10 @@ import net.minecraft.world.level.block.entity.BlockEntityType;
|
||||||
import net.minecraft.world.level.block.state.BlockState;
|
import net.minecraft.world.level.block.state.BlockState;
|
||||||
import net.minecraft.world.phys.AABB;
|
import net.minecraft.world.phys.AABB;
|
||||||
|
|
||||||
public class WaterWheelTileEntity extends GeneratingKineticTileEntity {
|
public class WaterWheelTileEntity extends KineticTileEntity {
|
||||||
|
|
||||||
private Map<Direction, Float> flows;
|
private Map<Direction, Float> flows;
|
||||||
|
private float generated;
|
||||||
|
|
||||||
public WaterWheelTileEntity(BlockEntityType<?> type, BlockPos pos, BlockState state) {
|
public WaterWheelTileEntity(BlockEntityType<?> type, BlockPos pos, BlockState state) {
|
||||||
super(type, pos, state);
|
super(type, pos, state);
|
||||||
|
@ -27,6 +28,12 @@ public class WaterWheelTileEntity extends GeneratingKineticTileEntity {
|
||||||
setLazyTickRate(20);
|
setLazyTickRate(20);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void initialize() {
|
||||||
|
updateGeneratedSpeed();
|
||||||
|
super.initialize();
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected void read(CompoundTag compound, boolean clientPacket) {
|
protected void read(CompoundTag compound, boolean clientPacket) {
|
||||||
super.read(compound, clientPacket);
|
super.read(compound, clientPacket);
|
||||||
|
@ -59,12 +66,15 @@ public class WaterWheelTileEntity extends GeneratingKineticTileEntity {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public float getGeneratedSpeed() {
|
public float getGeneratedSpeed() {
|
||||||
float speed = 0;
|
return generated;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void updateGeneratedSpeed() {
|
||||||
|
generated = 0;
|
||||||
for (Float f : flows.values())
|
for (Float f : flows.values())
|
||||||
speed += f;
|
generated += f;
|
||||||
if (speed != 0)
|
if (generated != 0)
|
||||||
speed += AllConfigs.SERVER.kinetics.waterWheelBaseSpeed.get() * Math.signum(speed);
|
generated += AllConfigs.SERVER.kinetics.waterWheelBaseSpeed.get() * Math.signum(generated);
|
||||||
return speed;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|
|
@ -100,8 +100,8 @@ public class PumpTileEntity extends KineticTileEntity {
|
||||||
|
|
||||||
if (previousSpeed == getSpeed())
|
if (previousSpeed == getSpeed())
|
||||||
return;
|
return;
|
||||||
if (theoreticalSpeed != 0)
|
if (getTheoreticalSpeed() != 0)
|
||||||
reversed = theoreticalSpeed < 0;
|
reversed = getTheoreticalSpeed() < 0;
|
||||||
if (level.isClientSide && !isVirtual())
|
if (level.isClientSide && !isVirtual())
|
||||||
return;
|
return;
|
||||||
|
|
||||||
|
|
|
@ -44,7 +44,7 @@ public class HosePulleyBlock extends HorizontalKineticBlock implements ITE<HoseP
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean hasShaftTowards(LevelReader world, BlockPos pos, BlockState state, Direction face) {
|
public boolean hasShaftTowards(BlockState state, Direction face) {
|
||||||
return state.getValue(HORIZONTAL_FACING)
|
return state.getValue(HORIZONTAL_FACING)
|
||||||
.getClockWise() == face;
|
.getClockWise() == face;
|
||||||
}
|
}
|
||||||
|
|
|
@ -8,7 +8,6 @@ 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.DirectionalKineticBlock;
|
import com.simibubi.create.content.contraptions.base.DirectionalKineticBlock;
|
||||||
import com.simibubi.create.content.contraptions.base.KineticTileEntity;
|
|
||||||
import com.simibubi.create.foundation.block.ITE;
|
import com.simibubi.create.foundation.block.ITE;
|
||||||
import com.simibubi.create.foundation.utility.Iterate;
|
import com.simibubi.create.foundation.utility.Iterate;
|
||||||
import com.simibubi.create.foundation.utility.Lang;
|
import com.simibubi.create.foundation.utility.Lang;
|
||||||
|
@ -31,7 +30,6 @@ import net.minecraft.world.item.context.UseOnContext;
|
||||||
import net.minecraft.world.level.BlockGetter;
|
import net.minecraft.world.level.BlockGetter;
|
||||||
import net.minecraft.world.level.Level;
|
import net.minecraft.world.level.Level;
|
||||||
import net.minecraft.world.level.LevelAccessor;
|
import net.minecraft.world.level.LevelAccessor;
|
||||||
import net.minecraft.world.level.LevelReader;
|
|
||||||
import net.minecraft.world.level.block.Block;
|
import net.minecraft.world.level.block.Block;
|
||||||
import net.minecraft.world.level.block.RenderShape;
|
import net.minecraft.world.level.block.RenderShape;
|
||||||
import net.minecraft.world.level.block.entity.BlockEntity;
|
import net.minecraft.world.level.block.entity.BlockEntity;
|
||||||
|
@ -229,9 +227,6 @@ public class GantryShaftBlock extends DirectionalKineticBlock implements ITE<Gan
|
||||||
toUpdate.add(pos);
|
toUpdate.add(pos);
|
||||||
for (BlockPos blockPos : toUpdate) {
|
for (BlockPos blockPos : toUpdate) {
|
||||||
BlockState blockState = worldIn.getBlockState(blockPos);
|
BlockState blockState = worldIn.getBlockState(blockPos);
|
||||||
BlockEntity te = worldIn.getBlockEntity(blockPos);
|
|
||||||
// if (te instanceof KineticTileEntity)
|
|
||||||
// ((KineticTileEntity) te).detachKinetics();
|
|
||||||
if (blockState.getBlock() instanceof GantryShaftBlock)
|
if (blockState.getBlock() instanceof GantryShaftBlock)
|
||||||
worldIn.setBlock(blockPos, blockState.setValue(POWERED, shouldPower), 2);
|
worldIn.setBlock(blockPos, blockState.setValue(POWERED, shouldPower), 2);
|
||||||
}
|
}
|
||||||
|
@ -257,23 +252,15 @@ public class GantryShaftBlock extends DirectionalKineticBlock implements ITE<Gan
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean hasShaftTowards(LevelReader world, BlockPos pos, BlockState state, Direction face) {
|
public boolean hasShaftTowards(BlockState state, Direction face) {
|
||||||
return face.getAxis() == state.getValue(FACING)
|
return face.getAxis() == state.getValue(FACING).getAxis();
|
||||||
.getAxis();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Axis getRotationAxis(BlockState state) {
|
public Axis getRotationAxis(BlockState state) {
|
||||||
return state.getValue(FACING)
|
return state.getValue(FACING).getAxis();
|
||||||
.getAxis();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// @Override
|
|
||||||
// protected boolean areStatesKineticallyEquivalent(BlockState oldState, BlockState newState) {
|
|
||||||
// return super.areStatesKineticallyEquivalent(oldState, newState)
|
|
||||||
// && oldState.getValue(POWERED) == newState.getValue(POWERED);
|
|
||||||
// }
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public float getParticleTargetRadius() {
|
public float getParticleTargetRadius() {
|
||||||
return .35f;
|
return .35f;
|
||||||
|
|
|
@ -4,6 +4,9 @@ import com.simibubi.create.AllBlocks;
|
||||||
import com.simibubi.create.content.contraptions.base.KineticTileEntity;
|
import com.simibubi.create.content.contraptions.base.KineticTileEntity;
|
||||||
import com.simibubi.create.content.contraptions.components.structureMovement.gantry.GantryCarriageBlock;
|
import com.simibubi.create.content.contraptions.components.structureMovement.gantry.GantryCarriageBlock;
|
||||||
import com.simibubi.create.content.contraptions.components.structureMovement.gantry.GantryCarriageTileEntity;
|
import com.simibubi.create.content.contraptions.components.structureMovement.gantry.GantryCarriageTileEntity;
|
||||||
|
import com.simibubi.create.content.contraptions.solver.AllConnections;
|
||||||
|
import com.simibubi.create.content.contraptions.solver.ConnectionsBuilder;
|
||||||
|
import com.simibubi.create.content.contraptions.solver.KineticConnections;
|
||||||
import com.simibubi.create.foundation.utility.Iterate;
|
import com.simibubi.create.foundation.utility.Iterate;
|
||||||
|
|
||||||
import net.minecraft.core.BlockPos;
|
import net.minecraft.core.BlockPos;
|
||||||
|
@ -19,6 +22,19 @@ public class GantryShaftTileEntity extends KineticTileEntity {
|
||||||
super(typeIn, pos, state);
|
super(typeIn, pos, state);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public KineticConnections getConnections() {
|
||||||
|
BlockState state = getBlockState();
|
||||||
|
Direction facing = state.getValue(GantryShaftBlock.FACING);
|
||||||
|
|
||||||
|
ConnectionsBuilder builder = ConnectionsBuilder.builder().withFullShaft(facing.getAxis());
|
||||||
|
|
||||||
|
if (!AllBlocks.GANTRY_SHAFT.has(state) || !state.getValue(GantryShaftBlock.POWERED))
|
||||||
|
return builder.build();
|
||||||
|
|
||||||
|
return builder.withDirectional(AllConnections.Directional.GANTRY_RACK, facing).build();
|
||||||
|
}
|
||||||
|
|
||||||
public void checkAttachedCarriageBlocks() {
|
public void checkAttachedCarriageBlocks() {
|
||||||
if (!canAssembleOn())
|
if (!canAssembleOn())
|
||||||
return;
|
return;
|
||||||
|
@ -44,35 +60,6 @@ public class GantryShaftTileEntity extends KineticTileEntity {
|
||||||
checkAttachedCarriageBlocks();
|
checkAttachedCarriageBlocks();
|
||||||
}
|
}
|
||||||
|
|
||||||
public float propagateRotationTo(KineticTileEntity target, BlockState stateFrom, BlockState stateTo, BlockPos diff,
|
|
||||||
boolean connectedViaAxes, boolean connectedViaCogs) {
|
|
||||||
// float defaultModifier =
|
|
||||||
// super.propagateRotationTo(target, stateFrom, stateTo, diff, connectedViaAxes, connectedViaCogs);
|
|
||||||
float defaultModifier = 1;
|
|
||||||
|
|
||||||
if (connectedViaAxes)
|
|
||||||
return defaultModifier;
|
|
||||||
if (!stateFrom.getValue(GantryShaftBlock.POWERED))
|
|
||||||
return defaultModifier;
|
|
||||||
if (!AllBlocks.GANTRY_CARRIAGE.has(stateTo))
|
|
||||||
return defaultModifier;
|
|
||||||
|
|
||||||
Direction direction = Direction.getNearest(diff.getX(), diff.getY(), diff.getZ());
|
|
||||||
if (stateTo.getValue(GantryCarriageBlock.FACING) != direction)
|
|
||||||
return defaultModifier;
|
|
||||||
return GantryCarriageTileEntity.getGantryPinionModifier(stateFrom.getValue(GantryShaftBlock.FACING),
|
|
||||||
stateTo.getValue(GantryCarriageBlock.FACING));
|
|
||||||
}
|
|
||||||
|
|
||||||
public boolean isCustomConnection(KineticTileEntity other, BlockState state, BlockState otherState) {
|
|
||||||
if (!AllBlocks.GANTRY_CARRIAGE.has(otherState))
|
|
||||||
return false;
|
|
||||||
final BlockPos diff = other.getBlockPos()
|
|
||||||
.subtract(worldPosition);
|
|
||||||
Direction direction = Direction.getNearest(diff.getX(), diff.getY(), diff.getZ());
|
|
||||||
return otherState.getValue(GantryCarriageBlock.FACING) == direction;
|
|
||||||
}
|
|
||||||
|
|
||||||
public boolean canAssembleOn() {
|
public boolean canAssembleOn() {
|
||||||
BlockState blockState = getBlockState();
|
BlockState blockState = getBlockState();
|
||||||
if (!AllBlocks.GANTRY_SHAFT.has(blockState))
|
if (!AllBlocks.GANTRY_SHAFT.has(blockState))
|
||||||
|
@ -81,17 +68,12 @@ public class GantryShaftTileEntity extends KineticTileEntity {
|
||||||
return false;
|
return false;
|
||||||
float speed = getPinionMovementSpeed();
|
float speed = getPinionMovementSpeed();
|
||||||
|
|
||||||
switch (blockState.getValue(GantryShaftBlock.PART)) {
|
return switch (blockState.getValue(GantryShaftBlock.PART)) {
|
||||||
case END:
|
case END -> speed < 0;
|
||||||
return speed < 0;
|
case MIDDLE -> speed != 0;
|
||||||
case MIDDLE:
|
case START -> speed > 0;
|
||||||
return speed != 0;
|
default -> false;
|
||||||
case START:
|
};
|
||||||
return speed > 0;
|
|
||||||
case SINGLE:
|
|
||||||
default:
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public float getPinionMovementSpeed() {
|
public float getPinionMovementSpeed() {
|
||||||
|
|
|
@ -11,6 +11,7 @@ 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.CogWheelBlock;
|
||||||
import com.simibubi.create.content.contraptions.relays.elementary.ICogWheel;
|
import com.simibubi.create.content.contraptions.relays.elementary.ICogWheel;
|
||||||
import com.simibubi.create.content.contraptions.solver.AllConnections;
|
import com.simibubi.create.content.contraptions.solver.AllConnections;
|
||||||
|
import com.simibubi.create.content.contraptions.solver.ConnectionsBuilder;
|
||||||
import com.simibubi.create.content.contraptions.solver.KineticConnections;
|
import com.simibubi.create.content.contraptions.solver.KineticConnections;
|
||||||
import com.simibubi.create.foundation.block.ITE;
|
import com.simibubi.create.foundation.block.ITE;
|
||||||
import com.simibubi.create.foundation.utility.placement.IPlacementHelper;
|
import com.simibubi.create.foundation.utility.placement.IPlacementHelper;
|
||||||
|
@ -46,8 +47,9 @@ public class SpeedControllerBlock extends HorizontalAxisKineticBlock implements
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public KineticConnections getInitialConnections(BlockState state) {
|
public ConnectionsBuilder buildInitialConnections(ConnectionsBuilder builder, BlockState state) {
|
||||||
return AllConnections.SPEED_CONTROLLER.apply(state.getValue(HORIZONTAL_AXIS));
|
return super.buildInitialConnections(builder, state)
|
||||||
|
.withAxial(AllConnections.Axial.SPEED_CONTROLLER_TOP, state.getValue(HORIZONTAL_AXIS));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|
|
@ -61,11 +61,13 @@ public class SpeedControllerTileEntity extends KineticTileEntity {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onUpdate(Level level, KineticSolver solver, KineticNode node) {
|
public void onKineticsTick(Level level, KineticSolver solver, KineticNode node) {
|
||||||
BlockPos pos = node.getPos(), above = pos.above();
|
BlockPos pos = node.getPos(), above = pos.above();
|
||||||
if (solver.isStressOnlyConnected(pos, above)) {
|
solver.getNode(above).ifPresent(to -> {
|
||||||
solver.getNode(above).get().setController(node, KineticControllerSerial.SPEED_CONTROLLER_COG);
|
if (node.checkStressOnlyConnection(to)) {
|
||||||
}
|
to.setController(KineticControllerSerial.SPEED_CONTROLLER_COG);
|
||||||
|
}
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
public void updateBracket() {
|
public void updateBracket() {
|
||||||
|
|
|
@ -1,5 +1,6 @@
|
||||||
package com.simibubi.create.content.contraptions.relays.advanced.sequencer;
|
package com.simibubi.create.content.contraptions.relays.advanced.sequencer;
|
||||||
|
|
||||||
|
import java.util.Optional;
|
||||||
import java.util.Vector;
|
import java.util.Vector;
|
||||||
|
|
||||||
import com.simibubi.create.content.contraptions.base.KineticTileEntity;
|
import com.simibubi.create.content.contraptions.base.KineticTileEntity;
|
||||||
|
@ -78,21 +79,11 @@ public class Instruction {
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
int getSpeedModifier() {
|
Optional<InstructionSpeedModifiers> getSpeedModifier() {
|
||||||
switch (instruction) {
|
return switch (instruction) {
|
||||||
|
case TURN_ANGLE, TURN_DISTANCE -> Optional.of(speedModifier);
|
||||||
case TURN_ANGLE:
|
default -> Optional.empty();
|
||||||
case TURN_DISTANCE:
|
};
|
||||||
return speedModifier.value;
|
|
||||||
|
|
||||||
case END:
|
|
||||||
case DELAY:
|
|
||||||
case AWAIT:
|
|
||||||
default:
|
|
||||||
break;
|
|
||||||
|
|
||||||
}
|
|
||||||
return 0;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
OnIsPoweredResult onRedstonePulse() {
|
OnIsPoweredResult onRedstonePulse() {
|
||||||
|
|
|
@ -18,12 +18,7 @@ public enum InstructionSpeedModifiers {
|
||||||
int value;
|
int value;
|
||||||
Component label;
|
Component label;
|
||||||
|
|
||||||
private InstructionSpeedModifiers(int modifier, Component label) {
|
InstructionSpeedModifiers(int modifier, String label) {
|
||||||
this.label = label;
|
|
||||||
translationKey = "gui.sequenced_gearshift.speed." + Lang.asId(name());
|
|
||||||
value = modifier;
|
|
||||||
}
|
|
||||||
private InstructionSpeedModifiers(int modifier, String label) {
|
|
||||||
this.label = new TextComponent(label);
|
this.label = new TextComponent(label);
|
||||||
translationKey = "gui.sequenced_gearshift.speed." + Lang.asId(name());
|
translationKey = "gui.sequenced_gearshift.speed." + Lang.asId(name());
|
||||||
value = modifier;
|
value = modifier;
|
||||||
|
|
|
@ -5,8 +5,8 @@ import java.util.Random;
|
||||||
import com.simibubi.create.AllItems;
|
import com.simibubi.create.AllItems;
|
||||||
import com.simibubi.create.AllTileEntities;
|
import com.simibubi.create.AllTileEntities;
|
||||||
import com.simibubi.create.content.contraptions.base.HorizontalAxisKineticBlock;
|
import com.simibubi.create.content.contraptions.base.HorizontalAxisKineticBlock;
|
||||||
|
import com.simibubi.create.content.contraptions.base.IRotate;
|
||||||
import com.simibubi.create.content.contraptions.base.KineticBlock;
|
import com.simibubi.create.content.contraptions.base.KineticBlock;
|
||||||
import com.simibubi.create.content.contraptions.base.RotatedPillarKineticBlock;
|
|
||||||
import com.simibubi.create.foundation.block.ITE;
|
import com.simibubi.create.foundation.block.ITE;
|
||||||
import com.simibubi.create.foundation.gui.ScreenOpener;
|
import com.simibubi.create.foundation.gui.ScreenOpener;
|
||||||
|
|
||||||
|
@ -38,6 +38,7 @@ import net.minecraftforge.fml.DistExecutor;
|
||||||
public class SequencedGearshiftBlock extends HorizontalAxisKineticBlock implements ITE<SequencedGearshiftTileEntity> {
|
public class SequencedGearshiftBlock extends HorizontalAxisKineticBlock implements ITE<SequencedGearshiftTileEntity> {
|
||||||
|
|
||||||
public static final BooleanProperty VERTICAL = BooleanProperty.create("vertical");
|
public static final BooleanProperty VERTICAL = BooleanProperty.create("vertical");
|
||||||
|
public static final BooleanProperty POSITIVE = BooleanProperty.create("positive");
|
||||||
public static final IntegerProperty STATE = IntegerProperty.create("state", 0, 5);
|
public static final IntegerProperty STATE = IntegerProperty.create("state", 0, 5);
|
||||||
|
|
||||||
public SequencedGearshiftBlock(Properties properties) {
|
public SequencedGearshiftBlock(Properties properties) {
|
||||||
|
@ -46,7 +47,7 @@ public class SequencedGearshiftBlock extends HorizontalAxisKineticBlock implemen
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected void createBlockStateDefinition(Builder<Block, BlockState> builder) {
|
protected void createBlockStateDefinition(Builder<Block, BlockState> builder) {
|
||||||
super.createBlockStateDefinition(builder.add(STATE, VERTICAL));
|
super.createBlockStateDefinition(builder.add(STATE, VERTICAL, POSITIVE));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -59,8 +60,7 @@ public class SequencedGearshiftBlock extends HorizontalAxisKineticBlock implemen
|
||||||
boolean isMoving) {
|
boolean isMoving) {
|
||||||
if (worldIn.isClientSide)
|
if (worldIn.isClientSide)
|
||||||
return;
|
return;
|
||||||
if (!worldIn.getBlockTicks()
|
if (!worldIn.getBlockTicks().willTickThisTick(pos, this))
|
||||||
.willTickThisTick(pos, this))
|
|
||||||
worldIn.scheduleTick(pos, this, 0);
|
worldIn.scheduleTick(pos, this, 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -72,11 +72,10 @@ public class SequencedGearshiftBlock extends HorizontalAxisKineticBlock implemen
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean hasShaftTowards(LevelReader world, BlockPos pos, BlockState state, Direction face) {
|
public boolean hasShaftTowards(BlockState state, Direction face) {
|
||||||
if (state.getValue(VERTICAL))
|
if (state.getValue(VERTICAL))
|
||||||
return face.getAxis()
|
return face.getAxis().isVertical();
|
||||||
.isVertical();
|
return super.hasShaftTowards(state, face);
|
||||||
return super.hasShaftTowards(world, pos, state, face);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -85,9 +84,8 @@ public class SequencedGearshiftBlock extends HorizontalAxisKineticBlock implemen
|
||||||
ItemStack held = player.getMainHandItem();
|
ItemStack held = player.getMainHandItem();
|
||||||
if (AllItems.WRENCH.isIn(held))
|
if (AllItems.WRENCH.isIn(held))
|
||||||
return InteractionResult.PASS;
|
return InteractionResult.PASS;
|
||||||
if (held.getItem() instanceof BlockItem) {
|
if (held.getItem() instanceof BlockItem blockItem) {
|
||||||
BlockItem blockItem = (BlockItem) held.getItem();
|
if (blockItem.getBlock() instanceof KineticBlock && hasShaftTowards(state, hit.getDirection(), worldIn, hit.getBlockPos()))
|
||||||
if (blockItem.getBlock() instanceof KineticBlock && hasShaftTowards(worldIn, pos, state, hit.getDirection()))
|
|
||||||
return InteractionResult.PASS;
|
return InteractionResult.PASS;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -102,37 +100,56 @@ public class SequencedGearshiftBlock extends HorizontalAxisKineticBlock implemen
|
||||||
ScreenOpener.open(new SequencedGearshiftScreen(te));
|
ScreenOpener.open(new SequencedGearshiftScreen(te));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private static boolean sideFacesShaft(BlockPlaceContext context, Direction side) {
|
||||||
|
BlockPos pos = context.getClickedPos().relative(side);
|
||||||
|
BlockState state = context.getLevel().getBlockState(pos);
|
||||||
|
return state.getBlock() instanceof IRotate ir
|
||||||
|
&& ir.hasShaftTowards(state, side.getOpposite(), context.getLevel(), pos);
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public BlockState getStateForPlacement(BlockPlaceContext context) {
|
public BlockState getStateForPlacement(BlockPlaceContext context) {
|
||||||
Axis preferredAxis = RotatedPillarKineticBlock.getPreferredAxis(context);
|
Direction preferredFacing = null;
|
||||||
if (preferredAxis != null && (context.getPlayer() == null || !context.getPlayer()
|
for (Direction dir : context.getNearestLookingDirections()) {
|
||||||
.isShiftKeyDown()))
|
if (sideFacesShaft(context, dir.getOpposite())) {
|
||||||
return withAxis(preferredAxis, context);
|
preferredFacing = dir;
|
||||||
return withAxis(context.getNearestLookingDirection()
|
break;
|
||||||
.getAxis(), context);
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (preferredFacing != null && (context.getPlayer() == null || !context.getPlayer().isShiftKeyDown()))
|
||||||
|
return withFacing(preferredFacing, context);
|
||||||
|
return withFacing(context.getNearestLookingDirection(), context);
|
||||||
|
}
|
||||||
|
|
||||||
|
private BlockState withFacing(Direction dir, BlockPlaceContext context) {
|
||||||
|
Axis axis = dir.getAxis();
|
||||||
|
BlockState state = defaultBlockState()
|
||||||
|
.setValue(VERTICAL, axis.isVertical())
|
||||||
|
.setValue(POSITIVE, dir.getAxisDirection() == Direction.AxisDirection.POSITIVE);
|
||||||
|
if (axis.isVertical())
|
||||||
|
return state.setValue(HORIZONTAL_AXIS, context.getHorizontalDirection().getAxis());
|
||||||
|
return state.setValue(HORIZONTAL_AXIS, axis);
|
||||||
|
}
|
||||||
|
|
||||||
|
public Direction getFacing(BlockState state) {
|
||||||
|
Direction.AxisDirection axisDir = state.getValue(POSITIVE)
|
||||||
|
? Direction.AxisDirection.POSITIVE
|
||||||
|
: Direction.AxisDirection.NEGATIVE;
|
||||||
|
return Direction.fromAxisAndDirection(getRotationAxis(state), axisDir);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public InteractionResult onWrenched(BlockState state, UseOnContext context) {
|
public InteractionResult onWrenched(BlockState state, UseOnContext context) {
|
||||||
BlockState newState = state;
|
BlockState newState = state;
|
||||||
|
|
||||||
if (context.getClickedFace()
|
if (context.getClickedFace().getAxis() != Axis.Y)
|
||||||
.getAxis() != Axis.Y)
|
if (newState.getValue(HORIZONTAL_AXIS) != context.getClickedFace().getAxis())
|
||||||
if (newState.getValue(HORIZONTAL_AXIS) != context.getClickedFace()
|
|
||||||
.getAxis())
|
|
||||||
newState = newState.cycle(VERTICAL);
|
newState = newState.cycle(VERTICAL);
|
||||||
|
|
||||||
return super.onWrenched(newState, context);
|
return super.onWrenched(newState, context);
|
||||||
}
|
}
|
||||||
|
|
||||||
private BlockState withAxis(Axis axis, BlockPlaceContext context) {
|
|
||||||
BlockState state = defaultBlockState().setValue(VERTICAL, axis.isVertical());
|
|
||||||
if (axis.isVertical())
|
|
||||||
return state.setValue(HORIZONTAL_AXIS, context.getHorizontalDirection()
|
|
||||||
.getAxis());
|
|
||||||
return state.setValue(HORIZONTAL_AXIS, axis);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Axis getRotationAxis(BlockState state) {
|
public Axis getRotationAxis(BlockState state) {
|
||||||
if (state.getValue(VERTICAL))
|
if (state.getValue(VERTICAL))
|
||||||
|
|
|
@ -1,20 +1,19 @@
|
||||||
package com.simibubi.create.content.contraptions.relays.advanced.sequencer;
|
package com.simibubi.create.content.contraptions.relays.advanced.sequencer;
|
||||||
|
|
||||||
|
import java.util.Optional;
|
||||||
import java.util.Vector;
|
import java.util.Vector;
|
||||||
|
|
||||||
import com.simibubi.create.content.contraptions.base.KineticTileEntity;
|
import com.simibubi.create.content.contraptions.base.KineticTileEntity;
|
||||||
|
|
||||||
import com.simibubi.create.content.contraptions.solver.AllConnections;
|
import com.simibubi.create.content.contraptions.solver.AllConnections;
|
||||||
|
import com.simibubi.create.content.contraptions.solver.ConnectionsBuilder;
|
||||||
import com.simibubi.create.content.contraptions.solver.KineticConnections;
|
import com.simibubi.create.content.contraptions.solver.KineticConnections;
|
||||||
import com.simibubi.create.content.contraptions.solver.KineticConnections.Entry;
|
|
||||||
|
|
||||||
import net.minecraft.core.BlockPos;
|
import net.minecraft.core.BlockPos;
|
||||||
import net.minecraft.core.Direction;
|
import net.minecraft.core.Direction;
|
||||||
import net.minecraft.nbt.CompoundTag;
|
import net.minecraft.nbt.CompoundTag;
|
||||||
import net.minecraft.nbt.Tag;
|
import net.minecraft.nbt.Tag;
|
||||||
import net.minecraft.world.level.block.entity.BlockEntityType;
|
import net.minecraft.world.level.block.entity.BlockEntityType;
|
||||||
import net.minecraft.world.level.block.state.BlockState;
|
import net.minecraft.world.level.block.state.BlockState;
|
||||||
import net.minecraft.world.level.block.state.properties.BlockStateProperties;
|
|
||||||
|
|
||||||
public class SequencedGearshiftTileEntity extends KineticTileEntity {
|
public class SequencedGearshiftTileEntity extends KineticTileEntity {
|
||||||
|
|
||||||
|
@ -47,7 +46,7 @@ public class SequencedGearshiftTileEntity extends KineticTileEntity {
|
||||||
return;
|
return;
|
||||||
if (timer < currentInstructionDuration) {
|
if (timer < currentInstructionDuration) {
|
||||||
timer++;
|
timer++;
|
||||||
currentInstructionProgress += getInstruction(currentInstruction).getTickProgress(theoreticalSpeed);
|
currentInstructionProgress += getInstruction(currentInstruction).getTickProgress(getTheoreticalSpeed());
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
run(currentInstruction + 1);
|
run(currentInstruction + 1);
|
||||||
|
@ -58,7 +57,7 @@ public class SequencedGearshiftTileEntity extends KineticTileEntity {
|
||||||
super.onSpeedChanged(previousSpeed);
|
super.onSpeedChanged(previousSpeed);
|
||||||
if (isIdle())
|
if (isIdle())
|
||||||
return;
|
return;
|
||||||
float currentSpeed = Math.abs(theoreticalSpeed);
|
float currentSpeed = Math.abs(getTheoreticalSpeed());
|
||||||
if (Math.abs(previousSpeed) == currentSpeed)
|
if (Math.abs(previousSpeed) == currentSpeed)
|
||||||
return;
|
return;
|
||||||
Instruction instruction = getInstruction(currentInstruction);
|
Instruction instruction = getInstruction(currentInstruction);
|
||||||
|
@ -101,12 +100,8 @@ public class SequencedGearshiftTileEntity extends KineticTileEntity {
|
||||||
return;
|
return;
|
||||||
poweredPreviously = true;
|
poweredPreviously = true;
|
||||||
|
|
||||||
switch (instruction.onRedstonePulse()) {
|
if (instruction.onRedstonePulse() == OnIsPoweredResult.CONTINUE) {
|
||||||
case CONTINUE:
|
|
||||||
run(currentInstruction + 1);
|
run(currentInstruction + 1);
|
||||||
break;
|
|
||||||
default:
|
|
||||||
break;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -160,31 +155,31 @@ public class SequencedGearshiftTileEntity extends KineticTileEntity {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public KineticConnections getConnections() {
|
public KineticConnections getConnections() {
|
||||||
Direction.Axis axis = getBlockState().getValue(BlockStateProperties.HORIZONTAL_AXIS);
|
BlockState state = getBlockState();
|
||||||
|
SequencedGearshiftBlock block = (SequencedGearshiftBlock) state.getBlock();
|
||||||
|
Direction facing = block.getFacing(state);
|
||||||
|
|
||||||
if (isVirtual()) return AllConnections.FULL_SHAFT.apply(axis);
|
ConnectionsBuilder builder = ConnectionsBuilder.builder();
|
||||||
|
if (isVirtual()) return builder.withFullShaft(facing.getAxis()).build();
|
||||||
|
|
||||||
return getSpeedSource()
|
builder = builder.withHalfShaft(facing.getOpposite());
|
||||||
.map(p -> {
|
|
||||||
Direction dir = Direction.fromNormal(p.subtract(getBlockPos()));
|
|
||||||
float modifier = getModifier();
|
|
||||||
if (modifier == 0 || isRemoved()) return AllConnections.HALF_SHAFT.apply(dir);
|
|
||||||
|
|
||||||
Direction opp = dir.getOpposite();
|
Optional<InstructionSpeedModifiers> modifier = getModifier();
|
||||||
String from = AllConnections.type(AllConnections.TYPE_SHAFT, opp);
|
if (modifier.isEmpty() || isRemoved()) return builder.build();
|
||||||
String to = AllConnections.type(AllConnections.TYPE_SHAFT, dir);
|
|
||||||
return new KineticConnections(new Entry(opp.getNormal(), from, to, modifier))
|
AllConnections.Shafts shaft = switch(modifier.get()) {
|
||||||
.merge(AllConnections.HALF_SHAFT.apply(dir));
|
case FORWARD_FAST -> AllConnections.Shafts.SHAFT_X2;
|
||||||
})
|
case FORWARD -> AllConnections.Shafts.SHAFT;
|
||||||
.orElse(AllConnections.FULL_SHAFT.apply(axis));
|
case BACK -> AllConnections.Shafts.SHAFT_REV;
|
||||||
|
case BACK_FAST -> AllConnections.Shafts.SHAFT_REV_X2;
|
||||||
|
};
|
||||||
|
return builder.withHalfShaft(shaft, facing).build();
|
||||||
}
|
}
|
||||||
|
|
||||||
public int getModifier() {
|
public Optional<InstructionSpeedModifiers> getModifier() {
|
||||||
if (currentInstruction >= instructions.size())
|
if (currentInstruction >= instructions.size() || isIdle())
|
||||||
return 0;
|
return Optional.empty();
|
||||||
return isIdle() ? 0
|
return instructions.get(currentInstruction).getSpeedModifier();
|
||||||
: instructions.get(currentInstruction)
|
|
||||||
.getSpeedModifier();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -5,6 +5,8 @@ import java.util.LinkedList;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.function.Consumer;
|
import java.util.function.Consumer;
|
||||||
|
|
||||||
|
import net.minecraft.world.level.LevelReader;
|
||||||
|
|
||||||
import org.apache.commons.lang3.mutable.MutableBoolean;
|
import org.apache.commons.lang3.mutable.MutableBoolean;
|
||||||
|
|
||||||
import com.simibubi.create.AllBlocks;
|
import com.simibubi.create.AllBlocks;
|
||||||
|
@ -52,7 +54,6 @@ import net.minecraft.world.item.context.UseOnContext;
|
||||||
import net.minecraft.world.level.BlockGetter;
|
import net.minecraft.world.level.BlockGetter;
|
||||||
import net.minecraft.world.level.Level;
|
import net.minecraft.world.level.Level;
|
||||||
import net.minecraft.world.level.LevelAccessor;
|
import net.minecraft.world.level.LevelAccessor;
|
||||||
import net.minecraft.world.level.LevelReader;
|
|
||||||
import net.minecraft.world.level.block.Block;
|
import net.minecraft.world.level.block.Block;
|
||||||
import net.minecraft.world.level.block.Blocks;
|
import net.minecraft.world.level.block.Blocks;
|
||||||
import net.minecraft.world.level.block.RenderShape;
|
import net.minecraft.world.level.block.RenderShape;
|
||||||
|
@ -113,10 +114,11 @@ public class BeltBlock extends HorizontalKineticBlock implements ITE<BeltTileEnt
|
||||||
// }
|
// }
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean hasShaftTowards(LevelReader world, BlockPos pos, BlockState state, Direction face) {
|
public boolean hasShaftTowards(BlockState state, Direction face, LevelReader level, BlockPos pos) {
|
||||||
if (face.getAxis() != getRotationAxis(state))
|
if (face.getAxis() != getRotationAxis(state))
|
||||||
return false;
|
return false;
|
||||||
return getTileEntityOptional(world, pos).map(BeltTileEntity::hasPulley)
|
|
||||||
|
return getTileEntityOptional(level, pos).map(BeltTileEntity::hasPulley)
|
||||||
.orElse(false);
|
.orElse(false);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -18,7 +18,6 @@ import net.minecraft.world.item.context.UseOnContext;
|
||||||
import net.minecraft.world.level.BlockGetter;
|
import net.minecraft.world.level.BlockGetter;
|
||||||
import net.minecraft.world.level.Level;
|
import net.minecraft.world.level.Level;
|
||||||
import net.minecraft.world.level.LevelAccessor;
|
import net.minecraft.world.level.LevelAccessor;
|
||||||
import net.minecraft.world.level.LevelReader;
|
|
||||||
import net.minecraft.world.level.block.Block;
|
import net.minecraft.world.level.block.Block;
|
||||||
import net.minecraft.world.level.block.Blocks;
|
import net.minecraft.world.level.block.Blocks;
|
||||||
import net.minecraft.world.level.block.SimpleWaterloggedBlock;
|
import net.minecraft.world.level.block.SimpleWaterloggedBlock;
|
||||||
|
@ -60,7 +59,7 @@ public abstract class AbstractShaftBlock extends RotatedPillarKineticBlock
|
||||||
// IRotate:
|
// IRotate:
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean hasShaftTowards(LevelReader world, BlockPos pos, BlockState state, Direction face) {
|
public boolean hasShaftTowards(BlockState state, Direction face) {
|
||||||
return face.getAxis() == state.getValue(AXIS);
|
return face.getAxis() == state.getValue(AXIS);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -94,7 +93,7 @@ public abstract class AbstractShaftBlock extends RotatedPillarKineticBlock
|
||||||
FluidState ifluidstate = context.getLevel()
|
FluidState ifluidstate = context.getLevel()
|
||||||
.getFluidState(context.getClickedPos());
|
.getFluidState(context.getClickedPos());
|
||||||
return super.getStateForPlacement(context).setValue(BlockStateProperties.WATERLOGGED,
|
return super.getStateForPlacement(context).setValue(BlockStateProperties.WATERLOGGED,
|
||||||
Boolean.valueOf(ifluidstate.getType() == Fluids.WATER));
|
ifluidstate.getType() == Fluids.WATER);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|
|
@ -8,7 +8,7 @@ import com.simibubi.create.content.contraptions.base.IRotate;
|
||||||
import com.simibubi.create.content.contraptions.base.KineticTileEntity;
|
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.encased.EncasedCogwheelBlock;
|
import com.simibubi.create.content.contraptions.relays.encased.EncasedCogwheelBlock;
|
||||||
import com.simibubi.create.content.contraptions.solver.AllConnections;
|
import com.simibubi.create.content.contraptions.solver.ConnectionsBuilder;
|
||||||
import com.simibubi.create.content.contraptions.solver.KineticConnections;
|
import com.simibubi.create.content.contraptions.solver.KineticConnections;
|
||||||
import com.simibubi.create.foundation.utility.Iterate;
|
import com.simibubi.create.foundation.utility.Iterate;
|
||||||
|
|
||||||
|
@ -62,12 +62,6 @@ public class CogWheelBlock extends AbstractShaftBlock implements ICogWheel {
|
||||||
return !isLarge;
|
return !isLarge;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
|
||||||
public KineticConnections getInitialConnections(BlockState state) {
|
|
||||||
return (isLargeCog() ? AllConnections.LARGE_COG_FULL_SHAFT : AllConnections.SMALL_COG_FULL_SHAFT)
|
|
||||||
.apply(state.getValue(AXIS));
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public VoxelShape getShape(BlockState state, BlockGetter worldIn, BlockPos pos, CollisionContext context) {
|
public VoxelShape getShape(BlockState state, BlockGetter worldIn, BlockPos pos, CollisionContext context) {
|
||||||
return (isLarge ? AllShapes.LARGE_GEAR : AllShapes.SMALL_GEAR).get(state.getValue(AXIS));
|
return (isLarge ? AllShapes.LARGE_GEAR : AllShapes.SMALL_GEAR).get(state.getValue(AXIS));
|
||||||
|
@ -104,10 +98,9 @@ public class CogWheelBlock extends AbstractShaftBlock implements ICogWheel {
|
||||||
|
|
||||||
for (Direction d : Iterate.directionsInAxis(state.getValue(AXIS))) {
|
for (Direction d : Iterate.directionsInAxis(state.getValue(AXIS))) {
|
||||||
BlockState adjacentState = world.getBlockState(pos.relative(d));
|
BlockState adjacentState = world.getBlockState(pos.relative(d));
|
||||||
if (!(adjacentState.getBlock() instanceof IRotate))
|
if (!(adjacentState.getBlock() instanceof IRotate def))
|
||||||
continue;
|
continue;
|
||||||
IRotate def = (IRotate) adjacentState.getBlock();
|
if (!def.hasShaftTowards(adjacentState, d.getOpposite(), world, pos.relative(d)))
|
||||||
if (!def.hasShaftTowards(world, pos.relative(d), adjacentState, d.getOpposite()))
|
|
||||||
continue;
|
continue;
|
||||||
encasedState =
|
encasedState =
|
||||||
encasedState.cycle(d.getAxisDirection() == AxisDirection.POSITIVE ? EncasedCogwheelBlock.TOP_SHAFT
|
encasedState.cycle(d.getAxisDirection() == AxisDirection.POSITIVE ? EncasedCogwheelBlock.TOP_SHAFT
|
||||||
|
|
|
@ -40,11 +40,6 @@ public class ShaftBlock extends AbstractShaftBlock {
|
||||||
return AllBlocks.SHAFT.has(state);
|
return AllBlocks.SHAFT.has(state);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
|
||||||
public KineticConnections getInitialConnections(BlockState state) {
|
|
||||||
return AllConnections.FULL_SHAFT.apply(state.getValue(AXIS));
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public VoxelShape getShape(BlockState state, BlockGetter worldIn, BlockPos pos, CollisionContext context) {
|
public VoxelShape getShape(BlockState state, BlockGetter worldIn, BlockPos pos, CollisionContext context) {
|
||||||
return AllShapes.SIX_VOXEL_POLE.get(state.getValue(AXIS));
|
return AllShapes.SIX_VOXEL_POLE.get(state.getValue(AXIS));
|
||||||
|
|
|
@ -47,7 +47,7 @@ public abstract class AbstractEncasedShaftBlock extends RotatedPillarKineticBloc
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean hasShaftTowards(LevelReader world, BlockPos pos, BlockState state, Direction face) {
|
public boolean hasShaftTowards(BlockState state, Direction face) {
|
||||||
return face.getAxis() == state.getValue(AXIS);
|
return face.getAxis() == state.getValue(AXIS);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -41,12 +41,6 @@ public class AdjustablePulleyBlock extends EncasedBeltBlock {
|
||||||
.hasNeighborSignal(context.getClickedPos()));
|
.hasNeighborSignal(context.getClickedPos()));
|
||||||
}
|
}
|
||||||
|
|
||||||
// @Override
|
|
||||||
// protected boolean areStatesKineticallyEquivalent(BlockState oldState, BlockState newState) {
|
|
||||||
// return super.areStatesKineticallyEquivalent(oldState, newState)
|
|
||||||
// && oldState.getValue(POWERED) == newState.getValue(POWERED);
|
|
||||||
// }
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void neighborChanged(BlockState state, Level worldIn, BlockPos pos, Block blockIn, BlockPos fromPos,
|
public void neighborChanged(BlockState state, Level worldIn, BlockPos pos, Block blockIn, BlockPos fromPos,
|
||||||
boolean isMoving) {
|
boolean isMoving) {
|
||||||
|
|
|
@ -3,6 +3,7 @@ package com.simibubi.create.content.contraptions.relays.encased;
|
||||||
import com.simibubi.create.content.contraptions.base.KineticTileEntity;
|
import com.simibubi.create.content.contraptions.base.KineticTileEntity;
|
||||||
|
|
||||||
import com.simibubi.create.content.contraptions.solver.AllConnections;
|
import com.simibubi.create.content.contraptions.solver.AllConnections;
|
||||||
|
import com.simibubi.create.content.contraptions.solver.ConnectionsBuilder;
|
||||||
import com.simibubi.create.content.contraptions.solver.KineticConnections;
|
import com.simibubi.create.content.contraptions.solver.KineticConnections;
|
||||||
|
|
||||||
import net.minecraft.core.BlockPos;
|
import net.minecraft.core.BlockPos;
|
||||||
|
@ -20,13 +21,12 @@ public class ClutchTileEntity extends KineticTileEntity {
|
||||||
@Override
|
@Override
|
||||||
public KineticConnections getConnections() {
|
public KineticConnections getConnections() {
|
||||||
BlockState state = getBlockState();
|
BlockState state = getBlockState();
|
||||||
Direction.Axis axis = state.getValue(BlockStateProperties.AXIS);
|
Direction dir = AllConnections.pos(state.getValue(GearshiftBlock.AXIS));
|
||||||
|
|
||||||
if (!state.getValue(BlockStateProperties.POWERED)) return AllConnections.FULL_SHAFT.apply(axis);
|
ConnectionsBuilder builder = ConnectionsBuilder.builder();
|
||||||
|
if (!state.getValue(BlockStateProperties.POWERED))
|
||||||
return getSpeedSource()
|
return builder.withFullShaft(dir.getAxis()).build();
|
||||||
.map(p -> AllConnections.HALF_SHAFT.apply(Direction.fromNormal(p.subtract(getBlockPos()))))
|
return builder.withHalfShaft(dir.getOpposite()).build();
|
||||||
.orElse(AllConnections.FULL_SHAFT.apply(axis));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -155,7 +155,7 @@ public class EncasedBeltBlock extends RotatedPillarKineticBlock implements ITE<K
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean hasShaftTowards(LevelReader world, BlockPos pos, BlockState state, Direction face) {
|
public boolean hasShaftTowards(BlockState state, Direction face) {
|
||||||
return face.getAxis() == state.getValue(AXIS);
|
return face.getAxis() == state.getValue(AXIS);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -48,15 +48,14 @@ public class EncasedCogInstance extends KineticTileInstance<KineticTileEntity> {
|
||||||
rotatingModel = setup(getCogModel().createInstance());
|
rotatingModel = setup(getCogModel().createInstance());
|
||||||
|
|
||||||
Block block = blockState.getBlock();
|
Block block = blockState.getBlock();
|
||||||
if (!(block instanceof IRotate))
|
if (!(block instanceof IRotate def))
|
||||||
return;
|
return;
|
||||||
|
|
||||||
IRotate def = (IRotate) block;
|
|
||||||
rotatingTopShaft = Optional.empty();
|
rotatingTopShaft = Optional.empty();
|
||||||
rotatingBottomShaft = Optional.empty();
|
rotatingBottomShaft = Optional.empty();
|
||||||
|
|
||||||
for (Direction d : Iterate.directionsInAxis(axis)) {
|
for (Direction d : Iterate.directionsInAxis(axis)) {
|
||||||
if (!def.hasShaftTowards(tile.getLevel(), tile.getBlockPos(), blockState, d))
|
if (!def.hasShaftTowards(blockState, d, tile.getLevel(), tile.getBlockPos()))
|
||||||
continue;
|
continue;
|
||||||
RotatingData data = setup(getRotatingMaterial().getModel(AllBlockPartials.SHAFT_HALF, blockState, d)
|
RotatingData data = setup(getRotatingMaterial().getModel(AllBlockPartials.SHAFT_HALF, blockState, d)
|
||||||
.createInstance());
|
.createInstance());
|
||||||
|
|
|
@ -45,12 +45,11 @@ public class EncasedCogRenderer extends KineticTileEntityRenderer {
|
||||||
|
|
||||||
BlockState blockState = te.getBlockState();
|
BlockState blockState = te.getBlockState();
|
||||||
Block block = blockState.getBlock();
|
Block block = blockState.getBlock();
|
||||||
if (!(block instanceof IRotate))
|
if (!(block instanceof IRotate def))
|
||||||
return;
|
return;
|
||||||
IRotate def = (IRotate) block;
|
|
||||||
|
|
||||||
for (Direction d : Iterate.directionsInAxis(getRotationAxisOf(te))) {
|
for (Direction d : Iterate.directionsInAxis(getRotationAxisOf(te))) {
|
||||||
if (!def.hasShaftTowards(te.getLevel(), te.getBlockPos(), blockState, d))
|
if (!def.hasShaftTowards(blockState, d, te.getLevel(), te.getBlockPos()))
|
||||||
continue;
|
continue;
|
||||||
renderRotatingBuffer(te, CachedBufferer.partialFacing(AllBlockPartials.SHAFT_HALF, te.getBlockState(), d),
|
renderRotatingBuffer(te, CachedBufferer.partialFacing(AllBlockPartials.SHAFT_HALF, te.getBlockState(), d),
|
||||||
ms, buffer.getBuffer(RenderType.solid()), light);
|
ms, buffer.getBuffer(RenderType.solid()), light);
|
||||||
|
|
|
@ -133,7 +133,7 @@ public class EncasedCogwheelBlock extends RotatedPillarKineticBlock
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean hasShaftTowards(LevelReader world, BlockPos pos, BlockState state, Direction face) {
|
public boolean hasShaftTowards(BlockState state, Direction face) {
|
||||||
return face.getAxis() == state.getValue(AXIS)
|
return face.getAxis() == state.getValue(AXIS)
|
||||||
&& state.getValue(face.getAxisDirection() == AxisDirection.POSITIVE ? TOP_SHAFT : BOTTOM_SHAFT);
|
&& state.getValue(face.getAxisDirection() == AxisDirection.POSITIVE ? TOP_SHAFT : BOTTOM_SHAFT);
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,25 +1,26 @@
|
||||||
package com.simibubi.create.content.contraptions.relays.encased;
|
package com.simibubi.create.content.contraptions.relays.encased;
|
||||||
|
|
||||||
import java.util.Random;
|
|
||||||
|
|
||||||
import com.simibubi.create.AllTileEntities;
|
import com.simibubi.create.AllTileEntities;
|
||||||
import com.simibubi.create.content.contraptions.base.KineticTileEntity;
|
import com.simibubi.create.content.contraptions.base.KineticTileEntity;
|
||||||
|
import com.simibubi.create.content.contraptions.base.RotatedPillarKineticBlock;
|
||||||
import com.simibubi.create.foundation.block.ITE;
|
import com.simibubi.create.foundation.block.ITE;
|
||||||
|
|
||||||
import net.minecraft.core.BlockPos;
|
import net.minecraft.core.BlockPos;
|
||||||
import net.minecraft.server.level.ServerLevel;
|
import net.minecraft.core.Direction;
|
||||||
import net.minecraft.world.item.context.BlockPlaceContext;
|
import net.minecraft.world.item.context.BlockPlaceContext;
|
||||||
import net.minecraft.world.level.Level;
|
import net.minecraft.world.level.Level;
|
||||||
|
import net.minecraft.world.level.LevelReader;
|
||||||
import net.minecraft.world.level.block.Block;
|
import net.minecraft.world.level.block.Block;
|
||||||
import net.minecraft.world.level.block.entity.BlockEntity;
|
|
||||||
import net.minecraft.world.level.block.entity.BlockEntityType;
|
import net.minecraft.world.level.block.entity.BlockEntityType;
|
||||||
import net.minecraft.world.level.block.state.BlockState;
|
import net.minecraft.world.level.block.state.BlockState;
|
||||||
import net.minecraft.world.level.block.state.StateDefinition.Builder;
|
import net.minecraft.world.level.block.state.StateDefinition.Builder;
|
||||||
import net.minecraft.world.level.block.state.properties.BlockStateProperties;
|
import net.minecraft.world.level.block.state.properties.BlockStateProperties;
|
||||||
import net.minecraft.world.level.block.state.properties.BooleanProperty;
|
import net.minecraft.world.level.block.state.properties.BooleanProperty;
|
||||||
import net.minecraft.world.ticks.TickPriority;
|
import net.minecraft.world.level.material.PushReaction;
|
||||||
|
|
||||||
public class GearshiftBlock extends AbstractEncasedShaftBlock implements ITE<KineticTileEntity> {
|
import javax.annotation.Nullable;
|
||||||
|
|
||||||
|
public class GearshiftBlock extends RotatedPillarKineticBlock implements ITE<KineticTileEntity> {
|
||||||
|
|
||||||
public static final BooleanProperty POWERED = BlockStateProperties.POWERED;
|
public static final BooleanProperty POWERED = BlockStateProperties.POWERED;
|
||||||
|
|
||||||
|
@ -36,8 +37,8 @@ public class GearshiftBlock extends AbstractEncasedShaftBlock implements ITE<Kin
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public BlockState getStateForPlacement(BlockPlaceContext context) {
|
public BlockState getStateForPlacement(BlockPlaceContext context) {
|
||||||
return super.getStateForPlacement(context).setValue(POWERED,
|
return super.getStateForPlacement(context)
|
||||||
context.getLevel().hasNeighborSignal(context.getClickedPos()));
|
.setValue(POWERED, context.getLevel().hasNeighborSignal(context.getClickedPos()));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -62,5 +63,23 @@ public class GearshiftBlock extends AbstractEncasedShaftBlock implements ITE<Kin
|
||||||
return AllTileEntities.GEARSHIFT.get();
|
return AllTileEntities.GEARSHIFT.get();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean shouldCheckWeakPower(BlockState state, LevelReader world, BlockPos pos, Direction side) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public PushReaction getPistonPushReaction(@Nullable BlockState state) {
|
||||||
|
return PushReaction.NORMAL;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean hasShaftTowards(BlockState state, Direction face) {
|
||||||
|
return face.getAxis() == state.getValue(AXIS);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Direction.Axis getRotationAxis(BlockState state) {
|
||||||
|
return state.getValue(AXIS);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -11,6 +11,7 @@ import com.simibubi.create.content.contraptions.base.IRotate;
|
||||||
import com.simibubi.create.content.contraptions.base.KineticTileEntity;
|
import com.simibubi.create.content.contraptions.base.KineticTileEntity;
|
||||||
import com.simibubi.create.content.contraptions.base.KineticTileInstance;
|
import com.simibubi.create.content.contraptions.base.KineticTileInstance;
|
||||||
import com.simibubi.create.content.contraptions.base.flwdata.RotatingData;
|
import com.simibubi.create.content.contraptions.base.flwdata.RotatingData;
|
||||||
|
import com.simibubi.create.content.contraptions.solver.KineticConnections;
|
||||||
import com.simibubi.create.foundation.utility.Iterate;
|
import com.simibubi.create.foundation.utility.Iterate;
|
||||||
|
|
||||||
import net.minecraft.core.Direction;
|
import net.minecraft.core.Direction;
|
||||||
|
@ -25,15 +26,13 @@ public class SplitShaftInstance extends KineticTileInstance<KineticTileEntity> {
|
||||||
|
|
||||||
keys = new ArrayList<>(2);
|
keys = new ArrayList<>(2);
|
||||||
|
|
||||||
float speed = tile.getSpeed();
|
|
||||||
|
|
||||||
Material<RotatingData> rotatingMaterial = getRotatingMaterial();
|
Material<RotatingData> rotatingMaterial = getRotatingMaterial();
|
||||||
|
|
||||||
for (Direction dir : Iterate.directionsInAxis(getRotationAxis())) {
|
for (Direction dir : Iterate.directionsInAxis(getRotationAxis())) {
|
||||||
|
|
||||||
Instancer<RotatingData> half = rotatingMaterial.getModel(AllBlockPartials.SHAFT_HALF, blockState, dir);
|
Instancer<RotatingData> half = rotatingMaterial.getModel(AllBlockPartials.SHAFT_HALF, blockState, dir);
|
||||||
|
|
||||||
float splitSpeed = speed * tile.getRotationSpeedModifier(dir);
|
float splitSpeed = tile.getShaftSpeed(dir);
|
||||||
|
|
||||||
keys.add(setup(half.createInstance(), splitSpeed));
|
keys.add(setup(half.createInstance(), splitSpeed));
|
||||||
}
|
}
|
||||||
|
@ -46,8 +45,8 @@ public class SplitShaftInstance extends KineticTileInstance<KineticTileEntity> {
|
||||||
|
|
||||||
Direction[] directions = Iterate.directionsInAxis(boxAxis);
|
Direction[] directions = Iterate.directionsInAxis(boxAxis);
|
||||||
|
|
||||||
for (int i : Iterate.zeroAndOne) {
|
for (int i : Iterate.zeroAndOne) {
|
||||||
updateRotation(keys.get(i), tile.getSpeed() * tile.getRotationSpeedModifier(directions[i]));
|
updateRotation(keys.get(i), tile.getShaftSpeed(directions[i]));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -6,6 +6,7 @@ import com.simibubi.create.AllBlockPartials;
|
||||||
import com.simibubi.create.content.contraptions.base.IRotate;
|
import com.simibubi.create.content.contraptions.base.IRotate;
|
||||||
import com.simibubi.create.content.contraptions.base.KineticTileEntity;
|
import com.simibubi.create.content.contraptions.base.KineticTileEntity;
|
||||||
import com.simibubi.create.content.contraptions.base.KineticTileEntityRenderer;
|
import com.simibubi.create.content.contraptions.base.KineticTileEntityRenderer;
|
||||||
|
import com.simibubi.create.content.contraptions.solver.KineticConnections;
|
||||||
import com.simibubi.create.foundation.render.CachedBufferer;
|
import com.simibubi.create.foundation.render.CachedBufferer;
|
||||||
import com.simibubi.create.foundation.render.SuperByteBuffer;
|
import com.simibubi.create.foundation.render.SuperByteBuffer;
|
||||||
import com.simibubi.create.foundation.utility.AnimationTickHolder;
|
import com.simibubi.create.foundation.utility.AnimationTickHolder;
|
||||||
|
@ -41,12 +42,8 @@ public class SplitShaftRenderer extends KineticTileEntityRenderer {
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
float offset = getRotationOffsetForPosition(te, pos, axis);
|
float offset = getRotationOffsetForPosition(te, pos, axis);
|
||||||
float angle = (time * te.getSpeed() * 3f / 10) % 360;
|
float angle = (time * te.getShaftSpeed(direction) * 3f / 10) % 360;
|
||||||
float modifier = 1;
|
|
||||||
|
|
||||||
modifier = te.getRotationSpeedModifier(direction);
|
|
||||||
|
|
||||||
angle *= modifier;
|
|
||||||
angle += offset;
|
angle += offset;
|
||||||
angle = angle / 180f * (float) Math.PI;
|
angle = angle / 180f * (float) Math.PI;
|
||||||
|
|
||||||
|
|
|
@ -69,7 +69,7 @@ public class GaugeBlock extends DirectionalAxisKineticBlock implements ITE<Gauge
|
||||||
BlockState placedOnState = world.getBlockState(placedOnPos);
|
BlockState placedOnState = world.getBlockState(placedOnPos);
|
||||||
Block block = placedOnState.getBlock();
|
Block block = placedOnState.getBlock();
|
||||||
|
|
||||||
if (block instanceof IRotate && ((IRotate) block).hasShaftTowards(world, placedOnPos, placedOnState, face)) {
|
if (block instanceof IRotate ir && ir.hasShaftTowards(placedOnState, face, world, placedOnPos)) {
|
||||||
BlockState toPlace = defaultBlockState();
|
BlockState toPlace = defaultBlockState();
|
||||||
Direction horizontalFacing = context.getHorizontalDirection();
|
Direction horizontalFacing = context.getHorizontalDirection();
|
||||||
Direction nearestLookingDirection = context.getNearestLookingDirection();
|
Direction nearestLookingDirection = context.getNearestLookingDirection();
|
||||||
|
|
|
@ -62,7 +62,7 @@ public class SpeedGaugeTileEntity extends GaugeTileEntity {
|
||||||
super.addToGoggleTooltip(tooltip, isPlayerSneaking);
|
super.addToGoggleTooltip(tooltip, isPlayerSneaking);
|
||||||
|
|
||||||
tooltip.add(componentSpacing.plainCopy().append(Lang.translate("gui.speedometer.title").withStyle(ChatFormatting.GRAY)));
|
tooltip.add(componentSpacing.plainCopy().append(Lang.translate("gui.speedometer.title").withStyle(ChatFormatting.GRAY)));
|
||||||
tooltip.add(componentSpacing.plainCopy().append(SpeedLevel.getFormattedSpeedText(theoreticalSpeed, isOverstressed())));
|
tooltip.add(componentSpacing.plainCopy().append(SpeedLevel.getFormattedSpeedText(getTheoreticalSpeed(), isOverstressed())));
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
|
@ -6,8 +6,15 @@ import java.util.List;
|
||||||
import com.simibubi.create.AllItems;
|
import com.simibubi.create.AllItems;
|
||||||
import com.simibubi.create.AllTileEntities;
|
import com.simibubi.create.AllTileEntities;
|
||||||
import com.simibubi.create.content.contraptions.base.RotatedPillarKineticBlock;
|
import com.simibubi.create.content.contraptions.base.RotatedPillarKineticBlock;
|
||||||
|
import com.simibubi.create.content.contraptions.solver.AllConnections;
|
||||||
|
import com.simibubi.create.content.contraptions.solver.ConnectionsBuilder;
|
||||||
|
import com.simibubi.create.content.contraptions.solver.KineticConnections;
|
||||||
import com.simibubi.create.foundation.block.ITE;
|
import com.simibubi.create.foundation.block.ITE;
|
||||||
|
|
||||||
|
import com.simibubi.create.foundation.utility.DirectionHelper;
|
||||||
|
|
||||||
|
import com.simibubi.create.foundation.utility.Iterate;
|
||||||
|
|
||||||
import net.minecraft.core.BlockPos;
|
import net.minecraft.core.BlockPos;
|
||||||
import net.minecraft.core.Direction;
|
import net.minecraft.core.Direction;
|
||||||
import net.minecraft.core.Direction.Axis;
|
import net.minecraft.core.Direction.Axis;
|
||||||
|
@ -17,7 +24,6 @@ import net.minecraft.world.item.CreativeModeTab;
|
||||||
import net.minecraft.world.item.ItemStack;
|
import net.minecraft.world.item.ItemStack;
|
||||||
import net.minecraft.world.item.context.BlockPlaceContext;
|
import net.minecraft.world.item.context.BlockPlaceContext;
|
||||||
import net.minecraft.world.level.BlockGetter;
|
import net.minecraft.world.level.BlockGetter;
|
||||||
import net.minecraft.world.level.LevelReader;
|
|
||||||
import net.minecraft.world.level.block.entity.BlockEntityType;
|
import net.minecraft.world.level.block.entity.BlockEntityType;
|
||||||
import net.minecraft.world.level.block.state.BlockState;
|
import net.minecraft.world.level.block.state.BlockState;
|
||||||
import net.minecraft.world.level.material.PushReaction;
|
import net.minecraft.world.level.material.PushReaction;
|
||||||
|
@ -65,7 +71,7 @@ public class GearboxBlock extends RotatedPillarKineticBlock implements ITE<Gearb
|
||||||
// IRotate:
|
// IRotate:
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean hasShaftTowards(LevelReader world, BlockPos pos, BlockState state, Direction face) {
|
public boolean hasShaftTowards(BlockState state, Direction face) {
|
||||||
return face.getAxis() != state.getValue(AXIS);
|
return face.getAxis() != state.getValue(AXIS);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -74,6 +80,26 @@ public class GearboxBlock extends RotatedPillarKineticBlock implements ITE<Gearb
|
||||||
return state.getValue(AXIS);
|
return state.getValue(AXIS);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private static boolean isReversed(Direction from, Direction to) {
|
||||||
|
if (from == to) return false;
|
||||||
|
Axis fromAxis = from.getAxis(), toAxis = to.getAxis();
|
||||||
|
if (fromAxis == toAxis) return true;
|
||||||
|
return AllConnections.perpendicularRatios(to.getNormal().subtract(from.getNormal()), fromAxis, toAxis) == -1;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public ConnectionsBuilder buildInitialConnections(ConnectionsBuilder builder, BlockState state) {
|
||||||
|
Axis axis = state.getValue(AXIS);
|
||||||
|
Direction start = DirectionHelper.getPositivePerpendicular(axis);
|
||||||
|
for (Direction cur : Iterate.directionsPerpendicularTo(axis)) {
|
||||||
|
AllConnections.Shafts shaft = isReversed(start, cur)
|
||||||
|
? AllConnections.Shafts.SHAFT_REV
|
||||||
|
: AllConnections.Shafts.SHAFT;
|
||||||
|
builder = builder.withHalfShaft(shaft, cur);
|
||||||
|
}
|
||||||
|
return builder;
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Class<GearboxTileEntity> getTileEntityClass() {
|
public Class<GearboxTileEntity> getTileEntityClass() {
|
||||||
return GearboxTileEntity.class;
|
return GearboxTileEntity.class;
|
||||||
|
|
|
@ -12,7 +12,6 @@ import com.simibubi.create.content.contraptions.base.KineticTileInstance;
|
||||||
import com.simibubi.create.content.contraptions.base.flwdata.RotatingData;
|
import com.simibubi.create.content.contraptions.base.flwdata.RotatingData;
|
||||||
import com.simibubi.create.foundation.utility.Iterate;
|
import com.simibubi.create.foundation.utility.Iterate;
|
||||||
|
|
||||||
import net.minecraft.core.BlockPos;
|
|
||||||
import net.minecraft.core.Direction;
|
import net.minecraft.core.Direction;
|
||||||
import net.minecraft.world.level.LightLayer;
|
import net.minecraft.world.level.LightLayer;
|
||||||
import net.minecraft.world.level.block.state.properties.BlockStateProperties;
|
import net.minecraft.world.level.block.state.properties.BlockStateProperties;
|
||||||
|
@ -20,7 +19,6 @@ import net.minecraft.world.level.block.state.properties.BlockStateProperties;
|
||||||
public class GearboxInstance extends KineticTileInstance<GearboxTileEntity> {
|
public class GearboxInstance extends KineticTileInstance<GearboxTileEntity> {
|
||||||
|
|
||||||
protected final EnumMap<Direction, RotatingData> keys;
|
protected final EnumMap<Direction, RotatingData> keys;
|
||||||
protected Direction sourceFacing;
|
|
||||||
|
|
||||||
public GearboxInstance(MaterialManager modelManager, GearboxTileEntity tile) {
|
public GearboxInstance(MaterialManager modelManager, GearboxTileEntity tile) {
|
||||||
super(modelManager, tile);
|
super(modelManager, tile);
|
||||||
|
@ -31,7 +29,6 @@ public class GearboxInstance extends KineticTileInstance<GearboxTileEntity> {
|
||||||
|
|
||||||
int blockLight = world.getBrightness(LightLayer.BLOCK, pos);
|
int blockLight = world.getBrightness(LightLayer.BLOCK, pos);
|
||||||
int skyLight = world.getBrightness(LightLayer.SKY, pos);
|
int skyLight = world.getBrightness(LightLayer.SKY, pos);
|
||||||
updateSourceFacing();
|
|
||||||
|
|
||||||
Material<RotatingData> rotatingMaterial = getRotatingMaterial();
|
Material<RotatingData> rotatingMaterial = getRotatingMaterial();
|
||||||
|
|
||||||
|
@ -56,29 +53,11 @@ public class GearboxInstance extends KineticTileInstance<GearboxTileEntity> {
|
||||||
}
|
}
|
||||||
|
|
||||||
private float getSpeed(Direction direction) {
|
private float getSpeed(Direction direction) {
|
||||||
float speed = tile.getSpeed();
|
return tile.getShaftSpeed(direction);
|
||||||
|
|
||||||
if (speed != 0 && sourceFacing != null) {
|
|
||||||
if (sourceFacing.getAxis() == direction.getAxis())
|
|
||||||
speed *= sourceFacing == direction ? 1 : -1;
|
|
||||||
else if (sourceFacing.getAxisDirection() == direction.getAxisDirection())
|
|
||||||
speed *= -1;
|
|
||||||
}
|
|
||||||
return speed;
|
|
||||||
}
|
|
||||||
|
|
||||||
protected void updateSourceFacing() {
|
|
||||||
if (tile.hasSource()) {
|
|
||||||
BlockPos source = tile.source.subtract(pos);
|
|
||||||
sourceFacing = Direction.getNearest(source.getX(), source.getY(), source.getZ());
|
|
||||||
} else {
|
|
||||||
sourceFacing = null;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void update() {
|
public void update() {
|
||||||
updateSourceFacing();
|
|
||||||
for (Map.Entry<Direction, RotatingData> key : keys.entrySet()) {
|
for (Map.Entry<Direction, RotatingData> key : keys.entrySet()) {
|
||||||
Direction direction = key.getKey();
|
Direction direction = key.getKey();
|
||||||
Direction.Axis axis = direction.getAxis();
|
Direction.Axis axis = direction.getAxis();
|
||||||
|
|
|
@ -40,16 +40,7 @@ public class GearboxRenderer extends KineticTileEntityRenderer {
|
||||||
|
|
||||||
SuperByteBuffer shaft = CachedBufferer.partialFacing(AllBlockPartials.SHAFT_HALF, te.getBlockState(), direction);
|
SuperByteBuffer shaft = CachedBufferer.partialFacing(AllBlockPartials.SHAFT_HALF, te.getBlockState(), direction);
|
||||||
float offset = getRotationOffsetForPosition(te, pos, axis);
|
float offset = getRotationOffsetForPosition(te, pos, axis);
|
||||||
float angle = (time * te.getSpeed() * 3f / 10) % 360;
|
float angle = (time * te.getShaftSpeed(direction) * 3f / 10) % 360;
|
||||||
|
|
||||||
if (te.getSpeed() != 0 && te.hasSource()) {
|
|
||||||
BlockPos source = te.source.subtract(te.getBlockPos());
|
|
||||||
Direction sourceFacing = Direction.getNearest(source.getX(), source.getY(), source.getZ());
|
|
||||||
if (sourceFacing.getAxis() == direction.getAxis())
|
|
||||||
angle *= sourceFacing == direction ? 1 : -1;
|
|
||||||
else if (sourceFacing.getAxisDirection() == direction.getAxisDirection())
|
|
||||||
angle *= -1;
|
|
||||||
}
|
|
||||||
|
|
||||||
angle += offset;
|
angle += offset;
|
||||||
angle = angle / 180f * (float) Math.PI;
|
angle = angle / 180f * (float) Math.PI;
|
||||||
|
|
|
@ -2,7 +2,9 @@ package com.simibubi.create.content.contraptions.relays.gearbox;
|
||||||
|
|
||||||
import com.simibubi.create.content.contraptions.base.KineticTileEntity;
|
import com.simibubi.create.content.contraptions.base.KineticTileEntity;
|
||||||
|
|
||||||
|
import com.simibubi.create.content.contraptions.relays.encased.GearshiftBlock;
|
||||||
import com.simibubi.create.content.contraptions.solver.AllConnections;
|
import com.simibubi.create.content.contraptions.solver.AllConnections;
|
||||||
|
import com.simibubi.create.content.contraptions.solver.ConnectionsBuilder;
|
||||||
import com.simibubi.create.content.contraptions.solver.KineticConnections;
|
import com.simibubi.create.content.contraptions.solver.KineticConnections;
|
||||||
|
|
||||||
import net.minecraft.core.BlockPos;
|
import net.minecraft.core.BlockPos;
|
||||||
|
@ -20,13 +22,15 @@ public class GearshiftTileEntity extends KineticTileEntity {
|
||||||
@Override
|
@Override
|
||||||
public KineticConnections getConnections() {
|
public KineticConnections getConnections() {
|
||||||
BlockState state = getBlockState();
|
BlockState state = getBlockState();
|
||||||
Direction.Axis axis = state.getValue(BlockStateProperties.AXIS);
|
Direction dir = AllConnections.pos(state.getValue(GearshiftBlock.AXIS));
|
||||||
|
|
||||||
if (!state.getValue(BlockStateProperties.POWERED)) return AllConnections.FULL_SHAFT.apply(axis);
|
ConnectionsBuilder builder = ConnectionsBuilder.builder();
|
||||||
|
if (!state.getValue(BlockStateProperties.POWERED))
|
||||||
return getSpeedSource()
|
return builder.withFullShaft(dir.getAxis()).build();
|
||||||
.map(p -> AllConnections.FULL_SHAFT_REVERSER.apply(Direction.fromNormal(p.subtract(getBlockPos()))))
|
return builder
|
||||||
.orElse(AllConnections.FULL_SHAFT.apply(axis));
|
.withHalfShaft(AllConnections.Shafts.SHAFT_REV, dir)
|
||||||
|
.withHalfShaft(AllConnections.Shafts.SHAFT, dir.getOpposite())
|
||||||
|
.build();
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -4,6 +4,7 @@ import java.util.Map;
|
||||||
|
|
||||||
import com.simibubi.create.AllBlocks;
|
import com.simibubi.create.AllBlocks;
|
||||||
import com.simibubi.create.content.contraptions.base.IRotate;
|
import com.simibubi.create.content.contraptions.base.IRotate;
|
||||||
|
import com.simibubi.create.content.contraptions.base.KineticTileEntity;
|
||||||
import com.simibubi.create.foundation.utility.Iterate;
|
import com.simibubi.create.foundation.utility.Iterate;
|
||||||
|
|
||||||
import net.minecraft.core.BlockPos;
|
import net.minecraft.core.BlockPos;
|
||||||
|
@ -41,25 +42,26 @@ public class VerticalGearboxItem extends BlockItem {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected boolean updateCustomBlockEntityTag(BlockPos pos, Level world, Player player, ItemStack stack, BlockState state) {
|
protected boolean updateCustomBlockEntityTag(BlockPos pos, Level world, Player player, ItemStack stack, BlockState state) {
|
||||||
Axis prefferedAxis = null;
|
Axis preferredAxis = null;
|
||||||
for (Direction side : Iterate.horizontalDirections) {
|
for (Direction side : Iterate.horizontalDirections) {
|
||||||
BlockState blockState = world.getBlockState(pos.relative(side));
|
BlockState blockState = world.getBlockState(pos.relative(side));
|
||||||
if (blockState.getBlock() instanceof IRotate) {
|
if (blockState.getBlock() instanceof IRotate ir) {
|
||||||
if (((IRotate) blockState.getBlock()).hasShaftTowards(world, pos.relative(side), blockState,
|
if (ir.hasShaftTowards(blockState, side.getOpposite(), world, pos.relative(side)))
|
||||||
side.getOpposite()))
|
if (preferredAxis != null && preferredAxis != side.getAxis()) {
|
||||||
if (prefferedAxis != null && prefferedAxis != side.getAxis()) {
|
preferredAxis = null;
|
||||||
prefferedAxis = null;
|
|
||||||
break;
|
break;
|
||||||
} else {
|
} else {
|
||||||
prefferedAxis = side.getAxis();
|
preferredAxis = side.getAxis();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
Axis axis = prefferedAxis == null ? player.getDirection()
|
Axis axis = preferredAxis == null ? player.getDirection()
|
||||||
.getClockWise()
|
.getClockWise()
|
||||||
.getAxis() : prefferedAxis == Axis.X ? Axis.Z : Axis.X;
|
.getAxis() : preferredAxis == Axis.X ? Axis.Z : Axis.X;
|
||||||
world.setBlockAndUpdate(pos, state.setValue(BlockStateProperties.AXIS, axis));
|
BlockState newState = state.setValue(BlockStateProperties.AXIS, axis);
|
||||||
|
KineticTileEntity.switchToBlockState(world, pos, newState);
|
||||||
|
|
||||||
return super.updateCustomBlockEntityTag(pos, world, player, stack, state);
|
return super.updateCustomBlockEntityTag(pos, world, player, stack, state);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -1,13 +1,13 @@
|
||||||
package com.simibubi.create.content.contraptions.solver;
|
package com.simibubi.create.content.contraptions.solver;
|
||||||
|
|
||||||
|
import com.simibubi.create.content.contraptions.components.structureMovement.gantry.GantryCarriageTileEntity;
|
||||||
import com.simibubi.create.foundation.utility.DirectionHelper;
|
import com.simibubi.create.foundation.utility.DirectionHelper;
|
||||||
import com.simibubi.create.foundation.utility.LazyMap;
|
|
||||||
import com.simibubi.create.content.contraptions.solver.KineticConnections.Entry;
|
import com.simibubi.create.foundation.utility.Iterate;
|
||||||
|
|
||||||
import net.minecraft.core.Direction;
|
import net.minecraft.core.Direction;
|
||||||
import net.minecraft.core.Direction.Axis;
|
import net.minecraft.core.Direction.Axis;
|
||||||
import net.minecraft.core.Vec3i;
|
import net.minecraft.core.Vec3i;
|
||||||
import net.minecraft.util.StringRepresentable;
|
|
||||||
|
|
||||||
import java.util.LinkedList;
|
import java.util.LinkedList;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
@ -15,34 +15,250 @@ import java.util.Optional;
|
||||||
|
|
||||||
public class AllConnections {
|
public class AllConnections {
|
||||||
|
|
||||||
private static Direction pos(Axis axis) {
|
public static void register() {
|
||||||
|
Shafts.registerTypes();
|
||||||
|
Directional.registerTypes();
|
||||||
|
Axial.registerTypes();
|
||||||
|
DirAxial.registerTypes();
|
||||||
|
|
||||||
|
Shafts.registerRatios();
|
||||||
|
Directional.registerRatios();
|
||||||
|
Axial.registerRatios();
|
||||||
|
DirAxial.registerRatios();
|
||||||
|
}
|
||||||
|
|
||||||
|
private static record Entry(Vec3i offset, String to, float ratio) {}
|
||||||
|
|
||||||
|
public enum Shafts {
|
||||||
|
SHAFT("shaft", 1),
|
||||||
|
SHAFT_REV("shaft_rev", -1),
|
||||||
|
SHAFT_X2("shaft_x2", 2),
|
||||||
|
SHAFT_REV_X2("shaft_rev_x2", -2);
|
||||||
|
|
||||||
|
public final String prefix;
|
||||||
|
public final float ratio;
|
||||||
|
Shafts(String prefix, float ratio) {
|
||||||
|
this.prefix = prefix;
|
||||||
|
this.ratio = ratio;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String type(Direction dir) {
|
||||||
|
return prefix + "." + dir;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static void registerTypes() {
|
||||||
|
for (Shafts value : values()) {
|
||||||
|
for (Direction dir : Direction.values()) {
|
||||||
|
KineticConnectionsRegistry.registerConnectionType(value.type(dir));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public static void registerRatios() {
|
||||||
|
for (Shafts from : values()) {
|
||||||
|
for (Shafts to : values()) {
|
||||||
|
for (Direction dir : Direction.values()) {
|
||||||
|
KineticConnectionsRegistry.registerConnectionRatio(
|
||||||
|
KineticConnectionsRegistry.getConnectionType(from.type(dir)).get(),
|
||||||
|
KineticConnectionsRegistry.getConnectionType(to.type(dir.getOpposite())).get(),
|
||||||
|
dir.getNormal(),
|
||||||
|
from.ratio / to.ratio
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public enum Directional {
|
||||||
|
GANTRY_RACK("gantry_rack") {
|
||||||
|
@Override
|
||||||
|
public List<Entry> genConnections(Direction dir) { return List.of(); }
|
||||||
|
};
|
||||||
|
|
||||||
|
public final String prefix;
|
||||||
|
|
||||||
|
Directional(String prefix) {
|
||||||
|
this.prefix = prefix;
|
||||||
|
}
|
||||||
|
|
||||||
|
public abstract List<Entry> genConnections(Direction dir);
|
||||||
|
|
||||||
|
public String type(Direction dir) {
|
||||||
|
return prefix + "." + dir;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static void registerTypes() {
|
||||||
|
for (Directional value : values()) {
|
||||||
|
for (Direction dir : Direction.values()) {
|
||||||
|
KineticConnectionsRegistry.registerConnectionType(value.type(dir));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public static void registerRatios() {
|
||||||
|
for (Directional from : values()) {
|
||||||
|
for (Direction dir : Direction.values()) {
|
||||||
|
String fromType = from.type(dir);
|
||||||
|
from.genConnections(dir).forEach(entry -> KineticConnectionsRegistry.registerConnectionRatio(
|
||||||
|
KineticConnectionsRegistry.getConnectionType(fromType).get(),
|
||||||
|
KineticConnectionsRegistry.getConnectionType(entry.to).get(),
|
||||||
|
entry.offset,
|
||||||
|
entry.ratio
|
||||||
|
));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public enum Axial {
|
||||||
|
SMALL_COG("small_cog") {
|
||||||
|
@Override
|
||||||
|
public List<Entry> genConnections(Axis axis) {
|
||||||
|
List<Entry> out = new LinkedList<>();
|
||||||
|
for (Direction cur : Iterate.directionsPerpendicularTo(axis)) {
|
||||||
|
Direction next = rot(cur, axis);
|
||||||
|
out.add(new Entry(cur.getNormal(), SMALL_COG.type(axis), -1));
|
||||||
|
out.add(new Entry(cur.getNormal().relative(next), LARGE_COG.type(axis), -0.5f));
|
||||||
|
}
|
||||||
|
return out;
|
||||||
|
}
|
||||||
|
},
|
||||||
|
|
||||||
|
LARGE_COG("large_cog") {
|
||||||
|
@Override
|
||||||
|
public List<Entry> genConnections(Axis axis) {
|
||||||
|
List<Entry> out = new LinkedList<>();
|
||||||
|
for (Direction cur : Iterate.directionsPerpendicularTo(axis)) {
|
||||||
|
out.add(largeToLarge(cur.getNormal().relative(pos(axis)), axis, cur.getAxis()));
|
||||||
|
out.add(largeToLarge(cur.getNormal().relative(neg(axis)), axis, cur.getAxis()));
|
||||||
|
}
|
||||||
|
return out;
|
||||||
|
}
|
||||||
|
},
|
||||||
|
|
||||||
|
SPEED_CONTROLLER_TOP("speed_controller_top") {
|
||||||
|
@Override
|
||||||
|
public List<Entry> genConnections(Axis axis) {
|
||||||
|
return oppAxis(axis)
|
||||||
|
.map(opp -> List.of(new Entry(Direction.UP.getNormal(), LARGE_COG.type(opp), 0)))
|
||||||
|
.orElseGet(List::of);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
public final String prefix;
|
||||||
|
|
||||||
|
Axial(String prefix) {
|
||||||
|
this.prefix = prefix;
|
||||||
|
}
|
||||||
|
|
||||||
|
public abstract List<Entry> genConnections(Axis axis);
|
||||||
|
|
||||||
|
public String type(Axis axis) {
|
||||||
|
return prefix + "." + axis;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static void registerTypes() {
|
||||||
|
for (Axial value : values()) {
|
||||||
|
for (Axis axis : Axis.values()) {
|
||||||
|
KineticConnectionsRegistry.registerConnectionType(value.type(axis));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public static void registerRatios() {
|
||||||
|
for (Axial from : values()) {
|
||||||
|
for (Axis axis : Axis.values()) {
|
||||||
|
String fromType = from.type(axis);
|
||||||
|
from.genConnections(axis).forEach(entry -> KineticConnectionsRegistry.registerConnectionRatio(
|
||||||
|
KineticConnectionsRegistry.getConnectionType(fromType).get(),
|
||||||
|
KineticConnectionsRegistry.getConnectionType(entry.to).get(),
|
||||||
|
entry.offset,
|
||||||
|
entry.ratio
|
||||||
|
));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public enum DirAxial {
|
||||||
|
GANTRY_PINION("gantry_pinion") {
|
||||||
|
@Override
|
||||||
|
public List<Entry> genConnections(Direction dir, boolean first) {
|
||||||
|
Axis shaftAxis = switch (dir.getAxis()) {
|
||||||
|
case X -> first ? Axis.Z : Axis.Y;
|
||||||
|
case Y -> first ? Axis.Z : Axis.X;
|
||||||
|
case Z -> first ? Axis.Y : Axis.X;
|
||||||
|
};
|
||||||
|
|
||||||
|
List<Entry> out = new LinkedList<>();
|
||||||
|
for (Direction shaftDir : Iterate.directionsInAxis(shaftAxis)) {
|
||||||
|
float ratio = GantryCarriageTileEntity.getGantryPinionModifier(shaftDir, dir);
|
||||||
|
out.add(new Entry(dir.getOpposite().getNormal(), Directional.GANTRY_RACK.type(shaftDir), ratio));
|
||||||
|
}
|
||||||
|
return out;
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
public final String prefix;
|
||||||
|
|
||||||
|
DirAxial(String prefix) {
|
||||||
|
this.prefix = prefix;
|
||||||
|
}
|
||||||
|
|
||||||
|
public abstract List<Entry> genConnections(Direction dir, boolean first);
|
||||||
|
|
||||||
|
public String type(Direction dir, boolean first) {
|
||||||
|
return prefix + "." + dir + "_" + (first ? "0" : "1");
|
||||||
|
}
|
||||||
|
|
||||||
|
public static void registerTypes() {
|
||||||
|
for (DirAxial value : values()) {
|
||||||
|
for (Direction dir : Direction.values()) {
|
||||||
|
for (boolean first : Iterate.trueAndFalse) {
|
||||||
|
KineticConnectionsRegistry.registerConnectionType(value.type(dir, first));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public static void registerRatios() {
|
||||||
|
for (DirAxial from : values()) {
|
||||||
|
for (Direction dir : Direction.values()) {
|
||||||
|
for (boolean first : Iterate.trueAndFalse) {
|
||||||
|
String fromType = from.type(dir, first);
|
||||||
|
from.genConnections(dir, first).forEach(entry -> KineticConnectionsRegistry.registerConnectionRatio(
|
||||||
|
KineticConnectionsRegistry.getConnectionType(fromType).get(),
|
||||||
|
KineticConnectionsRegistry.getConnectionType(entry.to).get(),
|
||||||
|
entry.offset,
|
||||||
|
entry.ratio
|
||||||
|
));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public static Direction pos(Axis axis) {
|
||||||
return Direction.get(Direction.AxisDirection.POSITIVE, axis);
|
return Direction.get(Direction.AxisDirection.POSITIVE, axis);
|
||||||
}
|
}
|
||||||
|
|
||||||
private static Direction neg(Axis axis) {
|
public static Direction neg(Axis axis) {
|
||||||
return Direction.get(Direction.AxisDirection.NEGATIVE, axis);
|
return Direction.get(Direction.AxisDirection.NEGATIVE, axis);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static String type(String name, StringRepresentable ext) {
|
public static Direction rot(Direction dir, Axis axis) {
|
||||||
return name + "." + ext;
|
return DirectionHelper.rotateAround(dir, axis);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static final String
|
public static float perpendicularRatios(Vec3i diff, Axis from, Axis to) {
|
||||||
TYPE_SHAFT = "shaft",
|
int fromDiff = from.choose(diff.getX(), diff.getY(), diff.getZ());
|
||||||
TYPE_LARGE_COG = "large_cog",
|
int toDiff = to.choose(diff.getX(), diff.getY(), diff.getZ());
|
||||||
TYPE_SMALL_COG = "small_cog",
|
return fromDiff * toDiff;
|
||||||
TYPE_SPEED_CONTROLLER_TOP = "speed_controller_top";
|
|
||||||
|
|
||||||
private static Vec3i rhr(Vec3i vec) {
|
|
||||||
if (vec.getX() == 0) return new Vec3i(vec.getY(), vec.getZ(), 0);
|
|
||||||
if (vec.getY() == 0) return new Vec3i(vec.getZ(), vec.getX(), 0);
|
|
||||||
return new Vec3i(vec.getX(), vec.getY(), 0);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private static Entry largeToLarge(Vec3i diff, Axis from, Axis to) {
|
private static Entry largeToLarge(Vec3i diff, Axis from, Axis to) {
|
||||||
Vec3i rhr = rhr(diff);
|
return new Entry(diff, Axial.LARGE_COG.type(to), perpendicularRatios(diff, from, to));
|
||||||
float ratio = rhr.getX() == rhr.getY() ? 1 : rhr.getX();
|
|
||||||
return new Entry(diff, type(TYPE_LARGE_COG, from), type(TYPE_LARGE_COG, to), ratio);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private static Optional<Axis> oppAxis(Axis axis) {
|
private static Optional<Axis> oppAxis(Axis axis) {
|
||||||
|
@ -53,69 +269,4 @@ public class AllConnections {
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
public static final KineticConnections EMPTY = new KineticConnections();
|
|
||||||
|
|
||||||
public static final LazyMap<Direction, KineticConnections>
|
|
||||||
HALF_SHAFT = new LazyMap<>(dir ->
|
|
||||||
new KineticConnections(
|
|
||||||
new Entry(dir.getNormal(), type(TYPE_SHAFT, dir), type(TYPE_SHAFT, dir.getOpposite())))),
|
|
||||||
|
|
||||||
HALF_SHAFT_REVERSER = new LazyMap<>(dir ->
|
|
||||||
new KineticConnections(
|
|
||||||
new Entry(dir.getNormal(), type(TYPE_SHAFT, dir), type(TYPE_SHAFT, dir.getOpposite()), -1))),
|
|
||||||
|
|
||||||
FULL_SHAFT_REVERSER = new LazyMap<>(dir ->
|
|
||||||
HALF_SHAFT.apply(dir).merge(HALF_SHAFT_REVERSER.apply(dir.getOpposite())));
|
|
||||||
|
|
||||||
public static final LazyMap<Axis, KineticConnections>
|
|
||||||
FULL_SHAFT = new LazyMap<>(axis -> HALF_SHAFT.apply(pos(axis)).merge(HALF_SHAFT.apply(neg(axis)))),
|
|
||||||
|
|
||||||
LARGE_COG = new LazyMap<>(axis -> {
|
|
||||||
String large = type(TYPE_LARGE_COG, axis);
|
|
||||||
String small = type(TYPE_SMALL_COG, axis);
|
|
||||||
|
|
||||||
List<Entry> out = new LinkedList<>();
|
|
||||||
Direction cur = DirectionHelper.getPositivePerpendicular(axis);
|
|
||||||
for (int i = 0; i < 4; i++) {
|
|
||||||
Direction next = DirectionHelper.rotateAround(cur, axis);
|
|
||||||
out.add(largeToLarge(cur.getNormal().relative(pos(axis)), axis, cur.getAxis()));
|
|
||||||
out.add(largeToLarge(cur.getNormal().relative(neg(axis)), axis, cur.getAxis()));
|
|
||||||
out.add(new Entry(cur.getNormal().relative(next), large, small, -2));
|
|
||||||
cur = next;
|
|
||||||
}
|
|
||||||
|
|
||||||
oppAxis(axis).ifPresent(opp -> {
|
|
||||||
String sc = type(TYPE_SPEED_CONTROLLER_TOP, opp);
|
|
||||||
out.add(new Entry(Direction.DOWN.getNormal(), large, sc).stressOnly());
|
|
||||||
});
|
|
||||||
return new KineticConnections(out);
|
|
||||||
}),
|
|
||||||
|
|
||||||
SMALL_COG = new LazyMap<>(axis -> {
|
|
||||||
String large = type(TYPE_LARGE_COG, axis);
|
|
||||||
String small = type(TYPE_SMALL_COG, axis);
|
|
||||||
|
|
||||||
List<Entry> out = new LinkedList<>();
|
|
||||||
Direction cur = DirectionHelper.getPositivePerpendicular(axis);
|
|
||||||
for (int i = 0; i < 4; i++) {
|
|
||||||
Direction next = DirectionHelper.rotateAround(cur, axis);
|
|
||||||
out.add(new Entry(cur.getNormal(), small, small, i < 2 ? -1 : 1));
|
|
||||||
out.add(new Entry(cur.getNormal().relative(next), small, large));
|
|
||||||
cur = next;
|
|
||||||
}
|
|
||||||
return new KineticConnections(out);
|
|
||||||
}),
|
|
||||||
|
|
||||||
LARGE_COG_FULL_SHAFT = new LazyMap<>(axis -> LARGE_COG.apply(axis).merge(FULL_SHAFT.apply(axis))),
|
|
||||||
|
|
||||||
SMALL_COG_FULL_SHAFT = new LazyMap<>(axis -> SMALL_COG.apply(axis).merge(FULL_SHAFT.apply(axis))),
|
|
||||||
|
|
||||||
SPEED_CONTROLLER = new LazyMap<>(axis -> {
|
|
||||||
String sc = type(TYPE_SPEED_CONTROLLER_TOP, axis);
|
|
||||||
String large = type(TYPE_LARGE_COG, oppAxis(axis).get());
|
|
||||||
Vec3i up = Direction.UP.getNormal();
|
|
||||||
return new KineticConnections(new Entry(up, sc, large).stressOnly()).merge(FULL_SHAFT.apply(axis));
|
|
||||||
});
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -0,0 +1,54 @@
|
||||||
|
package com.simibubi.create.content.contraptions.solver;
|
||||||
|
|
||||||
|
import net.minecraft.core.Direction;
|
||||||
|
|
||||||
|
import java.util.HashSet;
|
||||||
|
import java.util.Set;
|
||||||
|
|
||||||
|
public class ConnectionsBuilder {
|
||||||
|
private final Set<KineticConnection> connections = new HashSet<>();
|
||||||
|
|
||||||
|
public static ConnectionsBuilder builder() {
|
||||||
|
return new ConnectionsBuilder();
|
||||||
|
}
|
||||||
|
|
||||||
|
public KineticConnections build() {
|
||||||
|
return new KineticConnections(connections);
|
||||||
|
}
|
||||||
|
|
||||||
|
public ConnectionsBuilder withHalfShaft(AllConnections.Shafts shaft, Direction dir) {
|
||||||
|
connections.add(KineticConnectionsRegistry.getConnectionType(shaft.type(dir)).get());
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
|
public ConnectionsBuilder withHalfShaft(Direction dir) {
|
||||||
|
return withHalfShaft(AllConnections.Shafts.SHAFT, dir);
|
||||||
|
}
|
||||||
|
|
||||||
|
public ConnectionsBuilder withFullShaft(Direction.Axis axis) {
|
||||||
|
return this.withHalfShaft(AllConnections.pos(axis)).withHalfShaft(AllConnections.neg(axis));
|
||||||
|
}
|
||||||
|
|
||||||
|
public ConnectionsBuilder withDirectional(AllConnections.Directional directional, Direction dir) {
|
||||||
|
connections.add(KineticConnectionsRegistry.getConnectionType(directional.type(dir)).get());
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
|
public ConnectionsBuilder withAxial(AllConnections.Axial axial, Direction.Axis axis) {
|
||||||
|
connections.add(KineticConnectionsRegistry.getConnectionType(axial.type(axis)).get());
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
|
public ConnectionsBuilder withDirAxial(AllConnections.DirAxial dirAxial, Direction dir, boolean first) {
|
||||||
|
connections.add(KineticConnectionsRegistry.getConnectionType(dirAxial.type(dir, first)).get());
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
|
public ConnectionsBuilder withLargeCog(Direction.Axis axis) {
|
||||||
|
return withAxial(AllConnections.Axial.LARGE_COG, axis);
|
||||||
|
}
|
||||||
|
|
||||||
|
public ConnectionsBuilder withSmallCog(Direction.Axis axis) {
|
||||||
|
return withAxial(AllConnections.Axial.SMALL_COG, axis);
|
||||||
|
}
|
||||||
|
}
|
|
@ -4,10 +4,10 @@ import net.minecraft.nbt.CompoundTag;
|
||||||
import net.minecraft.world.level.Level;
|
import net.minecraft.world.level.Level;
|
||||||
|
|
||||||
public interface IKineticController {
|
public interface IKineticController {
|
||||||
default void onUpdate(Level level, KineticSolver solver, KineticNode node) { }
|
default void onKineticsTick(Level level, KineticSolver solver, KineticNode node) { }
|
||||||
|
|
||||||
default KineticConnections getConnections() {
|
default KineticConnections getConnections() {
|
||||||
return AllConnections.EMPTY;
|
return KineticConnections.empty();
|
||||||
}
|
}
|
||||||
|
|
||||||
default float getGeneratedSpeed() {
|
default float getGeneratedSpeed() {
|
||||||
|
|
|
@ -0,0 +1,11 @@
|
||||||
|
package com.simibubi.create.content.contraptions.solver;
|
||||||
|
|
||||||
|
import net.minecraft.core.Vec3i;
|
||||||
|
|
||||||
|
import java.util.Map;
|
||||||
|
|
||||||
|
public record KineticConnection(String name) {
|
||||||
|
public Map<Vec3i, Map<KineticConnection, Float>> getRatios() {
|
||||||
|
return KineticConnectionsRegistry.getConnections(this);
|
||||||
|
}
|
||||||
|
}
|
|
@ -1,106 +1,51 @@
|
||||||
package com.simibubi.create.content.contraptions.solver;
|
package com.simibubi.create.content.contraptions.solver;
|
||||||
|
|
||||||
import com.simibubi.create.foundation.utility.NBTHelper;
|
import net.minecraft.core.Direction;
|
||||||
|
|
||||||
import net.minecraft.core.Vec3i;
|
import net.minecraft.core.Vec3i;
|
||||||
import net.minecraft.nbt.CompoundTag;
|
import net.minecraft.nbt.CompoundTag;
|
||||||
import net.minecraft.nbt.ListTag;
|
import net.minecraft.nbt.ListTag;
|
||||||
|
import net.minecraft.nbt.StringTag;
|
||||||
import net.minecraft.nbt.Tag;
|
import net.minecraft.nbt.Tag;
|
||||||
import net.minecraft.util.Mth;
|
|
||||||
|
|
||||||
import javax.annotation.Nullable;
|
|
||||||
|
|
||||||
import java.util.Arrays;
|
|
||||||
import java.util.Collection;
|
|
||||||
import java.util.HashMap;
|
|
||||||
import java.util.HashSet;
|
import java.util.HashSet;
|
||||||
import java.util.Map;
|
|
||||||
import java.util.Objects;
|
import java.util.Objects;
|
||||||
import java.util.Optional;
|
import java.util.Optional;
|
||||||
import java.util.Set;
|
import java.util.Set;
|
||||||
import java.util.stream.Collectors;
|
|
||||||
import java.util.stream.Stream;
|
import java.util.stream.Stream;
|
||||||
|
|
||||||
public class KineticConnections {
|
public class KineticConnections {
|
||||||
|
private final Set<KineticConnection> connections;
|
||||||
|
|
||||||
public static record Entry(Vec3i offset, Value value) {
|
public KineticConnections(Set<KineticConnection> connections) {
|
||||||
public Entry(Vec3i offset, String from, String to, float ratio) {
|
|
||||||
this(offset, new Value(from, to, ratio));
|
|
||||||
}
|
|
||||||
public Entry(Vec3i offset, String from, String to) {
|
|
||||||
this(offset, from, to, 1);
|
|
||||||
}
|
|
||||||
public Entry(Vec3i offset, String from) {
|
|
||||||
this(offset, from, from);
|
|
||||||
}
|
|
||||||
public Entry stressOnly() {
|
|
||||||
return new Entry(offset, new Value(value.from, value.to, 0));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public static record Value(String from, String to, float ratio) {
|
|
||||||
public boolean isStressOnly() {
|
|
||||||
return ratio == 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public boolean equals(Object o) {
|
|
||||||
if (this == o) return true;
|
|
||||||
if (o == null || getClass() != o.getClass()) return false;
|
|
||||||
Value value = (Value) o;
|
|
||||||
return Float.compare(value.ratio, ratio) == 0 && from.equals(value.from) && to.equals(value.to);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public int hashCode() {
|
|
||||||
return Objects.hash(from, to, ratio);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
private final Map<Vec3i, Value> connections;
|
|
||||||
|
|
||||||
private KineticConnections(Map<Vec3i, Value> connections) {
|
|
||||||
this.connections = connections;
|
this.connections = connections;
|
||||||
}
|
}
|
||||||
|
|
||||||
public KineticConnections(Stream<Entry> entries) {
|
public static KineticConnections empty() {
|
||||||
this(entries.collect(Collectors.toMap(Entry::offset, Entry::value)));
|
return new KineticConnections(Set.of());
|
||||||
}
|
}
|
||||||
|
|
||||||
public KineticConnections(Collection<Entry> entries) {
|
public Stream<KineticConnection> stream() {
|
||||||
this(entries.stream());
|
return connections.stream();
|
||||||
}
|
}
|
||||||
|
|
||||||
public KineticConnections(Entry... entries) {
|
public boolean hasStressOnlyConnections() {
|
||||||
this(Arrays.stream(entries));
|
return connections.stream()
|
||||||
|
.flatMap(c -> c.getRatios().values().stream()
|
||||||
|
.flatMap(m -> m.values().stream()))
|
||||||
|
.anyMatch(r -> r == 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
public Set<Vec3i> getDirections() {
|
public float getShaftSpeedModifier(Direction face) {
|
||||||
return connections.keySet();
|
Vec3i offset = face.getNormal();
|
||||||
}
|
|
||||||
|
|
||||||
public Optional<Float> checkConnection(Vec3i offset) {
|
KineticConnection shaft = KineticConnectionsRegistry
|
||||||
Value value = connections.get(offset);
|
.getConnectionType(AllConnections.Shafts.SHAFT.type(face.getOpposite())).get();
|
||||||
if (value == null) return Optional.empty();
|
|
||||||
return Optional.of(value.ratio);
|
|
||||||
}
|
|
||||||
|
|
||||||
private Optional<Float> checkConnection(KineticConnections to, Vec3i offset, boolean stressOnly) {
|
return stream()
|
||||||
Value fromValue = connections.get(offset);
|
.flatMap(c -> Optional.ofNullable(c.getRatios().get(offset))
|
||||||
Value toValue = to.connections.get(offset.multiply(-1));
|
.flatMap(r -> Optional.ofNullable(r.get(shaft)))
|
||||||
if (fromValue == null || toValue == null) return Optional.empty();
|
.stream())
|
||||||
if (!fromValue.from.equals(toValue.to) || !fromValue.to.equals(toValue.from)) return Optional.empty();
|
.findFirst()
|
||||||
if (fromValue.isStressOnly() ^ toValue.isStressOnly()) return Optional.empty();
|
.orElse(0f);
|
||||||
if (fromValue.isStressOnly()) return stressOnly ? Optional.of(0f) : Optional.empty();
|
|
||||||
return Optional.of(fromValue.ratio / toValue.ratio);
|
|
||||||
}
|
|
||||||
|
|
||||||
public Optional<Float> checkConnection(KineticConnections to, Vec3i offset) {
|
|
||||||
return checkConnection(to, offset, false);
|
|
||||||
}
|
|
||||||
|
|
||||||
public boolean checkStressOnlyConnection(KineticConnections to, Vec3i offset) {
|
|
||||||
return checkConnection(to, offset, true).isPresent();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -116,43 +61,20 @@ public class KineticConnections {
|
||||||
return Objects.hash(connections);
|
return Objects.hash(connections);
|
||||||
}
|
}
|
||||||
|
|
||||||
public KineticConnections merge(KineticConnections other) {
|
|
||||||
Map<Vec3i, Value> connectionsNew = new HashMap<>();
|
|
||||||
connectionsNew.putAll(other.connections);
|
|
||||||
connectionsNew.putAll(connections);
|
|
||||||
return new KineticConnections(connectionsNew);
|
|
||||||
}
|
|
||||||
|
|
||||||
public boolean hasStressOnlyConnections() {
|
|
||||||
return connections.values().stream().anyMatch(Value::isStressOnly);
|
|
||||||
}
|
|
||||||
|
|
||||||
public CompoundTag save(CompoundTag tag) {
|
public CompoundTag save(CompoundTag tag) {
|
||||||
ListTag connectionsTags = new ListTag();
|
ListTag connectionsTags = new ListTag();
|
||||||
for (Map.Entry<Vec3i, Value> entry : connections.entrySet()) {
|
for (KineticConnection connection : connections) {
|
||||||
CompoundTag entryTag = new CompoundTag();
|
connectionsTags.add(StringTag.valueOf(connection.name()));
|
||||||
Value v = entry.getValue();
|
|
||||||
entryTag.put("Off", NBTHelper.writeVec3i(entry.getKey()));
|
|
||||||
entryTag.putString("From", v.from());
|
|
||||||
if (!v.to().equals(v.from()))
|
|
||||||
entryTag.putString("To", v.to());
|
|
||||||
if (v.ratio() != 1)
|
|
||||||
entryTag.putFloat("Ratio", v.ratio());
|
|
||||||
connectionsTags.add(entryTag);
|
|
||||||
}
|
}
|
||||||
tag.put("Connections", connectionsTags);
|
tag.put("Connections", connectionsTags);
|
||||||
return tag;
|
return tag;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static KineticConnections load(CompoundTag tag) {
|
public static KineticConnections load(CompoundTag tag) {
|
||||||
Map<Vec3i, Value> connections = new HashMap<>();
|
Set<KineticConnection> connections = new HashSet<>();
|
||||||
tag.getList("Connections", Tag.TAG_COMPOUND).forEach(c -> {
|
tag.getList("Connections", Tag.TAG_STRING).forEach(t -> {
|
||||||
CompoundTag comp = (CompoundTag) c;
|
KineticConnectionsRegistry.getConnectionType(t.getAsString())
|
||||||
Vec3i offset = NBTHelper.readVec3i(comp.getList("Off", Tag.TAG_INT));
|
.ifPresent(connections::add);
|
||||||
String from = comp.getString("From");
|
|
||||||
String to = comp.contains("To") ? comp.getString("To") : from;
|
|
||||||
float ratio = comp.contains("Ratio") ? comp.getFloat("Ratio") : 1;
|
|
||||||
connections.put(offset, new Value(from, to, ratio));
|
|
||||||
});
|
});
|
||||||
return new KineticConnections(connections);
|
return new KineticConnections(connections);
|
||||||
}
|
}
|
||||||
|
|
|
@ -0,0 +1,46 @@
|
||||||
|
package com.simibubi.create.content.contraptions.solver;
|
||||||
|
|
||||||
|
import net.minecraft.core.Vec3i;
|
||||||
|
|
||||||
|
import java.util.Collections;
|
||||||
|
import java.util.HashMap;
|
||||||
|
import java.util.Map;
|
||||||
|
import java.util.Optional;
|
||||||
|
|
||||||
|
public class KineticConnectionsRegistry {
|
||||||
|
private static final Map<String, KineticConnection> connectionTypes = new HashMap<>();
|
||||||
|
private static final Map<KineticConnection, Map<Vec3i, Map<KineticConnection, Float>>> connectionRatios
|
||||||
|
= new HashMap<>();
|
||||||
|
|
||||||
|
public static KineticConnection registerConnectionType(String name) {
|
||||||
|
if (connectionTypes.containsKey(name))
|
||||||
|
throw new IllegalStateException("connection type named \"" + name + "\" already exists");
|
||||||
|
KineticConnection connection = new KineticConnection(name);
|
||||||
|
connectionTypes.put(name, connection);
|
||||||
|
return connection;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static Optional<KineticConnection> getConnectionType(String name) {
|
||||||
|
return Optional.ofNullable(connectionTypes.get(name));
|
||||||
|
}
|
||||||
|
|
||||||
|
public static void registerConnectionRatio(KineticConnection from, KineticConnection to, Vec3i offset, float ratio) {
|
||||||
|
Map<KineticConnection, Float> fromMap = connectionRatios
|
||||||
|
.computeIfAbsent(from, $ -> new HashMap<>())
|
||||||
|
.computeIfAbsent(offset, $ -> new HashMap<>());
|
||||||
|
if (fromMap.containsKey(to)) return;
|
||||||
|
|
||||||
|
Map<KineticConnection, Float> toMap = connectionRatios
|
||||||
|
.computeIfAbsent(to, $ -> new HashMap<>())
|
||||||
|
.computeIfAbsent(offset.multiply(-1), $ -> new HashMap<>());
|
||||||
|
|
||||||
|
fromMap.put(to, ratio);
|
||||||
|
toMap.put(from, ratio == 0 ? 0 : 1/ratio);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static Map<Vec3i, Map<KineticConnection, Float>> getConnections(KineticConnection from) {
|
||||||
|
return Optional.ofNullable(connectionRatios.get(from))
|
||||||
|
.map(Collections::unmodifiableMap)
|
||||||
|
.orElseGet(Map::of);
|
||||||
|
}
|
||||||
|
}
|
|
@ -27,10 +27,14 @@ public enum KineticControllerSerial {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onUpdate(Level level, KineticSolver solver, KineticNode node) {
|
public void onKineticsTick(Level level, KineticSolver solver, KineticNode node) {
|
||||||
BlockPos below = node.getPos().below();
|
BlockPos below = node.getPos().below();
|
||||||
if (level.getBlockEntity(below) instanceof SpeedControllerTileEntity se) {
|
if (level.getBlockEntity(below) instanceof SpeedControllerTileEntity se) {
|
||||||
targetSpeed = se.getTargetSpeed();
|
targetSpeed = se.getTargetSpeed();
|
||||||
|
} else if (generatedSpeed != 0) {
|
||||||
|
generatedSpeed = 0;
|
||||||
|
} else {
|
||||||
|
node.removeController();
|
||||||
}
|
}
|
||||||
|
|
||||||
Optional<KineticNode> seNode = solver.getNode(below);
|
Optional<KineticNode> seNode = solver.getNode(below);
|
||||||
|
|
|
@ -1,5 +1,6 @@
|
||||||
package com.simibubi.create.content.contraptions.solver;
|
package com.simibubi.create.content.contraptions.solver;
|
||||||
|
|
||||||
|
import com.simibubi.create.content.contraptions.base.IRotate;
|
||||||
import com.simibubi.create.foundation.config.AllConfigs;
|
import com.simibubi.create.foundation.config.AllConfigs;
|
||||||
import com.simibubi.create.foundation.utility.Pair;
|
import com.simibubi.create.foundation.utility.Pair;
|
||||||
|
|
||||||
|
@ -18,6 +19,9 @@ import java.util.stream.Collectors;
|
||||||
|
|
||||||
public class KineticNetwork {
|
public class KineticNetwork {
|
||||||
|
|
||||||
|
private static long nextID = 1L;
|
||||||
|
public final long id;
|
||||||
|
|
||||||
private final Set<KineticNode> members = new HashSet<>();
|
private final Set<KineticNode> members = new HashSet<>();
|
||||||
private final Set<KineticNode> generators = new HashSet<>();
|
private final Set<KineticNode> generators = new HashSet<>();
|
||||||
private final Set<Pair<KineticNode, KineticNode>> conflictingCycles = new HashSet<>();
|
private final Set<Pair<KineticNode, KineticNode>> conflictingCycles = new HashSet<>();
|
||||||
|
@ -36,10 +40,14 @@ public class KineticNetwork {
|
||||||
private final ResetableLazy<Float> totalStressCapacity = ResetableLazy.of(() ->
|
private final ResetableLazy<Float> totalStressCapacity = ResetableLazy.of(() ->
|
||||||
(float) members.stream().mapToDouble(KineticNode::getStressCapacity).sum());
|
(float) members.stream().mapToDouble(KineticNode::getStressCapacity).sum());
|
||||||
|
|
||||||
|
private float latestSupernetworkStressImpact;
|
||||||
|
private float latestSupernetworkStressCapacity;
|
||||||
|
|
||||||
private boolean ticked;
|
private boolean ticked;
|
||||||
private final Set<KineticNode> stressConnectors = new HashSet<>();
|
private final Set<KineticNode> stressConnectors = new HashSet<>();
|
||||||
|
|
||||||
protected KineticNetwork(KineticNode root) {
|
protected KineticNetwork(KineticNode root) {
|
||||||
|
id = nextID++;
|
||||||
addMember(root);
|
addMember(root);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -150,11 +158,11 @@ public class KineticNetwork {
|
||||||
}
|
}
|
||||||
|
|
||||||
public float getTotalStressImpact() {
|
public float getTotalStressImpact() {
|
||||||
return totalStressImpact.get();
|
return latestSupernetworkStressImpact;
|
||||||
}
|
}
|
||||||
|
|
||||||
public float getTotalStressCapacity() {
|
public float getTotalStressCapacity() {
|
||||||
return totalStressCapacity.get();
|
return latestSupernetworkStressCapacity;
|
||||||
}
|
}
|
||||||
|
|
||||||
public float getRootTheoreticalSpeed() {
|
public float getRootTheoreticalSpeed() {
|
||||||
|
@ -191,11 +199,16 @@ public class KineticNetwork {
|
||||||
for (KineticNetwork cur : stressConnected) {
|
for (KineticNetwork cur : stressConnected) {
|
||||||
cur.ticked = true;
|
cur.ticked = true;
|
||||||
cur.checkForSpeedingNodes(popQueue::add);
|
cur.checkForSpeedingNodes(popQueue::add);
|
||||||
stressImpact += cur.getTotalStressImpact();
|
stressImpact += cur.totalStressImpact.get();
|
||||||
stressCapacity += cur.getTotalStressCapacity();
|
stressCapacity += cur.totalStressCapacity.get();
|
||||||
}
|
}
|
||||||
|
|
||||||
boolean nowOverstressed = stressImpact > stressCapacity;
|
for (KineticNetwork cur : stressConnected) {
|
||||||
|
cur.latestSupernetworkStressImpact = stressImpact;
|
||||||
|
cur.latestSupernetworkStressCapacity = stressCapacity;
|
||||||
|
}
|
||||||
|
|
||||||
|
boolean nowOverstressed = stressImpact > stressCapacity && IRotate.StressImpact.isEnabled();
|
||||||
if (!nowOverstressed) {
|
if (!nowOverstressed) {
|
||||||
// we should only pop speeding nodes if the network isn't actually overstressed now
|
// we should only pop speeding nodes if the network isn't actually overstressed now
|
||||||
popQueue.forEach(pop);
|
popQueue.forEach(pop);
|
||||||
|
|
|
@ -5,16 +5,18 @@ import com.simibubi.create.foundation.utility.NBTHelper;
|
||||||
import com.simibubi.create.foundation.utility.Pair;
|
import com.simibubi.create.foundation.utility.Pair;
|
||||||
|
|
||||||
import net.minecraft.core.BlockPos;
|
import net.minecraft.core.BlockPos;
|
||||||
|
import net.minecraft.core.Vec3i;
|
||||||
import net.minecraft.nbt.CompoundTag;
|
import net.minecraft.nbt.CompoundTag;
|
||||||
import net.minecraft.nbt.NbtUtils;
|
import net.minecraft.nbt.NbtUtils;
|
||||||
import net.minecraft.util.Mth;
|
import net.minecraft.util.Mth;
|
||||||
import net.minecraft.world.level.block.Block;
|
|
||||||
|
|
||||||
import javax.annotation.Nullable;
|
import javax.annotation.Nullable;
|
||||||
|
|
||||||
import java.util.HashSet;
|
import java.util.HashSet;
|
||||||
import java.util.LinkedList;
|
import java.util.LinkedList;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
import java.util.Map;
|
||||||
|
import java.util.Objects;
|
||||||
import java.util.Optional;
|
import java.util.Optional;
|
||||||
import java.util.Set;
|
import java.util.Set;
|
||||||
import java.util.stream.Collectors;
|
import java.util.stream.Collectors;
|
||||||
|
@ -28,7 +30,6 @@ public class KineticNode {
|
||||||
|
|
||||||
private @Nullable IKineticController controller;
|
private @Nullable IKineticController controller;
|
||||||
private @Nullable KineticControllerSerial controllerType;
|
private @Nullable KineticControllerSerial controllerType;
|
||||||
private @Nullable Set<BlockPos> controlling;
|
|
||||||
|
|
||||||
private @Nullable KineticNode parent;
|
private @Nullable KineticNode parent;
|
||||||
private @Nullable BlockPos speedSource;
|
private @Nullable BlockPos speedSource;
|
||||||
|
@ -83,12 +84,15 @@ public class KineticNode {
|
||||||
}
|
}
|
||||||
|
|
||||||
tag.put("Connections", connections.save(new CompoundTag()));
|
tag.put("Connections", connections.save(new CompoundTag()));
|
||||||
tag.putFloat("Generated", generatedSpeed);
|
if (generatedSpeed != 0)
|
||||||
tag.putFloat("Capacity", stressCapacity);
|
tag.putFloat("Generated", generatedSpeed);
|
||||||
tag.putFloat("Impact", stressImpact);
|
if (stressCapacity != 0)
|
||||||
if (constantStress) {
|
tag.putFloat("Capacity", stressCapacity);
|
||||||
|
if (stressImpact != 0)
|
||||||
|
tag.putFloat("Impact", stressImpact);
|
||||||
|
if (constantStress)
|
||||||
tag.putBoolean("ConstantStress", true);
|
tag.putBoolean("ConstantStress", true);
|
||||||
}
|
|
||||||
return tag;
|
return tag;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -127,13 +131,10 @@ public class KineticNode {
|
||||||
return Optional.empty();
|
return Optional.empty();
|
||||||
}
|
}
|
||||||
|
|
||||||
public boolean setController(KineticNode source, KineticControllerSerial controller) {
|
public boolean setController(KineticControllerSerial controller) {
|
||||||
if (this.controller != null) return false;
|
if (this.controller != null) return false;
|
||||||
this.controller = controller.init(this);
|
this.controller = controller.init(this);
|
||||||
this.controllerType = controller;
|
this.controllerType = controller;
|
||||||
if (source.controlling == null)
|
|
||||||
source.controlling = new HashSet<>();
|
|
||||||
source.controlling.add(pos);
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -158,24 +159,38 @@ public class KineticNode {
|
||||||
* @return a Stream containing a pair for each compatible connection with this node, where the first value is
|
* @return a Stream containing a pair for each compatible connection with this node, where the first value is
|
||||||
* the connecting node and the second value is the speed ratio of the connection
|
* the connecting node and the second value is the speed ratio of the connection
|
||||||
*/
|
*/
|
||||||
public Stream<Pair<KineticNode, Float>> getActiveConnections() {
|
private Stream<Pair<KineticNode, Float>> getAllActiveConnections() {
|
||||||
return connections.getDirections().stream()
|
return connections.stream()
|
||||||
.map(d -> solver.getNode(pos.offset(d))
|
.flatMap(from -> from.getRatios().entrySet().stream()
|
||||||
.map(n -> connections.checkConnection(n.connections, d)
|
.map(e -> {
|
||||||
.map(r -> Pair.of(n, r))))
|
Vec3i offset = e.getKey();
|
||||||
.flatMap(Optional::stream)
|
return solver.getNode(pos.offset(offset)).flatMap(node -> {
|
||||||
|
Map<KineticConnection, Float> ratios = e.getValue();
|
||||||
|
return node.getConnections().stream()
|
||||||
|
.map(ratios::get)
|
||||||
|
.filter(Objects::nonNull)
|
||||||
|
.findFirst()
|
||||||
|
.map(r -> Pair.of(node, r));
|
||||||
|
});
|
||||||
|
})
|
||||||
|
)
|
||||||
.flatMap(Optional::stream);
|
.flatMap(Optional::stream);
|
||||||
}
|
}
|
||||||
|
|
||||||
public Iterable<Pair<KineticNode, Float>> getActiveConnectionsList() {
|
public Stream<Pair<KineticNode, Float>> getActiveConnections() {
|
||||||
return getActiveConnections().collect(Collectors.toList());
|
return getAllActiveConnections().filter(p -> p.getSecond() != 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
public Stream<KineticNode> getActiveStressOnlyConnections() {
|
public Stream<KineticNode> getActiveStressOnlyConnections() {
|
||||||
return connections.getDirections().stream()
|
return getAllActiveConnections().filter(p -> p.getSecond() == 0).map(Pair::getFirst);
|
||||||
.map(d -> solver.getNode(pos.offset(d))
|
}
|
||||||
.filter(n -> connections.checkStressOnlyConnection(n.connections, d)))
|
|
||||||
.flatMap(Optional::stream);
|
public Optional<Float> checkConnection(KineticNode to) {
|
||||||
|
return getActiveConnections().filter(p -> p.getFirst() == to).findAny().map(Pair::getSecond);
|
||||||
|
}
|
||||||
|
|
||||||
|
public boolean checkStressOnlyConnection(KineticNode to) {
|
||||||
|
return getActiveStressOnlyConnections().anyMatch(n -> n == to);
|
||||||
}
|
}
|
||||||
|
|
||||||
public float getGeneratedSpeed() {
|
public float getGeneratedSpeed() {
|
||||||
|
@ -298,7 +313,7 @@ public class KineticNode {
|
||||||
|
|
||||||
while (!frontier.isEmpty()) {
|
while (!frontier.isEmpty()) {
|
||||||
KineticNode cur = frontier.remove(0);
|
KineticNode cur = frontier.remove(0);
|
||||||
for (Pair<KineticNode, Float> pair : cur.getActiveConnectionsList()) {
|
for (Pair<KineticNode, Float> pair : cur.getActiveConnections().collect(Collectors.toList())) {
|
||||||
KineticNode next = pair.getFirst();
|
KineticNode next = pair.getFirst();
|
||||||
float ratio = pair.getSecond();
|
float ratio = pair.getSecond();
|
||||||
|
|
||||||
|
@ -334,12 +349,6 @@ public class KineticNode {
|
||||||
.map(Pair::getFirst)
|
.map(Pair::getFirst)
|
||||||
.filter(n -> n.parent == this)
|
.filter(n -> n.parent == this)
|
||||||
.forEach(KineticNode::rerootHere);
|
.forEach(KineticNode::rerootHere);
|
||||||
if (controlling != null) {
|
|
||||||
controlling.stream()
|
|
||||||
.map(solver::getNode)
|
|
||||||
.flatMap(Optional::stream)
|
|
||||||
.forEach(KineticNode::removeController);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private void rerootHere() {
|
private void rerootHere() {
|
||||||
|
@ -361,7 +370,7 @@ public class KineticNode {
|
||||||
|
|
||||||
protected void flushChanges() {
|
protected void flushChanges() {
|
||||||
if (entity != null) {
|
if (entity != null) {
|
||||||
entity.updateFromSolver(getTheoreticalSpeed(), getSpeedSource(), getConnections(),
|
entity.updateFromSolver(getTheoreticalSpeed(), getSpeedSource(), network.id,
|
||||||
network.isOverstressed(), network.getTotalStressImpact(), network.getTotalStressCapacity());
|
network.isOverstressed(), network.getTotalStressImpact(), network.getTotalStressCapacity());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -7,25 +7,19 @@ import java.util.List;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
import java.util.Optional;
|
import java.util.Optional;
|
||||||
import java.util.Set;
|
import java.util.Set;
|
||||||
import java.util.stream.Collectors;
|
|
||||||
|
|
||||||
import com.simibubi.create.content.contraptions.base.KineticTileEntity;
|
import com.simibubi.create.content.contraptions.base.KineticTileEntity;
|
||||||
import com.simibubi.create.foundation.utility.Pair;
|
|
||||||
import com.simibubi.create.foundation.utility.WorldAttached;
|
import com.simibubi.create.foundation.utility.WorldAttached;
|
||||||
|
|
||||||
import net.minecraft.core.BlockPos;
|
import net.minecraft.core.BlockPos;
|
||||||
import net.minecraft.core.Vec3i;
|
|
||||||
import net.minecraft.nbt.CompoundTag;
|
import net.minecraft.nbt.CompoundTag;
|
||||||
import net.minecraft.nbt.ListTag;
|
import net.minecraft.nbt.ListTag;
|
||||||
import net.minecraft.nbt.NbtUtils;
|
import net.minecraft.nbt.NbtUtils;
|
||||||
import net.minecraft.nbt.Tag;
|
import net.minecraft.nbt.Tag;
|
||||||
import net.minecraft.server.level.ServerLevel;
|
import net.minecraft.server.level.ServerLevel;
|
||||||
import net.minecraft.world.level.Level;
|
import net.minecraft.world.level.Level;
|
||||||
import net.minecraft.world.level.LevelAccessor;
|
|
||||||
import net.minecraft.world.level.block.Block;
|
|
||||||
import net.minecraft.world.level.saveddata.SavedData;
|
import net.minecraft.world.level.saveddata.SavedData;
|
||||||
|
|
||||||
import org.checkerframework.checker.units.qual.C;
|
|
||||||
import org.jetbrains.annotations.NotNull;
|
import org.jetbrains.annotations.NotNull;
|
||||||
|
|
||||||
public class KineticSolver extends SavedData {
|
public class KineticSolver extends SavedData {
|
||||||
|
@ -162,7 +156,7 @@ public class KineticSolver extends SavedData {
|
||||||
Set<KineticNode> popQueue = new HashSet<>();
|
Set<KineticNode> popQueue = new HashSet<>();
|
||||||
Set<KineticNode> regenQueue = new HashSet<>();
|
Set<KineticNode> regenQueue = new HashSet<>();
|
||||||
for (KineticNode node : nodes.values()) {
|
for (KineticNode node : nodes.values()) {
|
||||||
node.getController().ifPresent(c -> c.onUpdate(level, this, node));
|
node.getController().ifPresent(c -> c.onKineticsTick(level, this, node));
|
||||||
switch (node.onUpdated()) {
|
switch (node.onUpdated()) {
|
||||||
case NEEDS_POP -> popQueue.add(node);
|
case NEEDS_POP -> popQueue.add(node);
|
||||||
case NEEDS_REGEN -> regenQueue.add(node);
|
case NEEDS_REGEN -> regenQueue.add(node);
|
||||||
|
@ -188,19 +182,4 @@ public class KineticSolver extends SavedData {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public Optional<Float> isConnected(BlockPos from, BlockPos to) {
|
|
||||||
return getNode(from).flatMap(fromNode ->
|
|
||||||
getNode(to).flatMap(toNode ->
|
|
||||||
fromNode.getConnections()
|
|
||||||
.checkConnection(toNode.getConnections(), to.subtract(from))));
|
|
||||||
}
|
|
||||||
|
|
||||||
public boolean isStressOnlyConnected(BlockPos from, BlockPos to) {
|
|
||||||
return getNode(from).flatMap(fromNode ->
|
|
||||||
getNode(to).map(toNode ->
|
|
||||||
fromNode.getConnections()
|
|
||||||
.checkStressOnlyConnection(toNode.getConnections(), to.subtract(from)))
|
|
||||||
).orElse(false);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -4,7 +4,6 @@ import com.simibubi.create.AllSoundEvents;
|
||||||
import com.simibubi.create.Create;
|
import com.simibubi.create.Create;
|
||||||
import com.simibubi.create.content.contraptions.base.DirectionalAxisKineticBlock;
|
import com.simibubi.create.content.contraptions.base.DirectionalAxisKineticBlock;
|
||||||
import com.simibubi.create.content.contraptions.base.DirectionalKineticBlock;
|
import com.simibubi.create.content.contraptions.base.DirectionalKineticBlock;
|
||||||
import com.simibubi.create.content.contraptions.base.GeneratingKineticTileEntity;
|
|
||||||
import com.simibubi.create.content.contraptions.base.HorizontalAxisKineticBlock;
|
import com.simibubi.create.content.contraptions.base.HorizontalAxisKineticBlock;
|
||||||
import com.simibubi.create.content.contraptions.base.HorizontalKineticBlock;
|
import com.simibubi.create.content.contraptions.base.HorizontalKineticBlock;
|
||||||
import com.simibubi.create.content.contraptions.base.KineticTileEntity;
|
import com.simibubi.create.content.contraptions.base.KineticTileEntity;
|
||||||
|
@ -34,12 +33,6 @@ public interface IWrenchable {
|
||||||
|
|
||||||
KineticTileEntity.switchToBlockState(world, context.getClickedPos(), updateAfterWrenched(rotated, context));
|
KineticTileEntity.switchToBlockState(world, context.getClickedPos(), updateAfterWrenched(rotated, context));
|
||||||
|
|
||||||
BlockEntity te = context.getLevel()
|
|
||||||
.getBlockEntity(context.getClickedPos());
|
|
||||||
if (te instanceof GeneratingKineticTileEntity) {
|
|
||||||
((GeneratingKineticTileEntity) te).reActivateSource = true;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (world.getBlockState(context.getClickedPos()) != state)
|
if (world.getBlockState(context.getClickedPos()) != state)
|
||||||
playRotateSound(world, context.getClickedPos());
|
playRotateSound(world, context.getClickedPos());
|
||||||
|
|
||||||
|
|
|
@ -29,7 +29,6 @@ import net.minecraft.world.item.enchantment.EnchantmentHelper;
|
||||||
import net.minecraft.world.level.BlockGetter;
|
import net.minecraft.world.level.BlockGetter;
|
||||||
import net.minecraft.world.level.Level;
|
import net.minecraft.world.level.Level;
|
||||||
import net.minecraft.world.level.LevelAccessor;
|
import net.minecraft.world.level.LevelAccessor;
|
||||||
import net.minecraft.world.level.LevelReader;
|
|
||||||
import net.minecraft.world.level.block.Block;
|
import net.minecraft.world.level.block.Block;
|
||||||
import net.minecraft.world.level.block.SimpleWaterloggedBlock;
|
import net.minecraft.world.level.block.SimpleWaterloggedBlock;
|
||||||
import net.minecraft.world.level.block.entity.BlockEntityType;
|
import net.minecraft.world.level.block.entity.BlockEntityType;
|
||||||
|
@ -92,7 +91,7 @@ public class CopperBacktankBlock extends HorizontalKineticBlock
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean hasShaftTowards(LevelReader world, BlockPos pos, BlockState state, Direction face) {
|
public boolean hasShaftTowards(BlockState state, Direction face) {
|
||||||
return face == Direction.UP;
|
return face == Direction.UP;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -139,7 +139,7 @@ public class EjectorBlock extends HorizontalKineticBlock implements ITE<EjectorT
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean hasShaftTowards(LevelReader world, BlockPos pos, BlockState state, Direction face) {
|
public boolean hasShaftTowards(BlockState state, Direction face) {
|
||||||
return getRotationAxis(state) == face.getAxis();
|
return getRotationAxis(state) == face.getAxis();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -19,60 +19,46 @@ public class DirectionHelper {
|
||||||
|
|
||||||
public static Direction rotateAround(Direction dir, Direction.Axis axis) {
|
public static Direction rotateAround(Direction dir, Direction.Axis axis) {
|
||||||
switch (axis) {
|
switch (axis) {
|
||||||
case X:
|
case X -> {
|
||||||
if (dir != WEST && dir != EAST) {
|
if (dir != WEST && dir != EAST) {
|
||||||
return rotateX(dir);
|
return rotateX(dir);
|
||||||
|
}
|
||||||
|
return dir;
|
||||||
}
|
}
|
||||||
|
case Y -> {
|
||||||
return dir;
|
if (dir != UP && dir != DOWN) {
|
||||||
case Y:
|
return dir.getClockWise();
|
||||||
if (dir != UP && dir != DOWN) {
|
}
|
||||||
return dir.getClockWise();
|
return dir;
|
||||||
}
|
}
|
||||||
|
case Z -> {
|
||||||
return dir;
|
if (dir != NORTH && dir != SOUTH) {
|
||||||
case Z:
|
return rotateZ(dir);
|
||||||
if (dir != NORTH && dir != SOUTH) {
|
}
|
||||||
return rotateZ(dir);
|
return dir;
|
||||||
}
|
}
|
||||||
|
default -> throw new IllegalStateException("Unable to get CW facing for axis " + axis);
|
||||||
return dir;
|
|
||||||
default:
|
|
||||||
throw new IllegalStateException("Unable to get CW facing for axis " + axis);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public static Direction rotateX(Direction dir) {
|
public static Direction rotateX(Direction dir) {
|
||||||
switch (dir) {
|
return switch (dir) {
|
||||||
case NORTH:
|
case NORTH -> DOWN;
|
||||||
return DOWN;
|
case SOUTH -> UP;
|
||||||
case EAST:
|
case UP -> NORTH;
|
||||||
case WEST:
|
case DOWN -> SOUTH;
|
||||||
default:
|
default -> throw new IllegalStateException("Unable to get X-rotated facing of " + dir);
|
||||||
throw new IllegalStateException("Unable to get X-rotated facing of " + dir);
|
};
|
||||||
case SOUTH:
|
|
||||||
return UP;
|
|
||||||
case UP:
|
|
||||||
return NORTH;
|
|
||||||
case DOWN:
|
|
||||||
return SOUTH;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public static Direction rotateZ(Direction dir) {
|
public static Direction rotateZ(Direction dir) {
|
||||||
switch (dir) {
|
return switch (dir) {
|
||||||
case EAST:
|
case EAST -> DOWN;
|
||||||
return DOWN;
|
case WEST -> UP;
|
||||||
case SOUTH:
|
case UP -> EAST;
|
||||||
default:
|
case DOWN -> WEST;
|
||||||
throw new IllegalStateException("Unable to get Z-rotated facing of " + dir);
|
default -> throw new IllegalStateException("Unable to get Z-rotated facing of " + dir);
|
||||||
case WEST:
|
};
|
||||||
return UP;
|
|
||||||
case UP:
|
|
||||||
return EAST;
|
|
||||||
case DOWN:
|
|
||||||
return WEST;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public static Direction getPositivePerpendicular(Axis horizontalAxis) {
|
public static Direction getPositivePerpendicular(Axis horizontalAxis) {
|
||||||
|
|
|
@ -27,15 +27,19 @@ public class Iterate {
|
||||||
}
|
}
|
||||||
|
|
||||||
public static Direction[] directionsInAxis(Axis axis) {
|
public static Direction[] directionsInAxis(Axis axis) {
|
||||||
switch (axis) {
|
return switch (axis) {
|
||||||
case X:
|
case X -> new Direction[]{Direction.EAST, Direction.WEST};
|
||||||
return new Direction[] { Direction.EAST, Direction.WEST };
|
case Y -> new Direction[]{Direction.UP, Direction.DOWN};
|
||||||
case Y:
|
case Z -> new Direction[]{Direction.SOUTH, Direction.NORTH};
|
||||||
return new Direction[] { Direction.UP, Direction.DOWN };
|
};
|
||||||
default:
|
}
|
||||||
case Z:
|
|
||||||
return new Direction[] { Direction.SOUTH, Direction.NORTH };
|
public static Direction[] directionsPerpendicularTo(Axis axis) {
|
||||||
}
|
return switch (axis) {
|
||||||
|
case X -> new Direction[]{Direction.SOUTH, Direction.DOWN, Direction.NORTH, Direction.UP};
|
||||||
|
case Y -> new Direction[]{Direction.EAST, Direction.SOUTH, Direction.WEST, Direction.NORTH};
|
||||||
|
case Z -> new Direction[]{Direction.EAST, Direction.UP, Direction.WEST, Direction.DOWN};
|
||||||
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
public static List<BlockPos> hereAndBelow(BlockPos pos) {
|
public static List<BlockPos> hereAndBelow(BlockPos pos) {
|
||||||
|
|
Loading…
Reference in a new issue