Merge branch 'master' into 1.17

This commit is contained in:
gnembon committed 2021-06-20 00:15:45 -03:00
commit 01aeb79617
3 files changed
+59 -83

No files matched your search

+2 -2
View File
@@ -252,7 +252,7 @@ public class CarpetSettings
@Rule( desc = "Merges stationary primed TNT entities", category = TNT ) @Rule( desc = "Merges stationary primed TNT entities", category = TNT )
public static boolean mergeTNT = false; public static boolean mergeTNT = false;
/*@Rule( @Rule(
desc = "Lag optimizations for redstone dust", desc = "Lag optimizations for redstone dust",
extra = { extra = {
"by Theosib", "by Theosib",
@@ -261,7 +261,7 @@ public class CarpetSettings
}, },
category = {EXPERIMENTAL, OPTIMIZATION} category = {EXPERIMENTAL, OPTIMIZATION}
) )
public static boolean fastRedstoneDust = false;*/ public static boolean fastRedstoneDust = false;
@Rule(desc = "Only husks spawn in desert temples", category = FEATURE) @Rule(desc = "Only husks spawn in desert temples", category = FEATURE)
public static boolean huskSpawningInTemples = false; public static boolean huskSpawningInTemples = false;
@@ -3,6 +3,7 @@ package carpet.mixins;
import carpet.CarpetSettings; import carpet.CarpetSettings;
import carpet.fakes.RedstoneWireBlockInterface; import carpet.fakes.RedstoneWireBlockInterface;
import carpet.helpers.RedstoneWireTurbo; import carpet.helpers.RedstoneWireTurbo;
import com.google.common.collect.Sets;
import net.minecraft.block.Block; import net.minecraft.block.Block;
import net.minecraft.block.BlockState; import net.minecraft.block.BlockState;
import net.minecraft.block.RedstoneWireBlock; import net.minecraft.block.RedstoneWireBlock;
@@ -27,22 +28,12 @@ import static net.minecraft.block.RedstoneWireBlock.POWER;
@Mixin(RedstoneWireBlock.class) @Mixin(RedstoneWireBlock.class)
public abstract class RedstoneWireBlockMixin implements RedstoneWireBlockInterface { public abstract class RedstoneWireBlockMixin implements RedstoneWireBlockInterface {
/*
needs reworking
@Shadow @Shadow
private boolean wiresGivePower; private void update(World world_1, BlockPos blockPos_1, BlockState blockState_1) { }
@Shadow @Shadow
@Final private int getReceivedRedstonePower(World world, BlockPos pos) { return 0; }
private Set<BlockPos> affectedNeighbors;
@Shadow
private int increasePower(int int_1, BlockState blockState_1) { return 0; }
@Shadow
private BlockState update(World world_1, BlockPos blockPos_1, BlockState blockState_1) { return null; }
@Override @Override
@Accessor("wiresGivePower") @Accessor("wiresGivePower")
@@ -64,96 +55,73 @@ public abstract class RedstoneWireBlockMixin implements RedstoneWireBlockInterfa
// = // =
public BlockState fastUpdate(World world, BlockPos pos, BlockState state, BlockPos source) { public void fastUpdate(World world, BlockPos pos, BlockState state, BlockPos source) {
// [CM] fastRedstoneDust -- update based on carpet rule // [CM] fastRedstoneDust -- update based on carpet rule
if (CarpetSettings.fastRedstoneDust) { if (CarpetSettings.fastRedstoneDust) {
return wireTurbo.updateSurroundingRedstone(world, pos, state, source); wireTurbo.updateSurroundingRedstone(world, pos, state, source);
return;
} }
return update(world, pos, state); update(world, pos, state);
} }
/** /**
* @author theosib, soykaf, gnembon * @author theosib, soykaf, gnembon
* */
@Inject(method = "updateLogic", at = @At("HEAD"), cancellable = true) @Inject(method = "update", at = @At("HEAD"), cancellable = true)
private void updateLogicAlternative(World world, BlockPos pos, BlockState state, CallbackInfoReturnable<BlockState> cir) private void updateLogicAlternative(World world, BlockPos pos, BlockState state, CallbackInfo cir) {
{ if (CarpetSettings.fastRedstoneDust) {
if (CarpetSettings.fastRedstoneDust) updateLogicPublic(world, pos, state);
cir.setReturnValue(updateLogicPublic(world, pos, state)); cir.cancel();
}
} }
@Override @Override
public BlockState updateLogicPublic(World world_1, BlockPos blockPos_1, BlockState blockState_1) { public BlockState updateLogicPublic(World world_1, BlockPos blockPos_1, BlockState blockState_1) {
BlockState blockState_2 = blockState_1; int i = this.getReceivedRedstonePower(world_1, blockPos_1);
int int_1 = (Integer)blockState_1.get(POWER); // i BlockState blockState = blockState_1;
this.wiresGivePower = false; if (blockState_1.get(POWER) != i) {
int int_2 = world_1.getReceivedRedstonePower(blockPos_1); // k blockState_1 = blockState_1.with(POWER, i);
this.wiresGivePower = true; if (world_1.getBlockState(blockPos_1) == blockState) {
int int_3 = 0; // l
if (!CarpetSettings.fastRedstoneDust || int_2 < 15) {
Iterator var8 = Direction.Type.HORIZONTAL.iterator();
label43:
while(true) {
while(true) {
if (!var8.hasNext()) {
break label43;
}
Direction direction_1 = (Direction)var8.next();
BlockPos blockPos_2 = blockPos_1.offset(direction_1);
BlockState blockState_3 = world_1.getBlockState(blockPos_2);
int_3 = this.increasePower(int_3, blockState_3);
BlockPos blockPos_3 = blockPos_1.up();
if (blockState_3.isSolidBlock(world_1, blockPos_2) && !world_1.getBlockState(blockPos_3).isSolidBlock(world_1, blockPos_3)) {
int_3 = this.increasePower(int_3, world_1.getBlockState(blockPos_2.up()));
} else if (!blockState_3.isSolidBlock(world_1, blockPos_2)) { //isSimpleFUllBLock
int_3 = this.increasePower(int_3, world_1.getBlockState(blockPos_2.down()));
}
}
}
}
int int_4 = int_3 - 1;
if (int_2 > int_4) int_4 = int_2;
if (int_1 != int_4) {
blockState_1 = (BlockState)blockState_1.with(POWER, int_4);
if (world_1.getBlockState(blockPos_1) == blockState_2) {
world_1.setBlockState(blockPos_1, blockState_1, 2); world_1.setBlockState(blockPos_1, blockState_1, 2);
} }
if (!CarpetSettings.fastRedstoneDust) { if (!CarpetSettings.fastRedstoneDust) {
this.affectedNeighbors.add(blockPos_1); Set<BlockPos> set = Sets.newHashSet();
Direction[] var14 = Direction.values(); set.add(blockPos_1);
int var15 = var14.length; Direction[] var6 = Direction.values();
int var7 = var6.length;
for (int var16 = 0; var16 < var15; ++var16) { for (int var8 = 0; var8 < var7; ++var8) {
Direction direction_2 = var14[var16]; Direction direction = var6[var8];
this.affectedNeighbors.add(blockPos_1.offset(direction_2)); set.add(blockPos_1.offset(direction));
}
}
} }
Iterator var10 = set.iterator();
while (var10.hasNext()) {
BlockPos blockPos = (BlockPos) var10.next();
world_1.updateNeighborsAlways(blockPos, blockState_1.getBlock());
}
}
}
return blockState_1; return blockState_1;
} }
// = // =
@Redirect(method = "onBlockAdded", at = @At(value = "INVOKE", target = "Lnet/minecraft/block/RedstoneWireBlock;update(Lnet/minecraft/world/World;Lnet/minecraft/util/math/BlockPos;Lnet/minecraft/block/BlockState;)Lnet/minecraft/block/BlockState;")) @Redirect(method = "onBlockAdded", at = @At(value = "INVOKE", target = "Lnet/minecraft/block/RedstoneWireBlock;update(Lnet/minecraft/world/World;Lnet/minecraft/util/math/BlockPos;Lnet/minecraft/block/BlockState;)V"))
private BlockState redirectOnBlockAddedUpdate(RedstoneWireBlock self, World world_1, BlockPos blockPos_1, BlockState blockState_1) { private void redirectOnBlockAddedUpdate(RedstoneWireBlock self, World world_1, BlockPos blockPos_1, BlockState blockState_1) {
return fastUpdate(world_1, blockPos_1, blockState_1, null); fastUpdate(world_1, blockPos_1, blockState_1, null);
} }
@Redirect(method = "onBlockRemoved", at = @At(value = "INVOKE", target = "Lnet/minecraft/block/RedstoneWireBlock;update(Lnet/minecraft/world/World;Lnet/minecraft/util/math/BlockPos;Lnet/minecraft/block/BlockState;)Lnet/minecraft/block/BlockState;")) @Redirect(method = "onStateReplaced", at = @At(value = "INVOKE", target = "Lnet/minecraft/block/RedstoneWireBlock;update(Lnet/minecraft/world/World;Lnet/minecraft/util/math/BlockPos;Lnet/minecraft/block/BlockState;)V"))
private BlockState redirectOnBlockRemovedUpdate(RedstoneWireBlock self, World world_1, BlockPos blockPos_1, BlockState blockState_1) { private void redirectOnStateReplacedUpdate(RedstoneWireBlock self, World world_1, BlockPos blockPos_1, BlockState blockState_1) {
return fastUpdate(world_1, blockPos_1, blockState_1, null); fastUpdate(world_1, blockPos_1, blockState_1, null);
} }
@Redirect(method = "neighborUpdate", at = @At(value = "INVOKE", target = "Lnet/minecraft/block/RedstoneWireBlock;update(Lnet/minecraft/world/World;Lnet/minecraft/util/math/BlockPos;Lnet/minecraft/block/BlockState;)Lnet/minecraft/block/BlockState;")) @Redirect(method = "neighborUpdate", at = @At(value = "INVOKE", target = "Lnet/minecraft/block/RedstoneWireBlock;update(Lnet/minecraft/world/World;Lnet/minecraft/util/math/BlockPos;Lnet/minecraft/block/BlockState;)V"))
private BlockState redirectNeighborUpdateUpdate( private void redirectNeighborUpdateUpdate(
RedstoneWireBlock self, RedstoneWireBlock self,
World world_1, World world_1,
BlockPos blockPos_1, BlockPos blockPos_1,
@@ -164,8 +132,6 @@ public abstract class RedstoneWireBlockMixin implements RedstoneWireBlockInterfa
Block block_1, Block block_1,
BlockPos blockPos_3, BlockPos blockPos_3,
boolean boolean_1) { boolean boolean_1) {
return fastUpdate(world_1, blockPos_1, blockState_1, blockPos_3); fastUpdate(world_1, blockPos_1, blockState_1, blockPos_3);
} }
*/
} }
@@ -1,6 +1,7 @@
package carpet.script.argument; package carpet.script.argument;
import carpet.CarpetServer; import carpet.CarpetServer;
import carpet.script.CarpetScriptServer;
import carpet.script.bundled.Module; import carpet.script.bundled.Module;
import carpet.script.exception.InternalExpressionException; import carpet.script.exception.InternalExpressionException;
import carpet.script.exception.ThrowStatement; import carpet.script.exception.ThrowStatement;
@@ -28,7 +29,6 @@ import java.io.BufferedReader;
import java.io.BufferedWriter; import java.io.BufferedWriter;
import java.io.DataInputStream; import java.io.DataInputStream;
import java.io.DataOutputStream; import java.io.DataOutputStream;
import java.io.File;
import java.io.IOException; import java.io.IOException;
import java.io.OutputStream; import java.io.OutputStream;
import java.io.OutputStreamWriter; import java.io.OutputStreamWriter;
@@ -193,8 +193,9 @@ public class FileArgument
if (!Files.exists(zipPath.getParent())) Files.createDirectories(zipPath.getParent()); if (!Files.exists(zipPath.getParent())) Files.createDirectories(zipPath.getParent());
zfs = FileSystems.newFileSystem(URI.create("jar:"+ zipPath.toUri().toString()), env); zfs = FileSystems.newFileSystem(URI.create("jar:"+ zipPath.toUri().toString()), env);
} }
catch (FileSystemNotFoundException | IOException fsnfe) catch (FileSystemNotFoundException | IOException e)
{ {
CarpetScriptServer.LOG.warn("Exception when opening zip file", e);
throw new ThrowStatement("Unable to open zip file: "+zipContainer, Throwables.IO_EXCEPTION); throw new ThrowStatement("Unable to open zip file: "+zipContainer, Throwables.IO_EXCEPTION);
} }
} }
@@ -295,6 +296,7 @@ public class FileArgument
Files.createDirectories(file.getParent()) == null Files.createDirectories(file.getParent()) == null
) throw new IOException(); ) throw new IOException();
} catch (IOException e) { } catch (IOException e) {
CarpetScriptServer.LOG.warn("IOException when creating paths", e);
throw new ThrowStatement("Unable to create paths for "+file.toString(), Throwables.IO_EXCEPTION); throw new ThrowStatement("Unable to create paths for "+file.toString(), Throwables.IO_EXCEPTION);
} }
@@ -319,6 +321,7 @@ public class FileArgument
} } } }
catch (IOException e) catch (IOException e)
{ {
CarpetScriptServer.LOG.warn("IOException when appending to text file", e);
throw new ThrowStatement("Error when writing to the file: "+e, Throwables.IO_EXCEPTION); throw new ThrowStatement("Error when writing to the file: "+e, Throwables.IO_EXCEPTION);
} }
finally finally
@@ -375,8 +378,11 @@ public class FileArgument
return NbtTypes.byId(byte_1).read(dataInput_1, 0, NbtTagSizeTracker.EMPTY); return NbtTypes.byId(byte_1).read(dataInput_1, 0, NbtTagSizeTracker.EMPTY);
} }
} }
catch (IOException ignored) catch (IOException secondIO)
{ {
CarpetScriptServer.LOG.warn("IOException when trying to read nbt file, something may have gone wrong with the fs",e);
CarpetScriptServer.LOG.catching(ioException);
CarpetScriptServer.LOG.catching(secondIO);
throw new ThrowStatement("Not a valid NBT tag in "+path.toString(), Throwables.NBT_ERROR); throw new ThrowStatement("Not a valid NBT tag in "+path.toString(), Throwables.NBT_ERROR);
} }
} }
@@ -409,7 +415,7 @@ public class FileArgument
{ {
if (!zipped) if (!zipped)
{ {
path = new File(path.toFile().getAbsolutePath() + "_tmp").toPath(); path = path.getParent().resolve(path.getFileName() + "_tmp");
Files.deleteIfExists(path); Files.deleteIfExists(path);
} }
@@ -438,6 +444,7 @@ public class FileArgument
} }
catch (IOException e) catch (IOException e)
{ {
CarpetScriptServer.LOG.warn("IO Exception when writing nbt file", e);
throw new ThrowStatement("Unable to write tag to "+original.toString(), Throwables.IO_EXCEPTION); throw new ThrowStatement("Unable to write tag to "+original.toString(), Throwables.IO_EXCEPTION);
} }
} }
@@ -453,6 +460,7 @@ public class FileArgument
} } } }
catch (IOException e) catch (IOException e)
{ {
CarpetScriptServer.LOG.warn("IOException when removing file", e);
throw new ThrowStatement("Error while removing file: "+getDisplayPath(), Throwables.IO_EXCEPTION); throw new ThrowStatement("Error while removing file: "+getDisplayPath(), Throwables.IO_EXCEPTION);
} }
finally finally
@@ -488,6 +496,7 @@ public class FileArgument
} }
catch (IOException e) catch (IOException e)
{ {
CarpetScriptServer.LOG.warn("IOException when reading text file", e);
throw new ThrowStatement("Failed to read text file "+filePath.toString(), Throwables.IO_EXCEPTION); throw new ThrowStatement("Failed to read text file "+filePath.toString(), Throwables.IO_EXCEPTION);
} }
} }
@@ -521,6 +530,7 @@ public class FileArgument
} }
catch (IOException e) catch (IOException e)
{ {
CarpetScriptServer.LOG.warn("IOException when reading JSON file", e);
throw new ThrowStatement("Failed to read json file content "+filePath.toString(), Throwables.IO_EXCEPTION); throw new ThrowStatement("Failed to read json file content "+filePath.toString(), Throwables.IO_EXCEPTION);
} }
} }