mirror of
https://github.com/Creators-of-Create/Create.git
synced 2024-12-15 00:23:42 +01:00
Lag science
- Trains now try to wait for chunks to load in when player passengers are present - Trains now sync clientside speed with the servers' tps to avoid overcorrection - Hoppers can now be picked up by the wrench
This commit is contained in:
parent
6ed8d31af0
commit
3e89d9a878
6 changed files with 60 additions and 19 deletions
|
@ -5636,7 +5636,7 @@ d063e12c9ef75f39518c6d129ea35d833464d547 data/create/tags/blocks/toolboxes.json
|
|||
50936b211d94167a35ec78c89954082a336b6269 data/create/tags/blocks/valve_handles.json
|
||||
eac71740fb12bdb38b5dfaa2268613d7ba82b809 data/create/tags/blocks/windmill_sails.json
|
||||
74700d556ca80c7a1db5fd4efb09c3ddb26cad66 data/create/tags/blocks/windowable.json
|
||||
893a01e6004d6d8272bd1658e98da88bb572ee57 data/create/tags/blocks/wrench_pickup.json
|
||||
c71f8ee0103d0c1b0d1b0727f1ecdc4d1999f1f6 data/create/tags/blocks/wrench_pickup.json
|
||||
a8bdc387cfa6296ebcc4af14323e2ddb632234dc data/create/tags/fluids/bottomless/allow.json
|
||||
74700d556ca80c7a1db5fd4efb09c3ddb26cad66 data/create/tags/fluids/bottomless/deny.json
|
||||
74700d556ca80c7a1db5fd4efb09c3ddb26cad66 data/create/tags/items/blaze_burner_fuel/regular.json
|
||||
|
|
|
@ -16,6 +16,7 @@
|
|||
"minecraft:tripwire",
|
||||
"minecraft:tripwire_hook",
|
||||
"minecraft:daylight_detector",
|
||||
"minecraft:target"
|
||||
"minecraft:target",
|
||||
"minecraft:hopper"
|
||||
]
|
||||
}
|
|
@ -412,7 +412,7 @@ public class AllTags {
|
|||
AllBlockTags.WRENCH_PICKUP.includeAll(BlockTags.PRESSURE_PLATES);
|
||||
AllBlockTags.WRENCH_PICKUP.add(Blocks.REDSTONE_WIRE, Blocks.REDSTONE_TORCH, Blocks.REPEATER, Blocks.LEVER,
|
||||
Blocks.COMPARATOR, Blocks.OBSERVER, Blocks.REDSTONE_WALL_TORCH, Blocks.PISTON, Blocks.STICKY_PISTON,
|
||||
Blocks.TRIPWIRE, Blocks.TRIPWIRE_HOOK, Blocks.DAYLIGHT_DETECTOR, Blocks.TARGET);
|
||||
Blocks.TRIPWIRE, Blocks.TRIPWIRE_HOOK, Blocks.DAYLIGHT_DETECTOR, Blocks.TARGET, Blocks.HOPPER);
|
||||
|
||||
AllBlockTags.ORE_OVERRIDE_STONE.includeAll(BlockTags.STONE_ORE_REPLACEABLES);
|
||||
|
||||
|
|
|
@ -118,9 +118,14 @@ public class Carriage {
|
|||
return entities.get(dimension);
|
||||
}
|
||||
|
||||
public double travel(Level level, TrackGraph graph, double distance,
|
||||
Function<TravellingPoint, ITrackSelector> forwardControl,
|
||||
Function<TravellingPoint, ITrackSelector> backwardControl, int type) {
|
||||
public double travel(Level level, TrackGraph graph, double distance, TravellingPoint toFollowForward,
|
||||
TravellingPoint toFollowBackward, int type) {
|
||||
|
||||
Function<TravellingPoint, ITrackSelector> forwardControl =
|
||||
toFollowForward == null ? train.navigation::control : mp -> mp.follow(toFollowForward);
|
||||
Function<TravellingPoint, ITrackSelector> backwardControl =
|
||||
toFollowBackward == null ? train.navigation::control : mp -> mp.follow(toFollowBackward);
|
||||
|
||||
boolean onTwoBogeys = isOnTwoBogeys();
|
||||
double stress = train.derailed ? 0 : onTwoBogeys ? bogeySpacing - getAnchorDiff() : 0;
|
||||
blocked = false;
|
||||
|
@ -825,13 +830,38 @@ public class Carriage {
|
|||
double diffY = positionVec.y - coupledVec.y;
|
||||
double diffZ = positionVec.z - coupledVec.z;
|
||||
|
||||
if (!entity.level.isClientSide())
|
||||
entity.setServerSidePrevPosition();
|
||||
|
||||
entity.setPos(positionAnchor);
|
||||
entity.prevYaw = entity.yaw;
|
||||
entity.prevPitch = entity.pitch;
|
||||
|
||||
if (!entity.level.isClientSide()) {
|
||||
Vec3 lookahead = positionAnchor.add(positionAnchor.subtract(entity.position())
|
||||
.normalize()
|
||||
.scale(16));
|
||||
|
||||
for (Entity e : entity.getPassengers()) {
|
||||
if (!(e instanceof Player))
|
||||
continue;
|
||||
if (e.distanceToSqr(entity) > 32 * 32)
|
||||
continue;
|
||||
if (CarriageEntityHandler.isActiveChunk(entity.level, new BlockPos(lookahead)))
|
||||
break;
|
||||
train.carriageWaitingForChunks = id;
|
||||
return;
|
||||
}
|
||||
|
||||
if (entity.getPassengers()
|
||||
.stream()
|
||||
.anyMatch(p -> p instanceof Player)
|
||||
) {
|
||||
}
|
||||
|
||||
if (train.carriageWaitingForChunks == id)
|
||||
train.carriageWaitingForChunks = -1;
|
||||
|
||||
entity.setServerSidePrevPosition();
|
||||
}
|
||||
|
||||
entity.setPos(positionAnchor);
|
||||
entity.yaw = (float) (Mth.atan2(diffZ, diffX) * 180 / Math.PI) + 180;
|
||||
entity.pitch = (float) (Math.atan2(diffY, Math.sqrt(diffX * diffX + diffZ * diffZ)) * 180 / Math.PI) * -1;
|
||||
|
||||
|
|
|
@ -21,6 +21,7 @@ import com.simibubi.create.content.logistics.trains.entity.TravellingPoint.ITrac
|
|||
import com.simibubi.create.foundation.utility.Couple;
|
||||
import com.simibubi.create.foundation.utility.Iterate;
|
||||
import com.simibubi.create.foundation.utility.Pair;
|
||||
import com.simibubi.create.foundation.utility.ServerSpeedProvider;
|
||||
import com.simibubi.create.foundation.utility.VecHelper;
|
||||
|
||||
import net.minecraft.network.FriendlyByteBuf;
|
||||
|
@ -39,6 +40,7 @@ public class CarriageSyncData {
|
|||
private TravellingPoint[] pointsToApproach;
|
||||
private float[] pointDistanceSnapshot;
|
||||
private float destinationDistanceSnapshot;
|
||||
private int ticksSince;
|
||||
|
||||
public CarriageSyncData() {
|
||||
wheelLocations = new Vector<>(4);
|
||||
|
@ -48,6 +50,7 @@ public class CarriageSyncData {
|
|||
fallbackPointSnapshot = null;
|
||||
destinationDistanceSnapshot = 0;
|
||||
leadingCarriage = false;
|
||||
ticksSince = 0;
|
||||
for (int i = 0; i < 4; i++) {
|
||||
wheelLocations.add(null);
|
||||
pointsToApproach[i] = new TravellingPoint();
|
||||
|
@ -92,6 +95,7 @@ public class CarriageSyncData {
|
|||
public void read(FriendlyByteBuf buffer) {
|
||||
leadingCarriage = buffer.readBoolean();
|
||||
boolean fallback = buffer.readBoolean();
|
||||
ticksSince = 0;
|
||||
|
||||
if (fallback) {
|
||||
fallbackLocations =
|
||||
|
@ -212,8 +216,17 @@ public class CarriageSyncData {
|
|||
destinationDistanceSnapshot = (float) (distanceToDestination - carriage.train.navigation.distanceToDestination);
|
||||
}
|
||||
|
||||
public void approach(CarriageContraptionEntity entity, Carriage carriage, float partial) {
|
||||
public void approach(CarriageContraptionEntity entity, Carriage carriage, float partialIn) {
|
||||
DimensionalCarriageEntity dce = carriage.getDimensional(entity.level);
|
||||
|
||||
int updateInterval = entity.getType()
|
||||
.updateInterval();
|
||||
if (ticksSince >= updateInterval * 2)
|
||||
partialIn /= ticksSince - updateInterval * 2 + 1;
|
||||
partialIn *= ServerSpeedProvider.get();
|
||||
final float partial = partialIn;
|
||||
|
||||
ticksSince++;
|
||||
|
||||
if (fallbackLocations != null && fallbackPointSnapshot != null) {
|
||||
dce.positionAnchor = approachVector(partial, dce.positionAnchor, fallbackLocations.getFirst(),
|
||||
|
|
|
@ -14,7 +14,6 @@ import java.util.UUID;
|
|||
import java.util.concurrent.atomic.AtomicInteger;
|
||||
import java.util.function.BiConsumer;
|
||||
import java.util.function.Consumer;
|
||||
import java.util.function.Function;
|
||||
|
||||
import javax.annotation.Nullable;
|
||||
|
||||
|
@ -32,7 +31,6 @@ import com.simibubi.create.content.logistics.trains.TrackGraph;
|
|||
import com.simibubi.create.content.logistics.trains.TrackNode;
|
||||
import com.simibubi.create.content.logistics.trains.entity.Carriage.DimensionalCarriageEntity;
|
||||
import com.simibubi.create.content.logistics.trains.entity.TravellingPoint.IEdgePointListener;
|
||||
import com.simibubi.create.content.logistics.trains.entity.TravellingPoint.ITrackSelector;
|
||||
import com.simibubi.create.content.logistics.trains.entity.TravellingPoint.SteerDirection;
|
||||
import com.simibubi.create.content.logistics.trains.management.edgePoint.EdgeData;
|
||||
import com.simibubi.create.content.logistics.trains.management.edgePoint.EdgePointType;
|
||||
|
@ -82,6 +80,7 @@ public class Train {
|
|||
public double speed = 0;
|
||||
public double targetSpeed = 0;
|
||||
public Double speedBeforeStall = null;
|
||||
public int carriageWaitingForChunks = -1;
|
||||
|
||||
public double throttle = 1;
|
||||
public boolean honk = false;
|
||||
|
@ -278,6 +277,9 @@ public class Train {
|
|||
int carriageCount = carriages.size();
|
||||
boolean stalled = false;
|
||||
double maxStress = 0;
|
||||
|
||||
if (carriageWaitingForChunks != -1)
|
||||
distance = 0;
|
||||
|
||||
for (int i = 0; i < carriageCount; i++) {
|
||||
Carriage carriage = carriages.get(i);
|
||||
|
@ -366,18 +368,13 @@ public class Train {
|
|||
: carriages.get(i + 1)
|
||||
.getLeadingPoint();
|
||||
|
||||
Function<TravellingPoint, ITrackSelector> forwardControl =
|
||||
toFollowForward == null ? navigation::control : mp -> mp.follow(toFollowForward);
|
||||
Function<TravellingPoint, ITrackSelector> backwardControl =
|
||||
toFollowBackward == null ? navigation::control : mp -> mp.follow(toFollowBackward);
|
||||
|
||||
double totalStress = derailed ? 0 : leadingStress + trailingStress;
|
||||
|
||||
boolean first = i == 0;
|
||||
boolean last = i == carriageCount - 1;
|
||||
int carriageType = first ? last ? Carriage.BOTH : Carriage.FIRST : last ? Carriage.LAST : Carriage.MIDDLE;
|
||||
double actualDistance =
|
||||
carriage.travel(level, graph, distance + totalStress, forwardControl, backwardControl, carriageType);
|
||||
carriage.travel(level, graph, distance + totalStress, toFollowForward, toFollowBackward, carriageType);
|
||||
blocked |= carriage.blocked;
|
||||
|
||||
boolean onTwoBogeys = carriage.isOnTwoBogeys();
|
||||
|
|
Loading…
Reference in a new issue