diff --git a/src/generated/resources/data/create/tags/blocks/wrench_pickup.json b/src/generated/resources/data/create/tags/blocks/wrench_pickup.json index e7e2d8c55..7e3b0efcc 100644 --- a/src/generated/resources/data/create/tags/blocks/wrench_pickup.json +++ b/src/generated/resources/data/create/tags/blocks/wrench_pickup.json @@ -15,6 +15,7 @@ "minecraft:tripwire", "minecraft:tripwire_hook", "minecraft:daylight_detector", - "minecraft:target" + "minecraft:target", + "minecraft:hopper" ] } \ No newline at end of file diff --git a/src/main/java/com/simibubi/create/AllTags.java b/src/main/java/com/simibubi/create/AllTags.java index 1d731f55b..f5071814b 100644 --- a/src/main/java/com/simibubi/create/AllTags.java +++ b/src/main/java/com/simibubi/create/AllTags.java @@ -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); diff --git a/src/main/java/com/simibubi/create/content/contraptions/components/crafter/RecipeGridHandler.java b/src/main/java/com/simibubi/create/content/contraptions/components/crafter/RecipeGridHandler.java index 8f6be9a34..8f6d69715 100644 --- a/src/main/java/com/simibubi/create/content/contraptions/components/crafter/RecipeGridHandler.java +++ b/src/main/java/com/simibubi/create/content/contraptions/components/crafter/RecipeGridHandler.java @@ -9,7 +9,6 @@ import java.util.List; import java.util.Map; import java.util.Set; import java.util.function.Predicate; -import java.util.stream.IntStream; import org.apache.commons.lang3.tuple.Pair; @@ -159,12 +158,16 @@ public class RecipeGridHandler { } public static boolean isRecipeAllowed(CraftingRecipe recipe, CraftingContainer inventory) { - if (!AllConfigs.SERVER.recipes.allowBiggerFireworksInCrafter.get() && recipe instanceof FireworkRocketRecipe) { - int numItems = IntStream.range(0, inventory.getContainerSize()) - .map(i -> inventory.getItem(i).isEmpty() ? 0 : 1) - .sum(); - if (numItems > 9) + if (recipe instanceof FireworkRocketRecipe) { + int numItems = 0; + for (int i = 0; i < inventory.getContainerSize(); i++) { + if (!inventory.getItem(i).isEmpty()) { + numItems++; + } + } + if (numItems > AllConfigs.SERVER.recipes.maxFireworkIngredientsInCrafter.get()) { return false; + } } if (AllRecipeTypes.shouldIgnoreInAutomation(recipe)) return false; diff --git a/src/main/java/com/simibubi/create/content/contraptions/fluids/FluidNetwork.java b/src/main/java/com/simibubi/create/content/contraptions/fluids/FluidNetwork.java index ee559d9ae..eeaf6000d 100644 --- a/src/main/java/com/simibubi/create/content/contraptions/fluids/FluidNetwork.java +++ b/src/main/java/com/simibubi/create/content/contraptions/fluids/FluidNetwork.java @@ -4,6 +4,7 @@ import java.lang.ref.WeakReference; import java.util.ArrayList; import java.util.HashMap; import java.util.HashSet; +import java.util.IdentityHashMap; import java.util.Iterator; import java.util.List; import java.util.Map; @@ -183,6 +184,8 @@ public class FluidNetwork { } int flowSpeed = transferSpeed; + Map accumulatedFill = new IdentityHashMap<>(); + for (boolean simulate : Iterate.trueAndFalse) { FluidAction action = simulate ? FluidAction.SIMULATE : FluidAction.EXECUTE; @@ -211,8 +214,9 @@ public class FluidNetwork { return; if (simulate) flowSpeed = transfer.getAmount(); - + List>> availableOutputs = new ArrayList<>(targets); + while (!availableOutputs.isEmpty() && transfer.getAmount() > 0) { int dividedTransfer = transfer.getAmount() / availableOutputs.size(); int remainder = transfer.getAmount() % availableOutputs.size(); @@ -234,12 +238,22 @@ public class FluidNetwork { iterator.remove(); continue; } - + + int simulatedTransfer = toTransfer; + if (simulate) + simulatedTransfer += accumulatedFill.getOrDefault(targetHandler, 0); + FluidStack divided = transfer.copy(); - divided.setAmount(toTransfer); + divided.setAmount(simulatedTransfer); int fill = targetHandler.fill(divided, action); + + if (simulate) { + accumulatedFill.put(targetHandler, Integer.valueOf(fill)); + fill -= simulatedTransfer - toTransfer; + } + transfer.setAmount(transfer.getAmount() - fill); - if (fill < toTransfer) + if (fill < simulatedTransfer) iterator.remove(); } diff --git a/src/main/java/com/simibubi/create/content/logistics/trains/entity/Carriage.java b/src/main/java/com/simibubi/create/content/logistics/trains/entity/Carriage.java index 43fbb12ee..6b4b71e51 100644 --- a/src/main/java/com/simibubi/create/content/logistics/trains/entity/Carriage.java +++ b/src/main/java/com/simibubi/create/content/logistics/trains/entity/Carriage.java @@ -118,9 +118,14 @@ public class Carriage { return entities.get(dimension); } - public double travel(Level level, TrackGraph graph, double distance, - Function forwardControl, - Function backwardControl, int type) { + public double travel(Level level, TrackGraph graph, double distance, TravellingPoint toFollowForward, + TravellingPoint toFollowBackward, int type) { + + Function forwardControl = + toFollowForward == null ? train.navigation::control : mp -> mp.follow(toFollowForward); + Function 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; diff --git a/src/main/java/com/simibubi/create/content/logistics/trains/entity/CarriageSyncData.java b/src/main/java/com/simibubi/create/content/logistics/trains/entity/CarriageSyncData.java index 1cf7226cb..54ebac747 100644 --- a/src/main/java/com/simibubi/create/content/logistics/trains/entity/CarriageSyncData.java +++ b/src/main/java/com/simibubi/create/content/logistics/trains/entity/CarriageSyncData.java @@ -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(), diff --git a/src/main/java/com/simibubi/create/content/logistics/trains/entity/Train.java b/src/main/java/com/simibubi/create/content/logistics/trains/entity/Train.java index 8dd8b40de..3007a2d41 100644 --- a/src/main/java/com/simibubi/create/content/logistics/trains/entity/Train.java +++ b/src/main/java/com/simibubi/create/content/logistics/trains/entity/Train.java @@ -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 forwardControl = - toFollowForward == null ? navigation::control : mp -> mp.follow(toFollowForward); - Function 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(); diff --git a/src/main/java/com/simibubi/create/foundation/config/CRecipes.java b/src/main/java/com/simibubi/create/foundation/config/CRecipes.java index ec35f974f..18b0a54fe 100644 --- a/src/main/java/com/simibubi/create/foundation/config/CRecipes.java +++ b/src/main/java/com/simibubi/create/foundation/config/CRecipes.java @@ -8,8 +8,8 @@ public class CRecipes extends ConfigBase { public final ConfigBool allowShapedSquareInPress = b(true, "allowShapedSquareInPress", Comments.allowShapedSquareInPress); public final ConfigBool allowRegularCraftingInCrafter = b(true, "allowRegularCraftingInCrafter", Comments.allowRegularCraftingInCrafter); - public final ConfigBool allowBiggerFireworksInCrafter = - b(false, "allowBiggerFireworksInCrafter", Comments.allowBiggerFireworksInCrafter); + public final ConfigInt maxFireworkIngredientsInCrafter = + i(9, 1, "maxFireworkIngredientsInCrafter", Comments.maxFireworkIngredientsInCrafter); public final ConfigBool allowStonecuttingOnSaw = b(true, "allowStonecuttingOnSaw", Comments.allowStonecuttingOnSaw); public final ConfigBool allowWoodcuttingOnSaw = b(true, "allowWoodcuttingOnSaw", Comments.allowWoodcuttingOnSaw); public final ConfigBool allowCastingBySpout = b(true, "allowCastingBySpout", Comments.allowCastingBySpout); @@ -34,8 +34,8 @@ public class CRecipes extends ConfigBase { "Allow any single-ingredient 2x2 or 3x3 crafting recipes to be processed by a Mechanical Press + Basin."; static String allowRegularCraftingInCrafter = "Allow any standard crafting recipes to be processed by Mechanical Crafters."; - static String allowBiggerFireworksInCrafter = - "Allow Firework Rockets with more than 9 ingredients to be crafted using Mechanical Crafters."; + static String maxFireworkIngredientsInCrafter = + "The Maximum amount of ingredients that can be used to craft Firework Rockets using Mechanical Crafters."; static String allowStonecuttingOnSaw = "Allow any stonecutting recipes to be processed by a Mechanical Saw."; static String allowWoodcuttingOnSaw =