Merge branch 'master' into future

This commit is contained in:
gnembon committed 2021-11-16 20:11:49 +01:00
commit ab989155ad
6 files changed
+86 -31

No files matched your search

+4 -4
View File
@@ -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 {
+26
View File
@@ -622,6 +622,32 @@ so some caution (prior testing) is advised. Some of these multi-argument built-i
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
@@ -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
+25 -3
View File
@@ -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);
@@ -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<Pair<Vec3d, Box>> densityCache = new Object2DoubleOpenHashMap<>();
private static MutablePair<Vec3d, Box> pairMutable = new MutablePair<>();
private static Object2ObjectOpenHashMap<BlockPos, BlockState> stateCache = new Object2ObjectOpenHashMap<>();
private static Object2ObjectOpenHashMap<BlockPos, FluidState> fluidCache = new Object2ObjectOpenHashMap<>();
private static HashMap<BlockPos.Mutable, Float> blastResCache = new HashMap<>();
private static HashMap<BlockPos.Mutable, BlockState> blockStateCache = new HashMap<>();
private static BlockPos.Mutable posMutable = new BlockPos.Mutable(0, 0, 0);
private static ObjectOpenHashSet<BlockPos> 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)
BlockState state = world.getBlockState(posImmutable);
Float resistance = null;
if (!state.isAir())
{
float resistance = Math.max(state.getBlock().getBlastResistance(), fluid.getBlastResistance());
FluidState fluid = world.getFluidState(posImmutable);
resistance = Math.max(state.getBlock().getBlastResistance(), fluid.getBlastResistance());
if (eAccess.getEntity() != null)
{
resistance = eAccess.getEntity().getEffectiveExplosionResistance(e, eAccess.getWorld(), posMutable, state, fluid, resistance);
resistance = eAccess.getEntity().getEffectiveExplosionResistance(e, world, posMutable, state, fluid, resistance);
}
}
blockStateCache.put(posMutable, state);
blastResCache.put(posMutable, resistance);
}
size -= (resistance + 0.3F) * 0.3F;
}
Float blastRes = blastResCache.get(posMutable);
BlockState state = blockStateCache.get(posMutable);
if(blastRes != null)
{
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;
@@ -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));
}