This commit is contained in:
eaglercraft 2024-11-16 23:22:14 -08:00
parent 5c8e0408e7
commit fef7defbe7
95 changed files with 732 additions and 658 deletions

View File

@ -247,4 +247,4 @@ The `crashReportShow` hook can be used to capture crash reports and append addit
There is currently no system in place to make forks of 1.8 and merge commits made to the patch files in this repository with the patch files or workspace of the fork, you're on your own if you try to keep a fork of this repo for reasons other than to contribute to it There is currently no system in place to make forks of 1.8 and merge commits made to the patch files in this repository with the patch files or workspace of the fork, you're on your own if you try to keep a fork of this repo for reasons other than to contribute to it
A javascript-based modding API resembling Minecraft Forge may be implemented someday though for adding custom content to the game. **Note:** If you are trying to use the desktop runtime on Linux, make sure you add the "desktopRuntime" folder to the `LD_LIBRARY_PATH` environment variable of the Java process. This should be done automatically by the Eclipse project's default run configuration, but it might not work properly on every system, or when the Eclipse project is imported into IntelliJ.

View File

@ -22,6 +22,8 @@ Java must be added to your PATH!
2. Open one of the .java files from the source folders (workaround for a bug) 2. Open one of the .java files from the source folders (workaround for a bug)
3. Run/Debug the client with the included "eaglercraftDebugRuntime" configuration 3. Run/Debug the client with the included "eaglercraftDebugRuntime" configuration
**Note:** If you are trying to use the desktop runtime on Linux, make sure you add the "desktopRuntime" folder to the `LD_LIBRARY_PATH` environment variable of the Java process. This should be done automatically by the Eclipse project's default run configuration, but it might not work properly on every system, or when the Eclipse project is imported into IntelliJ.
**See the main 1.8 repository's README for more info** **See the main 1.8 repository's README for more info**
The source codes of EaglercraftXBungee and EaglercraftXVelocity are not included here. The source codes of EaglercraftXBungee and EaglercraftXVelocity are not included here.

View File

@ -1 +1 @@
u41 u42

View File

@ -30,7 +30,6 @@
<option class="_eaglercraftX_boot_menu_launch_conf_val_launch_type_opt" value="PEYTON_V1">PeytonPlayz585 Indev</option> <option class="_eaglercraftX_boot_menu_launch_conf_val_launch_type_opt" value="PEYTON_V1">PeytonPlayz585 Indev</option>
<option class="_eaglercraftX_boot_menu_launch_conf_val_launch_type_opt" value="PEYTON_V2">PeytonPlayz585 Alpha/Beta</option> <option class="_eaglercraftX_boot_menu_launch_conf_val_launch_type_opt" value="PEYTON_V2">PeytonPlayz585 Alpha/Beta</option>
<option class="_eaglercraftX_boot_menu_launch_conf_val_launch_type_opt" value="STANDARD_OFFLINE_V1">Standard Offline</option> <option class="_eaglercraftX_boot_menu_launch_conf_val_launch_type_opt" value="STANDARD_OFFLINE_V1">Standard Offline</option>
<option class="_eaglercraftX_boot_menu_launch_conf_val_launch_type_opt" value="IFRAME_SANDBOX_V1">IFrame HTML File</option>
</select> </select>
</p> </p>
</div> </div>

View File

@ -1 +1 @@
{"pluginName":"EaglercraftXBungee","pluginVersion":"1.3.2","pluginButton":"Download \"EaglerXBungee-1.3.2.jar\"","pluginFilename":"EaglerXBungee.zip"} {"pluginName":"EaglercraftXBungee","pluginVersion":"1.3.3","pluginButton":"Download \"EaglerXBungee-1.3.3.jar\"","pluginFilename":"EaglerXBungee.zip"}

View File

