From 6be2e51e0c42921c9fd5efc4c40503276d9b3547 Mon Sep 17 00:00:00 2001 From: Trumeet Date: Thu, 21 Oct 2021 19:38:07 -0700 Subject: [PATCH 1/6] support '/tick freeze on', '/tick freeze off' and '/tick freeze status' The current implementation only allows toggling tick freeze, so scripting is hard. This patch enables users to specifically freeze or unfreeze other than just toggling. It also provides '/tick freeze status' command to dynamically check whether the game is frozen or not. This patch preserves compatibility to the existing '/tick freeze' toggle command. --- .../java/carpet/commands/TickCommand.java | 28 +++++++++++++++++-- 1 file changed, 25 insertions(+), 3 deletions(-) diff --git a/src/main/java/carpet/commands/TickCommand.java b/src/main/java/carpet/commands/TickCommand.java index 8b6b3826..b4ada51e 100644 --- a/src/main/java/carpet/commands/TickCommand.java +++ b/src/main/java/carpet/commands/TickCommand.java @@ -45,7 +45,11 @@ public class TickCommand getInteger(c,"ticks"), getString(c, "tail command")))))). then(literal("freeze").executes( (c)-> toggleFreeze(c.getSource(), false)). - then(literal("deep").executes( (c)-> toggleFreeze(c.getSource(), true)))). + then(literal("status").executes( (c) -> freezeStatus(c.getSource()))). + then(literal("deep").executes( (c) -> toggleFreeze(c.getSource(), true))). + then(literal("on").executes( (c) -> setFreeze(c.getSource(), false, true)). + then(literal("deep").executes( (c)-> setFreeze(c.getSource(), true, true)))). + then(literal("off").executes( (c) -> setFreeze(c.getSource(), false, false)))). then(literal("step"). executes((c) -> step(1)). then(argument("ticks", integer(1,72000)). @@ -94,9 +98,22 @@ public class TickCommand return 1; } - private static int toggleFreeze(ServerCommandSource source, boolean isDeep) + private static int freezeStatus(ServerCommandSource source) { - TickSpeed.setFrozenState(!TickSpeed.isPaused(), isDeep); + if(TickSpeed.isPaused()) + { + Messenger.m(source, "gi Freeze Status: Game is "+(TickSpeed.deeplyFrozen()?"deeply ":"")+"frozen"); + } + else + { + Messenger.m(source, "gi Freeze Status: Game runs normally"); + } + return 1; + } + + private static int setFreeze(ServerCommandSource source, boolean isDeep, boolean freeze) + { + TickSpeed.setFrozenState(freeze, isDeep); if (TickSpeed.isPaused()) { Messenger.m(source, "gi Game is "+(isDeep?"deeply ":"")+"frozen"); @@ -108,6 +125,11 @@ public class TickCommand return 1; } + private static int toggleFreeze(ServerCommandSource source, boolean isDeep) + { + return setFreeze(source, isDeep, !TickSpeed.isPaused()); + } + private static int step(int advance) { TickSpeed.add_ticks_to_run_in_pause(advance); From af2ba900b20bbb256e9e3ca114305e5a5e1e71db Mon Sep 17 00:00:00 2001 From: James103 <37945304+James103@users.noreply.github.com> Date: Wed, 10 Nov 2021 15:00:04 -0600 Subject: [PATCH 2/6] Fix gnembon/fabric-carpet#1161: Typo in extreme velocity log message --- src/main/java/carpet/script/value/EntityValue.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main/java/carpet/script/value/EntityValue.java b/src/main/java/carpet/script/value/EntityValue.java index a92d0dc7..3c0c59d7 100644 --- a/src/main/java/carpet/script/value/EntityValue.java +++ b/src/main/java/carpet/script/value/EntityValue.java @@ -941,7 +941,7 @@ public class EntityValue extends Value { e.velocityModified = true; if (Math.abs(scale) > 10000) - CarpetScriptServer.LOG.warn("Moved entity "+e.getEntityName()+" "+e.getName()+" at " +e.getPos()+" extremly fast: "+e.getVelocity()); + CarpetScriptServer.LOG.warn("Moved entity "+e.getEntityName()+" "+e.getName()+" at " +e.getPos()+" extremely fast: "+e.getVelocity()); //((ServerWorld)e.getEntityWorld()).method_14178().sendToNearbyPlayers(e, new EntityVelocityUpdateS2CPacket(e)); } From a9183d9fe3248a14602aa09c03d841d0a97f198a Mon Sep 17 00:00:00 2001 From: "github-actions[bot]" Date: Thu, 11 Nov 2021 22:30:47 +0000 Subject: [PATCH 3/6] Merge docs for 'Carpet Mod 1.4.53 for Minecraft 1.18-pre1 and 1.17.1' --- docs/scarpet/Full.md | 28 +++++++++++++++++++++++++++- 1 file changed, 27 insertions(+), 1 deletion(-) diff --git a/docs/scarpet/Full.md b/docs/scarpet/Full.md index 11b4b5d4..9256ca3d 100644 --- a/docs/scarpet/Full.md +++ b/docs/scarpet/Full.md @@ -621,7 +621,33 @@ so some caution (prior testing) is advised. Some of these multi-argument built-i `if`, `try`, `sort_key`, `system_variable_get`, `synchronize`, `sleep`, `in_dimension`, all container functions (`get`, `has`, `put`, `delete`), and all loop functions (`while`, `loop`, `map`, `filter`, `first`, `all`, `c_for`, `for` and`reduce`). - + +### `Binary (bitwise) operations` + +These are a bunch of operators that work exclusively on numbers, more specifically their binary representations. Some of these +work on multiple numbers, some on only 2, and others on only 1. Note that most of these functions (all but `double_to_long_bits`) +only take integer values, so if the input has a decimal part, it will be discarded. + + - `bitwise_and(...)` -> Does the bitwise AND operation on each number in order. Note that with larger ranges of numbers this will + tend to 0. + - `bitwise_xor(...)` -> Does the bitwise XOR operation on each number in order. + - `bitwise_or(...)` -> Does the bitwise AND operation on each number in order. Note that with larger ranges of numbers this will + tend to -1. + - `bitwise_shift_left(num, amount)` -> Shifts all the bits of the first number `amount` spots to the left. Note that shifting more + than 63 positions will result in a 0 (cos you shift out all the bits of the number) + - `bitwise_shift_right(num, amount)` -> Shifts all the bits of the first number `amount` spots to the right. Like with the above, + shifting more than 63 bits results in a 0. + - `bitwise_roll_left(num, amount)` -> Rolls the bits of the first number `amount` bits to the left. This is basically where you + shift out the first `amount` bits and then add them on at the back, essentially 'rolling' the number. Note that unlike with + shifting, you can roll more than 63 bits at a time, as it just makes the number roll over more times, which isn't an issue + - `bitwise_roll_right(num, amount)` -> Same as above, just rolling in the other direction + - `bitwise_not(num)` -> Flips all the bits of the number. This is simply done by performing xor operation with -1, which in binary is + all ones. + - `bitwise_popcount(num)` -> Returns the number of ones in the binary representation of the number. For the number of zeroes, just + do 64 minus this number. + - `double_to_long_bits(num)` -> Returns a representation of the specified floating-point value according to the IEEE 754 floating-point + "double format" bit layout. + - `long_to_double_bits(num)` -> Returns the double value corresponding to a given bit representation. # Arithmetic operations ## Basic Arithmetic Functions From 0998a78cae2d417d6c654696a1ea56db9e031339 Mon Sep 17 00:00:00 2001 From: gnembon Date: Sat, 13 Nov 2021 21:32:09 +0100 Subject: [PATCH 4/6] well --- docs/scarpet/resources/editors/npp/scarpet.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docs/scarpet/resources/editors/npp/scarpet.xml b/docs/scarpet/resources/editors/npp/scarpet.xml index 8a6df073..ed775767 100644 --- a/docs/scarpet/resources/editors/npp/scarpet.xml +++ b/docs/scarpet/resources/editors/npp/scarpet.xml @@ -32,7 +32,7 @@ sqrt max min abs round floor ceil then sum difference product quotient equal unique increasing decreasing nonincreasing nondecreasing or and - bitwise_or bitwise_and bitwise_xor bitwise_shift_left bitwise_shit_right bitwise_roll_left bitwise_roll_right bitwise_not bitwise_popcount + bitwise_or bitwise_and bitwise_xor bitwise_shift_left bitwise_shift_right bitwise_roll_left bitwise_roll_right bitwise_not bitwise_popcount double_to_long_bits long_bits_to_double mandelbrot relu perlin simplex From 5005268df4ebc2a99b73e78f4c05c68518c675d7 Mon Sep 17 00:00:00 2001 From: intricate Date: Sat, 13 Nov 2021 18:08:03 -0300 Subject: [PATCH 5/6] Optimize explosion BlockState caching (#1156) optimize caching for explosions --- .../carpet/helpers/OptimizedExplosion.java | 61 +++++++++++-------- 1 file changed, 34 insertions(+), 27 deletions(-) diff --git a/src/main/java/carpet/helpers/OptimizedExplosion.java b/src/main/java/carpet/helpers/OptimizedExplosion.java index ce9a331c..214a38e2 100644 --- a/src/main/java/carpet/helpers/OptimizedExplosion.java +++ b/src/main/java/carpet/helpers/OptimizedExplosion.java @@ -5,6 +5,7 @@ import java.math.RoundingMode; import java.text.NumberFormat; import java.util.ArrayList; import java.util.Collections; +import java.util.HashMap; import java.util.List; import carpet.logging.logHelpers.ExplosionLogHelper; @@ -12,7 +13,6 @@ import carpet.mixins.ExplosionAccessor; import carpet.CarpetSettings; import carpet.utils.Messenger; import it.unimi.dsi.fastutil.objects.Object2DoubleOpenHashMap; -import it.unimi.dsi.fastutil.objects.Object2ObjectOpenHashMap; import it.unimi.dsi.fastutil.objects.ObjectArrayList; import it.unimi.dsi.fastutil.objects.ObjectOpenHashSet; import net.minecraft.block.BlockState; @@ -58,8 +58,8 @@ public class OptimizedExplosion // masa's optimizations private static Object2DoubleOpenHashMap> densityCache = new Object2DoubleOpenHashMap<>(); private static MutablePair pairMutable = new MutablePair<>(); - private static Object2ObjectOpenHashMap stateCache = new Object2ObjectOpenHashMap<>(); - private static Object2ObjectOpenHashMap fluidCache = new Object2ObjectOpenHashMap<>(); + private static HashMap blastResCache = new HashMap<>(); + private static HashMap blockStateCache = new HashMap<>(); private static BlockPos.Mutable posMutable = new BlockPos.Mutable(0, 0, 0); private static ObjectOpenHashSet affectedBlockPositionsSet = new ObjectOpenHashSet<>(); private static boolean firstRay; @@ -86,8 +86,8 @@ public class OptimizedExplosion getAffectedPositionsOnPlaneX(e, 15, 1, 14, 0, 15); // east getAffectedPositionsOnPlaneZ(e, 0, 1, 14, 1, 14); // north getAffectedPositionsOnPlaneZ(e, 15, 1, 14, 1, 14); // south - stateCache.clear(); - fluidCache.clear(); + blastResCache.clear(); + blockStateCache.clear(); e.getAffectedBlocks().addAll(affectedBlockPositionsSet); affectedBlockPositionsSet.clear(); @@ -446,6 +446,7 @@ public class OptimizedExplosion double xInc = (xRel / len) * 0.3; double yInc = (yRel / len) * 0.3; double zInc = (zRel / len) * 0.3; + World world = eAccess.getWorld(); float rand = eAccess.getWorld().random.nextFloat(); float sizeRand = (CarpetSettings.tntRandomRange >= 0 ? (float) CarpetSettings.tntRandomRange : rand); float size = eAccess.getPower() * (0.7F + sizeRand * 0.6F); @@ -457,38 +458,44 @@ public class OptimizedExplosion { posMutable.set(posX, posY, posZ); - // Don't query already cached positions again from the world - BlockState state = stateCache.get(posMutable); - FluidState fluid = fluidCache.get(posMutable); BlockPos posImmutable = null; - if (state == null) + // Don't query already cached positions again from the world + if (!blastResCache.containsKey(posMutable)) { posImmutable = posMutable.toImmutable(); - state = eAccess.getWorld().getBlockState(posImmutable); - stateCache.put(posImmutable, state); - fluid = eAccess.getWorld().getFluidState(posImmutable); - fluidCache.put(posImmutable, fluid); - } - - if (state.getMaterial() != Material.AIR) - { - float resistance = Math.max(state.getBlock().getBlastResistance(), fluid.getBlastResistance()); - - if (eAccess.getEntity() != null) + BlockState state = world.getBlockState(posImmutable); + Float resistance = null; + if (!state.isAir()) { - resistance = eAccess.getEntity().getEffectiveExplosionResistance(e, eAccess.getWorld(), posMutable, state, fluid, resistance); + FluidState fluid = world.getFluidState(posImmutable); + resistance = Math.max(state.getBlock().getBlastResistance(), fluid.getBlastResistance()); + if (eAccess.getEntity() != null) + { + resistance = eAccess.getEntity().getEffectiveExplosionResistance(e, world, posMutable, state, fluid, resistance); + } } - - size -= (resistance + 0.3F) * 0.3F; + blockStateCache.put(posMutable, state); + blastResCache.put(posMutable, resistance); } - if (size > 0.0F) + Float blastRes = blastResCache.get(posMutable); + BlockState state = blockStateCache.get(posMutable); + + if(blastRes != null) { - if ((eAccess.getEntity() == null || eAccess.getEntity().canExplosionDestroyBlock(e, eAccess.getWorld(), posMutable, state, size))) - affectedBlockPositionsSet.add(posImmutable != null ? posImmutable : posMutable.toImmutable()); + size -= (blastRes + 0.3F) * 0.3F; + if (size > 0.0F) + { + if ((eAccess.getEntity() == null || eAccess.getEntity().canExplosionDestroyBlock(e, eAccess.getWorld(), posMutable, state, size))) + { + affectedBlockPositionsSet.add(posImmutable != null ? posImmutable : posMutable.toImmutable()); + blastResCache.put(posMutable, null); + blockStateCache.remove(posMutable); + } + } } - else if (firstRay) + if (firstRay) { rayCalcDone = true; return true; From 03d5aa5904b51794f5e529d965d212ffa3da2f6f Mon Sep 17 00:00:00 2001 From: gnembon Date: Tue, 16 Nov 2021 20:11:19 +0100 Subject: [PATCH 6/6] one more java --- build.gradle | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/build.gradle b/build.gradle index 0a206e0a..19cccefc 100644 --- a/build.gradle +++ b/build.gradle @@ -3,8 +3,8 @@ plugins { id 'maven-publish' } -sourceCompatibility = JavaVersion.VERSION_16 -targetCompatibility = JavaVersion.VERSION_16 +sourceCompatibility = JavaVersion.VERSION_17 +targetCompatibility = JavaVersion.VERSION_17 archivesBaseName = project.archives_base_name version = project.minecraft_version+'-'+project.mod_version+'+v'+new Date().format('yyMMdd') @@ -44,8 +44,8 @@ tasks.withType(JavaCompile).configureEach { // If Javadoc is generated, this must be specified in that task too. it.options.encoding = "UTF-8" - // Minecraft 1.17 (21w19a) upwards uses Java 16. - it.options.release = 16 + // Minecraft 1.18 upwards uses Java 17. + it.options.release = 17 } java {