@ -103,8 +103,7 @@ public class BlockFarmland extends Block {
} }
private boolean hasWater(World worldIn, BlockPos pos) { private boolean hasWater(World worldIn, BlockPos pos) {
for (BlockPos.MutableBlockPos blockpos$mutableblockpos : BlockPos.getAllInBoxMutable(pos.add(-4, 0, -4), for (BlockPos blockpos$mutableblockpos : BlockPos.getAllInBoxMutable(pos.add(-4, 0, -4), pos.add(4, 1, 4))) {
pos.add(4, 1, 4))) {
if (worldIn.getBlockState(blockpos$mutableblockpos).getBlock().getMaterial() == Material.water) { if (worldIn.getBlockState(blockpos$mutableblockpos).getBlock().getMaterial() == Material.water) {
return true; return true;
} }

View File

@ -71,19 +71,22 @@ public class BlockGrass extends Block implements IGrowable {
public void updateTick(World world, BlockPos blockpos, IBlockState var3, EaglercraftRandom random) { public void updateTick(World world, BlockPos blockpos, IBlockState var3, EaglercraftRandom random) {
if (!world.isRemote) { if (!world.isRemote) {
if (world.getLightFromNeighbors(blockpos.up()) < 4 BlockPos tmp = new BlockPos();
&& world.getBlockState(blockpos.up()).getBlock().getLightOpacity() > 2) { if (world.getLightFromNeighbors(blockpos.up(tmp)) < 4
&& world.getBlockState(blockpos.up(tmp)).getBlock().getLightOpacity() > 2) {
world.setBlockState(blockpos, Blocks.dirt.getDefaultState()); world.setBlockState(blockpos, Blocks.dirt.getDefaultState());
} else { } else {
if (world.getLightFromNeighbors(blockpos.up()) >= 9) { if (world.getLightFromNeighbors(blockpos.up(tmp)) >= 9) {
BlockPos tmp2 = new BlockPos();
for (int i = 0; i < 4; ++i) { for (int i = 0; i < 4; ++i) {
BlockPos blockpos1 = blockpos.add(random.nextInt(3) - 1, random.nextInt(5) - 3, BlockPos blockpos1 = blockpos.add(random.nextInt(3) - 1, random.nextInt(5) - 3,
random.nextInt(3) - 1); random.nextInt(3) - 1, tmp2);
Block block = world.getBlockState(blockpos1.up()).getBlock(); Block block = world.getBlockState(blockpos1.up(tmp)).getBlock();
IBlockState iblockstate = world.getBlockState(blockpos1); IBlockState iblockstate = world.getBlockState(blockpos1);
if (iblockstate.getBlock() == Blocks.dirt if (iblockstate.getBlock() == Blocks.dirt
&& iblockstate.getValue(BlockDirt.VARIANT) == BlockDirt.DirtType.DIRT && iblockstate.getValue(BlockDirt.VARIANT) == BlockDirt.DirtType.DIRT
&& world.getLightFromNeighbors(blockpos1.up()) >= 4 && block.getLightOpacity() <= 2) { && world.getLightFromNeighbors(blockpos1.up(tmp)) >= 4
&& block.getLightOpacity() <= 2) {
world.setBlockState(blockpos1, Blocks.grass.getDefaultState()); world.setBlockState(blockpos1, Blocks.grass.getDefaultState());
} }
} }

View File

@ -106,7 +106,7 @@ public abstract class BlockLeaves extends BlockLeavesBase {
} }
if (world.isAreaLoaded(new BlockPos(j - i, k - i, l - i), new BlockPos(j + i, k + i, l + i))) { if (world.isAreaLoaded(new BlockPos(j - i, k - i, l - i), new BlockPos(j + i, k + i, l + i))) {
BlockPos.MutableBlockPos blockpos$mutableblockpos = new BlockPos.MutableBlockPos(); BlockPos blockpos$mutableblockpos = new BlockPos();
for (int k1 = -b0; k1 <= b0; ++k1) { for (int k1 = -b0; k1 <= b0; ++k1) {
for (int l1 = -b0; l1 <= b0; ++l1) { for (int l1 = -b0; l1 <= b0; ++l1) {

View File

@ -243,10 +243,11 @@ public class BlockVine extends Block {
int i = 5; int i = 5;
boolean flag = false; boolean flag = false;
BlockPos tmp = new BlockPos(0, 0, 0);
label62: for (int j = -b0; j <= b0; ++j) { label62: for (int j = -b0; j <= b0; ++j) {
for (int k = -b0; k <= b0; ++k) { for (int k = -b0; k <= b0; ++k) {
for (int l = -1; l <= 1; ++l) { for (int l = -1; l <= 1; ++l) {
if (world.getBlockState(blockpos.add(j, l, k)).getBlock() == this) { if (world.getBlockState(blockpos.add(j, l, k, tmp)).getBlock() == this) {
--i; --i;
if (i <= 0) { if (i <= 0) {
flag = true; flag = true;
@ -259,7 +260,6 @@ public class BlockVine extends Block {
EnumFacing enumfacing1 = EnumFacing.random(random); EnumFacing enumfacing1 = EnumFacing.random(random);
BlockPos blockpos2 = blockpos.up(); BlockPos blockpos2 = blockpos.up();
BlockPos tmp = new BlockPos(0, 0, 0);
if (enumfacing1 == EnumFacing.UP && blockpos.getY() < 255 && world.isAirBlock(blockpos2)) { if (enumfacing1 == EnumFacing.UP && blockpos.getY() < 255 && world.isAirBlock(blockpos2)) {
if (!flag) { if (!flag) {
IBlockState iblockstate3 = iblockstate; IBlockState iblockstate3 = iblockstate;
@ -285,7 +285,7 @@ public class BlockVine extends Block {
} else if (enumfacing1.getAxis().isHorizontal() } else if (enumfacing1.getAxis().isHorizontal()
&& !((Boolean) iblockstate.getValue(getPropertyFor(enumfacing1))).booleanValue()) { && !((Boolean) iblockstate.getValue(getPropertyFor(enumfacing1))).booleanValue()) {
if (!flag) { if (!flag) {
BlockPos blockpos4 = blockpos.offset(enumfacing1); BlockPos blockpos4 = blockpos.offsetEvenFaster(enumfacing1, blockpos2);
Block block1 = world.getBlockState(blockpos4).getBlock(); Block block1 = world.getBlockState(blockpos4).getBlock();
if (block1.blockMaterial == Material.air) { if (block1.blockMaterial == Material.air) {
EnumFacing enumfacing2 = enumfacing1.rotateY(); EnumFacing enumfacing2 = enumfacing1.rotateY();
@ -310,7 +310,7 @@ public class BlockVine extends Block {
world.getBlockState(blockpos.offsetEvenFaster(enumfacing4, tmp)).getBlock())) { world.getBlockState(blockpos.offsetEvenFaster(enumfacing4, tmp)).getBlock())) {
world.setBlockState(blockpos1, this.getDefaultState().withProperty( world.setBlockState(blockpos1, this.getDefaultState().withProperty(
getPropertyFor(enumfacing1.getOpposite()), Boolean.valueOf(true)), 2); getPropertyFor(enumfacing1.getOpposite()), Boolean.valueOf(true)), 2);
} else if (this.canPlaceOn(world.getBlockState(blockpos4.up()).getBlock())) { } else if (this.canPlaceOn(world.getBlockState(blockpos4.up(tmp)).getBlock())) {
world.setBlockState(blockpos4, this.getDefaultState(), 2); world.setBlockState(blockpos4, this.getDefaultState(), 2);
} }
} else if (block1.blockMaterial.isOpaque() && block1.isFullCube()) { } else if (block1.blockMaterial.isOpaque() && block1.isFullCube()) {
@ -321,7 +321,7 @@ public class BlockVine extends Block {
} }
} else { } else {
if (blockpos.getY() > 1) { if (blockpos.getY() > 1) {
BlockPos blockpos3 = blockpos.down(); BlockPos blockpos3 = blockpos.down(blockpos2);
IBlockState iblockstate1 = world.getBlockState(blockpos3); IBlockState iblockstate1 = world.getBlockState(blockpos3);
Block block = iblockstate1.getBlock(); Block block = iblockstate1.getBlock();
EnumFacing[] facings = EnumFacing.Plane.HORIZONTAL.facingsArray; EnumFacing[] facings = EnumFacing.Plane.HORIZONTAL.facingsArray;

View File

@ -1171,6 +1171,11 @@ public class Minecraft implements IThreadListener {
if (wasPaused != isGamePaused) { if (wasPaused != isGamePaused) {
SingleplayerServerController.setPaused(this.isGamePaused); SingleplayerServerController.setPaused(this.isGamePaused);
if (isGamePaused) {
mcSoundHandler.pauseSounds();
} else {
mcSoundHandler.resumeSounds();
}
wasPaused = isGamePaused; wasPaused = isGamePaused;
} }

View File

@ -31,7 +31,6 @@ public class GuardianSound extends MovingSound {
this.guardian = guardian; this.guardian = guardian;
this.attenuationType = ISound.AttenuationType.NONE; this.attenuationType = ISound.AttenuationType.NONE;
this.repeat = true; this.repeat = true;
this.repeatDelay = 0;
} }
/**+ /**+

View File

@ -27,8 +27,6 @@ public interface ISound {
boolean canRepeat(); boolean canRepeat();
int getRepeatDelay();
float getVolume(); float getVolume();
float getPitch(); float getPitch();

View File

@ -32,7 +32,6 @@ public class MovingSoundMinecart extends MovingSound {
super(new ResourceLocation("minecraft:minecart.base")); super(new ResourceLocation("minecraft:minecart.base"));
this.minecart = minecartIn; this.minecart = minecartIn;
this.repeat = true; this.repeat = true;
this.repeatDelay = 0;
} }
/**+ /**+
@ -54,7 +53,6 @@ public class MovingSoundMinecart extends MovingSound {
this.distance = 0.0F; this.distance = 0.0F;
this.volume = 0.0F; this.volume = 0.0F;
} }
} }
} }
} }

View File

@ -35,7 +35,6 @@ public class MovingSoundMinecartRiding extends MovingSound {
this.minecart = minecart; this.minecart = minecart;
this.attenuationType = ISound.AttenuationType.NONE; this.attenuationType = ISound.AttenuationType.NONE;
this.repeat = true; this.repeat = true;
this.repeatDelay = 0;
} }
/**+ /**+

View File

@ -30,10 +30,6 @@ public abstract class PositionedSound implements ISound {
protected float yPosF; protected float yPosF;
protected float zPosF; protected float zPosF;
protected boolean repeat = false; protected boolean repeat = false;
/**+
* The number of ticks between repeating the sound
*/
protected int repeatDelay = 0;
protected ISound.AttenuationType attenuationType = ISound.AttenuationType.LINEAR; protected ISound.AttenuationType attenuationType = ISound.AttenuationType.LINEAR;
protected PositionedSound(ResourceLocation soundResource) { protected PositionedSound(ResourceLocation soundResource) {
@ -48,10 +44,6 @@ public abstract class PositionedSound implements ISound {
return this.repeat; return this.repeat;
} }
public int getRepeatDelay() {
return this.repeatDelay;
}
public float getVolume() { public float getVolume() {
return this.volume; return this.volume;
} }

View File

@ -24,29 +24,28 @@ import net.minecraft.util.ResourceLocation;
*/ */
public class PositionedSoundRecord extends PositionedSound { public class PositionedSoundRecord extends PositionedSound {
public static PositionedSoundRecord create(ResourceLocation soundResource, float pitch) { public static PositionedSoundRecord create(ResourceLocation soundResource, float pitch) {
return new PositionedSoundRecord(soundResource, 0.25F, pitch, false, 0, ISound.AttenuationType.NONE, 0.0F, 0.0F, return new PositionedSoundRecord(soundResource, 0.25F, pitch, false, ISound.AttenuationType.NONE, 0.0F, 0.0F,
0.0F); 0.0F);
} }
public static PositionedSoundRecord create(ResourceLocation soundResource) { public static PositionedSoundRecord create(ResourceLocation soundResource) {
return new PositionedSoundRecord(soundResource, 1.0F, 1.0F, false, 0, ISound.AttenuationType.NONE, 0.0F, 0.0F, return new PositionedSoundRecord(soundResource, 1.0F, 1.0F, false, ISound.AttenuationType.NONE, 0.0F, 0.0F,
0.0F); 0.0F);
} }
public static PositionedSoundRecord create(ResourceLocation soundResource, float xPosition, float yPosition, public static PositionedSoundRecord create(ResourceLocation soundResource, float xPosition, float yPosition,
float zPosition) { float zPosition) {
return new PositionedSoundRecord(soundResource, 4.0F, 1.0F, false, 0, ISound.AttenuationType.LINEAR, xPosition, return new PositionedSoundRecord(soundResource, 4.0F, 1.0F, false, ISound.AttenuationType.LINEAR, xPosition,
yPosition, zPosition); yPosition, zPosition);
} }
public PositionedSoundRecord(ResourceLocation soundResource, float volume, float pitch, float xPosition, public PositionedSoundRecord(ResourceLocation soundResource, float volume, float pitch, float xPosition,
float yPosition, float zPosition) { float yPosition, float zPosition) {
this(soundResource, volume, pitch, false, 0, ISound.AttenuationType.LINEAR, xPosition, yPosition, zPosition); this(soundResource, volume, pitch, false, ISound.AttenuationType.LINEAR, xPosition, yPosition, zPosition);
} }
private PositionedSoundRecord(ResourceLocation soundResource, float volume, float pitch, boolean repeat, private PositionedSoundRecord(ResourceLocation soundResource, float volume, float pitch, boolean repeat,
int repeatDelay, ISound.AttenuationType attenuationType, float xPosition, float yPosition, ISound.AttenuationType attenuationType, float xPosition, float yPosition, float zPosition) {
float zPosition) {
super(soundResource); super(soundResource);
this.volume = volume; this.volume = volume;
this.pitch = pitch; this.pitch = pitch;
@ -54,7 +53,6 @@ public class PositionedSoundRecord extends PositionedSound {
this.yPosF = yPosition; this.yPosF = yPosition;
this.zPosF = zPosition; this.zPosF = zPosition;
this.repeat = repeat; this.repeat = repeat;
this.repeatDelay = repeatDelay;
this.attenuationType = attenuationType; this.attenuationType = attenuationType;
} }
} }

View File

@ -281,7 +281,7 @@ public class WorldClient extends World {
ItemStack itemstack = this.mc.thePlayer.getHeldItem(); ItemStack itemstack = this.mc.thePlayer.getHeldItem();
boolean flag = this.mc.playerController.getCurrentGameType() == WorldSettings.GameType.CREATIVE boolean flag = this.mc.playerController.getCurrentGameType() == WorldSettings.GameType.CREATIVE
&& itemstack != null && Block.getBlockFromItem(itemstack.getItem()) == Blocks.barrier; && itemstack != null && Block.getBlockFromItem(itemstack.getItem()) == Blocks.barrier;
BlockPos.MutableBlockPos blockpos$mutableblockpos = new BlockPos.MutableBlockPos(); BlockPos blockpos$mutableblockpos = new BlockPos();
for (int i = 0; i < 1000; ++i) { for (int i = 0; i < 1000; ++i) {
int j = parInt1 + this.rand.nextInt(b0) - this.rand.nextInt(b0); int j = parInt1 + this.rand.nextInt(b0) - this.rand.nextInt(b0);

View File

@ -110,7 +110,7 @@ public class BlockModelRenderer {
float[] afloat = isDeferred ? new float[EnumFacing._VALUES.length * 2] : null; float[] afloat = isDeferred ? new float[EnumFacing._VALUES.length * 2] : null;
BitSet bitset = new BitSet(3); BitSet bitset = new BitSet(3);
BlockPos.MutableBlockPos pointer = new BlockPos.MutableBlockPos(); BlockPos pointer = new BlockPos();
EnumFacing[] facings = EnumFacing._VALUES; EnumFacing[] facings = EnumFacing._VALUES;
for (int m = 0; m < facings.length; ++m) { for (int m = 0; m < facings.length; ++m) {
EnumFacing enumfacing = facings[m]; EnumFacing enumfacing = facings[m];

View File

@ -1496,7 +1496,7 @@ public class EntityRenderer implements IResourceManagerReloadListener {
float f1 = (float) this.rendererUpdateCount + partialTicks; float f1 = (float) this.rendererUpdateCount + partialTicks;
worldrenderer.setTranslation(-d0, -d1, -d2); worldrenderer.setTranslation(-d0, -d1, -d2);
GlStateManager.color(1.0F, 1.0F, 1.0F, 1.0F); GlStateManager.color(1.0F, 1.0F, 1.0F, 1.0F);
BlockPos.MutableBlockPos blockpos$mutableblockpos = new BlockPos.MutableBlockPos(); BlockPos blockpos$mutableblockpos = new BlockPos();
for (int i1 = k - b0; i1 <= k + b0; ++i1) { for (int i1 = k - b0; i1 <= k + b0; ++i1) {
for (int j1 = i - b0; j1 <= i + b0; ++j1) { for (int j1 = i - b0; j1 <= i + b0; ++j1) {

View File

@ -988,8 +988,7 @@ public class RenderGlobal implements IWorldAccess, IResourceManagerReloadListene
BlockPos blockpos = new BlockPos(pos.getX() >> 4 << 4, pos.getY() >> 4 << 4, pos.getZ() >> 4 << 4); BlockPos blockpos = new BlockPos(pos.getX() >> 4 << 4, pos.getY() >> 4 << 4, pos.getZ() >> 4 << 4);
Chunk chunk = this.theWorld.getChunkFromBlockCoords(blockpos); Chunk chunk = this.theWorld.getChunkFromBlockCoords(blockpos);
for (BlockPos.MutableBlockPos blockpos$mutableblockpos : BlockPos.getAllInBoxMutable(blockpos, for (BlockPos blockpos$mutableblockpos : BlockPos.getAllInBoxMutable(blockpos, blockpos.add(15, 15, 15))) {
blockpos.add(15, 15, 15))) {
if (chunk.getBlock(blockpos$mutableblockpos).isOpaqueCube()) { if (chunk.getBlock(blockpos$mutableblockpos).isOpaqueCube()) {
visgraph.func_178606_a(blockpos$mutableblockpos); visgraph.func_178606_a(blockpos$mutableblockpos);
} }

View File

@ -151,7 +151,7 @@ public class RenderChunk {
boolean[] aboolean = new boolean[EnumWorldBlockLayer._VALUES.length]; boolean[] aboolean = new boolean[EnumWorldBlockLayer._VALUES.length];
BlockRendererDispatcher blockrendererdispatcher = Minecraft.getMinecraft().getBlockRendererDispatcher(); BlockRendererDispatcher blockrendererdispatcher = Minecraft.getMinecraft().getBlockRendererDispatcher();
for (BlockPos blockpos$mutableblockpos : BlockPos.getAllInBox(blockpos, blockpos1)) { for (BlockPos blockpos$mutableblockpos : BlockPos.getAllInBoxMutable(blockpos, blockpos1)) {
IBlockState iblockstate = regionrendercache.getBlockStateFaster(blockpos$mutableblockpos); IBlockState iblockstate = regionrendercache.getBlockStateFaster(blockpos$mutableblockpos);
Block block = iblockstate.getBlock(); Block block = iblockstate.getBlock();
if (block.isOpaqueCube()) { if (block.isOpaqueCube()) {

View File

@ -83,8 +83,8 @@ public class CommandCompare extends CommandBase {
BlockPos blockpos3 = new BlockPos(structureboundingbox1.minX - structureboundingbox.minX, BlockPos blockpos3 = new BlockPos(structureboundingbox1.minX - structureboundingbox.minX,
structureboundingbox1.minY - structureboundingbox.minY, structureboundingbox1.minY - structureboundingbox.minY,
structureboundingbox1.minZ - structureboundingbox.minZ); structureboundingbox1.minZ - structureboundingbox.minZ);
BlockPos.MutableBlockPos blockpos$mutableblockpos = new BlockPos.MutableBlockPos(); BlockPos blockpos$mutableblockpos = new BlockPos();
BlockPos.MutableBlockPos blockpos$mutableblockpos1 = new BlockPos.MutableBlockPos(); BlockPos blockpos$mutableblockpos1 = new BlockPos();
for (int j = structureboundingbox.minZ; j <= structureboundingbox.maxZ; ++j) { for (int j = structureboundingbox.minZ; j <= structureboundingbox.maxZ; ++j) {
for (int k = structureboundingbox.minY; k <= structureboundingbox.maxY; ++k) { for (int k = structureboundingbox.minY; k <= structureboundingbox.maxY; ++k) {

View File

@ -1514,8 +1514,7 @@ public abstract class Entity implements ICommandSender {
if (this.noClip) { if (this.noClip) {
return false; return false;
} else { } else {
BlockPos.MutableBlockPos blockpos$mutableblockpos = new BlockPos.MutableBlockPos(Integer.MIN_VALUE, BlockPos blockpos$mutableblockpos = new BlockPos(Integer.MIN_VALUE, Integer.MIN_VALUE, Integer.MIN_VALUE);
Integer.MIN_VALUE, Integer.MIN_VALUE);
for (int i = 0; i < 8; ++i) { for (int i = 0; i < 8; ++i) {
int j = MathHelper.floor_double( int j = MathHelper.floor_double(

View File

@ -656,7 +656,7 @@ public class EntityZombie extends EntityMob {
int i = 1; int i = 1;
if (this.rand.nextFloat() < 0.01F) { if (this.rand.nextFloat() < 0.01F) {
int j = 0; int j = 0;
BlockPos.MutableBlockPos blockpos$mutableblockpos = new BlockPos.MutableBlockPos(); BlockPos blockpos$mutableblockpos = new BlockPos();
for (int k = (int) this.posX - 4; k < (int) this.posX + 4 && j < 14; ++k) { for (int k = (int) this.posX - 4; k < (int) this.posX + 4 && j < 14; ++k) {
for (int l = (int) this.posY - 4; l < (int) this.posY + 4 && j < 14; ++l) { for (int l = (int) this.posY - 4; l < (int) this.posY + 4 && j < 14; ++l) {

View File

@ -126,7 +126,7 @@ public class ItemMap extends ItemMapBase {
d1 = 100.0D; d1 = 100.0D;
} else { } else {
BlockPos.MutableBlockPos blockpos$mutableblockpos = new BlockPos.MutableBlockPos(); BlockPos blockpos$mutableblockpos = new BlockPos();
for (int i4 = 0; i4 < i; ++i4) { for (int i4 = 0; i4 < i; ++i4) {
for (int j4 = 0; j4 < i; ++j4) { for (int j4 = 0; j4 < i; ++j4) {

View File

@ -217,7 +217,7 @@ public class PathNavigateGround extends PathNavigate {
*/ */
private boolean isPositionClear(int parInt1, int parInt2, int parInt3, int parInt4, int parInt5, int parInt6, private boolean isPositionClear(int parInt1, int parInt2, int parInt3, int parInt4, int parInt5, int parInt6,
Vec3 parVec3_1, double parDouble1, double parDouble2) { Vec3 parVec3_1, double parDouble1, double parDouble2) {
for (BlockPos blockpos : BlockPos.getAllInBox(new BlockPos(parInt1, parInt2, parInt3), for (BlockPos blockpos : BlockPos.getAllInBoxMutable(new BlockPos(parInt1, parInt2, parInt3),
new BlockPos(parInt1 + parInt4 - 1, parInt2 + parInt5 - 1, parInt3 + parInt6 - 1))) { new BlockPos(parInt1 + parInt4 - 1, parInt2 + parInt5 - 1, parInt3 + parInt6 - 1))) {
double d0 = (double) blockpos.getX() + 0.5D - parVec3_1.xCoord; double d0 = (double) blockpos.getX() + 0.5D - parVec3_1.xCoord;
double d1 = (double) blockpos.getZ() + 0.5D - parVec3_1.zCoord; double d1 = (double) blockpos.getZ() + 0.5D - parVec3_1.zCoord;

View File

@ -2,7 +2,6 @@ package net.minecraft.stats;
import com.google.common.collect.Maps; import com.google.common.collect.Maps;
import com.google.common.collect.Sets; import com.google.common.collect.Sets;
import java.lang.reflect.Constructor;
import java.util.HashMap; import java.util.HashMap;
import java.util.HashSet; import java.util.HashSet;
import java.util.Map; import java.util.Map;

View File

@ -125,7 +125,7 @@ public class TileEntityBeacon extends TileEntityLockable implements ITickable, I
EntitySheep.func_175513_a(EnumDyeColor.WHITE)); EntitySheep.func_175513_a(EnumDyeColor.WHITE));
this.beamSegments.add(tileentitybeacon$beamsegment); this.beamSegments.add(tileentitybeacon$beamsegment);
boolean flag = true; boolean flag = true;
BlockPos.MutableBlockPos blockpos$mutableblockpos = new BlockPos.MutableBlockPos(); BlockPos blockpos$mutableblockpos = new BlockPos();
for (int i1 = k + 1; i1 < 256; ++i1) { for (int i1 = k + 1; i1 < 256; ++i1) {
IBlockState iblockstate = this.worldObj.getBlockState(blockpos$mutableblockpos.func_181079_c(j, i1, l)); IBlockState iblockstate = this.worldObj.getBlockState(blockpos$mutableblockpos.func_181079_c(j, i1, l));

View File

@ -40,6 +40,10 @@ public class BlockPos extends Vec3i {
private static final long Y_MASK = (1L << NUM_Y_BITS) - 1L; private static final long Y_MASK = (1L << NUM_Y_BITS) - 1L;
private static final long Z_MASK = (1L << NUM_Z_BITS) - 1L; private static final long Z_MASK = (1L << NUM_Z_BITS) - 1L;
public BlockPos() {
super(0, 0, 0);
}
public BlockPos(int x, int y, int z) { public BlockPos(int x, int y, int z) {
super(x, y, z); super(x, y, z);
} }
@ -65,30 +69,43 @@ public class BlockPos extends Vec3i {
*/ */
public BlockPos add(double x, double y, double z) { public BlockPos add(double x, double y, double z) {
return x == 0.0D && y == 0.0D && z == 0.0D ? this return x == 0.0D && y == 0.0D && z == 0.0D ? this
: new BlockPos((double) this.getX() + x, (double) this.getY() + y, (double) this.getZ() + z); : new BlockPos((double) this.x + x, (double) this.y + y, (double) this.z + z);
} }
/**+ /**+
* Add the given coordinates to the coordinates of this BlockPos * Add the given coordinates to the coordinates of this BlockPos
*/ */
public BlockPos add(int x, int y, int z) { public BlockPos add(int x, int y, int z) {
return x == 0 && y == 0 && z == 0 ? this : new BlockPos(this.getX() + x, this.getY() + y, this.getZ() + z); return x == 0 && y == 0 && z == 0 ? this : new BlockPos(this.x + x, this.y + y, this.z + z);
}
/**
* eagler
*/
/**+
* Add the given coordinates to the coordinates of this BlockPos
*/
public BlockPos add(int x, int y, int z, BlockPos dst) {
dst.x = this.x + x;
dst.y = this.y + y;
dst.z = this.z + z;
return dst;
} }
/**+ /**+
* Add the given coordinates to the coordinates of this BlockPos * Add the given coordinates to the coordinates of this BlockPos
*/ */
public BlockPos add(Vec3i vec) { public BlockPos add(Vec3i vec) {
return vec.getX() == 0 && vec.getY() == 0 && vec.getZ() == 0 ? this return vec.x == 0 && vec.y == 0 && vec.z == 0 ? this
: new BlockPos(this.getX() + vec.getX(), this.getY() + vec.getY(), this.getZ() + vec.getZ()); : new BlockPos(this.x + vec.x, this.y + vec.y, this.z + vec.z);
} }
/**+ /**+
* Subtract the given Vector from this BlockPos * Subtract the given Vector from this BlockPos
*/ */
public BlockPos subtract(Vec3i vec) { public BlockPos subtract(Vec3i vec) {
return vec.getX() == 0 && vec.getY() == 0 && vec.getZ() == 0 ? this return vec.x == 0 && vec.y == 0 && vec.z == 0 ? this
: new BlockPos(this.getX() - vec.getX(), this.getY() - vec.getY(), this.getZ() - vec.getZ()); : new BlockPos(this.x - vec.x, this.y - vec.y, this.z - vec.z);
} }
/**+ /**+
@ -261,9 +278,9 @@ public class BlockPos extends Vec3i {
} }
public BlockPos offsetFaster(EnumFacing facing, BlockPos ret) { public BlockPos offsetFaster(EnumFacing facing, BlockPos ret) {
ret.x = this.getX() + facing.getFrontOffsetX(); ret.x = this.x + facing.getFrontOffsetX();
ret.y = this.getY() + facing.getFrontOffsetY(); ret.y = this.y + facing.getFrontOffsetY();
ret.z = this.getZ() + facing.getFrontOffsetZ(); ret.z = this.z + facing.getFrontOffsetZ();
return ret; return ret;
} }
@ -290,17 +307,16 @@ public class BlockPos extends Vec3i {
* Calculate the cross product of this and the given Vector * Calculate the cross product of this and the given Vector
*/ */
public BlockPos crossProduct(Vec3i vec3i) { public BlockPos crossProduct(Vec3i vec3i) {
return new BlockPos(this.getY() * vec3i.getZ() - this.getZ() * vec3i.getY(), return new BlockPos(this.y * vec3i.z - this.z * vec3i.y, this.z * vec3i.x - this.x * vec3i.z,
this.getZ() * vec3i.getX() - this.getX() * vec3i.getZ(), this.x * vec3i.y - this.y * vec3i.x);
this.getX() * vec3i.getY() - this.getY() * vec3i.getX());
} }
/**+ /**+
* Serialize this BlockPos into a long value * Serialize this BlockPos into a long value
*/ */
public long toLong() { public long toLong() {
return ((long) this.getX() & X_MASK) << X_SHIFT | ((long) this.getY() & Y_MASK) << Y_SHIFT return ((long) this.x & X_MASK) << X_SHIFT | ((long) this.y & Y_MASK) << Y_SHIFT
| ((long) this.getZ() & Z_MASK) << 0; | ((long) this.z & Z_MASK) << 0;
} }
/**+ /**+
@ -319,10 +335,8 @@ public class BlockPos extends Vec3i {
* specified by the given corners * specified by the given corners
*/ */
public static Iterable<BlockPos> getAllInBox(BlockPos from, BlockPos to) { public static Iterable<BlockPos> getAllInBox(BlockPos from, BlockPos to) {
final BlockPos blockpos = new BlockPos(Math.min(from.getX(), to.getX()), Math.min(from.getY(), to.getY()), final BlockPos blockpos = new BlockPos(Math.min(from.x, to.x), Math.min(from.y, to.y), Math.min(from.z, to.z));
Math.min(from.getZ(), to.getZ())); final BlockPos blockpos1 = new BlockPos(Math.max(from.x, to.x), Math.max(from.y, to.y), Math.max(from.z, to.z));
final BlockPos blockpos1 = new BlockPos(Math.max(from.getX(), to.getX()), Math.max(from.getY(), to.getY()),
Math.max(from.getZ(), to.getZ()));
return new Iterable<BlockPos>() { return new Iterable<BlockPos>() {
public Iterator<BlockPos> iterator() { public Iterator<BlockPos> iterator() {
return new AbstractIterator<BlockPos>() { return new AbstractIterator<BlockPos>() {
@ -335,17 +349,17 @@ public class BlockPos extends Vec3i {
} else if (this.lastReturned.equals(blockpos1)) { } else if (this.lastReturned.equals(blockpos1)) {
return (BlockPos) this.endOfData(); return (BlockPos) this.endOfData();
} else { } else {
int i = this.lastReturned.getX(); int i = this.lastReturned.x;
int j = this.lastReturned.getY(); int j = this.lastReturned.y;
int k = this.lastReturned.getZ(); int k = this.lastReturned.z;
if (i < blockpos1.getX()) { if (i < blockpos1.x) {
++i; ++i;
} else if (j < blockpos1.getY()) { } else if (j < blockpos1.y) {
i = blockpos.getX(); i = blockpos.x;
++j; ++j;
} else if (k < blockpos1.getZ()) { } else if (k < blockpos1.z) {
i = blockpos.getX(); i = blockpos.x;
j = blockpos.getY(); j = blockpos.y;
++k; ++k;
} }
@ -363,35 +377,32 @@ public class BlockPos extends Vec3i {
* If this method is used, the resulting BlockPos instances can * If this method is used, the resulting BlockPos instances can
* only be used inside the iteration loop. * only be used inside the iteration loop.
*/ */
public static Iterable<BlockPos.MutableBlockPos> getAllInBoxMutable(BlockPos from, BlockPos to) { public static Iterable<BlockPos> getAllInBoxMutable(BlockPos from, BlockPos to) {
final BlockPos blockpos = new BlockPos(Math.min(from.getX(), to.getX()), Math.min(from.getY(), to.getY()), final BlockPos blockpos = new BlockPos(Math.min(from.x, to.x), Math.min(from.y, to.y), Math.min(from.z, to.z));
Math.min(from.getZ(), to.getZ())); final BlockPos blockpos1 = new BlockPos(Math.max(from.x, to.x), Math.max(from.y, to.y), Math.max(from.z, to.z));
final BlockPos blockpos1 = new BlockPos(Math.max(from.getX(), to.getX()), Math.max(from.getY(), to.getY()), return new Iterable<BlockPos>() {
Math.max(from.getZ(), to.getZ())); public Iterator<BlockPos> iterator() {
return new Iterable<BlockPos.MutableBlockPos>() { return new AbstractIterator<BlockPos>() {
public Iterator<BlockPos.MutableBlockPos> iterator() { private BlockPos theBlockPos = null;
return new AbstractIterator<BlockPos.MutableBlockPos>() {
private BlockPos.MutableBlockPos theBlockPos = null;
protected BlockPos.MutableBlockPos computeNext() { protected BlockPos computeNext() {
if (this.theBlockPos == null) { if (this.theBlockPos == null) {
this.theBlockPos = new BlockPos.MutableBlockPos(blockpos.getX(), blockpos.getY(), this.theBlockPos = new BlockPos(blockpos.x, blockpos.y, blockpos.z);
blockpos.getZ());
return this.theBlockPos; return this.theBlockPos;
} else if (this.theBlockPos.equals(blockpos1)) { } else if (this.theBlockPos.equals(blockpos1)) {
return (BlockPos.MutableBlockPos) this.endOfData(); return (BlockPos) this.endOfData();
} else { } else {
int i = this.theBlockPos.getX(); int i = this.theBlockPos.x;
int j = this.theBlockPos.getY(); int j = this.theBlockPos.y;
int k = this.theBlockPos.getZ(); int k = this.theBlockPos.z;
if (i < blockpos1.getX()) { if (i < blockpos1.x) {
++i; ++i;
} else if (j < blockpos1.getY()) { } else if (j < blockpos1.y) {
i = blockpos.getX(); i = blockpos.x;
++j; ++j;
} else if (k < blockpos1.getZ()) { } else if (k < blockpos1.z) {
i = blockpos.getX(); i = blockpos.x;
j = blockpos.getY(); j = blockpos.y;
++k; ++k;
} }
@ -406,33 +417,11 @@ public class BlockPos extends Vec3i {
}; };
} }
public static final class MutableBlockPos extends BlockPos { public BlockPos func_181079_c(int x, int y, int z) {
this.x = x;
public MutableBlockPos() { this.y = y;
this(0, 0, 0); this.z = z;
} return this;
public MutableBlockPos(int x_, int y_, int z_) {
super(x_, y_, z_);
}
public int getX() {
return this.x;
}
public int getY() {
return this.y;
}
public int getZ() {
return this.z;
}
public BlockPos.MutableBlockPos func_181079_c(int parInt1, int parInt2, int parInt3) {
this.x = parInt1;
this.y = parInt2;
this.z = parInt3;
return this;
}
} }
} }

View File

@ -233,6 +233,9 @@ public interface IChatComponent extends Iterable<IChatComponent> {
* So sorry for this implementation * So sorry for this implementation
*/ */
public static String componentToJson(IChatComponent component) { public static String componentToJson(IChatComponent component) {
if (component == null) {
return "null";
}
if ((component instanceof ChatComponentText) && component.getChatStyle().isEmpty() if ((component instanceof ChatComponentText) && component.getChatStyle().isEmpty()
&& component.getSiblings().isEmpty()) { && component.getSiblings().isEmpty()) {
String escaped = new JSONObject().put("E", component.getUnformattedTextForChat()).toString(); String escaped = new JSONObject().put("E", component.getUnformattedTextForChat()).toString();

View File

@ -203,7 +203,7 @@ public class Teleporter {
int j1 = k; int j1 = k;
int k1 = 0; int k1 = 0;
int l1 = this.random.nextInt(4); int l1 = this.random.nextInt(4);
BlockPos.MutableBlockPos blockpos$mutableblockpos = new BlockPos.MutableBlockPos(); BlockPos blockpos$mutableblockpos = new BlockPos();
for (int i2 = i - b0; i2 <= i + b0; ++i2) { for (int i2 = i - b0; i2 <= i + b0; ++i2) {
double d1 = (double) i2 + 0.5D - parEntity.posX; double d1 = (double) i2 + 0.5D - parEntity.posX;

View File

@ -524,11 +524,12 @@ public abstract class World implements IBlockAccess {
public int getLight(BlockPos pos, boolean checkNeighbors) { public int getLight(BlockPos pos, boolean checkNeighbors) {
if (pos.getX() >= -30000000 && pos.getZ() >= -30000000 && pos.getX() < 30000000 && pos.getZ() < 30000000) { if (pos.getX() >= -30000000 && pos.getZ() >= -30000000 && pos.getX() < 30000000 && pos.getZ() < 30000000) {
if (checkNeighbors && this.getBlockState(pos).getBlock().getUseNeighborBrightness()) { if (checkNeighbors && this.getBlockState(pos).getBlock().getUseNeighborBrightness()) {
int i1 = this.getLight(pos.up(), false); BlockPos tmp = new BlockPos(0, 0, 0);
int i = this.getLight(pos.east(), false); int i1 = this.getLight(pos.up(tmp), false);
int j = this.getLight(pos.west(), false); int i = this.getLight(pos.east(tmp), false);
int k = this.getLight(pos.south(), false); int j = this.getLight(pos.west(tmp), false);
int l = this.getLight(pos.north(), false); int k = this.getLight(pos.south(tmp), false);
int l = this.getLight(pos.north(tmp), false);
if (i > i1) { if (i > i1) {
i1 = i; i1 = i;
} }
@ -610,11 +611,12 @@ public abstract class World implements IBlockAccess {
} else if (!this.isBlockLoaded(pos)) { } else if (!this.isBlockLoaded(pos)) {
return type.defaultLightValue; return type.defaultLightValue;
} else if (this.getBlockState(pos).getBlock().getUseNeighborBrightness()) { } else if (this.getBlockState(pos).getBlock().getUseNeighborBrightness()) {
int i1 = this.getLightFor(type, pos.up()); BlockPos tmp = new BlockPos();
int i = this.getLightFor(type, pos.east()); int i1 = this.getLightFor(type, pos.up(tmp));
int j = this.getLightFor(type, pos.west()); int i = this.getLightFor(type, pos.east(tmp));
int k = this.getLightFor(type, pos.south()); int j = this.getLightFor(type, pos.west(tmp));
int l = this.getLightFor(type, pos.north()); int k = this.getLightFor(type, pos.south(tmp));
int l = this.getLightFor(type, pos.north(tmp));
if (i > i1) { if (i > i1) {
i1 = i; i1 = i;
} }
@ -1060,7 +1062,7 @@ public abstract class World implements IBlockAccess {
boolean flag = entityIn.isOutsideBorder(); boolean flag = entityIn.isOutsideBorder();
boolean flag1 = this.isInsideBorder(worldborder, entityIn); boolean flag1 = this.isInsideBorder(worldborder, entityIn);
IBlockState iblockstate = Blocks.stone.getDefaultState(); IBlockState iblockstate = Blocks.stone.getDefaultState();
BlockPos.MutableBlockPos blockpos$mutableblockpos = new BlockPos.MutableBlockPos(); BlockPos blockpos$mutableblockpos = new BlockPos();
for (int k1 = i; k1 < j; ++k1) { for (int k1 = i; k1 < j; ++k1) {
for (int l1 = i1; l1 < j1; ++l1) { for (int l1 = i1; l1 < j1; ++l1) {
@ -1133,7 +1135,7 @@ public abstract class World implements IBlockAccess {
int l = MathHelper.floor_double(bb.maxY + 1.0D); int l = MathHelper.floor_double(bb.maxY + 1.0D);
int i1 = MathHelper.floor_double(bb.minZ); int i1 = MathHelper.floor_double(bb.minZ);
int j1 = MathHelper.floor_double(bb.maxZ + 1.0D); int j1 = MathHelper.floor_double(bb.maxZ + 1.0D);
BlockPos.MutableBlockPos blockpos$mutableblockpos = new BlockPos.MutableBlockPos(); BlockPos blockpos$mutableblockpos = new BlockPos();
for (int k1 = i; k1 < j; ++k1) { for (int k1 = i; k1 < j; ++k1) {
for (int l1 = i1; l1 < j1; ++l1) { for (int l1 = i1; l1 < j1; ++l1) {
@ -1628,7 +1630,7 @@ public abstract class World implements IBlockAccess {
int l = MathHelper.floor_double(bb.maxY); int l = MathHelper.floor_double(bb.maxY);
int i1 = MathHelper.floor_double(bb.minZ); int i1 = MathHelper.floor_double(bb.minZ);
int j1 = MathHelper.floor_double(bb.maxZ); int j1 = MathHelper.floor_double(bb.maxZ);
BlockPos.MutableBlockPos blockpos$mutableblockpos = new BlockPos.MutableBlockPos(); BlockPos blockpos$mutableblockpos = new BlockPos();
for (int k1 = i; k1 <= j; ++k1) { for (int k1 = i; k1 <= j; ++k1) {
for (int l1 = k; l1 <= l; ++l1) { for (int l1 = k; l1 <= l; ++l1) {
@ -1655,7 +1657,7 @@ public abstract class World implements IBlockAccess {
int l = MathHelper.floor_double(bb.maxY); int l = MathHelper.floor_double(bb.maxY);
int i1 = MathHelper.floor_double(bb.minZ); int i1 = MathHelper.floor_double(bb.minZ);
int j1 = MathHelper.floor_double(bb.maxZ); int j1 = MathHelper.floor_double(bb.maxZ);
BlockPos.MutableBlockPos blockpos$mutableblockpos = new BlockPos.MutableBlockPos(); BlockPos blockpos$mutableblockpos = new BlockPos();
for (int k1 = i; k1 <= j; ++k1) { for (int k1 = i; k1 <= j; ++k1) {
for (int l1 = k; l1 <= l; ++l1) { for (int l1 = k; l1 <= l; ++l1) {
@ -1679,7 +1681,7 @@ public abstract class World implements IBlockAccess {
int i1 = MathHelper.floor_double(bb.minZ); int i1 = MathHelper.floor_double(bb.minZ);
int j1 = MathHelper.floor_double(bb.maxZ + 1.0D); int j1 = MathHelper.floor_double(bb.maxZ + 1.0D);
if (this.isAreaLoaded(i, k, i1, j, l, j1, true)) { if (this.isAreaLoaded(i, k, i1, j, l, j1, true)) {
BlockPos.MutableBlockPos blockpos$mutableblockpos = new BlockPos.MutableBlockPos(); BlockPos blockpos$mutableblockpos = new BlockPos();
for (int k1 = i; k1 < j; ++k1) { for (int k1 = i; k1 < j; ++k1) {
for (int l1 = k; l1 < l; ++l1) { for (int l1 = k; l1 < l; ++l1) {
@ -1712,7 +1714,7 @@ public abstract class World implements IBlockAccess {
} else { } else {
boolean flag = false; boolean flag = false;
Vec3 vec3 = new Vec3(0.0D, 0.0D, 0.0D); Vec3 vec3 = new Vec3(0.0D, 0.0D, 0.0D);
BlockPos.MutableBlockPos blockpos$mutableblockpos = new BlockPos.MutableBlockPos(); BlockPos blockpos$mutableblockpos = new BlockPos();
for (int k1 = i; k1 < j; ++k1) { for (int k1 = i; k1 < j; ++k1) {
for (int l1 = k; l1 < l; ++l1) { for (int l1 = k; l1 < l; ++l1) {
@ -1755,7 +1757,7 @@ public abstract class World implements IBlockAccess {
int l = MathHelper.floor_double(bb.maxY + 1.0D); int l = MathHelper.floor_double(bb.maxY + 1.0D);
int i1 = MathHelper.floor_double(bb.minZ); int i1 = MathHelper.floor_double(bb.minZ);
int j1 = MathHelper.floor_double(bb.maxZ + 1.0D); int j1 = MathHelper.floor_double(bb.maxZ + 1.0D);
BlockPos.MutableBlockPos blockpos$mutableblockpos = new BlockPos.MutableBlockPos(); BlockPos blockpos$mutableblockpos = new BlockPos();
for (int k1 = i; k1 < j; ++k1) { for (int k1 = i; k1 < j; ++k1) {
for (int l1 = k; l1 < l; ++l1) { for (int l1 = k; l1 < l; ++l1) {
@ -1782,7 +1784,7 @@ public abstract class World implements IBlockAccess {
int l = MathHelper.floor_double(bb.maxY + 1.0D); int l = MathHelper.floor_double(bb.maxY + 1.0D);
int i1 = MathHelper.floor_double(bb.minZ); int i1 = MathHelper.floor_double(bb.minZ);
int j1 = MathHelper.floor_double(bb.maxZ + 1.0D); int j1 = MathHelper.floor_double(bb.maxZ + 1.0D);
BlockPos.MutableBlockPos blockpos$mutableblockpos = new BlockPos.MutableBlockPos(); BlockPos blockpos$mutableblockpos = new BlockPos();
for (int k1 = i; k1 < j; ++k1) { for (int k1 = i; k1 < j; ++k1) {
for (int l1 = k; l1 < l; ++l1) { for (int l1 = k; l1 < l; ++l1) {
@ -2210,8 +2212,9 @@ public abstract class World implements IBlockAccess {
return true; return true;
} }
boolean flag = this.isWater(pos.west()) && this.isWater(pos.east()) && this.isWater(pos.north()) BlockPos tmp = new BlockPos();
&& this.isWater(pos.south()); boolean flag = this.isWater(pos.west(tmp)) && this.isWater(pos.east(tmp))
&& this.isWater(pos.north(tmp)) && this.isWater(pos.south(tmp));
if (!flag) { if (!flag) {
return true; return true;
} }
@ -2332,7 +2335,7 @@ public abstract class World implements IBlockAccess {
int k3 = MathHelper.abs_int(j2 - j1); int k3 = MathHelper.abs_int(j2 - j1);
int l3 = MathHelper.abs_int(k2 - k1); int l3 = MathHelper.abs_int(k2 - k1);
if (j3 + k3 + l3 < 17) { if (j3 + k3 + l3 < 17) {
BlockPos.MutableBlockPos blockpos$mutableblockpos = new BlockPos.MutableBlockPos(); BlockPos blockpos$mutableblockpos = new BlockPos();
EnumFacing[] facings = EnumFacing._VALUES; EnumFacing[] facings = EnumFacing._VALUES;
for (int m = 0; m < facings.length; ++m) { for (int m = 0; m < facings.length; ++m) {
@ -2363,6 +2366,7 @@ public abstract class World implements IBlockAccess {
int k5 = (i5 >> 6 & 63) - 32 + j1; int k5 = (i5 >> 6 & 63) - 32 + j1;
int l5 = (i5 >> 12 & 63) - 32 + k1; int l5 = (i5 >> 12 & 63) - 32 + k1;
BlockPos blockpos1 = new BlockPos(j5, k5, l5); BlockPos blockpos1 = new BlockPos(j5, k5, l5);
BlockPos tmp = new BlockPos(0, 0, 0);
int i6 = this.getLightFor(lightType, blockpos1); int i6 = this.getLightFor(lightType, blockpos1);
int j6 = this.getRawLight(blockpos1, lightType); int j6 = this.getRawLight(blockpos1, lightType);
if (j6 != i6) { if (j6 != i6) {
@ -2373,32 +2377,32 @@ public abstract class World implements IBlockAccess {
int i7 = Math.abs(l5 - k1); int i7 = Math.abs(l5 - k1);
boolean flag = j < this.lightUpdateBlockList.length - 6; boolean flag = j < this.lightUpdateBlockList.length - 6;
if (k6 + l6 + i7 < 17 && flag) { if (k6 + l6 + i7 < 17 && flag) {
if (this.getLightFor(lightType, blockpos1.west()) < j6) { if (this.getLightFor(lightType, blockpos1.west(tmp)) < j6) {
this.lightUpdateBlockList[j++] = j5 - 1 - i1 + 32 + (k5 - j1 + 32 << 6) this.lightUpdateBlockList[j++] = j5 - 1 - i1 + 32 + (k5 - j1 + 32 << 6)
+ (l5 - k1 + 32 << 12); + (l5 - k1 + 32 << 12);
} }
if (this.getLightFor(lightType, blockpos1.east()) < j6) { if (this.getLightFor(lightType, blockpos1.east(tmp)) < j6) {
this.lightUpdateBlockList[j++] = j5 + 1 - i1 + 32 + (k5 - j1 + 32 << 6) this.lightUpdateBlockList[j++] = j5 + 1 - i1 + 32 + (k5 - j1 + 32 << 6)
+ (l5 - k1 + 32 << 12); + (l5 - k1 + 32 << 12);
} }
if (this.getLightFor(lightType, blockpos1.down()) < j6) { if (this.getLightFor(lightType, blockpos1.down(tmp)) < j6) {
this.lightUpdateBlockList[j++] = j5 - i1 + 32 + (k5 - 1 - j1 + 32 << 6) this.lightUpdateBlockList[j++] = j5 - i1 + 32 + (k5 - 1 - j1 + 32 << 6)
+ (l5 - k1 + 32 << 12); + (l5 - k1 + 32 << 12);
} }
if (this.getLightFor(lightType, blockpos1.up()) < j6) { if (this.getLightFor(lightType, blockpos1.up(tmp)) < j6) {
this.lightUpdateBlockList[j++] = j5 - i1 + 32 + (k5 + 1 - j1 + 32 << 6) this.lightUpdateBlockList[j++] = j5 - i1 + 32 + (k5 + 1 - j1 + 32 << 6)
+ (l5 - k1 + 32 << 12); + (l5 - k1 + 32 << 12);
} }
if (this.getLightFor(lightType, blockpos1.north()) < j6) { if (this.getLightFor(lightType, blockpos1.north(tmp)) < j6) {
this.lightUpdateBlockList[j++] = j5 - i1 + 32 + (k5 - j1 + 32 << 6) this.lightUpdateBlockList[j++] = j5 - i1 + 32 + (k5 - j1 + 32 << 6)
+ (l5 - 1 - k1 + 32 << 12); + (l5 - 1 - k1 + 32 << 12);
} }
if (this.getLightFor(lightType, blockpos1.south()) < j6) { if (this.getLightFor(lightType, blockpos1.south(tmp)) < j6) {
this.lightUpdateBlockList[j++] = j5 - i1 + 32 + (k5 - j1 + 32 << 6) this.lightUpdateBlockList[j++] = j5 - i1 + 32 + (k5 - j1 + 32 << 6)
+ (l5 + 1 - k1 + 32 << 12); + (l5 + 1 - k1 + 32 << 12);
} }
@ -2617,27 +2621,28 @@ public abstract class World implements IBlockAccess {
*/ */
public int getStrongPower(BlockPos pos) { public int getStrongPower(BlockPos pos) {
int i = 0; int i = 0;
i = Math.max(i, this.getStrongPower(pos.down(), EnumFacing.DOWN)); BlockPos tmp = new BlockPos();
i = Math.max(i, this.getStrongPower(pos.down(tmp), EnumFacing.DOWN));
if (i >= 15) { if (i >= 15) {
return i; return i;
} else { } else {
i = Math.max(i, this.getStrongPower(pos.up(), EnumFacing.UP)); i = Math.max(i, this.getStrongPower(pos.up(tmp), EnumFacing.UP));
if (i >= 15) { if (i >= 15) {
return i; return i;
} else { } else {
i = Math.max(i, this.getStrongPower(pos.north(), EnumFacing.NORTH)); i = Math.max(i, this.getStrongPower(pos.north(tmp), EnumFacing.NORTH));
if (i >= 15) { if (i >= 15) {
return i; return i;
} else { } else {
i = Math.max(i, this.getStrongPower(pos.south(), EnumFacing.SOUTH)); i = Math.max(i, this.getStrongPower(pos.south(tmp), EnumFacing.SOUTH));
if (i >= 15) { if (i >= 15) {
return i; return i;
} else { } else {
i = Math.max(i, this.getStrongPower(pos.west(), EnumFacing.WEST)); i = Math.max(i, this.getStrongPower(pos.west(tmp), EnumFacing.WEST));
if (i >= 15) { if (i >= 15) {
return i; return i;
} else { } else {
i = Math.max(i, this.getStrongPower(pos.east(), EnumFacing.EAST)); i = Math.max(i, this.getStrongPower(pos.east(tmp), EnumFacing.EAST));
return i >= 15 ? i : i; return i >= 15 ? i : i;
} }
} }
@ -2657,12 +2662,13 @@ public abstract class World implements IBlockAccess {
} }
public boolean isBlockPowered(BlockPos pos) { public boolean isBlockPowered(BlockPos pos) {
return this.getRedstonePower(pos.down(), EnumFacing.DOWN) > 0 ? true BlockPos tmp = new BlockPos(0, 0, 0);
: (this.getRedstonePower(pos.up(), EnumFacing.UP) > 0 ? true return this.getRedstonePower(pos.down(tmp), EnumFacing.DOWN) > 0 ? true
: (this.getRedstonePower(pos.north(), EnumFacing.NORTH) > 0 ? true : (this.getRedstonePower(pos.up(tmp), EnumFacing.UP) > 0 ? true
: (this.getRedstonePower(pos.south(), EnumFacing.SOUTH) > 0 ? true : (this.getRedstonePower(pos.north(tmp), EnumFacing.NORTH) > 0 ? true
: (this.getRedstonePower(pos.west(), EnumFacing.WEST) > 0 ? true : (this.getRedstonePower(pos.south(tmp), EnumFacing.SOUTH) > 0 ? true
: this.getRedstonePower(pos.east(), EnumFacing.EAST) > 0)))); : (this.getRedstonePower(pos.west(tmp), EnumFacing.WEST) > 0 ? true
: this.getRedstonePower(pos.east(tmp), EnumFacing.EAST) > 0))));
} }
/**+ /**+

View File

@ -46,7 +46,7 @@ public class BiomeColorHelper {
int j = 0; int j = 0;
int k = 0; int k = 0;
for (BlockPos.MutableBlockPos blockpos$mutableblockpos : BlockPos.getAllInBoxMutable(parBlockPos.add(-1, 0, -1), for (BlockPos blockpos$mutableblockpos : BlockPos.getAllInBoxMutable(parBlockPos.add(-1, 0, -1),
parBlockPos.add(1, 0, 1))) { parBlockPos.add(1, 0, 1))) {
int l = parColorResolver.getColorAtPos(parIBlockAccess.getBiomeGenForCoords(blockpos$mutableblockpos), int l = parColorResolver.getColorAtPos(parIBlockAccess.getBiomeGenForCoords(blockpos$mutableblockpos),
blockpos$mutableblockpos); blockpos$mutableblockpos);

View File

@ -406,7 +406,7 @@ public abstract class BiomeGenBase {
int k = (int) (parDouble1 / 3.0D + 3.0D + rand.nextDouble() * 0.25D); int k = (int) (parDouble1 / 3.0D + 3.0D + rand.nextDouble() * 0.25D);
int l = parInt1 & 15; int l = parInt1 & 15;
int i1 = parInt2 & 15; int i1 = parInt2 & 15;
BlockPos.MutableBlockPos blockpos$mutableblockpos = new BlockPos.MutableBlockPos(); BlockPos blockpos$mutableblockpos = new BlockPos();
for (int j1 = 255; j1 >= 0; --j1) { for (int j1 = 255; j1 >= 0; --j1) {
if (j1 <= rand.nextInt(5)) { if (j1 <= rand.nextInt(5)) {

View File

@ -1290,8 +1290,7 @@ public class Chunk {
int i = this.getTopFilledSegment(); int i = this.getTopFilledSegment();
boolean flag = false; boolean flag = false;
boolean flag1 = false; boolean flag1 = false;
BlockPos.MutableBlockPos blockpos$mutableblockpos = new BlockPos.MutableBlockPos((this.xPosition << 4) + x, 0, BlockPos blockpos$mutableblockpos = new BlockPos((this.xPosition << 4) + x, 0, (this.zPosition << 4) + z);
(this.zPosition << 4) + z);
for (int j = i + 16 - 1; j > this.worldObj.func_181545_F() || j > 0 && !flag1; --j) { for (int j = i + 16 - 1; j > this.worldObj.func_181545_F() || j > 0 && !flag1; --j) {
blockpos$mutableblockpos.func_181079_c(blockpos$mutableblockpos.getX(), j, blockpos$mutableblockpos.getZ()); blockpos$mutableblockpos.func_181079_c(blockpos$mutableblockpos.getX(), j, blockpos$mutableblockpos.getZ());

View File

@ -113,7 +113,7 @@ public class ChunkLoader {
parNBTTagCompound.setTag("Sections", nbttaglist); parNBTTagCompound.setTag("Sections", nbttaglist);
byte[] abyte = new byte[256]; byte[] abyte = new byte[256];
BlockPos.MutableBlockPos blockpos$mutableblockpos = new BlockPos.MutableBlockPos(); BlockPos blockpos$mutableblockpos = new BlockPos();
for (int j2 = 0; j2 < 16; ++j2) { for (int j2 = 0; j2 < 16; ++j2) {
for (int k2 = 0; k2 < 16; ++k2) { for (int k2 = 0; k2 < 16; ++k2) {

View File

@ -157,7 +157,7 @@ public class MapGenCaves extends MapGenBase {
} }
if (!flag3) { if (!flag3) {
BlockPos.MutableBlockPos blockpos$mutableblockpos = new BlockPos.MutableBlockPos(); BlockPos blockpos$mutableblockpos = new BlockPos();
for (int j3 = k2; j3 < k; ++j3) { for (int j3 = k2; j3 < k; ++j3) {
double d10 = ((double) (j3 + parInt1 * 16) + 0.5D - parDouble1) / d2; double d10 = ((double) (j3 + parInt1 * 16) + 0.5D - parDouble1) / d2;

View File

@ -144,7 +144,7 @@ public class MapGenRavine extends MapGenBase {
} }
if (!flag2) { if (!flag2) {
BlockPos.MutableBlockPos blockpos$mutableblockpos = new BlockPos.MutableBlockPos(); BlockPos blockpos$mutableblockpos = new BlockPos();
for (int j3 = k2; j3 < k; ++j3) { for (int j3 = k2; j3 < k; ++j3) {
double d10 = ((double) (j3 + parInt1 * 16) + 0.5D - parDouble1) / d9; double d10 = ((double) (j3 + parInt1 * 16) + 0.5D - parDouble1) / d9;

View File

@ -54,7 +54,7 @@ public class WorldGenBigMushroom extends WorldGenerator {
b0 = 0; b0 = 0;
} }
BlockPos.MutableBlockPos blockpos$mutableblockpos = new BlockPos.MutableBlockPos(); BlockPos blockpos$mutableblockpos = new BlockPos();
for (int k = blockpos.getX() - b0; k <= blockpos.getX() + b0 && flag; ++k) { for (int k = blockpos.getX() - b0; k <= blockpos.getX() + b0 && flag; ++k) {
for (int l = blockpos.getZ() - b0; l <= blockpos.getZ() + b0 && flag; ++l) { for (int l = blockpos.getZ() - b0; l <= blockpos.getZ() + b0 && flag; ++l) {

View File

@ -205,7 +205,7 @@ public class WorldGenBigTree extends WorldGenAbstractTree {
*/ */
void generateLeaves() { void generateLeaves() {
for (int i = 0, l = this.field_175948_j.size(); i < l; ++i) { for (int i = 0, l = this.field_175948_j.size(); i < l; ++i) {
this.generateLeafNode(this.field_175948_j.get(i)); this.generateLeafNode(this.field_175948_j.get(i).blockPos);
} }
} }
@ -245,9 +245,9 @@ public class WorldGenBigTree extends WorldGenAbstractTree {
WorldGenBigTree.FoliageCoordinates worldgenbigtree$foliagecoordinates = this.field_175948_j.get(j); WorldGenBigTree.FoliageCoordinates worldgenbigtree$foliagecoordinates = this.field_175948_j.get(j);
int i = worldgenbigtree$foliagecoordinates.func_177999_q(); int i = worldgenbigtree$foliagecoordinates.func_177999_q();
BlockPos blockpos = new BlockPos(this.basePos.getX(), i, this.basePos.getZ()); BlockPos blockpos = new BlockPos(this.basePos.getX(), i, this.basePos.getZ());
if (!blockpos.equals(worldgenbigtree$foliagecoordinates) if (!blockpos.equals(worldgenbigtree$foliagecoordinates.blockPos)
&& this.leafNodeNeedsBase(i - this.basePos.getY())) { && this.leafNodeNeedsBase(i - this.basePos.getY())) {
this.func_175937_a(blockpos, worldgenbigtree$foliagecoordinates, Blocks.log); this.func_175937_a(blockpos, worldgenbigtree$foliagecoordinates.blockPos, Blocks.log);
} }
} }
@ -325,12 +325,13 @@ public class WorldGenBigTree extends WorldGenAbstractTree {
} }
} }
static class FoliageCoordinates extends BlockPos { static class FoliageCoordinates {
private final int field_178000_b; private final int field_178000_b;
private final BlockPos blockPos;
public FoliageCoordinates(BlockPos parBlockPos, int parInt1) { public FoliageCoordinates(BlockPos parBlockPos, int parInt1) {
super(parBlockPos.getX(), parBlockPos.getY(), parBlockPos.getZ());
this.field_178000_b = parInt1; this.field_178000_b = parInt1;
this.blockPos = parBlockPos;
} }
public int func_177999_q() { public int func_177999_q() {

View File

@ -62,7 +62,8 @@ public class WorldGenBlockBlob extends WorldGenerator {
int l = i1 + random.nextInt(2); int l = i1 + random.nextInt(2);
float f = (float) (j + k + l) * 0.333F + 0.5F; float f = (float) (j + k + l) * 0.333F + 0.5F;
for (BlockPos blockpos1 : BlockPos.getAllInBox(blockpos.add(-j, -k, -l), blockpos.add(j, k, l))) { for (BlockPos blockpos1 : BlockPos.getAllInBoxMutable(blockpos.add(-j, -k, -l),
blockpos.add(j, k, l))) {
if (blockpos1.distanceSq(blockpos) <= (double) (f * f)) { if (blockpos1.distanceSq(blockpos) <= (double) (f * f)) {
world.setBlockState(blockpos1, this.field_150545_a.getDefaultState(), 4); world.setBlockState(blockpos1, this.field_150545_a.getDefaultState(), 4);
} }

View File

@ -156,7 +156,7 @@ public class WorldGenCanopyTree extends WorldGenAbstractTree {
int i = parBlockPos.getX(); int i = parBlockPos.getX();
int j = parBlockPos.getY(); int j = parBlockPos.getY();
int k = parBlockPos.getZ(); int k = parBlockPos.getZ();
BlockPos.MutableBlockPos blockpos$mutableblockpos = new BlockPos.MutableBlockPos(); BlockPos blockpos$mutableblockpos = new BlockPos();
for (int l = 0; l <= parInt1 + 1; ++l) { for (int l = 0; l <= parInt1 + 1; ++l) {
byte b0 = 1; byte b0 = 1;

View File

@ -62,7 +62,7 @@ public class WorldGenForest extends WorldGenAbstractTree {
b0 = 2; b0 = 2;
} }
BlockPos.MutableBlockPos blockpos$mutableblockpos = new BlockPos.MutableBlockPos(); BlockPos blockpos$mutableblockpos = new BlockPos();
for (int k = blockpos.getX() - b0; k <= blockpos.getX() + b0 && flag; ++k) { for (int k = blockpos.getX() - b0; k <= blockpos.getX() + b0 && flag; ++k) {
for (int l = blockpos.getZ() - b0; l <= blockpos.getZ() + b0 && flag; ++l) { for (int l = blockpos.getZ() - b0; l <= blockpos.getZ() + b0 && flag; ++l) {

View File

@ -58,7 +58,7 @@ public class WorldGenSavannaTree extends WorldGenAbstractTree {
b0 = 2; b0 = 2;
} }
BlockPos.MutableBlockPos blockpos$mutableblockpos = new BlockPos.MutableBlockPos(); BlockPos blockpos$mutableblockpos = new BlockPos();
for (int k = blockpos.getX() - b0; k <= blockpos.getX() + b0 && flag; ++k) { for (int k = blockpos.getX() - b0; k <= blockpos.getX() + b0 && flag; ++k) {
for (int l = blockpos.getZ() - b0; l <= blockpos.getZ() + b0 && flag; ++l) { for (int l = blockpos.getZ() - b0; l <= blockpos.getZ() + b0 && flag; ++l) {

View File

@ -38,7 +38,7 @@ public class WorldGenSpikes extends WorldGenerator {
if (world.isAirBlock(blockpos) && world.getBlockState(blockpos.down()).getBlock() == this.baseBlockRequired) { if (world.isAirBlock(blockpos) && world.getBlockState(blockpos.down()).getBlock() == this.baseBlockRequired) {
int i = random.nextInt(32) + 6; int i = random.nextInt(32) + 6;
int j = random.nextInt(4) + 1; int j = random.nextInt(4) + 1;
BlockPos.MutableBlockPos blockpos$mutableblockpos = new BlockPos.MutableBlockPos(); BlockPos blockpos$mutableblockpos = new BlockPos();
for (int k = blockpos.getX() - j; k <= blockpos.getX() + j; ++k) { for (int k = blockpos.getX() - j; k <= blockpos.getX() + j; ++k) {
for (int l = blockpos.getZ() - j; l <= blockpos.getZ() + j; ++l) { for (int l = blockpos.getZ() - j; l <= blockpos.getZ() + j; ++l) {

View File

@ -63,7 +63,7 @@ public class WorldGenSwamp extends WorldGenAbstractTree {
b0 = 3; b0 = 3;
} }
BlockPos.MutableBlockPos blockpos$mutableblockpos = new BlockPos.MutableBlockPos(); BlockPos blockpos$mutableblockpos = new BlockPos();
for (int k = blockpos.getX() - b0; k <= blockpos.getX() + b0 && flag; ++k) { for (int k = blockpos.getX() - b0; k <= blockpos.getX() + b0 && flag; ++k) {
for (int l = blockpos.getZ() - b0; l <= blockpos.getZ() + b0 && flag; ++l) { for (int l = blockpos.getZ() - b0; l <= blockpos.getZ() + b0 && flag; ++l) {
@ -121,7 +121,7 @@ public class WorldGenSwamp extends WorldGenAbstractTree {
for (int i2 = blockpos.getY() - 3 + i; i2 <= blockpos.getY() + i; ++i2) { for (int i2 = blockpos.getY() - 3 + i; i2 <= blockpos.getY() + i; ++i2) {
int k2 = i2 - (blockpos.getY() + i); int k2 = i2 - (blockpos.getY() + i);
int i3 = 2 - k2 / 2; int i3 = 2 - k2 / 2;
BlockPos.MutableBlockPos blockpos$mutableblockpos1 = new BlockPos.MutableBlockPos(); BlockPos blockpos$mutableblockpos1 = new BlockPos();
for (int l3 = blockpos.getX() - i3; l3 <= blockpos.getX() + i3; ++l3) { for (int l3 = blockpos.getX() - i3; l3 <= blockpos.getX() + i3; ++l3) {
for (int i4 = blockpos.getZ() - i3; i4 <= blockpos.getZ() + i3; ++i4) { for (int i4 = blockpos.getZ() - i3; i4 <= blockpos.getZ() + i3; ++i4) {

View File

@ -58,7 +58,7 @@ public class WorldGenTaiga1 extends WorldGenAbstractTree {
j1 = l; j1 = l;
} }
BlockPos.MutableBlockPos blockpos$mutableblockpos = new BlockPos.MutableBlockPos(); BlockPos blockpos$mutableblockpos = new BlockPos();
for (int k1 = blockpos.getX() - j1; k1 <= blockpos.getX() + j1 && flag; ++k1) { for (int k1 = blockpos.getX() - j1; k1 <= blockpos.getX() + j1 && flag; ++k1) {
for (int l1 = blockpos.getZ() - j1; l1 <= blockpos.getZ() + j1 && flag; ++l1) { for (int l1 = blockpos.getZ() - j1; l1 <= blockpos.getZ() + j1 && flag; ++l1) {

View File

@ -58,7 +58,7 @@ public class WorldGenTaiga2 extends WorldGenAbstractTree {
j1 = l; j1 = l;
} }
BlockPos.MutableBlockPos blockpos$mutableblockpos = new BlockPos.MutableBlockPos(); BlockPos blockpos$mutableblockpos = new BlockPos();
for (int k1 = blockpos.getX() - j1; k1 <= blockpos.getX() + j1 && flag; ++k1) { for (int k1 = blockpos.getX() - j1; k1 <= blockpos.getX() + j1 && flag; ++k1) {
for (int l1 = blockpos.getZ() - j1; l1 <= blockpos.getZ() + j1 && flag; ++l1) { for (int l1 = blockpos.getZ() - j1; l1 <= blockpos.getZ() + j1 && flag; ++l1) {

View File

@ -74,7 +74,7 @@ public class WorldGenTrees extends WorldGenAbstractTree {
b0 = 2; b0 = 2;
} }
BlockPos.MutableBlockPos blockpos$mutableblockpos = new BlockPos.MutableBlockPos(); BlockPos blockpos$mutableblockpos = new BlockPos();
for (int k = blockpos.getX() - b0; k <= blockpos.getX() + b0 && flag; ++k) { for (int k = blockpos.getX() - b0; k <= blockpos.getX() + b0 && flag; ++k) {
for (int l = blockpos.getZ() - b0; l <= blockpos.getZ() + b0 && flag; ++l) { for (int l = blockpos.getZ() - b0; l <= blockpos.getZ() + b0 && flag; ++l) {
@ -150,7 +150,7 @@ public class WorldGenTrees extends WorldGenAbstractTree {
for (int l2 = blockpos.getY() - 3 + i; l2 <= blockpos.getY() + i; ++l2) { for (int l2 = blockpos.getY() - 3 + i; l2 <= blockpos.getY() + i; ++l2) {
int k3 = l2 - (blockpos.getY() + i); int k3 = l2 - (blockpos.getY() + i);
int l3 = 2 - k3 / 2; int l3 = 2 - k3 / 2;
BlockPos.MutableBlockPos blockpos$mutableblockpos1 = new BlockPos.MutableBlockPos(); BlockPos blockpos$mutableblockpos1 = new BlockPos();
for (int i4 = blockpos.getX() - l3; i4 <= blockpos.getX() + l3; ++i4) { for (int i4 = blockpos.getX() - l3; i4 <= blockpos.getX() + l3; ++i4) {
for (int j4 = blockpos.getZ() - l3; j4 <= blockpos.getZ() + l3; ++j4) { for (int j4 = blockpos.getZ() - l3; j4 <= blockpos.getZ() + l3; ++j4) {

View File

@ -510,7 +510,7 @@ public class ComponentScatteredFeaturePieces {
} else { } else {
int i = 0; int i = 0;
int j = 0; int j = 0;
BlockPos.MutableBlockPos blockpos$mutableblockpos = new BlockPos.MutableBlockPos(); BlockPos blockpos$mutableblockpos = new BlockPos();
for (int k = this.boundingBox.minZ; k <= this.boundingBox.maxZ; ++k) { for (int k = this.boundingBox.minZ; k <= this.boundingBox.maxZ; ++k) {
for (int l = this.boundingBox.minX; l <= this.boundingBox.maxX; ++l) { for (int l = this.boundingBox.minX; l <= this.boundingBox.maxX; ++l) {

View File

@ -139,7 +139,7 @@ public abstract class StructureComponent {
int l = Math.min(this.boundingBox.maxX + 1, boundingboxIn.maxX); int l = Math.min(this.boundingBox.maxX + 1, boundingboxIn.maxX);
int i1 = Math.min(this.boundingBox.maxY + 1, boundingboxIn.maxY); int i1 = Math.min(this.boundingBox.maxY + 1, boundingboxIn.maxY);
int j1 = Math.min(this.boundingBox.maxZ + 1, boundingboxIn.maxZ); int j1 = Math.min(this.boundingBox.maxZ + 1, boundingboxIn.maxZ);
BlockPos.MutableBlockPos blockpos$mutableblockpos = new BlockPos.MutableBlockPos(); BlockPos blockpos$mutableblockpos = new BlockPos();
for (int k1 = i; k1 <= l; ++k1) { for (int k1 = i; k1 <= l; ++k1) {
for (int l1 = k; l1 <= j1; ++l1) { for (int l1 = k; l1 <= j1; ++l1) {

View File

@ -1749,7 +1749,7 @@ public class StructureVillagePieces {
protected int getAverageGroundLevel(World worldIn, StructureBoundingBox parStructureBoundingBox) { protected int getAverageGroundLevel(World worldIn, StructureBoundingBox parStructureBoundingBox) {
int i = 0; int i = 0;
int j = 0; int j = 0;
BlockPos.MutableBlockPos blockpos$mutableblockpos = new BlockPos.MutableBlockPos(); BlockPos blockpos$mutableblockpos = new BlockPos();
for (int k = this.boundingBox.minZ; k <= this.boundingBox.maxZ; ++k) { for (int k = this.boundingBox.minZ; k <= this.boundingBox.maxZ; ++k) {
for (int l = this.boundingBox.minX; l <= this.boundingBox.maxX; ++l) { for (int l = this.boundingBox.minX; l <= this.boundingBox.maxX; ++l) {

View File

@ -89,7 +89,7 @@ public class SwimNodeProcessor extends NodeProcessor {
} }
private int func_176186_b(Entity entityIn, int x, int y, int z) { private int func_176186_b(Entity entityIn, int x, int y, int z) {
BlockPos.MutableBlockPos blockpos$mutableblockpos = new BlockPos.MutableBlockPos(); BlockPos blockpos$mutableblockpos = new BlockPos();
for (int i = x; i < x + this.entitySizeX; ++i) { for (int i = x; i < x + this.entitySizeX; ++i) {
for (int j = y; j < y + this.entitySizeY; ++j) { for (int j = y; j < y + this.entitySizeY; ++j) {

View File

@ -66,8 +66,8 @@ public class WalkNodeProcessor extends NodeProcessor {
int i; int i;
if (this.canSwim && entity.isInWater()) { if (this.canSwim && entity.isInWater()) {
i = (int) entity.getEntityBoundingBox().minY; i = (int) entity.getEntityBoundingBox().minY;
BlockPos.MutableBlockPos blockpos$mutableblockpos = new BlockPos.MutableBlockPos( BlockPos blockpos$mutableblockpos = new BlockPos(MathHelper.floor_double(entity.posX), i,
MathHelper.floor_double(entity.posX), i, MathHelper.floor_double(entity.posZ)); MathHelper.floor_double(entity.posZ));
for (Block block = this.blockaccess.getBlockState(blockpos$mutableblockpos) for (Block block = this.blockaccess.getBlockState(blockpos$mutableblockpos)
.getBlock(); block == Blocks.flowing_water .getBlock(); block == Blocks.flowing_water
@ -194,7 +194,7 @@ public class WalkNodeProcessor extends NodeProcessor {
int sizeY, int sizeZ, boolean avoidWater, boolean breakDoors, boolean enterDoors) { int sizeY, int sizeZ, boolean avoidWater, boolean breakDoors, boolean enterDoors) {
boolean flag = false; boolean flag = false;
BlockPos blockpos = new BlockPos(entityIn); BlockPos blockpos = new BlockPos(entityIn);
BlockPos.MutableBlockPos blockpos$mutableblockpos = new BlockPos.MutableBlockPos(); BlockPos blockpos$mutableblockpos = new BlockPos();
for (int i = x; i < x + sizeX; ++i) { for (int i = x; i < x + sizeX; ++i) {
for (int j = y; j < y + sizeY; ++j) { for (int j = y; j < y + sizeY; ++j) {

View File

@ -53,18 +53,23 @@ public class PlatformAudio {
@Override @Override
public void pause(boolean setPaused) { public void pause(boolean setPaused) {
if(setPaused) { if(setPaused) {
if(sndSystem.playing(sourceName)) { if(!paused) {
sndSystem.pause(sourceName); sndSystem.pause(sourceName);
paused = true;
} }
paused = true;
}else { }else {
if(!sndSystem.playing(sourceName)) { if(paused) {
sndSystem.play(sourceName); sndSystem.play(sourceName);
paused = false;
} }
paused = false;
} }
} }
@Override
public void repeat(boolean en) {
sndSystem.setLooping(sourceName, en);
}
@Override @Override
public void restart() { public void restart() {
this.stall = PlatformRuntime.steadyTimeMillis(); this.stall = PlatformRuntime.steadyTimeMillis();
@ -172,7 +177,7 @@ public class PlatformAudio {
private static int sourceCounter = 0; private static int sourceCounter = 0;
public static IAudioHandle beginPlayback(IAudioResource track, float x, float y, float z, public static IAudioHandle beginPlayback(IAudioResource track, float x, float y, float z,
float volume, float pitch) { float volume, float pitch, boolean repeat) {
if(sndSystem == null) { if(sndSystem == null) {
return null; return null;
} }
@ -188,12 +193,13 @@ public class PlatformAudio {
sndSystem.setTemporary(srcName, true); sndSystem.setTemporary(srcName, true);
sndSystem.setPitch(srcName, pitch); sndSystem.setPitch(srcName, pitch);
sndSystem.setVolume(srcName, volume); sndSystem.setVolume(srcName, volume);
sndSystem.setLooping(srcName, repeat);
sndSystem.play(srcName); sndSystem.play(srcName);
return new PaulscodeAudioHandle(srcName); return new PaulscodeAudioHandle(srcName);
} }
public static IAudioHandle beginPlaybackStatic(IAudioResource track, float volume, float pitch) { public static IAudioHandle beginPlaybackStatic(IAudioResource track, float volume, float pitch, boolean repeat) {
if(sndSystem == null) { if(sndSystem == null) {
return null; return null;
} }
@ -204,6 +210,7 @@ public class PlatformAudio {
sndSystem.setTemporary(srcName, true); sndSystem.setTemporary(srcName, true);
sndSystem.setPitch(srcName, pitch); sndSystem.setPitch(srcName, pitch);
sndSystem.setVolume(srcName, volume); sndSystem.setVolume(srcName, volume);
sndSystem.setLooping(srcName, repeat);
sndSystem.play(srcName); sndSystem.play(srcName);
return new PaulscodeAudioHandle(srcName); return new PaulscodeAudioHandle(srcName);

View File

@ -567,7 +567,11 @@ public class PlatformRuntime {
public static InputStream newGZIPInputStream(InputStream is) throws IOException { public static InputStream newGZIPInputStream(InputStream is) throws IOException {
return new GZIPInputStream(is); return new GZIPInputStream(is);
} }
public static void downloadRemoteURIByteArray(String assetPackageURI, boolean forceCache, final Consumer<byte[]> cb) {
downloadRemoteURIByteArray(assetPackageURI, cb);
}
public static void downloadRemoteURIByteArray(String assetPackageURI, final Consumer<byte[]> cb) { public static void downloadRemoteURIByteArray(String assetPackageURI, final Consumer<byte[]> cb) {
logger.info("Downloading: {}"); logger.info("Downloading: {}");
try(InputStream is = (new URL(assetPackageURI)).openStream()) { try(InputStream is = (new URL(assetPackageURI)).openStream()) {

View File

@ -1,7 +1,6 @@
package net.lax1dude.eaglercraft.v1_8.internal; package net.lax1dude.eaglercraft.v1_8.internal;
import net.lax1dude.eaglercraft.v1_8.EaglercraftUUID; import net.lax1dude.eaglercraft.v1_8.EaglercraftUUID;
import net.lax1dude.eaglercraft.v1_8.voice.EnumVoiceChannelPeerState;
import net.lax1dude.eaglercraft.v1_8.voice.EnumVoiceChannelReadyState; import net.lax1dude.eaglercraft.v1_8.voice.EnumVoiceChannelReadyState;
/** /**
@ -89,28 +88,8 @@ public class PlatformVoiceClient {
} }
public static EnumVoiceChannelPeerState getPeerState() {
return EnumVoiceChannelPeerState.LOADING;
}
public static EnumVoiceChannelReadyState getReadyState() { public static EnumVoiceChannelReadyState getReadyState() {
return EnumVoiceChannelReadyState.NONE; return EnumVoiceChannelReadyState.NONE;
} }
public static EnumVoiceChannelPeerState getPeerStateConnect() {
return EnumVoiceChannelPeerState.LOADING;
}
public static EnumVoiceChannelPeerState getPeerStateInitial() {
return EnumVoiceChannelPeerState.LOADING;
}
public static EnumVoiceChannelPeerState getPeerStateDesc() {
return EnumVoiceChannelPeerState.LOADING;
}
public static EnumVoiceChannelPeerState getPeerStateIce() {
return EnumVoiceChannelPeerState.LOADING;
}
} }

View File

@ -5,18 +5,8 @@ import dev.onvoid.webrtc.internal.NativeLoader;
import net.lax1dude.eaglercraft.v1_8.EagRuntime; import net.lax1dude.eaglercraft.v1_8.EagRuntime;
import net.lax1dude.eaglercraft.v1_8.log4j.LogManager; import net.lax1dude.eaglercraft.v1_8.log4j.LogManager;
import net.lax1dude.eaglercraft.v1_8.log4j.Logger; import net.lax1dude.eaglercraft.v1_8.log4j.Logger;
import net.lax1dude.eaglercraft.v1_8.sp.internal.ClientPlatformSingleplayer;
import net.lax1dude.eaglercraft.v1_8.sp.lan.LANPeerEvent; import net.lax1dude.eaglercraft.v1_8.sp.lan.LANPeerEvent;
import net.lax1dude.eaglercraft.v1_8.sp.relay.RelayLoggerImpl;
import net.lax1dude.eaglercraft.v1_8.sp.relay.RelayQuery;
import net.lax1dude.eaglercraft.v1_8.sp.relay.RelayQueryImpl;
import net.lax1dude.eaglercraft.v1_8.sp.relay.RelayQueryRateLimitDummy;
import net.lax1dude.eaglercraft.v1_8.sp.relay.RelayServerRateLimitTracker;
import net.lax1dude.eaglercraft.v1_8.sp.relay.RelayServerSocket;
import net.lax1dude.eaglercraft.v1_8.sp.relay.RelayServerSocketImpl;
import net.lax1dude.eaglercraft.v1_8.sp.relay.RelayServerSocketRateLimitDummy;
import net.lax1dude.eaglercraft.v1_8.sp.relay.RelayWorldsQuery;
import net.lax1dude.eaglercraft.v1_8.sp.relay.RelayWorldsQueryImpl;
import net.lax1dude.eaglercraft.v1_8.sp.relay.RelayWorldsQueryRateLimitDummy;
import org.apache.commons.lang3.SystemUtils; import org.apache.commons.lang3.SystemUtils;
import org.json.JSONArray; import org.json.JSONArray;
@ -50,11 +40,8 @@ public class PlatformWebRTC {
private static final Logger logger = LogManager.getLogger("PlatformWebRTC"); private static final Logger logger = LogManager.getLogger("PlatformWebRTC");
private static final RelayLoggerImpl loggerImpl = new RelayLoggerImpl(LogManager.getLogger("RelayPacket"));
private static final Object lock1 = new Object(); private static final Object lock1 = new Object();
private static final Object lock2 = new Object(); private static final Object lock2 = new Object();
private static final Object lock3 = new Object();
private static final List<ScheduledRunnable> scheduledRunnables = new LinkedList<>(); private static final List<ScheduledRunnable> scheduledRunnables = new LinkedList<>();
@ -93,8 +80,6 @@ public class PlatformWebRTC {
return supported; return supported;
} }
private static final Map<String, RTCDataChannel> fuckTeaVM = new HashMap<>();
private static final Comparator<ScheduledRunnable> sortTasks = (r1, r2) -> { private static final Comparator<ScheduledRunnable> sortTasks = (r1, r2) -> {
return (int)(r1.runAt - r2.runAt); return (int)(r1.runAt - r2.runAt);
}; };
@ -177,9 +162,17 @@ public class PlatformWebRTC {
synchronized (lock1) { synchronized (lock1) {
if (iceCandidate.sdp != null && !iceCandidate.sdp.isEmpty()) { if (iceCandidate.sdp != null && !iceCandidate.sdp.isEmpty()) {
if (iceCandidates.isEmpty()) { if (iceCandidates.isEmpty()) {
scheduleTask(3000l, () -> { final int[] candidateState = new int[2];
final Runnable[] runnable = new Runnable[1];
scheduleTask(2000l, runnable[0] = () -> {
synchronized (lock1) { synchronized (lock1) {
if (peerConnection != null && peerConnection.getConnectionState() != RTCPeerConnectionState.DISCONNECTED) { if (peerConnection != null && peerConnection.getConnectionState() != RTCPeerConnectionState.DISCONNECTED) {
int trial = ++candidateState[1];
if(candidateState[0] != iceCandidates.size() && trial < 3) {
candidateState[0] = iceCandidates.size();
scheduleTask(2000l, runnable[0]);
return;
}
clientICECandidate = JSONWriter.valueToString(iceCandidates); clientICECandidate = JSONWriter.valueToString(iceCandidates);
iceCandidates.clear(); iceCandidates.clear();
} }
@ -382,6 +375,8 @@ public class PlatformWebRTC {
public LANServer client; public LANServer client;
public String peerId; public String peerId;
public RTCPeerConnection peerConnection; public RTCPeerConnection peerConnection;
public RTCDataChannel dataChannel;
public String ipcChannel;
public LANPeer(LANServer client, String peerId, RTCPeerConnection peerConnection) { public LANPeer(LANServer client, String peerId, RTCPeerConnection peerConnection) {
this.client = client; this.client = client;
@ -390,10 +385,9 @@ public class PlatformWebRTC {
} }
public void disconnect() { public void disconnect() {
synchronized (fuckTeaVM) { if(dataChannel != null) {
if (fuckTeaVM.get(peerId) != null) { dataChannel.close();
fuckTeaVM.remove(peerId).close(); dataChannel = null;
}
} }
peerConnection.close(); peerConnection.close();
peerConnection = null; peerConnection = null;
@ -472,16 +466,36 @@ public class PlatformWebRTC {
client.signalRemoteDisconnect(peerId); client.signalRemoteDisconnect(peerId);
} }
} }
public void mapIPC(String ipcChannel) {
if(this.ipcChannel == null) {
if(ipcChannel != null) {
this.ipcChannel = ipcChannel;
synchronized(this.client.ipcMapList) {
this.client.ipcMapList.put(ipcChannel, this);
}
}
}else {
if(ipcChannel == null) {
synchronized(this.client.ipcMapList) {
this.client.ipcMapList.remove(this.ipcChannel);
}
this.ipcChannel = null;
}
}
}
} }
public static class LANServer { public static class LANServer {
public Set<Map<String, String>> iceServers = new HashSet<>(); public Set<Map<String, String>> iceServers = new HashSet<>();
public Map<String, LANPeer> peerList = new HashMap<>(); public Map<String, LANPeer> peerList = new HashMap<>();
public Map<String, LANPeer> ipcMapList = new HashMap<>();
public byte peerState = PEERSTATE_LOADING; public byte peerState = PEERSTATE_LOADING;
public byte peerStateConnect = PEERSTATE_LOADING; public byte peerStateConnect = PEERSTATE_LOADING;
public byte peerStateInitial = PEERSTATE_LOADING; public byte peerStateInitial = PEERSTATE_LOADING;
public byte peerStateDesc = PEERSTATE_LOADING; public byte peerStateDesc = PEERSTATE_LOADING;
public byte peerStateIce = PEERSTATE_LOADING; public byte peerStateIce = PEERSTATE_LOADING;
private final Object lock3 = new Object();
public void setIceServers(String[] urls) { public void setIceServers(String[] urls) {
iceServers.clear(); iceServers.clear();
@ -502,23 +516,28 @@ public class PlatformWebRTC {
} }
public void sendPacketToRemoteClient(String peerId, RTCDataChannelBuffer buffer) { public void sendPacketToRemoteClient(String peerId, RTCDataChannelBuffer buffer) {
LANPeer thePeer = this.peerList.get(peerId); LANPeer thePeer;
synchronized(peerList) {
thePeer = peerList.get(peerId);
}
if (thePeer != null) { if (thePeer != null) {
boolean b = false; sendPacketToRemoteClient(thePeer, buffer);
synchronized (fuckTeaVM) { }
if (fuckTeaVM.get(thePeer.peerId) != null && fuckTeaVM.get(thePeer.peerId).getState() == RTCDataChannelState.OPEN) { }
try {
fuckTeaVM.get(thePeer.peerId).send(buffer); public void sendPacketToRemoteClient(LANPeer thePeer, RTCDataChannelBuffer buffer) {
} catch (Throwable e) { boolean b = false;
b = true; if(thePeer.dataChannel != null && thePeer.dataChannel.getState() == RTCDataChannelState.OPEN) {
} try {
} else { thePeer.dataChannel.send(buffer);
b = true; } catch (Exception e) {
} b = true;
}
if (b) {
signalRemoteDisconnect(peerId);
} }
} else {
b = true;
}
if (b) {
signalRemoteDisconnect(thePeer.peerId);
} }
} }
@ -537,16 +556,25 @@ public class PlatformWebRTC {
iceServer.password = server.getOrDefault("credential", null); iceServer.password = server.getOrDefault("credential", null);
rtcConfig.iceServers.add(iceServer); rtcConfig.iceServers.add(iceServer);
} }
RTCPeerConnection[] peerConnection = new RTCPeerConnection[1]; final RTCPeerConnection[] peerConnection = new RTCPeerConnection[1];
final LANPeer[] peerInstance = new LANPeer[1];
peerConnection[0] = pcFactory.createPeerConnection(rtcConfig, new PeerConnectionObserver() { peerConnection[0] = pcFactory.createPeerConnection(rtcConfig, new PeerConnectionObserver() {
@Override @Override
public void onIceCandidate(RTCIceCandidate iceCandidate) { public void onIceCandidate(RTCIceCandidate iceCandidate) {
synchronized (lock3) { synchronized (lock3) {
if (iceCandidate.sdp != null && !iceCandidate.sdp.isEmpty()) { if (iceCandidate.sdp != null && !iceCandidate.sdp.isEmpty()) {
if (iceCandidates.isEmpty()) { if (iceCandidates.isEmpty()) {
scheduleTask(3000l, () -> { final int[] candidateState = new int[2];
final Runnable[] runnable = new Runnable[1];
scheduleTask(2000l, runnable[0] = () -> {
synchronized (lock3) { synchronized (lock3) {
if (peerConnection[0] != null && peerConnection[0].getConnectionState() != RTCPeerConnectionState.DISCONNECTED) { if (peerConnection[0] != null && peerConnection[0].getConnectionState() != RTCPeerConnectionState.DISCONNECTED) {
int trial = ++candidateState[1];
if(candidateState[0] != iceCandidates.size() && trial < 3) {
candidateState[0] = iceCandidates.size();
scheduleTask(2000l, runnable[0]);
return;
}
LANPeerEvent.LANPeerICECandidateEvent e = new LANPeerEvent.LANPeerICECandidateEvent(peerId, JSONWriter.valueToString(iceCandidates)); LANPeerEvent.LANPeerICECandidateEvent e = new LANPeerEvent.LANPeerICECandidateEvent(peerId, JSONWriter.valueToString(iceCandidates));
synchronized (serverLANEventBuffer) { synchronized (serverLANEventBuffer) {
serverLANEventBuffer.put(peerId, e); serverLANEventBuffer.put(peerId, e);
@ -582,9 +610,11 @@ public class PlatformWebRTC {
return; return;
} }
if (dataChannel == null) return; if (dataChannel == null) return;
synchronized (fuckTeaVM) { if(peerInstance[0].dataChannel != null) {
fuckTeaVM.put(peerId, dataChannel); dataChannel.close();
return;
} }
peerInstance[0].dataChannel = dataChannel;
synchronized (serverLANEventBuffer) { synchronized (serverLANEventBuffer) {
serverLANEventBuffer.put(peerId, new LANPeerEvent.LANPeerDataChannelEvent(peerId)); serverLANEventBuffer.put(peerId, new LANPeerEvent.LANPeerDataChannelEvent(peerId));
} }
@ -604,9 +634,14 @@ public class PlatformWebRTC {
if (!buffer.binary) return; if (!buffer.binary) return;
byte[] data = new byte[buffer.data.remaining()]; byte[] data = new byte[buffer.data.remaining()];
buffer.data.get(data); buffer.data.get(data);
LANPeerEvent.LANPeerPacketEvent e = new LANPeerEvent.LANPeerPacketEvent(peerId, data); LANPeer peer = peerInstance[0];
synchronized (serverLANEventBuffer) { if(peer.ipcChannel != null) {
serverLANEventBuffer.put(peerId, e); ClientPlatformSingleplayer.sendPacket(new IPCPacketData(peer.ipcChannel, data));
}else {
LANPeerEvent.LANPeerPacketEvent e = new LANPeerEvent.LANPeerPacketEvent(peerId, data);
synchronized (serverLANEventBuffer) {
serverLANEventBuffer.put(peerId, e);
}
} }
} }
}); });
@ -627,8 +662,10 @@ public class PlatformWebRTC {
} }
} }
}); });
LANPeer peerInstance = new LANPeer(this, peerId, peerConnection[0]); peerInstance[0] = new LANPeer(this, peerId, peerConnection[0]);
peerList.put(peerId, peerInstance); synchronized(peerList) {
peerList.put(peerId, peerInstance[0]);
}
if (peerStateConnect != PEERSTATE_SUCCESS) peerStateConnect = PEERSTATE_SUCCESS; if (peerStateConnect != PEERSTATE_SUCCESS) peerStateConnect = PEERSTATE_SUCCESS;
} catch (Throwable e) { } catch (Throwable e) {
if (peerStateConnect == PEERSTATE_LOADING) peerStateConnect = PEERSTATE_FAILED; if (peerStateConnect == PEERSTATE_LOADING) peerStateConnect = PEERSTATE_FAILED;
@ -636,14 +673,20 @@ public class PlatformWebRTC {
} }
public void signalRemoteDescription(String peerId, String descJSON) { public void signalRemoteDescription(String peerId, String descJSON) {
LANPeer thePeer = peerList.get(peerId); LANPeer thePeer;
synchronized(peerList) {
thePeer = peerList.get(peerId);
}
if (thePeer != null) { if (thePeer != null) {
thePeer.setRemoteDescription(descJSON); thePeer.setRemoteDescription(descJSON);
} }
} }
public void signalRemoteICECandidate(String peerId, String candidate) { public void signalRemoteICECandidate(String peerId, String candidate) {
LANPeer thePeer = peerList.get(peerId); LANPeer thePeer;
synchronized(peerList) {
thePeer = peerList.get(peerId);
}
if (thePeer != null) { if (thePeer != null) {
thePeer.addICECandidate(candidate); thePeer.addICECandidate(candidate);
} }
@ -651,7 +694,12 @@ public class PlatformWebRTC {
public void signalRemoteDisconnect(String peerId) { public void signalRemoteDisconnect(String peerId) {
if (peerId == null || peerId.isEmpty()) { if (peerId == null || peerId.isEmpty()) {
for (LANPeer thePeer : peerList.values()) { List<LANPeer> cpy;
synchronized(peerList) {
cpy = new ArrayList<>(peerList.values());
peerList.clear();
}
for (LANPeer thePeer : cpy) {
if (thePeer != null) { if (thePeer != null) {
try { try {
thePeer.disconnect(); thePeer.disconnect();
@ -662,55 +710,44 @@ public class PlatformWebRTC {
} }
} }
} }
peerList.clear();
synchronized (fuckTeaVM) {
fuckTeaVM.clear();
}
return; return;
} }
LANPeer thePeer = peerList.get(peerId); LANPeer thePeer;
synchronized(peerList) {
thePeer = peerList.remove(peerId);
}
if (thePeer != null) { if (thePeer != null) {
peerList.remove(peerId); if(thePeer.ipcChannel != null) {
synchronized(ipcMapList) {
ipcMapList.remove(thePeer.ipcChannel);
}
}
try { try {
thePeer.disconnect(); thePeer.disconnect();
} catch (Throwable ignored) { } catch (Throwable ignored) {
} }
synchronized (fuckTeaVM) {
fuckTeaVM.remove(peerId);
}
synchronized (serverLANEventBuffer) { synchronized (serverLANEventBuffer) {
serverLANEventBuffer.put(thePeer.peerId, new LANPeerEvent.LANPeerDisconnectEvent(peerId)); serverLANEventBuffer.put(thePeer.peerId, new LANPeerEvent.LANPeerDisconnectEvent(peerId));
} }
} }
} }
public void serverPeerMapIPC(String peer, String ipcChannel) {
LANPeer peerr;
synchronized(peerList) {
peerr = peerList.get(peer);
}
if(peerr != null) {
peerr.mapIPC(ipcChannel);
}
}
public int countPeers() { public int countPeers() {
return peerList.size(); synchronized(peerList) {
return peerList.size();
}
} }
} }
public static RelayQuery openRelayQuery(String addr) {
RelayQuery.RateLimit limit = RelayServerRateLimitTracker.isLimited(addr);
if(limit == RelayQuery.RateLimit.LOCKED || limit == RelayQuery.RateLimit.BLOCKED) {
return new RelayQueryRateLimitDummy(limit);
}
return new RelayQueryImpl(addr);
}
public static RelayWorldsQuery openRelayWorldsQuery(String addr) {
RelayQuery.RateLimit limit = RelayServerRateLimitTracker.isLimited(addr);
if(limit == RelayQuery.RateLimit.LOCKED || limit == RelayQuery.RateLimit.BLOCKED) {
return new RelayWorldsQueryRateLimitDummy(limit);
}
return new RelayWorldsQueryImpl(addr);
}
public static RelayServerSocket openRelayConnection(String addr, int timeout) {
RelayQuery.RateLimit limit = RelayServerRateLimitTracker.isLimited(addr);
if(limit == RelayQuery.RateLimit.LOCKED || limit == RelayQuery.RateLimit.BLOCKED) {
return new RelayServerSocketRateLimitDummy(limit);
}
return new RelayServerSocketImpl(addr, timeout);
}
private static LANClient rtcLANClient = null; private static LANClient rtcLANClient = null;
@ -883,6 +920,27 @@ public class PlatformWebRTC {
rtcLANServer.signalRemoteDescription(peer, description); rtcLANServer.signalRemoteDescription(peer, description);
} }
public static void serverLANPeerMapIPC(String peer, String ipcChannel) {
rtcLANServer.serverPeerMapIPC(peer, ipcChannel);
}
public static boolean serverLANPeerPassIPC(IPCPacketData ipcPacket) {
if(rtcLANServer != null) {
LANPeer peer;
synchronized(rtcLANServer.ipcMapList) {
peer = rtcLANServer.ipcMapList.get(ipcPacket.channel);
}
if(peer != null) {
rtcLANServer.sendPacketToRemoteClient(peer, new RTCDataChannelBuffer(ByteBuffer.wrap(ipcPacket.contents), true));
return true;
}else {
return false;
}
}else {
return false;
}
}
public static void serverLANDisconnectPeer(String peer) { public static void serverLANDisconnectPeer(String peer) {
rtcLANServer.signalRemoteDisconnect(peer); rtcLANServer.signalRemoteDisconnect(peer);
} }
@ -893,4 +951,5 @@ public class PlatformWebRTC {
} }
return rtcLANServer.countPeers(); return rtcLANServer.countPeers();
} }
} }

View File

@ -141,7 +141,7 @@ public class EaglerLWJGLByteBuffer implements ByteBuffer {
int l = src.remaining(); int l = src.remaining();
if(position + l > limit) throw Buffer.makeIOOBE(position + l - 1); if(position + l > limit) throw Buffer.makeIOOBE(position + l - 1);
for(int i = 0; i < l; ++i) { for(int i = 0; i < l; ++i) {
UnsafeUtils.setMemByte(address + position + l, src.get()); UnsafeUtils.setMemByte(address + position + i, src.get());
} }
position += l; position += l;
} }

View File

@ -150,7 +150,7 @@ public class EaglerLWJGLFloatBuffer implements FloatBuffer {
int l = src.remaining(); int l = src.remaining();
if(position + l > limit) throw Buffer.makeIOOBE(position + l - 1); if(position + l > limit) throw Buffer.makeIOOBE(position + l - 1);
for(int i = 0; i < l; ++i) { for(int i = 0; i < l; ++i) {
UnsafeUtils.setMemFloat(address + ((position + l) << SHIFT), src.get()); UnsafeUtils.setMemFloat(address + ((position + i) << SHIFT), src.get());
} }
position += l; position += l;
} }

View File

@ -150,7 +150,7 @@ public class EaglerLWJGLIntBuffer implements IntBuffer {
int l = src.remaining(); int l = src.remaining();
if(position + l > limit) throw Buffer.makeIOOBE(position + l - 1); if(position + l > limit) throw Buffer.makeIOOBE(position + l - 1);
for(int i = 0; i < l; ++i) { for(int i = 0; i < l; ++i) {
UnsafeUtils.setMemInt(address + ((position + l) << SHIFT), src.get()); UnsafeUtils.setMemInt(address + ((position + i) << SHIFT), src.get());
} }
position += l; position += l;
} }

View File

@ -150,7 +150,7 @@ public class EaglerLWJGLShortBuffer implements ShortBuffer {
int l = src.remaining(); int l = src.remaining();
if(position + l > limit) throw Buffer.makeIOOBE(position + l - 1); if(position + l > limit) throw Buffer.makeIOOBE(position + l - 1);
for(int i = 0; i < l; ++i) { for(int i = 0; i < l; ++i) {
UnsafeUtils.setMemInt(address + ((position + l) << SHIFT), src.get()); UnsafeUtils.setMemInt(address + ((position + i) << SHIFT), src.get());
} }
position += l; position += l;
} }

View File

@ -8,6 +8,7 @@ import net.lax1dude.eaglercraft.v1_8.Filesystem;
import net.lax1dude.eaglercraft.v1_8.internal.IClientConfigAdapter; import net.lax1dude.eaglercraft.v1_8.internal.IClientConfigAdapter;
import net.lax1dude.eaglercraft.v1_8.internal.IEaglerFilesystem; import net.lax1dude.eaglercraft.v1_8.internal.IEaglerFilesystem;
import net.lax1dude.eaglercraft.v1_8.internal.IPCPacketData; import net.lax1dude.eaglercraft.v1_8.internal.IPCPacketData;
import net.lax1dude.eaglercraft.v1_8.internal.PlatformWebRTC;
import net.lax1dude.eaglercraft.v1_8.internal.lwjgl.DesktopClientConfigAdapter; import net.lax1dude.eaglercraft.v1_8.internal.lwjgl.DesktopClientConfigAdapter;
import net.lax1dude.eaglercraft.v1_8.sp.server.internal.lwjgl.MemoryConnection; import net.lax1dude.eaglercraft.v1_8.sp.server.internal.lwjgl.MemoryConnection;
@ -45,6 +46,9 @@ public class ServerPlatformSingleplayer {
} }
public static void sendPacket(IPCPacketData packet) { public static void sendPacket(IPCPacketData packet) {
if(PlatformWebRTC.serverLANPeerPassIPC(packet)) {
return;
}
synchronized(MemoryConnection.serverToClientQueue) { synchronized(MemoryConnection.serverToClientQueue) {
MemoryConnection.serverToClientQueue.add(packet); MemoryConnection.serverToClientQueue.add(packet);
} }

View File

@ -215,10 +215,12 @@ public class EagRuntime {
} }
public static void getStackTrace(Throwable t, Consumer<String> ret) { public static void getStackTrace(Throwable t, Consumer<String> ret) {
if(t == null) return;
PlatformRuntime.getStackTrace(t, ret); PlatformRuntime.getStackTrace(t, ret);
} }
public static String[] getStackTraceElements(Throwable t) { public static String[] getStackTraceElements(Throwable t) {
if(t == null) return new String[0];
List<String> lst = new ArrayList<>(); List<String> lst = new ArrayList<>();
PlatformRuntime.getStackTrace(t, (s) -> { PlatformRuntime.getStackTrace(t, (s) -> {
lst.add(s); lst.add(s);
@ -227,6 +229,9 @@ public class EagRuntime {
} }
public static String getStackTrace(Throwable t) { public static String getStackTrace(Throwable t) {
if(t == null) {
return "[null]";
}
StringBuilder sb = new StringBuilder(); StringBuilder sb = new StringBuilder();
getStackTrace0(t, sb); getStackTrace0(t, sb);
Throwable c = t.getCause(); Throwable c = t.getCause();

View File

@ -21,7 +21,6 @@ import net.minecraft.client.audio.SoundHandler;
import net.minecraft.client.audio.SoundPoolEntry; import net.minecraft.client.audio.SoundPoolEntry;
import net.minecraft.client.settings.GameSettings; import net.minecraft.client.settings.GameSettings;
import net.minecraft.entity.player.EntityPlayer; import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.util.ITickable;
import net.minecraft.util.MathHelper; import net.minecraft.util.MathHelper;
import net.minecraft.util.ResourceLocation; import net.minecraft.util.ResourceLocation;
@ -42,7 +41,7 @@ import net.minecraft.util.ResourceLocation;
*/ */
public class EaglercraftSoundManager { public class EaglercraftSoundManager {
protected static class ActiveSoundEvent { protected class ActiveSoundEvent {
protected final EaglercraftSoundManager manager; protected final EaglercraftSoundManager manager;
@ -88,14 +87,11 @@ public class EaglercraftSoundManager {
activeZ = z; activeZ = z;
} }
if(pitch != activePitch) { if(pitch != activePitch) {
soundHandle.pitch(MathHelper.clamp_float(pitch * (float)soundConfig.getPitch(), 0.5f, 2.0f)); soundHandle.pitch(EaglercraftSoundManager.this.getNormalizedPitch(soundInstance, soundConfig));
activePitch = pitch; activePitch = pitch;
} }
if(gain != activeGain) { if(gain != activeGain) {
float attenuatedGain = gain * manager.categoryVolumes[SoundCategory.MASTER.getCategoryId()] * soundHandle.gain(EaglercraftSoundManager.this.getNormalizedVolume(soundInstance, soundConfig, soundCategory));
(soundCategory == SoundCategory.MASTER ? 1.0f : manager.categoryVolumes[soundCategory.getCategoryId()])
* (float)soundConfig.getVolume();
soundHandle.gain(MathHelper.clamp_float(attenuatedGain, 0.0f, 1.0f));
activeGain = gain; activeGain = gain;
} }
} }
@ -152,10 +148,7 @@ public class EaglercraftSoundManager {
ActiveSoundEvent evt = soundItr.next(); ActiveSoundEvent evt = soundItr.next();
if((category == SoundCategory.MASTER || evt.soundCategory == category) if((category == SoundCategory.MASTER || evt.soundCategory == category)
&& !evt.soundHandle.shouldFree()) { && !evt.soundHandle.shouldFree()) {
float newVolume = (evt.activeGain = evt.soundInstance.getVolume()) * categoryVolumes[SoundCategory.MASTER.getCategoryId()] * float newVolume = getNormalizedVolume(evt.soundInstance, evt.soundConfig, evt.soundCategory);
(evt.soundCategory == SoundCategory.MASTER ? 1.0f : categoryVolumes[evt.soundCategory.getCategoryId()])
* (float)evt.soundConfig.getVolume();
newVolume = MathHelper.clamp_float(newVolume, 0.0f, 1.0f);
if(newVolume > 0.0f) { if(newVolume > 0.0f) {
evt.soundHandle.gain(newVolume); evt.soundHandle.gain(newVolume);
}else { }else {
@ -211,34 +204,34 @@ public class EaglercraftSoundManager {
Iterator<ActiveSoundEvent> soundItr = activeSounds.iterator(); Iterator<ActiveSoundEvent> soundItr = activeSounds.iterator();
while(soundItr.hasNext()) { while(soundItr.hasNext()) {
ActiveSoundEvent evt = soundItr.next(); ActiveSoundEvent evt = soundItr.next();
if(!evt.paused && (evt.soundInstance instanceof ITickable)) { boolean persist = false;
if(!evt.paused && (evt.soundInstance instanceof ITickableSound)) {
boolean destroy = false; boolean destroy = false;
try { ITickableSound snd = (ITickableSound) evt.soundInstance;
((ITickable)evt.soundInstance).update(); lbl : {
if ((evt.soundInstance instanceof ITickableSound) try {
&& ((ITickableSound) evt.soundInstance).isDonePlaying()) { snd.update();
if(snd.isDonePlaying()) {
destroy = true;
break lbl;
}
persist = true;
}catch(Throwable t) {
logger.error("Error ticking sound: {}", t.toString());
logger.error(t);
destroy = true; destroy = true;
} }
}catch(Throwable t) {
logger.error("Error ticking sound: {}", t.toString());
logger.error(t);
destroy = true;
} }
if(destroy) { if(destroy) {
if(!evt.soundHandle.shouldFree()) { if(!evt.soundHandle.shouldFree()) {
evt.soundHandle.end(); evt.soundHandle.end();
} }
soundItr.remove(); soundItr.remove();
continue;
} }
} }
if(evt.soundHandle.shouldFree()) { if(evt.soundHandle.shouldFree()) {
if(evt.soundInstance.canRepeat()) { if(!persist) {
if(!evt.paused && ++evt.repeatCounter > evt.soundInstance.getRepeatDelay()) {
evt.repeatCounter = 0;
evt.updateLocation();
evt.soundHandle.restart();
}
}else {
soundItr.remove(); soundItr.remove();
} }
}else { }else {
@ -323,17 +316,16 @@ public class EaglercraftSoundManager {
ActiveSoundEvent newSound = new ActiveSoundEvent(this, sound, accessor.getSoundCategory(), etr, null); ActiveSoundEvent newSound = new ActiveSoundEvent(this, sound, accessor.getSoundCategory(), etr, null);
float pitch = MathHelper.clamp_float(newSound.activePitch * (float)etr.getPitch(), 0.5f, 2.0f); float pitch = getNormalizedPitch(sound, etr);
float attenuatedGain = newSound.activeGain * categoryVolumes[SoundCategory.MASTER.getCategoryId()] * float attenuatedGain = getNormalizedVolume(sound, etr, accessor.getSoundCategory());
(accessor.getSoundCategory() == SoundCategory.MASTER ? 1.0f : boolean repeat = sound.canRepeat();
categoryVolumes[accessor.getSoundCategory().getCategoryId()]) * (float)etr.getVolume();
AttenuationType tp = sound.getAttenuationType(); AttenuationType tp = sound.getAttenuationType();
if(tp == AttenuationType.LINEAR) { if(tp == AttenuationType.LINEAR) {
newSound.soundHandle = PlatformAudio.beginPlayback(trk, newSound.activeX, newSound.activeY, newSound.soundHandle = PlatformAudio.beginPlayback(trk, newSound.activeX, newSound.activeY,
newSound.activeZ, attenuatedGain, pitch); newSound.activeZ, attenuatedGain, pitch, repeat);
}else { }else {
newSound.soundHandle = PlatformAudio.beginPlaybackStatic(trk, attenuatedGain, pitch); newSound.soundHandle = PlatformAudio.beginPlaybackStatic(trk, attenuatedGain, pitch, repeat);
} }
if(newSound.soundHandle == null) { if(newSound.soundHandle == null) {
@ -351,6 +343,17 @@ public class EaglercraftSoundManager {
queuedSounds.add(new WaitingSoundEvent(sound, delay)); queuedSounds.add(new WaitingSoundEvent(sound, delay));
} }
private float getNormalizedVolume(ISound sound, SoundPoolEntry entry, SoundCategory category) {
return (float) MathHelper.clamp_double((double) sound.getVolume() * entry.getVolume(), 0.0D, 1.0D)
* (category.getCategoryId() == SoundCategory.MASTER.getCategoryId() ? 1.0f
: categoryVolumes[category.getCategoryId()])
* categoryVolumes[SoundCategory.MASTER.getCategoryId()];
}
private float getNormalizedPitch(ISound sound, SoundPoolEntry entry) {
return MathHelper.clamp_float(sound.getPitch() * (float)entry.getPitch(), 0.5f, 2.0f);
}
public void setListener(EntityPlayer player, float partialTicks) { public void setListener(EntityPlayer player, float partialTicks) {
if(!PlatformAudio.available()) { if(!PlatformAudio.available()) {
return; return;

View File

@ -10,7 +10,7 @@ public class EaglercraftVersion {
/// Customize these to fit your fork: /// Customize these to fit your fork:
public static final String projectForkName = "EaglercraftX"; public static final String projectForkName = "EaglercraftX";
public static final String projectForkVersion = "u41"; public static final String projectForkVersion = "u42";
public static final String projectForkVendor = "lax1dude"; public static final String projectForkVendor = "lax1dude";
public static final String projectForkURL = "https://gitlab.com/lax1dude/eaglercraftx-1.8"; public static final String projectForkURL = "https://gitlab.com/lax1dude/eaglercraftx-1.8";
@ -20,20 +20,20 @@ public class EaglercraftVersion {
public static final String projectOriginName = "EaglercraftX"; public static final String projectOriginName = "EaglercraftX";
public static final String projectOriginAuthor = "lax1dude"; public static final String projectOriginAuthor = "lax1dude";
public static final String projectOriginRevision = "1.8"; public static final String projectOriginRevision = "1.8";
public static final String projectOriginVersion = "u41"; public static final String projectOriginVersion = "u42";
public static final String projectOriginURL = "https://gitlab.com/lax1dude/eaglercraftx-1.8"; // rest in peace public static final String projectOriginURL = "https://gitlab.com/lax1dude/eaglercraftx-1.8"; // rest in peace
// EPK Version Identifier // EPK Version Identifier
public static final String EPKVersionIdentifier = "u41"; // Set to null to disable EPK version check public static final String EPKVersionIdentifier = "u42"; // Set to null to disable EPK version check
// Updating configuration // Updating configuration
public static final boolean enableUpdateService = true; public static final boolean enableUpdateService = true;
public static final String updateBundlePackageName = "net.lax1dude.eaglercraft.v1_8.client"; public static final String updateBundlePackageName = "net.lax1dude.eaglercraft.v1_8.client";
public static final int updateBundlePackageVersionInt = 41; public static final int updateBundlePackageVersionInt = 42;
public static final String updateLatestLocalStorageKey = "latestUpdate_" + updateBundlePackageName; public static final String updateLatestLocalStorageKey = "latestUpdate_" + updateBundlePackageName;

View File

@ -16,7 +16,7 @@ package net.lax1dude.eaglercraft.v1_8.internal;
* *
*/ */
public enum EnumPlatformType { public enum EnumPlatformType {
DESKTOP("Desktop"), JAVASCRIPT("JavaScript"), ASM("ASM"); DESKTOP("Desktop"), JAVASCRIPT("JavaScript"), WASM_GC("ASM");
private final String name; private final String name;

View File

@ -21,6 +21,8 @@ public interface IAudioHandle {
void restart(); void restart();
void repeat(boolean en);
void move(float x, float y, float z); void move(float x, float y, float z);
void pitch(float f); void pitch(float f);

View File

@ -283,7 +283,7 @@ public class EaglerFolderResourcePack extends AbstractResourcePack {
return; return;
} }
} }
PlatformRuntime.downloadRemoteURIByteArray(url, arr -> { PlatformRuntime.downloadRemoteURIByteArray(url, true, arr -> {
ast.accept(() -> { ast.accept(() -> {
if (arr == null) { if (arr == null) {
cb.accept(null); cb.accept(null);

View File

@ -517,6 +517,8 @@ public class FontMappingHelper {
return 253; return 253;
case 9632: case 9632:
return 254; return 254;
case 160:
return 32; //nbsp
default: default:
return -1; return -1;
} }

View File

@ -162,7 +162,6 @@ public class SingleplayerServerController implements ISaveFormat {
}else { }else {
openLANChannels.add(ch); openLANChannels.add(ch);
sendIPCPacket(new IPCPacket0CPlayerChannel(ch, true)); sendIPCPacket(new IPCPacket0CPlayerChannel(ch, true));
PlatformWebRTC.serverLANCreatePeer(ch);
} }
} }
@ -288,6 +287,8 @@ public class SingleplayerServerController implements ISaveFormat {
logger.warn("Recieved {} byte packet on closed local player connection", packetData.contents.length); logger.warn("Recieved {} byte packet on closed local player connection", packetData.contents.length);
} }
}else { }else {
//logger.warn("Recieved packet on IPC channel '{}', forwarding to PlatformWebRTC even though the channel should be mapped", packetData.channel);
// just to be safe
PlatformWebRTC.serverLANWritePacket(packetData.channel, packetData.contents); PlatformWebRTC.serverLANWritePacket(packetData.channel, packetData.contents);
} }
} }

View File

@ -6,9 +6,7 @@ import net.lax1dude.eaglercraft.v1_8.sp.WorkerStartupFailedException;
import net.lax1dude.eaglercraft.v1_8.sp.ipc.IPCPacket15Crashed; import net.lax1dude.eaglercraft.v1_8.sp.ipc.IPCPacket15Crashed;
import net.lax1dude.eaglercraft.v1_8.sp.ipc.IPCPacket1CIssueDetected; import net.lax1dude.eaglercraft.v1_8.sp.ipc.IPCPacket1CIssueDetected;
import net.minecraft.client.gui.GuiButton; import net.minecraft.client.gui.GuiButton;
import net.minecraft.client.gui.GuiMainMenu;
import net.minecraft.client.gui.GuiScreen; import net.minecraft.client.gui.GuiScreen;
import net.minecraft.client.gui.GuiSelectWorld;
import net.minecraft.client.resources.I18n; import net.minecraft.client.resources.I18n;
/** /**

View File

@ -151,7 +151,7 @@ public class GuiShareToLan extends GuiScreen {
} }
this.mc.displayGuiScreen(null); this.mc.displayGuiScreen(null);
LoadingScreenRenderer ls = mc.loadingScreen; LoadingScreenRenderer ls = mc.loadingScreen;
String code = LANServerController.shareToLAN(ls::resetProgressAndMessage, worldName, hiddenToggle); String code = LANServerController.shareToLAN((msg) -> ls.eaglerShow(msg, null), worldName, hiddenToggle);
if (code != null) { if (code != null) {
SingleplayerServerController.configureLAN(WorldSettings.GameType.getByName(this.gameMode), this.allowCommands); SingleplayerServerController.configureLAN(WorldSettings.GameType.getByName(this.gameMode), this.allowCommands);
this.mc.ingameGUI.getChatGUI().printChatMessage(new ChatComponentText(I18n.format("lanServer.opened") this.mc.ingameGUI.getChatGUI().printChatMessage(new ChatComponentText(I18n.format("lanServer.opened")

View File

@ -1,10 +1,8 @@
package net.lax1dude.eaglercraft.v1_8.sp.lan; package net.lax1dude.eaglercraft.v1_8.sp.lan;
import java.util.Iterator;
import java.util.List; import java.util.List;
import net.lax1dude.eaglercraft.v1_8.EagRuntime; import net.lax1dude.eaglercraft.v1_8.EagRuntime;
import net.lax1dude.eaglercraft.v1_8.EagUtils;
import net.lax1dude.eaglercraft.v1_8.internal.IPCPacketData; import net.lax1dude.eaglercraft.v1_8.internal.IPCPacketData;
import net.lax1dude.eaglercraft.v1_8.internal.PlatformWebRTC; import net.lax1dude.eaglercraft.v1_8.internal.PlatformWebRTC;
import net.lax1dude.eaglercraft.v1_8.log4j.LogManager; import net.lax1dude.eaglercraft.v1_8.log4j.LogManager;
@ -33,42 +31,26 @@ class LANClientPeer {
private static final Logger logger = LogManager.getLogger("LANClientPeer"); private static final Logger logger = LogManager.getLogger("LANClientPeer");
private static final int PRE = 0, SENT_ICE_CANDIDATE = 2, SENT_DESCRIPTION = 3, CONNECTED = 4, CLOSED = 5; private static final int PRE = 0, RECEIVED_ICE_CANDIDATE = 1, SENT_ICE_CANDIDATE = 2, RECEIVED_DESCRIPTION = 3,
SENT_DESCRIPTION = 4, RECEIVED_SUCCESS = 5, CONNECTED = 6, CLOSED = 7;
protected final String clientId; protected final String clientId;
protected int state = PRE; protected int state = PRE;
protected boolean dead = false; protected boolean dead = false;
protected long startTime;
protected LANClientPeer(String clientId) { protected LANClientPeer(String clientId) {
this.clientId = clientId; this.clientId = clientId;
this.startTime = EagRuntime.steadyTimeMillis();
PlatformWebRTC.serverLANCreatePeer(clientId); PlatformWebRTC.serverLANCreatePeer(clientId);
} }
protected void handleICECandidates(String candidates) { protected void handleICECandidates(String candidates) {
if(state == SENT_DESCRIPTION) { if(state == SENT_DESCRIPTION) {
PlatformWebRTC.serverLANPeerICECandidates(clientId, candidates); PlatformWebRTC.serverLANPeerICECandidates(clientId, candidates);
long millis = EagRuntime.steadyTimeMillis(); state = RECEIVED_ICE_CANDIDATE;
do {
PlatformWebRTC.runScheduledTasks();
LANPeerEvent evt;
if((evt = PlatformWebRTC.serverLANGetEvent(clientId)) != null) {
if(evt instanceof LANPeerEvent.LANPeerICECandidateEvent) {
LANServerController.lanRelaySocket.writePacket(new RelayPacket03ICECandidate(clientId, ((LANPeerEvent.LANPeerICECandidateEvent)evt).candidates));
state = SENT_ICE_CANDIDATE;
return;
}else if(evt instanceof LANPeerEvent.LANPeerDisconnectEvent) {
logger.error("LAN client '{}' disconnected while waiting for server ICE candidates", clientId);
}else {
logger.error("LAN client '{}' had an accident: {}", clientId, evt.getClass().getSimpleName());
}
disconnect();
return;
}
EagUtils.sleep(20);
}while(EagRuntime.steadyTimeMillis() - millis < 5000l);
logger.error("Getting server ICE candidates for '{}' timed out!", clientId);
disconnect();
}else { }else {
logger.error("Relay [{}] unexpected IPacket03ICECandidate for '{}'", LANServerController.lanRelaySocket.getURI(), clientId); logger.error("Relay [{}] unexpected IPacket03ICECandidate for '{}'", LANServerController.lanRelaySocket.getURI(), clientId);
} }
@ -77,27 +59,7 @@ class LANClientPeer {
protected void handleDescription(String description) { protected void handleDescription(String description) {
if(state == PRE) { if(state == PRE) {
PlatformWebRTC.serverLANPeerDescription(clientId, description); PlatformWebRTC.serverLANPeerDescription(clientId, description);
long millis = EagRuntime.steadyTimeMillis(); state = RECEIVED_DESCRIPTION;
do {
PlatformWebRTC.runScheduledTasks();
LANPeerEvent evt;
if((evt = PlatformWebRTC.serverLANGetEvent(clientId)) != null) {
if(evt instanceof LANPeerEvent.LANPeerDescriptionEvent) {
LANServerController.lanRelaySocket.writePacket(new RelayPacket04Description(clientId, ((LANPeerEvent.LANPeerDescriptionEvent)evt).description));
state = SENT_DESCRIPTION;
return;
}else if(evt instanceof LANPeerEvent.LANPeerDisconnectEvent) {
logger.error("LAN client '{}' disconnected while waiting for server description", clientId);
}else {
logger.error("LAN client '{}' had an accident: {}", clientId, evt.getClass().getSimpleName());
}
disconnect();
return;
}
EagUtils.sleep(20);
}while(EagRuntime.steadyTimeMillis() - millis < 5000l);
logger.error("Getting server description for '{}' timed out!", clientId);
disconnect();
}else { }else {
logger.error("Relay [{}] unexpected IPacket04Description for '{}'", LANServerController.lanRelaySocket.getURI(), clientId); logger.error("Relay [{}] unexpected IPacket04Description for '{}'", LANServerController.lanRelaySocket.getURI(), clientId);
} }
@ -105,31 +67,8 @@ class LANClientPeer {
protected void handleSuccess() { protected void handleSuccess() {
if(state == SENT_ICE_CANDIDATE) { if(state == SENT_ICE_CANDIDATE) {
long millis = EagRuntime.steadyTimeMillis(); state = RECEIVED_SUCCESS;
do { }else if(state != CONNECTED) {
PlatformWebRTC.runScheduledTasks();
LANPeerEvent evt;
while((evt = PlatformWebRTC.serverLANGetEvent(clientId)) != null && evt instanceof LANPeerEvent.LANPeerICECandidateEvent) {
// skip ice candidates
}
if(evt != null) {
if(evt instanceof LANPeerEvent.LANPeerDataChannelEvent) {
SingleplayerServerController.openPlayerChannel(clientId);
state = CONNECTED;
return;
}else if(evt instanceof LANPeerEvent.LANPeerDisconnectEvent) {
logger.error("LAN client '{}' disconnected while waiting for connection", clientId);
}else {
logger.error("LAN client '{}' had an accident: {}", clientId, evt.getClass().getSimpleName());
}
disconnect();
return;
}
EagUtils.sleep(20);
}while(EagRuntime.steadyTimeMillis() - millis < 5000l);
logger.error("Getting server description for '{}' timed out!", clientId);
disconnect();
}else {
logger.error("Relay [{}] unexpected IPacket05ClientSuccess for '{}'", LANServerController.lanRelaySocket.getURI(), clientId); logger.error("Relay [{}] unexpected IPacket05ClientSuccess for '{}'", LANServerController.lanRelaySocket.getURI(), clientId);
} }
} }
@ -144,24 +83,67 @@ class LANClientPeer {
} }
protected void update() { protected void update() {
if(state == CONNECTED) { if(state != CLOSED) {
if(state != CONNECTED && EagRuntime.steadyTimeMillis() - startTime > 10000l) {
logger.info("LAN client '{}' handshake timed out", clientId);
disconnect();
return;
}
List<LANPeerEvent> l = PlatformWebRTC.serverLANGetAllEvent(clientId); List<LANPeerEvent> l = PlatformWebRTC.serverLANGetAllEvent(clientId);
if(l == null) { if(l == null) {
return; return;
} }
Iterator<LANPeerEvent> itr = l.iterator(); read_loop: for(int i = 0, s = l.size(); i < s; ++i) {
while(state == CONNECTED && itr.hasNext()) { LANPeerEvent evt = l.get(i);
LANPeerEvent evt = itr.next(); if(evt instanceof LANPeerEvent.LANPeerDisconnectEvent) {
if(evt instanceof LANPeerEvent.LANPeerPacketEvent) {
ClientPlatformSingleplayer.sendPacket(new IPCPacketData(clientId, ((LANPeerEvent.LANPeerPacketEvent)evt).payload));
}else if(evt instanceof LANPeerEvent.LANPeerDisconnectEvent) {
logger.info("LAN client '{}' disconnected", clientId); logger.info("LAN client '{}' disconnected", clientId);
disconnect(); disconnect();
}else { }else {
logger.error("LAN client '{}' had an accident: {}", clientId, evt.getClass().getSimpleName()); switch(state) {
case RECEIVED_ICE_CANDIDATE: {
if(evt instanceof LANPeerEvent.LANPeerICECandidateEvent) {
LANServerController.lanRelaySocket.writePacket(new RelayPacket03ICECandidate(clientId, ((LANPeerEvent.LANPeerICECandidateEvent)evt).candidates));
state = SENT_ICE_CANDIDATE;
continue read_loop;
}
}
case RECEIVED_DESCRIPTION: {
if(evt instanceof LANPeerEvent.LANPeerDescriptionEvent) {
LANServerController.lanRelaySocket.writePacket(new RelayPacket04Description(clientId, ((LANPeerEvent.LANPeerDescriptionEvent)evt).description));
state = SENT_DESCRIPTION;
continue read_loop;
}
}
case SENT_ICE_CANDIDATE:
case RECEIVED_SUCCESS: {
if(evt instanceof LANPeerEvent.LANPeerDataChannelEvent) {
SingleplayerServerController.openPlayerChannel(clientId);
PlatformWebRTC.serverLANPeerMapIPC(clientId, clientId);
state = CONNECTED;
continue read_loop;
}
}
case CONNECTED: {
if(evt instanceof LANPeerEvent.LANPeerPacketEvent) {
//logger.warn("Forwarding packet for '{}' to IPC channel manually, even though the channel should be mapped", clientId);
// just to be safe
ClientPlatformSingleplayer.sendPacket(new IPCPacketData(clientId, ((LANPeerEvent.LANPeerPacketEvent)evt).payload));
continue read_loop;
}
}
default: {
break;
}
}
if(state != CLOSED) {
logger.error("LAN client '{}' had an accident: {}", clientId, evt.getClass().getSimpleName());
}
disconnect(); disconnect();
return;
} }
} }
}else {
disconnect();
} }
} }

View File

@ -12,6 +12,7 @@ import java.util.Set;
import net.lax1dude.eaglercraft.v1_8.EagRuntime; import net.lax1dude.eaglercraft.v1_8.EagRuntime;
import net.lax1dude.eaglercraft.v1_8.internal.PlatformWebRTC; import net.lax1dude.eaglercraft.v1_8.internal.PlatformWebRTC;
import net.lax1dude.eaglercraft.v1_8.sp.relay.RelayManager; import net.lax1dude.eaglercraft.v1_8.sp.relay.RelayManager;
import net.lax1dude.eaglercraft.v1_8.sp.relay.RelayQueryDispatch;
import net.lax1dude.eaglercraft.v1_8.sp.relay.RelayServer; import net.lax1dude.eaglercraft.v1_8.sp.relay.RelayServer;
import net.lax1dude.eaglercraft.v1_8.sp.relay.RelayWorldsQuery; import net.lax1dude.eaglercraft.v1_8.sp.relay.RelayWorldsQuery;
import net.lax1dude.eaglercraft.v1_8.sp.relay.pkt.RelayPacket07LocalWorlds; import net.lax1dude.eaglercraft.v1_8.sp.relay.pkt.RelayPacket07LocalWorlds;
@ -123,7 +124,7 @@ public class LANServerList {
for(int i = 0, l = RelayManager.relayManager.count(); i < l; ++i) { for(int i = 0, l = RelayManager.relayManager.count(); i < l; ++i) {
RelayServer srv = RelayManager.relayManager.get(i); RelayServer srv = RelayManager.relayManager.get(i);
if(!lanServersQueryList.containsKey(srv.address) && !deadURIs.contains(srv.address)) { if(!lanServersQueryList.containsKey(srv.address) && !deadURIs.contains(srv.address)) {
lanServersQueryList.put(srv.address, PlatformWebRTC.openRelayWorldsQuery(srv.address)); lanServersQueryList.put(srv.address, RelayQueryDispatch.openRelayWorldsQuery(srv.address));
} }
} }
} }

View File

@ -0,0 +1,44 @@
package net.lax1dude.eaglercraft.v1_8.sp.relay;
/**
* Copyright (c) 2024 lax1dude. All Rights Reserved.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
* IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
* INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
* NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
* PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
* WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
* POSSIBILITY OF SUCH DAMAGE.
*
*/
public class RelayQueryDispatch {
public static RelayQuery openRelayQuery(String addr) {
RelayQuery.RateLimit limit = RelayServerRateLimitTracker.isLimited(addr);
if(limit == RelayQuery.RateLimit.LOCKED || limit == RelayQuery.RateLimit.BLOCKED) {
return new RelayQueryRateLimitDummy(limit);
}
return new RelayQueryImpl(addr);
}
public static RelayWorldsQuery openRelayWorldsQuery(String addr) {
RelayQuery.RateLimit limit = RelayServerRateLimitTracker.isLimited(addr);
if(limit == RelayQuery.RateLimit.LOCKED || limit == RelayQuery.RateLimit.BLOCKED) {
return new RelayWorldsQueryRateLimitDummy(limit);
}
return new RelayWorldsQueryImpl(addr);
}
public static RelayServerSocket openRelayConnection(String addr, int timeout) {
RelayQuery.RateLimit limit = RelayServerRateLimitTracker.isLimited(addr);
if(limit == RelayQuery.RateLimit.LOCKED || limit == RelayQuery.RateLimit.BLOCKED) {
return new RelayServerSocketRateLimitDummy(limit);
}
return new RelayServerSocketImpl(addr, timeout);
}
}

View File

@ -89,7 +89,7 @@ public class RelayServer {
public void ping() { public void ping() {
if(PlatformWebRTC.supported()) { if(PlatformWebRTC.supported()) {
close(); close();
query = PlatformWebRTC.openRelayQuery(address); query = RelayQueryDispatch.openRelayQuery(address);
queriedVersion = -1; queriedVersion = -1;
queriedComment = null; queriedComment = null;
queriedVendor = null; queriedVendor = null;
@ -142,7 +142,7 @@ public class RelayServer {
} }
public RelayServerSocket openSocket() { public RelayServerSocket openSocket() {
return PlatformWebRTC.openRelayConnection(address, Minecraft.getMinecraft().gameSettings.relayTimeout * 1000); return RelayQueryDispatch.openRelayConnection(address, Minecraft.getMinecraft().gameSettings.relayTimeout * 1000);
} }
} }

View File

@ -10,8 +10,8 @@ import net.lax1dude.eaglercraft.v1_8.EagRuntime;
import net.lax1dude.eaglercraft.v1_8.EaglerInputStream; import net.lax1dude.eaglercraft.v1_8.EaglerInputStream;
import net.lax1dude.eaglercraft.v1_8.EaglerOutputStream; import net.lax1dude.eaglercraft.v1_8.EaglerOutputStream;
import net.lax1dude.eaglercraft.v1_8.internal.PlatformApplication; import net.lax1dude.eaglercraft.v1_8.internal.PlatformApplication;
import net.lax1dude.eaglercraft.v1_8.internal.PlatformWebRTC;
import net.lax1dude.eaglercraft.v1_8.sp.relay.RelayManager; import net.lax1dude.eaglercraft.v1_8.sp.relay.RelayManager;
import net.lax1dude.eaglercraft.v1_8.sp.relay.RelayQueryDispatch;
import net.lax1dude.eaglercraft.v1_8.sp.relay.RelayServerSocket; import net.lax1dude.eaglercraft.v1_8.sp.relay.RelayServerSocket;
import net.lax1dude.eaglercraft.v1_8.sp.relay.pkt.RelayPacket00Handshake; import net.lax1dude.eaglercraft.v1_8.sp.relay.pkt.RelayPacket00Handshake;
import net.minecraft.client.Minecraft; import net.minecraft.client.Minecraft;
@ -111,7 +111,7 @@ public class RelayUpdateChecker {
private static void connect(RelayEntry socket) { private static void connect(RelayEntry socket) {
try { try {
socket.handshake = false; socket.handshake = false;
socket.currentSocket = PlatformWebRTC.openRelayConnection(socket.uri, 10000); socket.currentSocket = RelayQueryDispatch.openRelayConnection(socket.uri, 10000);
if(socket.currentSocket.isClosed()) { if(socket.currentSocket.isClosed()) {
socket.currentSocket = null; socket.currentSocket = null;
} }

View File

@ -1,20 +0,0 @@
package net.lax1dude.eaglercraft.v1_8.voice;
/**
* Copyright (c) 2024 ayunami2000. All Rights Reserved.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
* IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
* INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
* NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
* PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
* WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
* POSSIBILITY OF SUCH DAMAGE.
*
*/
public enum EnumVoiceChannelPeerState {
FAILED, SUCCESS, LOADING;
}

View File

@ -20,6 +20,7 @@ import net.lax1dude.eaglercraft.v1_8.profile.EaglerProfile;
import net.lax1dude.eaglercraft.v1_8.socket.protocol.pkt.GameMessagePacket; import net.lax1dude.eaglercraft.v1_8.socket.protocol.pkt.GameMessagePacket;
import net.lax1dude.eaglercraft.v1_8.socket.protocol.pkt.client.*; import net.lax1dude.eaglercraft.v1_8.socket.protocol.pkt.client.*;
import net.lax1dude.eaglercraft.v1_8.socket.protocol.pkt.server.SPacketVoiceSignalGlobalEAG; import net.lax1dude.eaglercraft.v1_8.socket.protocol.pkt.server.SPacketVoiceSignalGlobalEAG;
import net.lax1dude.eaglercraft.v1_8.sp.lan.LANServerController;
import net.minecraft.client.Minecraft; import net.minecraft.client.Minecraft;
import net.minecraft.entity.player.EntityPlayer; import net.minecraft.entity.player.EntityPlayer;
@ -133,23 +134,23 @@ public class VoiceClientController {
} }
public static void handleVoiceSignalPacketTypeConnect(EaglercraftUUID user, boolean offer) { public static void handleVoiceSignalPacketTypeConnect(EaglercraftUUID user, boolean offer) {
PlatformVoiceClient.signalConnect(user, offer); if (voiceChannel != EnumVoiceChannelType.NONE) PlatformVoiceClient.signalConnect(user, offer);
} }
public static void handleVoiceSignalPacketTypeConnectAnnounce(EaglercraftUUID user) { public static void handleVoiceSignalPacketTypeConnectAnnounce(EaglercraftUUID user) {
sendPacketRequest(user); if (voiceChannel != EnumVoiceChannelType.NONE) sendPacketRequest(user);
} }
public static void handleVoiceSignalPacketTypeDisconnect(EaglercraftUUID user) { public static void handleVoiceSignalPacketTypeDisconnect(EaglercraftUUID user) {
PlatformVoiceClient.signalDisconnect(user, true); if (voiceChannel != EnumVoiceChannelType.NONE) PlatformVoiceClient.signalDisconnect(user, true);
} }
public static void handleVoiceSignalPacketTypeICECandidate(EaglercraftUUID user, String ice) { public static void handleVoiceSignalPacketTypeICECandidate(EaglercraftUUID user, String ice) {
PlatformVoiceClient.signalICECandidate(user, ice); if (voiceChannel != EnumVoiceChannelType.NONE) PlatformVoiceClient.signalICECandidate(user, ice);
} }
public static void handleVoiceSignalPacketTypeDescription(EaglercraftUUID user, String desc) { public static void handleVoiceSignalPacketTypeDescription(EaglercraftUUID user, String desc) {
PlatformVoiceClient.signalDescription(user, desc); if (voiceChannel != EnumVoiceChannelType.NONE) PlatformVoiceClient.signalDescription(user, desc);
} }
public static void tickVoiceClient(Minecraft mc) { public static void tickVoiceClient(Minecraft mc) {
@ -161,6 +162,11 @@ public class VoiceClientController {
if (getVoiceChannel() != EnumVoiceChannelType.NONE && (getVoiceStatus() == EnumVoiceChannelStatus.CONNECTING || getVoiceStatus() == EnumVoiceChannelStatus.CONNECTED)) { if (getVoiceChannel() != EnumVoiceChannelType.NONE && (getVoiceStatus() == EnumVoiceChannelStatus.CONNECTING || getVoiceStatus() == EnumVoiceChannelStatus.CONNECTED)) {
activateVoice((mc.currentScreen == null || !mc.currentScreen.blockPTTKey()) && Keyboard.isKeyDown(mc.gameSettings.voicePTTKey)); activateVoice((mc.currentScreen == null || !mc.currentScreen.blockPTTKey()) && Keyboard.isKeyDown(mc.gameSettings.voicePTTKey));
if(mc.isSingleplayer() && !LANServerController.isHostingLAN()) {
setVoiceChannel(EnumVoiceChannelType.NONE);
return;
}
if (mc.theWorld != null && mc.thePlayer != null) { if (mc.theWorld != null && mc.thePlayer != null) {
HashSet<EaglercraftUUID> seenPlayers = new HashSet<>(); HashSet<EaglercraftUUID> seenPlayers = new HashSet<>();
for (EntityPlayer player : mc.theWorld.playerEntities) { for (EntityPlayer player : mc.theWorld.playerEntities) {
@ -209,7 +215,6 @@ public class VoiceClientController {
public static void setVoiceChannel(EnumVoiceChannelType channel) { public static void setVoiceChannel(EnumVoiceChannelType channel) {
if (voiceChannel == channel) return; if (voiceChannel == channel) return;
if (channel != EnumVoiceChannelType.NONE) PlatformVoiceClient.initializeDevices(); if (channel != EnumVoiceChannelType.NONE) PlatformVoiceClient.initializeDevices();
PlatformVoiceClient.resetPeerStates();
if (channel == EnumVoiceChannelType.NONE) { if (channel == EnumVoiceChannelType.NONE) {
for (EaglercraftUUID uuid : nearbyPlayers) { for (EaglercraftUUID uuid : nearbyPlayers) {
PlatformVoiceClient.signalDisconnect(uuid, false); PlatformVoiceClient.signalDisconnect(uuid, false);
@ -261,13 +266,10 @@ public class VoiceClientController {
return voiceChannel; return voiceChannel;
} }
private static boolean voicePeerErrored() {
return PlatformVoiceClient.getPeerState() == EnumVoiceChannelPeerState.FAILED || PlatformVoiceClient.getPeerStateConnect() == EnumVoiceChannelPeerState.FAILED || PlatformVoiceClient.getPeerStateInitial() == EnumVoiceChannelPeerState.FAILED || PlatformVoiceClient.getPeerStateDesc() == EnumVoiceChannelPeerState.FAILED || PlatformVoiceClient.getPeerStateIce() == EnumVoiceChannelPeerState.FAILED;
}
public static EnumVoiceChannelStatus getVoiceStatus() { public static EnumVoiceChannelStatus getVoiceStatus() {
return (!isClientSupported() || !isServerSupported()) ? EnumVoiceChannelStatus.UNAVAILABLE : return (!isClientSupported() || !isServerSupported()) ? EnumVoiceChannelStatus.UNAVAILABLE :
(PlatformVoiceClient.getReadyState() != EnumVoiceChannelReadyState.DEVICE_INITIALIZED ? (PlatformVoiceClient.getReadyState() != EnumVoiceChannelReadyState.DEVICE_INITIALIZED ?
EnumVoiceChannelStatus.CONNECTING : (voicePeerErrored() ? EnumVoiceChannelStatus.UNAVAILABLE : EnumVoiceChannelStatus.CONNECTED)); EnumVoiceChannelStatus.CONNECTING : EnumVoiceChannelStatus.CONNECTED);
} }
private static boolean talkStatus = false; private static boolean talkStatus = false;
@ -352,35 +354,47 @@ public class VoiceClientController {
} }
public static void sendPacketICE(EaglercraftUUID peerId, String candidate) { public static void sendPacketICE(EaglercraftUUID peerId, String candidate) {
packetSendCallback.accept(new CPacketVoiceSignalICEEAG(peerId.msb, peerId.lsb, candidate)); if(packetSendCallback != null) {
packetSendCallback.accept(new CPacketVoiceSignalICEEAG(peerId.msb, peerId.lsb, candidate));
}
} }
public static void sendPacketDesc(EaglercraftUUID peerId, String desc) { public static void sendPacketDesc(EaglercraftUUID peerId, String desc) {
packetSendCallback.accept(new CPacketVoiceSignalDescEAG(peerId.msb, peerId.lsb, desc)); if(packetSendCallback != null) {
packetSendCallback.accept(new CPacketVoiceSignalDescEAG(peerId.msb, peerId.lsb, desc));
}
} }
public static void sendPacketDisconnect() { public static void sendPacketDisconnect() {
if(protocolVersion <= 3) { if(packetSendCallback != null) {
packetSendCallback.accept(new CPacketVoiceSignalDisconnectV3EAG()); if(protocolVersion <= 3) {
}else { packetSendCallback.accept(new CPacketVoiceSignalDisconnectV3EAG());
packetSendCallback.accept(new CPacketVoiceSignalDisconnectV4EAG()); }else {
packetSendCallback.accept(new CPacketVoiceSignalDisconnectV4EAG());
}
} }
} }
public static void sendPacketDisconnectPeer(EaglercraftUUID peerId) { public static void sendPacketDisconnectPeer(EaglercraftUUID peerId) {
if(protocolVersion <= 3) { if(packetSendCallback != null) {
packetSendCallback.accept(new CPacketVoiceSignalDisconnectV3EAG(true, peerId.msb, peerId.lsb)); if(protocolVersion <= 3) {
}else { packetSendCallback.accept(new CPacketVoiceSignalDisconnectV3EAG(true, peerId.msb, peerId.lsb));
packetSendCallback.accept(new CPacketVoiceSignalDisconnectPeerV4EAG(peerId.msb, peerId.lsb)); }else {
packetSendCallback.accept(new CPacketVoiceSignalDisconnectPeerV4EAG(peerId.msb, peerId.lsb));
}
} }
} }
public static void sendPacketConnect() { public static void sendPacketConnect() {
packetSendCallback.accept(new CPacketVoiceSignalConnectEAG()); if(packetSendCallback != null) {
packetSendCallback.accept(new CPacketVoiceSignalConnectEAG());
}
} }
public static void sendPacketRequest(EaglercraftUUID peerId) { public static void sendPacketRequest(EaglercraftUUID peerId) {
packetSendCallback.accept(new CPacketVoiceSignalRequestEAG(peerId.msb, peerId.lsb)); if(packetSendCallback != null) {
packetSendCallback.accept(new CPacketVoiceSignalRequestEAG(peerId.msb, peerId.lsb));
}
} }
private static void sendPacketRequestIfNeeded(EaglercraftUUID uuid) { private static void sendPacketRequestIfNeeded(EaglercraftUUID uuid) {

View File

@ -119,7 +119,7 @@ public class PlatformApplication {
}); });
} }
@JSBody(params = { "cb" }, script = "if(!navigator.clipboard) { cb(null); } else if (!navigator.clipboard.readText) cb(null); else navigator.clipboard.readText().then(function(s) { cb(s || null); }, function() { cb(null); });") @JSBody(params = { "cb" }, script = "if(!navigator.clipboard) { cb(null); } else if (!navigator.clipboard.readText) cb(null); else navigator.clipboard.readText().then(function(s) { cb((typeof s === \"string\") ? s : null); }, function(err) { cb(null); });")
private static native void getClipboard1(StupidFunctionResolveString cb); private static native void getClipboard1(StupidFunctionResolveString cb);
@JSBody(params = { "str" }, script = "if(navigator.clipboard) { navigator.clipboard.writeText(str); return true; } else { return false; }") @JSBody(params = { "str" }, script = "if(navigator.clipboard) { navigator.clipboard.writeText(str); return true; } else { return false; }")
@ -212,7 +212,7 @@ public class PlatformApplication {
} }
@JSBody(params = { "ctx", "buffer", "w", "h" }, script = "var imgData = ctx.createImageData(w, h); var ww = w * 4; for(var i = 0; i < h; ++i) { imgData.data.set(new Uint8ClampedArray(buffer, (h - i - 1) * ww, ww), i * ww); } ctx.putImageData(imgData, 0, 0);") @JSBody(params = { "ctx", "buffer", "w", "h" }, script = "var imgData = ctx.createImageData(w, h); var ww = w * 4; for(var i = 0; i < h; ++i) { imgData.data.set(new Uint8ClampedArray(buffer, (h - i - 1) * ww, ww), i * ww); } ctx.putImageData(imgData, 0, 0);")
private static native JSObject putImageData(CanvasRenderingContext2D ctx, ArrayBuffer buffer, int w, int h); private static native void putImageData(CanvasRenderingContext2D ctx, ArrayBuffer buffer, int w, int h);
@JSBody(params = { "cvs", "name", "parentElement" }, script = @JSBody(params = { "cvs", "name", "parentElement" }, script =
"var vigg = function(el, url){" + "var vigg = function(el, url){" +
@ -474,7 +474,7 @@ public class PlatformApplication {
} }
@JSFunctor @JSFunctor
private static interface DownloadBytesBlobURLRevoke extends JSObject { static interface DownloadBytesBlobURLRevoke extends JSObject {
void call(); void call();
} }
@ -507,6 +507,10 @@ public class PlatformApplication {
downloadBytesImpl(str, blobHandle.toExternalForm(), blobHandle::release, PlatformRuntime.parent); downloadBytesImpl(str, blobHandle.toExternalForm(), blobHandle::release, PlatformRuntime.parent);
} }
static void downloadURLWithNameTeaVM(String str, String url, DownloadBytesBlobURLRevoke revoker) {
downloadBytesImpl(str, url, revoker, PlatformRuntime.parent);
}
public static void showDebugConsole() { public static void showDebugConsole() {
DebugConsoleWindow.showDebugConsole(); DebugConsoleWindow.showDebugConsole();
} }

View File

@ -87,16 +87,19 @@ public class PlatformAudio {
protected final PannerNode panner; protected final PannerNode panner;
protected final GainNode gain; protected final GainNode gain;
protected float pitch; protected float pitch;
protected boolean repeat;
protected boolean isPaused = false; protected boolean isPaused = false;
protected boolean isEnded = false; protected boolean isEnded = false;
protected boolean isDisposed = false;
public BrowserAudioHandle(BrowserAudioResource resource, AudioBufferSourceNode source, PannerNode panner, public BrowserAudioHandle(BrowserAudioResource resource, AudioBufferSourceNode source, PannerNode panner,
GainNode gain, float pitch) { GainNode gain, float pitch, boolean repeat) {
this.resource = resource; this.resource = resource;
this.source = source; this.source = source;
this.panner = panner; this.panner = panner;
this.gain = gain; this.gain = gain;
this.pitch = pitch; this.pitch = pitch;
this.repeat = repeat;
source.setOnEnded(this); source.setOnEnded(this);
} }
@ -115,6 +118,14 @@ public class PlatformAudio {
} }
} }
@Override
public void repeat(boolean en) {
repeat = en;
if(!isEnded) {
source.setLoop(en);
}
}
@Override @Override
public void restart() { public void restart() {
if(isEnded) { if(isEnded) {
@ -124,11 +135,21 @@ public class PlatformAudio {
resource.cacheHit = PlatformRuntime.steadyTimeMillis(); resource.cacheHit = PlatformRuntime.steadyTimeMillis();
src.setBuffer(resource.buffer); src.setBuffer(resource.buffer);
src.getPlaybackRate().setValue(pitch); src.getPlaybackRate().setValue(pitch);
src.setLoop(repeat);
source.disconnect(); source.disconnect();
src.connect(panner == null ? gain : panner); src.connect(panner == null ? gain : panner);
if(isDisposed) {
isDisposed = false;
activeSounds.add(this);
gain.connect(audioctx.getDestination());
if(gameRecGain != null) {
gain.connect(gameRecGain);
}
}
source = src; source = src;
source.start(); source.start();
}else { }else {
isPaused = false;
source.getPlaybackRate().setValue(pitch); source.getPlaybackRate().setValue(pitch);
source.start(0.0); source.start(0.0);
} }
@ -179,6 +200,12 @@ public class PlatformAudio {
isEnded = true; isEnded = true;
} }
private void dispose() {
if(!isDisposed) {
isDisposed = true;
gain.disconnect();
}
}
} }
static void initialize() { static void initialize() {
@ -304,10 +331,9 @@ public class PlatformAudio {
gameRecGain = audioctx.createGain(); gameRecGain = audioctx.createGain();
gameRecGain.getGain().setValue(gameVol); gameRecGain.getGain().setValue(gameVol);
for(BrowserAudioHandle handle : activeSounds) { for(BrowserAudioHandle handle : activeSounds) {
if(handle.panner != null) { try {
handle.panner.connect(gameRecGain);
}else {
handle.gain.connect(gameRecGain); handle.gain.connect(gameRecGain);
}catch(Throwable t) {
} }
} }
PlatformVoiceClient.addRecordingDest(gameRecGain); PlatformVoiceClient.addRecordingDest(gameRecGain);
@ -342,11 +368,7 @@ public class PlatformAudio {
} }
for(BrowserAudioHandle handle : activeSounds) { for(BrowserAudioHandle handle : activeSounds) {
try { try {
if(handle.panner != null) { handle.gain.disconnect(gameRecGain);
handle.panner.disconnect(gameRecGain);
}else {
handle.gain.disconnect(gameRecGain);
}
}catch(Throwable t) { }catch(Throwable t) {
} }
} }
@ -451,8 +473,10 @@ public class PlatformAudio {
activeFreeTimer = millis; activeFreeTimer = millis;
Iterator<BrowserAudioHandle> itr = activeSounds.iterator(); Iterator<BrowserAudioHandle> itr = activeSounds.iterator();
while(itr.hasNext()) { while(itr.hasNext()) {
if(itr.next().shouldFree()) { BrowserAudioHandle h = itr.next();
if(h.shouldFree()) {
itr.remove(); itr.remove();
h.dispose();
} }
} }
} }
@ -460,6 +484,10 @@ public class PlatformAudio {
public static void flushAudioCache() { public static void flushAudioCache() {
soundCache.clear(); soundCache.clear();
Iterator<BrowserAudioHandle> itr = activeSounds.iterator();
while(itr.hasNext()) {
itr.next().dispose();
}
activeSounds.clear(); activeSounds.clear();
} }
@ -468,13 +496,14 @@ public class PlatformAudio {
} }
public static IAudioHandle beginPlayback(IAudioResource track, float x, float y, float z, public static IAudioHandle beginPlayback(IAudioResource track, float x, float y, float z,
float volume, float pitch) { float volume, float pitch, boolean repeat) {
BrowserAudioResource internalTrack = (BrowserAudioResource) track; BrowserAudioResource internalTrack = (BrowserAudioResource) track;
internalTrack.cacheHit = PlatformRuntime.steadyTimeMillis(); internalTrack.cacheHit = PlatformRuntime.steadyTimeMillis();
AudioBufferSourceNode src = audioctx.createBufferSource(); AudioBufferSourceNode src = audioctx.createBufferSource();
src.setBuffer(internalTrack.buffer); src.setBuffer(internalTrack.buffer);
src.getPlaybackRate().setValue(pitch); src.getPlaybackRate().setValue(pitch);
src.setLoop(repeat);
PannerNode panner = audioctx.createPanner(); PannerNode panner = audioctx.createPanner();
panner.setPosition(x, y, z); panner.setPosition(x, y, z);
@ -503,18 +532,19 @@ public class PlatformAudio {
src.start(); src.start();
BrowserAudioHandle ret = new BrowserAudioHandle(internalTrack, src, panner, gain, pitch); BrowserAudioHandle ret = new BrowserAudioHandle(internalTrack, src, panner, gain, pitch, repeat);
activeSounds.add(ret); activeSounds.add(ret);
return ret; return ret;
} }
public static IAudioHandle beginPlaybackStatic(IAudioResource track, float volume, float pitch) { public static IAudioHandle beginPlaybackStatic(IAudioResource track, float volume, float pitch, boolean repeat) {
BrowserAudioResource internalTrack = (BrowserAudioResource) track; BrowserAudioResource internalTrack = (BrowserAudioResource) track;
internalTrack.cacheHit = PlatformRuntime.steadyTimeMillis(); internalTrack.cacheHit = PlatformRuntime.steadyTimeMillis();
AudioBufferSourceNode src = audioctx.createBufferSource(); AudioBufferSourceNode src = audioctx.createBufferSource();
src.setBuffer(internalTrack.buffer); src.setBuffer(internalTrack.buffer);
src.getPlaybackRate().setValue(pitch); src.getPlaybackRate().setValue(pitch);
src.setLoop(repeat);
GainNode gain = audioctx.createGain(); GainNode gain = audioctx.createGain();
float v2 = volume; float v2 = volume;
@ -529,7 +559,7 @@ public class PlatformAudio {
src.start(); src.start();
BrowserAudioHandle ret = new BrowserAudioHandle(internalTrack, src, null, gain, pitch); BrowserAudioHandle ret = new BrowserAudioHandle(internalTrack, src, null, gain, pitch, repeat);
activeSounds.add(ret); activeSounds.add(ret);
return ret; return ret;
} }

View File

@ -330,7 +330,7 @@ public class PlatformInput {
if(tryGrabCursorHook()) return; if(tryGrabCursorHook()) return;
int b = evt.getButton(); int b = evt.getButton();
b = b == 1 ? 2 : (b == 2 ? 1 : b); b = b == 1 ? 2 : (b == 2 ? 1 : b);
buttonStates[b] = true; if(b >= 0 && b < buttonStates.length) buttonStates[b] = true;
int eventX = (int)(getOffsetX(evt, touchOffsetXTeaVM) * windowDPI); int eventX = (int)(getOffsetX(evt, touchOffsetXTeaVM) * windowDPI);
int eventY = windowHeight - (int)(getOffsetY(evt, touchOffsetYTeaVM) * windowDPI) - 1; int eventY = windowHeight - (int)(getOffsetY(evt, touchOffsetYTeaVM) * windowDPI) - 1;
synchronized(mouseEvents) { synchronized(mouseEvents) {
@ -348,7 +348,7 @@ public class PlatformInput {
evt.stopPropagation(); evt.stopPropagation();
int b = evt.getButton(); int b = evt.getButton();
b = b == 1 ? 2 : (b == 2 ? 1 : b); b = b == 1 ? 2 : (b == 2 ? 1 : b);
buttonStates[b] = false; if(b >= 0 && b < buttonStates.length) buttonStates[b] = false;
int eventX = (int)(getOffsetX(evt, touchOffsetXTeaVM) * windowDPI); int eventX = (int)(getOffsetX(evt, touchOffsetXTeaVM) * windowDPI);
int eventY = windowHeight - (int)(getOffsetY(evt, touchOffsetYTeaVM) * windowDPI) - 1; int eventY = windowHeight - (int)(getOffsetY(evt, touchOffsetYTeaVM) * windowDPI) - 1;
synchronized(mouseEvents) { synchronized(mouseEvents) {
@ -366,8 +366,10 @@ public class PlatformInput {
evt.stopPropagation(); evt.stopPropagation();
mouseX = (int)(getOffsetX(evt, touchOffsetXTeaVM) * windowDPI); mouseX = (int)(getOffsetX(evt, touchOffsetXTeaVM) * windowDPI);
mouseY = windowHeight - (int)(getOffsetY(evt, touchOffsetYTeaVM) * windowDPI) - 1; mouseY = windowHeight - (int)(getOffsetY(evt, touchOffsetYTeaVM) * windowDPI) - 1;
mouseDX += evt.getMovementX(); if(pointerLockFlag) {
mouseDY += -evt.getMovementY(); mouseDX += evt.getMovementX();
mouseDY += -evt.getMovementY();
}
if(hasShownPressAnyKey) { if(hasShownPressAnyKey) {
int eventX = (int)(getOffsetX(evt, touchOffsetXTeaVM) * windowDPI); int eventX = (int)(getOffsetX(evt, touchOffsetXTeaVM) * windowDPI);
int eventY = windowHeight - (int)(getOffsetY(evt, touchOffsetYTeaVM) * windowDPI) - 1; int eventY = windowHeight - (int)(getOffsetY(evt, touchOffsetYTeaVM) * windowDPI) - 1;
@ -765,7 +767,7 @@ public class PlatformInput {
win.addEventListener("gamepaddisconnected", gamepaddisconnected = new EventListener<GamepadEvent>() { win.addEventListener("gamepaddisconnected", gamepaddisconnected = new EventListener<GamepadEvent>() {
@Override @Override
public void handleEvent(GamepadEvent evt) { public void handleEvent(GamepadEvent evt) {
if(evt.getGamepad() == selectedGamepad) { if(selectedGamepad != null && evt.getGamepad().getIndex() == selectedGamepad.getIndex()) {
selectedGamepad = null; selectedGamepad = null;
} }
enumerateGamepads(); enumerateGamepads();
@ -1287,7 +1289,7 @@ public class PlatformInput {
public static int mouseGetDWheel() { public static int mouseGetDWheel() {
int ret = (int)mouseDWheel; int ret = (int)mouseDWheel;
mouseDWheel = 0.0D; mouseDWheel -= ret;
return ret; return ret;
} }

View File

@ -599,7 +599,11 @@ public class PlatformRuntime {
} }
public static void downloadRemoteURIByteArray(String assetPackageURI, final Consumer<byte[]> cb) { public static void downloadRemoteURIByteArray(String assetPackageURI, final Consumer<byte[]> cb) {
downloadRemoteURI(assetPackageURI, arr -> cb.accept(TeaVMUtils.wrapByteArrayBuffer(arr))); downloadRemoteURIByteArray(assetPackageURI, false, cb);
}
public static void downloadRemoteURIByteArray(String assetPackageURI, boolean useCache, final Consumer<byte[]> cb) {
downloadRemoteURI(assetPackageURI, useCache, arr -> cb.accept(TeaVMUtils.wrapByteArrayBuffer(arr)));
} }
public static void downloadRemoteURI(String assetPackageURI, final Consumer<ArrayBuffer> cb) { public static void downloadRemoteURI(String assetPackageURI, final Consumer<ArrayBuffer> cb) {

View File

@ -3,7 +3,6 @@ package net.lax1dude.eaglercraft.v1_8.internal;
import java.text.SimpleDateFormat; import java.text.SimpleDateFormat;
import java.util.Date; import java.util.Date;
import java.util.EnumSet; import java.util.EnumSet;
import java.util.HashSet;
import java.util.Set; import java.util.Set;
import org.teavm.interop.Async; import org.teavm.interop.Async;
@ -16,7 +15,6 @@ import org.teavm.jso.browser.Window;
import org.teavm.jso.canvas.CanvasRenderingContext2D; import org.teavm.jso.canvas.CanvasRenderingContext2D;
import org.teavm.jso.dom.events.Event; import org.teavm.jso.dom.events.Event;
import org.teavm.jso.dom.events.EventListener; import org.teavm.jso.dom.events.EventListener;
import org.teavm.jso.dom.html.HTMLAnchorElement;
import org.teavm.jso.dom.html.HTMLCanvasElement; import org.teavm.jso.dom.html.HTMLCanvasElement;
import org.teavm.jso.webaudio.MediaStream; import org.teavm.jso.webaudio.MediaStream;
@ -193,19 +191,11 @@ public class PlatformScreenRecord {
final String fileName = EaglercraftVersion.mainMenuStringB + " - " + EaglerProfile.getName() + " - " + fmt.format(new Date()) + "." + params.codec.fileExt; final String fileName = EaglercraftVersion.mainMenuStringB + " - " + EaglerProfile.getName() + " - " + fmt.format(new Date()) + "." + params.codec.fileExt;
if("video/webm".equals(params.codec.container)) { if("video/webm".equals(params.codec.container)) {
FixWebMDurationJS.getRecUrl(evt, (int) (PlatformRuntime.steadyTimeMillis() - startTime), url -> { FixWebMDurationJS.getRecUrl(evt, (int) (PlatformRuntime.steadyTimeMillis() - startTime), url -> {
HTMLAnchorElement a = (HTMLAnchorElement) win.getDocument().createElement("a"); PlatformApplication.downloadURLWithNameTeaVM(fileName, url, () -> TeaVMUtils.freeDataURL(url));
a.setDownload(fileName);
a.setHref(url);
a.click();
TeaVMUtils.freeDataURL(url);
}, logger::info); }, logger::info);
}else { }else {
String url = TeaVMUtils.getDataURL(evt.getData()); String url = TeaVMUtils.getDataURL(evt.getData());
HTMLAnchorElement a = (HTMLAnchorElement) win.getDocument().createElement("a"); PlatformApplication.downloadURLWithNameTeaVM(fileName, url, () -> TeaVMUtils.freeDataURL(url));
a.setDownload(fileName);
a.setHref(url);
a.click();
TeaVMUtils.freeDataURL(url);
} }
} }
}); });

View File

@ -4,7 +4,6 @@ import net.lax1dude.eaglercraft.v1_8.EaglercraftUUID;
import net.lax1dude.eaglercraft.v1_8.internal.teavm.TeaVMUtils; import net.lax1dude.eaglercraft.v1_8.internal.teavm.TeaVMUtils;
import net.lax1dude.eaglercraft.v1_8.log4j.LogManager; import net.lax1dude.eaglercraft.v1_8.log4j.LogManager;
import net.lax1dude.eaglercraft.v1_8.log4j.Logger; import net.lax1dude.eaglercraft.v1_8.log4j.Logger;
import net.lax1dude.eaglercraft.v1_8.voice.EnumVoiceChannelPeerState;
import net.lax1dude.eaglercraft.v1_8.voice.EnumVoiceChannelReadyState; import net.lax1dude.eaglercraft.v1_8.voice.EnumVoiceChannelReadyState;
import net.lax1dude.eaglercraft.v1_8.voice.EnumVoiceChannelType; import net.lax1dude.eaglercraft.v1_8.voice.EnumVoiceChannelType;
import net.lax1dude.eaglercraft.v1_8.voice.VoiceClientController; import net.lax1dude.eaglercraft.v1_8.voice.VoiceClientController;
@ -179,32 +178,17 @@ public class PlatformVoiceClient {
VoiceClientController.sendPacketDesc(peerId, JSON.stringify(desc)); VoiceClientController.sendPacketDesc(peerId, JSON.stringify(desc));
}, err -> { }, err -> {
logger.error("Failed to set local description for \"{}\"! {}", peerId, err); logger.error("Failed to set local description for \"{}\"! {}", peerId, err);
if (peerStateInitial == EnumVoiceChannelPeerState.LOADING) {
peerStateInitial = EnumVoiceChannelPeerState.FAILED;
}
signalDisconnect(VoicePeer.this, false); signalDisconnect(VoicePeer.this, false);
}); });
}, err -> { }, err -> {
logger.error("Failed to set create offer for \"{}\"! {}", peerId, err); logger.error("Failed to set create offer for \"{}\"! {}", peerId, err);
if (peerStateInitial == EnumVoiceChannelPeerState.LOADING) {
peerStateInitial = EnumVoiceChannelPeerState.FAILED;
}
signalDisconnect(VoicePeer.this, false); signalDisconnect(VoicePeer.this, false);
}); });
} }
TeaVMUtils.addEventListener(peerConnection, "connectionstatechange", (EventListener<Event>) evt -> { TeaVMUtils.addEventListener(peerConnection, "connectionstatechange", (EventListener<Event>) evt -> {
String cs = PlatformWebRTC.getConnectionState(peerConnection); String cs = PlatformWebRTC.getConnectionState(peerConnection);
if ("disconnected".equals(cs)) { if ("disconnected".equals(cs) || "failed".equals(cs)) {
signalDisconnect(VoicePeer.this, false);
} else if ("connected".equals(cs)) {
if (peerState != EnumVoiceChannelPeerState.SUCCESS) {
peerState = EnumVoiceChannelPeerState.SUCCESS;
}
} else if ("failed".equals(cs)) {
if (peerState == EnumVoiceChannelPeerState.LOADING) {
peerState = EnumVoiceChannelPeerState.FAILED;
}
signalDisconnect(VoicePeer.this, false); signalDisconnect(VoicePeer.this, false);
} }
}); });
@ -226,26 +210,21 @@ public class PlatformVoiceClient {
PlatformWebRTC.createAnswer(peerConnection, desc -> { PlatformWebRTC.createAnswer(peerConnection, desc -> {
PlatformWebRTC.setLocalDescription(peerConnection, desc, () -> { PlatformWebRTC.setLocalDescription(peerConnection, desc, () -> {
VoiceClientController.sendPacketDesc(peerId, JSON.stringify(desc)); VoiceClientController.sendPacketDesc(peerId, JSON.stringify(desc));
if (peerStateDesc != EnumVoiceChannelPeerState.SUCCESS) peerStateDesc = EnumVoiceChannelPeerState.SUCCESS;
}, err -> { }, err -> {
logger.error("Failed to set local description for \"{}\"! {}", peerId, err.getMessage()); logger.error("Failed to set local description for \"{}\"! {}", peerId, err.getMessage());
if (peerStateDesc == EnumVoiceChannelPeerState.LOADING) peerStateDesc = EnumVoiceChannelPeerState.FAILED;
signalDisconnect(VoicePeer.this, false); signalDisconnect(VoicePeer.this, false);
}); });
}, err -> { }, err -> {
logger.error("Failed to create answer for \"{}\"! {}", peerId, err.getMessage()); logger.error("Failed to create answer for \"{}\"! {}", peerId, err.getMessage());
if (peerStateDesc == EnumVoiceChannelPeerState.LOADING) peerStateDesc = EnumVoiceChannelPeerState.FAILED;
signalDisconnect(VoicePeer.this, false); signalDisconnect(VoicePeer.this, false);
}); });
} }
}, err -> { }, err -> {
logger.error("Failed to set remote description for \"{}\"! {}", peerId, err.getMessage()); logger.error("Failed to set remote description for \"{}\"! {}", peerId, err.getMessage());
if (peerStateDesc == EnumVoiceChannelPeerState.LOADING) peerStateDesc = EnumVoiceChannelPeerState.FAILED;
signalDisconnect(VoicePeer.this, false); signalDisconnect(VoicePeer.this, false);
}); });
} catch (Throwable err) { } catch (Throwable err) {
logger.error("Failed to parse remote description for \"{}\"! {}", peerId, err.getMessage()); logger.error("Failed to parse remote description for \"{}\"! {}", peerId, err.getMessage());
if (peerStateDesc == EnumVoiceChannelPeerState.LOADING) peerStateDesc = EnumVoiceChannelPeerState.FAILED;
signalDisconnect(VoicePeer.this, false); signalDisconnect(VoicePeer.this, false);
} }
} }
@ -253,10 +232,8 @@ public class PlatformVoiceClient {
public void addICECandidate(String candidate) { public void addICECandidate(String candidate) {
try { try {
addIceCandidate(peerConnection, candidate); addIceCandidate(peerConnection, candidate);
if (peerStateIce != EnumVoiceChannelPeerState.SUCCESS) peerStateIce = EnumVoiceChannelPeerState.SUCCESS;
} catch (Throwable err) { } catch (Throwable err) {
logger.error("Failed to parse ice candidate for \"{}\"! {}", peerId, err.getMessage()); logger.error("Failed to parse ice candidate for \"{}\"! {}", peerId, err.getMessage());
if (peerStateIce == EnumVoiceChannelPeerState.LOADING) peerStateIce = EnumVoiceChannelPeerState.FAILED;
signalDisconnect(VoicePeer.this, false); signalDisconnect(VoicePeer.this, false);
} }
} }
@ -269,11 +246,6 @@ public class PlatformVoiceClient {
public static GainNode localMediaStreamGain; public static GainNode localMediaStreamGain;
public static MediaStream localRawMediaStream; public static MediaStream localRawMediaStream;
public static EnumVoiceChannelReadyState readyState = EnumVoiceChannelReadyState.NONE; public static EnumVoiceChannelReadyState readyState = EnumVoiceChannelReadyState.NONE;
public static EnumVoiceChannelPeerState peerState = EnumVoiceChannelPeerState.LOADING;
public static EnumVoiceChannelPeerState peerStateConnect = EnumVoiceChannelPeerState.LOADING;
public static EnumVoiceChannelPeerState peerStateInitial = EnumVoiceChannelPeerState.LOADING;
public static EnumVoiceChannelPeerState peerStateDesc = EnumVoiceChannelPeerState.LOADING;
public static EnumVoiceChannelPeerState peerStateIce = EnumVoiceChannelPeerState.LOADING;
public static AudioContext microphoneVolumeAudioContext = null; public static AudioContext microphoneVolumeAudioContext = null;
public static void setICEServers(String[] urls) { public static void setICEServers(String[] urls) {
@ -348,43 +320,16 @@ public class PlatformVoiceClient {
} }
} }
public static void resetPeerStates() {
peerState = peerStateConnect = peerStateInitial = peerStateDesc = peerStateIce = EnumVoiceChannelPeerState.LOADING;
}
public static EnumVoiceChannelPeerState getPeerState() {
return peerState;
}
public static EnumVoiceChannelPeerState getPeerStateConnect() {
return peerStateConnect;
}
public static EnumVoiceChannelPeerState getPeerStateInitial() {
return peerStateInitial;
}
public static EnumVoiceChannelPeerState getPeerStateDesc() {
return peerStateDesc;
}
public static EnumVoiceChannelPeerState getPeerStateIce() {
return peerStateIce;
}
public static EnumVoiceChannelReadyState getReadyState() { public static EnumVoiceChannelReadyState getReadyState() {
return readyState; return readyState;
} }
public static void signalConnect(EaglercraftUUID peerId, boolean offer) { public static void signalConnect(EaglercraftUUID peerId, boolean offer) {
if (!hasInit) initializeDevices();
try { try {
JSObject peerConnection = PlatformWebRTC.createRTCPeerConnection(JSONWriter.valueToString(iceServers)); JSObject peerConnection = PlatformWebRTC.createRTCPeerConnection(JSONWriter.valueToString(iceServers));
VoicePeer peerInstance = new VoicePeer(peerId, peerConnection, offer); VoicePeer peerInstance = new VoicePeer(peerId, peerConnection, offer);
peerList.put(peerId, peerInstance); peerList.put(peerId, peerInstance);
if (peerStateConnect != EnumVoiceChannelPeerState.SUCCESS) peerStateConnect = EnumVoiceChannelPeerState.SUCCESS;
} catch (Throwable e) { } catch (Throwable e) {
if (peerStateConnect == EnumVoiceChannelPeerState.LOADING) peerStateConnect = EnumVoiceChannelPeerState.FAILED;
} }
} }

View File

@ -4,23 +4,15 @@ import net.lax1dude.eaglercraft.v1_8.EagRuntime;
import net.lax1dude.eaglercraft.v1_8.internal.teavm.TeaVMUtils; import net.lax1dude.eaglercraft.v1_8.internal.teavm.TeaVMUtils;
import net.lax1dude.eaglercraft.v1_8.log4j.LogManager; import net.lax1dude.eaglercraft.v1_8.log4j.LogManager;
import net.lax1dude.eaglercraft.v1_8.log4j.Logger; import net.lax1dude.eaglercraft.v1_8.log4j.Logger;
import net.lax1dude.eaglercraft.v1_8.sp.internal.ClientPlatformSingleplayer;
import net.lax1dude.eaglercraft.v1_8.sp.lan.LANPeerEvent; import net.lax1dude.eaglercraft.v1_8.sp.lan.LANPeerEvent;
import net.lax1dude.eaglercraft.v1_8.sp.relay.RelayQuery;
import net.lax1dude.eaglercraft.v1_8.sp.relay.RelayQueryImpl;
import net.lax1dude.eaglercraft.v1_8.sp.relay.RelayQueryRateLimitDummy;
import net.lax1dude.eaglercraft.v1_8.sp.relay.RelayServerRateLimitTracker;
import net.lax1dude.eaglercraft.v1_8.sp.relay.RelayServerSocket;
import net.lax1dude.eaglercraft.v1_8.sp.relay.RelayServerSocketImpl;
import net.lax1dude.eaglercraft.v1_8.sp.relay.RelayServerSocketRateLimitDummy;
import net.lax1dude.eaglercraft.v1_8.sp.relay.RelayWorldsQuery;
import net.lax1dude.eaglercraft.v1_8.sp.relay.RelayWorldsQueryImpl;
import net.lax1dude.eaglercraft.v1_8.sp.relay.RelayWorldsQueryRateLimitDummy;
import org.json.JSONObject; import org.json.JSONObject;
import org.json.JSONWriter; import org.json.JSONWriter;
import org.teavm.jso.JSBody; import org.teavm.jso.JSBody;
import org.teavm.jso.JSFunctor; import org.teavm.jso.JSFunctor;
import org.teavm.jso.JSObject; import org.teavm.jso.JSObject;
import org.teavm.jso.browser.TimerHandler;
import org.teavm.jso.browser.Window; import org.teavm.jso.browser.Window;
import org.teavm.jso.core.JSError; import org.teavm.jso.core.JSError;
import org.teavm.jso.dom.events.Event; import org.teavm.jso.dom.events.Event;
@ -326,8 +318,6 @@ public class PlatformWebRTC {
@JSBody(params = { "sock", "buffer" }, script = "sock.send(buffer);") @JSBody(params = { "sock", "buffer" }, script = "sock.send(buffer);")
static native void nativeBinarySend(WebSocket sock, ArrayBuffer buffer); static native void nativeBinarySend(WebSocket sock, ArrayBuffer buffer);
private static final Map<String, JSObject> fuckTeaVM = new HashMap<>();
public static void runScheduledTasks() { public static void runScheduledTasks() {
} }
@ -403,12 +393,20 @@ public class PlatformWebRTC {
TeaVMUtils.addEventListener(peerConnection, "icecandidate", (EventListener<Event>) evt -> { TeaVMUtils.addEventListener(peerConnection, "icecandidate", (EventListener<Event>) evt -> {
if (hasCandidate(evt)) { if (hasCandidate(evt)) {
if (iceCandidates.isEmpty()) { if (iceCandidates.isEmpty()) {
Window.setTimeout(() -> { final int[] candidateState = new int[2];
final TimerHandler[] runnable = new TimerHandler[1];
Window.setTimeout(runnable[0] = () -> {
if (peerConnection != null && !"disconnected".equals(getConnectionState(peerConnection))) { if (peerConnection != null && !"disconnected".equals(getConnectionState(peerConnection))) {
int trial = ++candidateState[1];
if(candidateState[0] != iceCandidates.size() && trial < 3) {
candidateState[0] = iceCandidates.size();
Window.setTimeout(runnable[0], 2000);
return;
}
clientICECandidate = JSONWriter.valueToString(iceCandidates); clientICECandidate = JSONWriter.valueToString(iceCandidates);
iceCandidates.clear(); iceCandidates.clear();
} }
}, 3000); }, 2000);
} }
Map<String, String> m = new HashMap<>(); Map<String, String> m = new HashMap<>();
m.put("sdpMLineIndex", "" + getSdpMLineIndex(evt)); m.put("sdpMLineIndex", "" + getSdpMLineIndex(evt));
@ -506,6 +504,8 @@ public class PlatformWebRTC {
public LANServer client; public LANServer client;
public String peerId; public String peerId;
public JSObject peerConnection; public JSObject peerConnection;
public JSObject dataChannel;
public String ipcChannel;
public LANPeer(LANServer client, String peerId, JSObject peerConnection) { public LANPeer(LANServer client, String peerId, JSObject peerConnection) {
this.client = client; this.client = client;
@ -517,15 +517,23 @@ public class PlatformWebRTC {
TeaVMUtils.addEventListener(peerConnection, "icecandidate", (EventListener<Event>) evt -> { TeaVMUtils.addEventListener(peerConnection, "icecandidate", (EventListener<Event>) evt -> {
if (hasCandidate(evt)) { if (hasCandidate(evt)) {
if (iceCandidates.isEmpty()) { if (iceCandidates.isEmpty()) {
Window.setTimeout(() -> { final int[] candidateState = new int[2];
final TimerHandler[] runnable = new TimerHandler[1];
Window.setTimeout(runnable[0] = () -> {
if (peerConnection != null && !"disconnected".equals(getConnectionState(peerConnection))) { if (peerConnection != null && !"disconnected".equals(getConnectionState(peerConnection))) {
int trial = ++candidateState[1];
if(candidateState[0] != iceCandidates.size() && trial < 3) {
candidateState[0] = iceCandidates.size();
Window.setTimeout(runnable[0], 2000);
return;
}
LANPeerEvent.LANPeerICECandidateEvent e = new LANPeerEvent.LANPeerICECandidateEvent(peerId, JSONWriter.valueToString(iceCandidates)); LANPeerEvent.LANPeerICECandidateEvent e = new LANPeerEvent.LANPeerICECandidateEvent(peerId, JSONWriter.valueToString(iceCandidates));
synchronized(serverLANEventBuffer) { synchronized(serverLANEventBuffer) {
serverLANEventBuffer.put(peerId, e); serverLANEventBuffer.put(peerId, e);
} }
iceCandidates.clear(); iceCandidates.clear();
} }
}, 3000); }, 2000);
} }
Map<String, String> m = new HashMap<>(); Map<String, String> m = new HashMap<>();
m.put("sdpMLineIndex", "" + getSdpMLineIndex(evt)); m.put("sdpMLineIndex", "" + getSdpMLineIndex(evt));
@ -542,16 +550,23 @@ public class PlatformWebRTC {
} }
if (getChannel(evt) == null) return; if (getChannel(evt) == null) return;
JSObject dataChannel = getChannel(evt); JSObject dataChannel = getChannel(evt);
synchronized(fuckTeaVM) { if(this.dataChannel != null) {
fuckTeaVM.put(peerId, dataChannel); closeIt(dataChannel);
return;
} }
this.dataChannel = dataChannel;
synchronized(serverLANEventBuffer) { synchronized(serverLANEventBuffer) {
serverLANEventBuffer.put(peerId, new LANPeerEvent.LANPeerDataChannelEvent(peerId)); serverLANEventBuffer.put(peerId, new LANPeerEvent.LANPeerDataChannelEvent(peerId));
} }
TeaVMUtils.addEventListener(dataChannel, "message", (EventListener<Event>) evt2 -> { TeaVMUtils.addEventListener(dataChannel, "message", (EventListener<Event>) evt2 -> {
LANPeerEvent.LANPeerPacketEvent e = new LANPeerEvent.LANPeerPacketEvent(peerId, TeaVMUtils.wrapByteArrayBuffer(getData(evt2))); ArrayBuffer data = getData(evt2);
synchronized(serverLANEventBuffer) { if(ipcChannel != null) {
serverLANEventBuffer.put(peerId, e); ClientPlatformSingleplayer.sendPacketTeaVM(ipcChannel, data);
}else {
LANPeerEvent.LANPeerPacketEvent e = new LANPeerEvent.LANPeerPacketEvent(peerId, TeaVMUtils.wrapByteArrayBuffer(data));
synchronized(serverLANEventBuffer) {
serverLANEventBuffer.put(peerId, e);
}
} }
}); });
}; };
@ -572,11 +587,8 @@ public class PlatformWebRTC {
} }
public void disconnect() { public void disconnect() {
synchronized(fuckTeaVM) { if(dataChannel != null) {
if (fuckTeaVM.get(peerId) != null) { closeIt(dataChannel);
closeIt(fuckTeaVM.get(peerId));
fuckTeaVM.remove(peerId);
}
} }
closeIt(peerConnection); closeIt(peerConnection);
} }
@ -627,11 +639,26 @@ public class PlatformWebRTC {
client.signalRemoteDisconnect(peerId); client.signalRemoteDisconnect(peerId);
} }
} }
public void mapIPC(String ipcChannel) {
if(this.ipcChannel == null) {
if(ipcChannel != null) {
this.ipcChannel = ipcChannel;
this.client.ipcMapList.put(ipcChannel, this);
}
}else {
if(ipcChannel == null) {
this.client.ipcMapList.remove(this.ipcChannel);
this.ipcChannel = null;
}
}
}
} }
public static class LANServer { public static class LANServer {
public Set<Map<String, String>> iceServers = new HashSet<>(); public Set<Map<String, String>> iceServers = new HashSet<>();
public Map<String, LANPeer> peerList = new HashMap<>(); public Map<String, LANPeer> peerList = new HashMap<>();
public Map<String, LANPeer> ipcMapList = new HashMap<>();
public byte peerState = PEERSTATE_LOADING; public byte peerState = PEERSTATE_LOADING;
public byte peerStateConnect = PEERSTATE_LOADING; public byte peerStateConnect = PEERSTATE_LOADING;
public byte peerStateInitial = PEERSTATE_LOADING; public byte peerStateInitial = PEERSTATE_LOADING;
@ -659,21 +686,23 @@ public class PlatformWebRTC {
public void sendPacketToRemoteClient(String peerId, ArrayBuffer buffer) { public void sendPacketToRemoteClient(String peerId, ArrayBuffer buffer) {
LANPeer thePeer = this.peerList.get(peerId); LANPeer thePeer = this.peerList.get(peerId);
if (thePeer != null) { if (thePeer != null) {
boolean b = false; sendPacketToRemoteClient(thePeer, buffer);
synchronized(fuckTeaVM) { }
if (fuckTeaVM.get(thePeer.peerId) != null && "open".equals(getReadyState(fuckTeaVM.get(thePeer.peerId)))) { }
try {
sendIt(fuckTeaVM.get(thePeer.peerId), buffer); public void sendPacketToRemoteClient(LANPeer thePeer, ArrayBuffer buffer) {
} catch (Throwable e) { boolean b = false;
b = true; if (thePeer.dataChannel != null && "open".equals(getReadyState(thePeer.dataChannel))) {
} try {
} else { sendIt(thePeer.dataChannel, buffer);
b = true; } catch (Throwable e) {
} b = true;
}
if(b) {
signalRemoteDisconnect(peerId);
} }
} else {
b = true;
}
if(b) {
signalRemoteDisconnect(thePeer.peerId);
} }
} }
@ -719,26 +748,29 @@ public class PlatformWebRTC {
} }
} }
peerList.clear(); peerList.clear();
synchronized(fuckTeaVM) {
fuckTeaVM.clear();
}
return; return;
} }
LANPeer thePeer = peerList.get(peerId); LANPeer thePeer = peerList.remove(peerId);
if(thePeer != null) { if(thePeer != null) {
peerList.remove(peerId); if(thePeer.ipcChannel != null) {
ipcMapList.remove(thePeer.ipcChannel);
}
try { try {
thePeer.disconnect(); thePeer.disconnect();
} catch (Throwable ignored) {} } catch (Throwable ignored) {}
synchronized(fuckTeaVM) {
fuckTeaVM.remove(peerId);
}
synchronized(serverLANEventBuffer) { synchronized(serverLANEventBuffer) {
serverLANEventBuffer.put(thePeer.peerId, new LANPeerEvent.LANPeerDisconnectEvent(peerId)); serverLANEventBuffer.put(thePeer.peerId, new LANPeerEvent.LANPeerDisconnectEvent(peerId));
} }
} }
} }
public void serverPeerMapIPC(String peer, String ipcChannel) {
LANPeer peerr = peerList.get(peer);
if(peerr != null) {
peerr.mapIPC(ipcChannel);
}
}
public int countPeers() { public int countPeers() {
return peerList.size(); return peerList.size();
} }
@ -759,30 +791,6 @@ public class PlatformWebRTC {
void call(JSError err); void call(JSError err);
} }
public static RelayQuery openRelayQuery(String addr) {
RelayQuery.RateLimit limit = RelayServerRateLimitTracker.isLimited(addr);
if(limit == RelayQuery.RateLimit.LOCKED || limit == RelayQuery.RateLimit.BLOCKED) {
return new RelayQueryRateLimitDummy(limit);
}
return new RelayQueryImpl(addr);
}
public static RelayWorldsQuery openRelayWorldsQuery(String addr) {
RelayQuery.RateLimit limit = RelayServerRateLimitTracker.isLimited(addr);
if(limit == RelayQuery.RateLimit.LOCKED || limit == RelayQuery.RateLimit.BLOCKED) {
return new RelayWorldsQueryRateLimitDummy(limit);
}
return new RelayWorldsQueryImpl(addr);
}
public static RelayServerSocket openRelayConnection(String addr, int timeout) {
RelayQuery.RateLimit limit = RelayServerRateLimitTracker.isLimited(addr);
if(limit == RelayQuery.RateLimit.LOCKED || limit == RelayQuery.RateLimit.BLOCKED) {
return new RelayServerSocketRateLimitDummy(limit);
}
return new RelayServerSocketImpl(addr, timeout);
}
private static LANClient rtcLANClient = null; private static LANClient rtcLANClient = null;
public static void startRTCLANClient() { public static void startRTCLANClient() {
@ -806,7 +814,6 @@ public class PlatformWebRTC {
rtcLANClient.signalRemoteDisconnect(false); rtcLANClient.signalRemoteDisconnect(false);
} }
// todo: ArrayBuffer version
public static void clientLANSendPacket(byte[] pkt) { public static void clientLANSendPacket(byte[] pkt) {
rtcLANClient.sendPacketToServer(TeaVMUtils.unwrapArrayBuffer(pkt)); rtcLANClient.sendPacketToServer(TeaVMUtils.unwrapArrayBuffer(pkt));
} }
@ -949,6 +956,24 @@ public class PlatformWebRTC {
rtcLANServer.signalRemoteDescription(peer, description); rtcLANServer.signalRemoteDescription(peer, description);
} }
public static void serverLANPeerMapIPC(String peer, String ipcChannel) {
rtcLANServer.serverPeerMapIPC(peer, ipcChannel);
}
public static boolean serverLANPeerPassIPC(String channelName, ArrayBuffer data) {
if(rtcLANServer != null) {
LANPeer peer = rtcLANServer.ipcMapList.get(channelName);
if(peer != null) {
rtcLANServer.sendPacketToRemoteClient(peer, data);
return true;
}else {
return false;
}
}else {
return false;
}
}
public static void serverLANDisconnectPeer(String peer) { public static void serverLANDisconnectPeer(String peer) {
rtcLANServer.signalRemoteDisconnect(peer); rtcLANServer.signalRemoteDisconnect(peer);
} }

View File

@ -169,7 +169,7 @@ public class EaglerArrayByteBuffer implements ByteBuffer {
int l = src.remaining(); int l = src.remaining();
if(position + l > limit) throw Buffer.makeIOOBE(position + l - 1); if(position + l > limit) throw Buffer.makeIOOBE(position + l - 1);
for(int i = 0; i < l; ++i) { for(int i = 0; i < l; ++i) {
dataView.setInt8(position + l, src.get()); dataView.setInt8(position + i, src.get());
} }
position += l; position += l;
} }

View File

@ -153,7 +153,7 @@ public class EaglerArrayFloatBuffer implements FloatBuffer {
int l = src.remaining(); int l = src.remaining();
if(position + l > limit) throw Buffer.makeIOOBE(position + l - 1); if(position + l > limit) throw Buffer.makeIOOBE(position + l - 1);
for(int i = 0; i < l; ++i) { for(int i = 0; i < l; ++i) {
typedArray.set(position + l, src.get()); typedArray.set(position + i, src.get());
} }
position += l; position += l;
} }

View File

@ -153,7 +153,7 @@ public class EaglerArrayIntBuffer implements IntBuffer {
int l = src.remaining(); int l = src.remaining();
if(position + l > limit) throw Buffer.makeIOOBE(position + l - 1); if(position + l > limit) throw Buffer.makeIOOBE(position + l - 1);
for(int i = 0; i < l; ++i) { for(int i = 0; i < l; ++i) {
typedArray.set(position + l, src.get()); typedArray.set(position + i, src.get());
} }
position += l; position += l;
} }

View File

@ -153,7 +153,7 @@ public class EaglerArrayShortBuffer implements ShortBuffer {
int l = src.remaining(); int l = src.remaining();
if(position + l > limit) throw Buffer.makeIOOBE(position + l - 1); if(position + l > limit) throw Buffer.makeIOOBE(position + l - 1);
for(int i = 0; i < l; ++i) { for(int i = 0; i < l; ++i) {
typedArray.set(position + l, src.get()); typedArray.set(position + i, src.get());
} }
position += l; position += l;
} }

View File

@ -130,7 +130,7 @@ public class TeaVMUtils {
@GeneratedBy(TeaVMUtilsUnwrapGenerator.WrapArrayBuffer.class) @GeneratedBy(TeaVMUtilsUnwrapGenerator.WrapArrayBuffer.class)
public static native short[] wrapShortArrayBuffer(ArrayBuffer buf); public static native short[] wrapShortArrayBuffer(ArrayBuffer buf);
@InjectedBy(TeaVMUtilsUnwrapGenerator.UnwrapArrayBuffer.class) @GeneratedBy(TeaVMUtilsUnwrapGenerator.WrapArrayBufferView.class)
public static native short[] wrapShortArrayBuffer(ArrayBufferView buf); public static native short[] wrapShortArrayBuffer(ArrayBufferView buf);
@Async @Async
@ -140,12 +140,8 @@ public class TeaVMUtils {
Window.setTimeout(() -> cb.complete(null), millis); Window.setTimeout(() -> cb.complete(null), millis);
} }
public static final Comparator<Touch> touchSortingComparator = (t1, t2) -> {
return t1.getIdentifier() - t2.getIdentifier();
};
public static final Comparator<OffsetTouch> touchSortingComparator2 = (t1, t2) -> { public static final Comparator<OffsetTouch> touchSortingComparator2 = (t1, t2) -> {
return t1.touch.getIdentifier() - t2.touch.getIdentifier(); return t1.eventUID - t2.eventUID;
}; };
public static List<OffsetTouch> toSortedTouchList(TouchList touchList, SortedTouchEvent.ITouchUIDMapper mapper, public static List<OffsetTouch> toSortedTouchList(TouchList touchList, SortedTouchEvent.ITouchUIDMapper mapper,

View File

@ -16,6 +16,7 @@ import org.teavm.jso.workers.Worker;
import net.lax1dude.eaglercraft.v1_8.internal.IPCPacketData; import net.lax1dude.eaglercraft.v1_8.internal.IPCPacketData;
import net.lax1dude.eaglercraft.v1_8.internal.PlatformRuntime; import net.lax1dude.eaglercraft.v1_8.internal.PlatformRuntime;
import net.lax1dude.eaglercraft.v1_8.internal.PlatformWebRTC;
import net.lax1dude.eaglercraft.v1_8.internal.teavm.ClientMain; import net.lax1dude.eaglercraft.v1_8.internal.teavm.ClientMain;
import net.lax1dude.eaglercraft.v1_8.internal.teavm.TeaVMBlobURLManager; import net.lax1dude.eaglercraft.v1_8.internal.teavm.TeaVMBlobURLManager;
import net.lax1dude.eaglercraft.v1_8.internal.teavm.TeaVMClientConfigAdapter; import net.lax1dude.eaglercraft.v1_8.internal.teavm.TeaVMClientConfigAdapter;
@ -101,6 +102,10 @@ public class ClientPlatformSingleplayer {
return; return;
} }
if(PlatformWebRTC.serverLANPeerPassIPC(channel, buf)) {
return;
}
synchronized(messageQueue) { synchronized(messageQueue) {
messageQueue.add(new IPCPacketData(channel, TeaVMUtils.wrapByteArrayBuffer(buf))); messageQueue.add(new IPCPacketData(channel, TeaVMUtils.wrapByteArrayBuffer(buf)));
} }