1
0
Fork 0

add firework boosting and elytra sound

This commit is contained in:
HoosierTransfer 2024-05-06 16:52:39 -04:00
parent a58a275824
commit 93bfd94628
18 changed files with 41142 additions and 40984 deletions

View File

@ -1580,6 +1580,12 @@
"random/drink" "random/drink"
] ]
}, },
"item.elytra.flying": {
"category": "player",
"sounds": [
"item/elytra/elytra_loop"
]
},
"random.eat": { "random.eat": {
"category": "player", "category": "player",
"sounds": [ "sounds": [

Binary file not shown.

Before

Width:  |  Height:  |  Size: 326 B

After

Width:  |  Height:  |  Size: 211 B

Binary file not shown.

File diff suppressed because it is too large Load Diff

View File

@ -4,13 +4,12 @@ import java.math.BigInteger;
public class EaglercraftVersion { public class EaglercraftVersion {
////////////////////////////////////////////////////////////////////// //////////////////////////////////////////////////////////////////////
/// Customize these to fit your fork: /// Customize these to fit your fork:
public static final String projectForkName = "Eaglercraft Lambda"; public static final String projectForkName = "Eaglercraft Lambda";
public static final String projectForkVersion = "2.0.0"; public static final String projectForkVersion = "0.3.0";
public static final String projectForkVendor = "hoosiertransfer"; public static final String projectForkVendor = "hoosiertransfer";
public static final String projectForkURL = "https://gitlab.com/lax1dude/eaglercraftx-1.8"; public static final String projectForkURL = "https://gitlab.com/lax1dude/eaglercraftx-1.8";
@ -19,13 +18,11 @@ 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.9";
public static final String projectOriginVersion = "u29"; public static final String projectOriginVersion = "u29";
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
// Updating configuration // Updating configuration
public static final boolean enableUpdateService = false; public static final boolean enableUpdateService = false;
@ -36,9 +33,8 @@ public class EaglercraftVersion {
public static final String updateLatestLocalStorageKey = "latestUpdate_" + updateBundlePackageName; public static final String updateLatestLocalStorageKey = "latestUpdate_" + updateBundlePackageName;
// public key modulus for official 1.8 updates // public key modulus for official 1.8 updates
public static final BigInteger updateSignatureModulus = new BigInteger("14419476194820052109078379102436982757438300194194974078260570958862225232043861026588258585967060437391326494976080031137298500457111529693806931143421725626747051503616606418909609840275122831550688481329699012469742002429706330734797679859799085213517354399295425740214330234086361416936984593337389989505613123225737002654977194421571825036717017788527234114501215218715499682638139386636103589791643964827904791195488978835113700772208317974307363542114867750505953323167521731238542123593257269990619007858952216110012513121779359926747737258698347806747854986471035713105133999027704095451858121831297923962641"); public static final BigInteger updateSignatureModulus = new BigInteger(
"14419476194820052109078379102436982757438300194194974078260570958862225232043861026588258585967060437391326494976080031137298500457111529693806931143421725626747051503616606418909609840275122831550688481329699012469742002429706330734797679859799085213517354399295425740214330234086361416936984593337389989505613123225737002654977194421571825036717017788527234114501215218715499682638139386636103589791643964827904791195488978835113700772208317974307363542114867750505953323167521731238542123593257269990619007858952216110012513121779359926747737258698347806747854986471035713105133999027704095451858121831297923962641");
// Miscellaneous variables: // Miscellaneous variables:

View File

@ -1676,7 +1676,7 @@ public class Block implements ILitBlock {
if (flag1 || flag2 || flag3 || flag4 || flag5) { if (flag1 || flag2 || flag3 || flag4 || flag5) {
flag = true; flag = true;
} }
flag |= block instanceof BlockLiquid;
block13.useNeighborBrightness = flag; block13.useNeighborBrightness = flag;
} }
} }

View File

@ -8,7 +8,6 @@ import net.lax1dude.eaglercraft.v1_8.EaglercraftRandom;
import net.minecraft.block.material.MapColor; import net.minecraft.block.material.MapColor;
import net.minecraft.block.material.Material; import net.minecraft.block.material.Material;
import net.minecraft.block.properties.IProperty; import net.minecraft.block.properties.IProperty;
import net.minecraft.block.properties.PropertyBool;
import net.minecraft.block.properties.PropertyEnum; import net.minecraft.block.properties.PropertyEnum;
import net.minecraft.block.state.BlockState; import net.minecraft.block.state.BlockState;
import net.minecraft.block.state.IBlockState; import net.minecraft.block.state.IBlockState;
@ -234,7 +233,6 @@ public abstract class BlockPurpurSlab extends BlockSlab {
for (int i = 0; i < types.length; ++i) { for (int i = 0; i < types.length; ++i) {
META_LOOKUP[types[i].getMetadata()] = types[i]; META_LOOKUP[types[i].getMetadata()] = types[i];
} }
} }
} }
} }

View File

@ -0,0 +1,56 @@
package net.minecraft.client.audio;
import net.minecraft.client.entity.EntityPlayerSP;
import net.minecraft.util.MathHelper;
import net.minecraft.util.ResourceLocation;
public class ElytraSound extends MovingSound {
private final EntityPlayerSP player;
private int time;
public ElytraSound(EntityPlayerSP p_i47113_1_) {
super(new ResourceLocation("minecraft:item.elytra.flying"));
this.player = p_i47113_1_;
this.repeat = true;
this.repeatDelay = 0;
this.volume = 0.1F;
}
/**
* Like the old updateEntity(), except more generic.
*/
public void update() {
++this.time;
if (!this.player.isDead && (this.time <= 20 || this.player.isElytraFlying())) {
this.xPosF = (float) this.player.posX;
this.yPosF = (float) this.player.posY;
this.zPosF = (float) this.player.posZ;
float f = MathHelper.sqrt_double(this.player.motionX * this.player.motionX
+ this.player.motionZ * this.player.motionZ + this.player.motionY * this.player.motionY);
float f1 = f / 2.0F;
if ((double) f >= 0.01D) {
this.volume = MathHelper.clamp_float(f1 * f1, 0.0F, 1.0F);
} else {
this.volume = 0.0F;
}
if (this.time < 20) {
this.volume = 0.0F;
} else if (this.time < 40) {
this.volume = (float) ((double) this.volume * ((double) (this.time - 20) / 20.0D));
}
float f2 = 0.8F;
if (this.volume > 0.8F) {
this.pitch = 1.0F + (this.volume - 0.8F);
} else {
this.pitch = 1.0F;
}
} else {
this.donePlaying = true;
}
}
}

View File

@ -4,6 +4,7 @@ import net.hoosiertransfer.EaglerItems;
import net.lax1dude.eaglercraft.v1_8.sp.lan.LANClientNetworkManager; import net.lax1dude.eaglercraft.v1_8.sp.lan.LANClientNetworkManager;
import net.lax1dude.eaglercraft.v1_8.sp.socket.ClientIntegratedServerNetworkManager; import net.lax1dude.eaglercraft.v1_8.sp.socket.ClientIntegratedServerNetworkManager;
import net.minecraft.client.Minecraft; import net.minecraft.client.Minecraft;
import net.minecraft.client.audio.ElytraSound;
import net.minecraft.client.audio.MovingSoundMinecartRiding; import net.minecraft.client.audio.MovingSoundMinecartRiding;
import net.minecraft.client.audio.PositionedSoundRecord; import net.minecraft.client.audio.PositionedSoundRecord;
import net.minecraft.client.gui.GuiCommandBlock; import net.minecraft.client.gui.GuiCommandBlock;
@ -755,7 +756,7 @@ public class EntityPlayerSP extends AbstractClientPlayer {
this.sendQueue.addToSendQueue(new C0BPacketEntityAction(this, this.sendQueue.addToSendQueue(new C0BPacketEntityAction(this,
C0BPacketEntityAction.Action.START_FALL_FLYING)); C0BPacketEntityAction.Action.START_FALL_FLYING));
// TODO Eltrya sound // TODO Eltrya sound
// this.mc.getSoundHandler().playSound(new ElytraSound(this)); this.mc.getSoundHandler().playSound(new ElytraSound(this));
} }
} }

View File

@ -13,45 +13,47 @@ import net.minecraft.util.MathHelper;
import net.minecraft.util.ResourceLocation; import net.minecraft.util.ResourceLocation;
public class LayerElytra implements LayerRenderer<AbstractClientPlayer> { public class LayerElytra implements LayerRenderer<AbstractClientPlayer> {
private static final ResourceLocation TEXTURE_ELYTRA = new ResourceLocation("textures/entity/elytra.png"); private static final ResourceLocation TEXTURE_ELYTRA = new ResourceLocation("textures/entity/elytra.png");
private final RenderPlayer renderPlayer; private final RenderPlayer renderPlayer;
private final ModelElytra modelElytra = new ModelElytra(); private final ModelElytra modelElytra = new ModelElytra();
public LayerElytra(RenderPlayer renderPlayerIn) { public LayerElytra(RenderPlayer renderPlayerIn) {
this.renderPlayer = renderPlayerIn; this.renderPlayer = renderPlayerIn;
} }
public void doRenderLayer(AbstractClientPlayer entitylivingbaseIn, float limbSwing, float limbSwingAmount, public void doRenderLayer(AbstractClientPlayer entitylivingbaseIn, float limbSwing, float limbSwingAmount,
float partialTicks, float ageInTicks, float netHeadYaw, float headPitch, float scale) { float partialTicks, float ageInTicks, float netHeadYaw, float headPitch, float scale) {
ItemStack itemstack = entitylivingbaseIn.getCurrentArmor(2); ItemStack itemstack = entitylivingbaseIn.getCurrentArmor(2);
if (itemstack != null && itemstack.getItem() == EaglerItems.getEaglerItem("elytra")) { if (itemstack != null && itemstack.getItem() == EaglerItems.getEaglerItem("elytra")) {
GlStateManager.color(1.0F, 1.0F, 1.0F, 1.0F); GlStateManager.color(1.0F, 1.0F, 1.0F, 1.0F);
GlStateManager.enableBlend(); GlStateManager.enableBlend();
this.renderPlayer.bindTexture(TEXTURE_ELYTRA); this.renderPlayer.bindTexture(TEXTURE_ELYTRA);
GlStateManager.pushMatrix(); GlStateManager.pushMatrix();
GlStateManager.translate(0.0F, 0.0F, 0.125F); GlStateManager.translate(0.0F, 0.0F, 0.125F);
this.modelElytra.setRotationAngles(limbSwing, limbSwingAmount, ageInTicks, netHeadYaw, this.modelElytra.setRotationAngles(limbSwing, limbSwingAmount, ageInTicks, netHeadYaw,
headPitch, scale, headPitch, scale,
entitylivingbaseIn); entitylivingbaseIn);
this.modelElytra.render(entitylivingbaseIn, limbSwing, limbSwingAmount, ageInTicks, netHeadYaw, this.modelElytra.render(entitylivingbaseIn, limbSwing, limbSwingAmount, ageInTicks, netHeadYaw,
headPitch, headPitch,
scale); scale);
GlStateManager.popMatrix();
if (itemstack.isItemEnchanted()) { if (itemstack.isItemEnchanted()) {
LayerArmorBase.renderEnchantedGlint(this.renderPlayer, entitylivingbaseIn, GlStateManager.pushMatrix();
this.modelElytra, limbSwing, LayerArmorBase.renderEnchantedGlint(this.renderPlayer, entitylivingbaseIn,
limbSwingAmount, partialTicks, ageInTicks, netHeadYaw, headPitch, this.modelElytra, limbSwing,
scale); limbSwingAmount, partialTicks, ageInTicks, netHeadYaw, headPitch,
} scale);
GlStateManager.popMatrix();
GlStateManager.popMatrix(); }
}
} }
public boolean shouldCombineTextures() { }
return false;
} public boolean shouldCombineTextures() {
return false;
}
} }

View File

@ -1459,6 +1459,10 @@ public abstract class EntityLivingBase extends Entity {
this.attackEntityFrom(DamageSource.flyIntoWall, f5); this.attackEntityFrom(DamageSource.flyIntoWall, f5);
} }
} }
if (this.onGround && !this.worldObj.isRemote) {
this.setFlag(7, false);
}
} else { } else {
float f6 = 0.91F; float f6 = 0.91F;
if (this.onGround) { if (this.onGround) {

View File

@ -1,10 +1,12 @@
package net.minecraft.entity.item; package net.minecraft.entity.item;
import net.minecraft.entity.Entity; import net.minecraft.entity.Entity;
import net.minecraft.entity.EntityLivingBase;
import net.minecraft.item.ItemStack; import net.minecraft.item.ItemStack;
import net.minecraft.nbt.NBTTagCompound; import net.minecraft.nbt.NBTTagCompound;
import net.minecraft.util.EnumParticleTypes; import net.minecraft.util.EnumParticleTypes;
import net.minecraft.util.MathHelper; import net.minecraft.util.MathHelper;
import net.minecraft.util.Vec3;
import net.minecraft.world.World; import net.minecraft.world.World;
/** /**
@ -41,6 +43,10 @@ public class EntityFireworkRocket extends Entity {
private int fireworkAge; private int fireworkAge;
private int lifetime; private int lifetime;
private EntityLivingBase creator;
private int creatorId;
public EntityFireworkRocket(World worldIn) { public EntityFireworkRocket(World worldIn) {
super(worldIn); super(worldIn);
this.setSize(0.25F, 0.25F); this.setSize(0.25F, 0.25F);
@ -81,6 +87,12 @@ public class EntityFireworkRocket extends Entity {
this.lifetime = 10 * i + this.rand.nextInt(6) + this.rand.nextInt(7); this.lifetime = 10 * i + this.rand.nextInt(6) + this.rand.nextInt(7);
} }
public EntityFireworkRocket(World p_i47367_1_, ItemStack p_i47367_2_, EntityLivingBase p_i47367_3_) {
this(p_i47367_1_, p_i47367_3_.posX, p_i47367_3_.posY, p_i47367_3_.posZ, p_i47367_2_);
this.creatorId = p_i47367_3_.getEntityId();
this.creator = p_i47367_3_;
}
/** /**
* + * +
* Sets the velocity to the args. Args: x, y, z * Sets the velocity to the args. Args: x, y, z
@ -108,10 +120,34 @@ public class EntityFireworkRocket extends Entity {
this.lastTickPosY = this.posY; this.lastTickPosY = this.posY;
this.lastTickPosZ = this.posZ; this.lastTickPosZ = this.posZ;
super.onUpdate(); super.onUpdate();
this.motionX *= 1.15D;
this.motionZ *= 1.15D; Entity entity = this.worldObj.getEntityByID(this.creatorId);
this.motionY += 0.04D;
this.moveEntity(this.motionX, this.motionY, this.motionZ); if (entity instanceof EntityLivingBase) {
this.creator = (EntityLivingBase) entity;
}
if (this.creator != null) {
if (this.creator.isElytraFlying()) {
Vec3 look = this.creator.getLookVec();
double newMotionX = look.xCoord * 0.1D + (look.xCoord * 1.5D - this.creator.motionX) * 0.5D;
double newMotionY = look.yCoord * 0.1D + (look.yCoord * 1.5D - this.creator.motionY) * 0.5D;
double newMotionZ = look.zCoord * 0.1D + (look.zCoord * 1.5D - this.creator.motionZ) * 0.5D;
this.creator.addVelocity(newMotionX, newMotionY, newMotionZ);
}
this.setPosition(this.creator.posX, this.creator.posY, this.creator.posZ);
this.motionX = this.creator.motionX;
this.motionY = this.creator.motionY;
this.motionZ = this.creator.motionZ;
} else {
this.motionX *= 1.15D;
this.motionZ *= 1.15D;
this.motionY += 0.04D;
this.moveEntity(this.motionX, this.motionY, this.motionZ);
}
float f = MathHelper.sqrt_double(this.motionX * this.motionX + this.motionZ * this.motionZ); float f = MathHelper.sqrt_double(this.motionX * this.motionX + this.motionZ * this.motionZ);
this.rotationYaw = (float) (MathHelper.func_181159_b(this.motionX, this.motionZ) * 180.0D this.rotationYaw = (float) (MathHelper.func_181159_b(this.motionX, this.motionZ) * 180.0D
/ 3.1415927410125732D); / 3.1415927410125732D);

View File

@ -363,6 +363,12 @@ public abstract class EntityPlayer extends EntityLivingBase implements ICommandS
if (this.isElytraFlying()) { if (this.isElytraFlying()) {
f = 0.6F; f = 0.6F;
f1 = 0.6F; f1 = 0.6F;
} else if (this.isPlayerSleeping()) {
f = 0.2F;
f1 = 0.2F;
} else if (this.isSneaking()) {
f = 0.6F;
f1 = 1.65F;
} else { } else {
f = 0.6F; f = 0.6F;
f1 = 1.8F; f1 = 1.8F;
@ -373,7 +379,7 @@ public abstract class EntityPlayer extends EntityLivingBase implements ICommandS
axisalignedbb = new AxisAlignedBB(axisalignedbb.minX, axisalignedbb.minY, axisalignedbb.minZ, axisalignedbb = new AxisAlignedBB(axisalignedbb.minX, axisalignedbb.minY, axisalignedbb.minZ,
axisalignedbb.minX + (double) f, axisalignedbb.minY + (double) f1, axisalignedbb.minZ + (double) f); axisalignedbb.minX + (double) f, axisalignedbb.minY + (double) f1, axisalignedbb.minZ + (double) f);
if (!this.worldObj.checkBlockCollision(axisalignedbb)) { if (!this.worldObj.checkSolidBlockCollision(axisalignedbb)) {
this.setSize(f, f1); this.setSize(f, f1);
} }
} }
@ -1589,6 +1595,7 @@ public abstract class EntityPlayer extends EntityLivingBase implements ICommandS
super.moveEntityWithHeading(f, f1); super.moveEntityWithHeading(f, f1);
this.motionY = d3 * 0.6D; this.motionY = d3 * 0.6D;
this.jumpMovementFactor = f2; this.jumpMovementFactor = f2;
this.setFlag(7, false);
} else { } else {
super.moveEntityWithHeading(f, f1); super.moveEntityWithHeading(f, f1);
} }

View File

@ -64,6 +64,19 @@ public class ItemFirework extends Item {
} }
} }
public ItemStack onItemRightClick(ItemStack itemstack, World world, EntityPlayer entityplayer) {
if (entityplayer.isElytraFlying() && !world.isRemote) {
EntityFireworkRocket entityfireworkrocket = new EntityFireworkRocket(world, itemstack, entityplayer);
world.spawnEntityInWorld(entityfireworkrocket);
if (!entityplayer.capabilities.isCreativeMode) {
--itemstack.stackSize;
}
}
return itemstack;
}
/** /**
* + * +
* allows items to add custom lines of information to the * allows items to add custom lines of information to the

View File

@ -358,10 +358,6 @@ public class NetHandlerPlayServer implements INetHandlerPlayServer, ITickable {
return; return;
} }
if (this.playerEntity.isInWater() || this.playerEntity.isInLava() || this.playerEntity.onGround) {
this.playerEntity.clearElytraFlying();
}
float f3 = 0.0625F; float f3 = 0.0625F;
boolean flag = worldserver.getCollidingBoundingBoxes(this.playerEntity, boolean flag = worldserver.getCollidingBoundingBoxes(this.playerEntity,
this.playerEntity.getEntityBoundingBox().contract((double) f3, (double) f3, (double) f3)) this.playerEntity.getEntityBoundingBox().contract((double) f3, (double) f3, (double) f3))

View File

@ -1668,6 +1668,30 @@ public abstract class World implements IBlockAccess, ILightingEngineProvider, IL
return false; return false;
} }
public boolean checkSolidBlockCollision(AxisAlignedBB bb) {
int i = MathHelper.floor_double(bb.minX);
int j = MathHelper.floor_double(bb.maxX);
int k = MathHelper.floor_double(bb.minY);
int l = MathHelper.floor_double(bb.maxY);
int i1 = MathHelper.floor_double(bb.minZ);
int j1 = MathHelper.floor_double(bb.maxZ);
BlockPos.MutableBlockPos blockpos$mutableblockpos = new BlockPos.MutableBlockPos();
for (int k1 = i; k1 <= j; ++k1) {
for (int l1 = k; l1 <= l; ++l1) {
for (int i2 = i1; i2 <= j1; ++i2) {
Block block = this.getBlockState(blockpos$mutableblockpos.func_181079_c(k1, l1, i2)).getBlock();
if (block.getMaterial() != Material.air || block.getMaterial() != Material.water
|| block.getMaterial() != Material.lava) {
return true;
}
}
}
}
return false;
}
/** /**
* + * +
* Returns if any of the blocks within the aabb are liquids. * Returns if any of the blocks within the aabb are liquids.

View File

@ -14,14 +14,21 @@ import com.jcraft.jzlib.InflaterInputStream;
/** /**
* Copyright (c) 2022 lax1dude. All Rights Reserved. * Copyright (c) 2022 lax1dude. All Rights Reserved.
* *
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND * 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 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
* IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, * DISCLAIMED.
* INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT * IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY
* NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR * DIRECT,
* PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
* WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) * (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 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
* POSSIBILITY OF SUCH DAMAGE. * POSSIBILITY OF SUCH DAMAGE.
* *
@ -32,10 +39,11 @@ public class EPKLoader {
loadEPK(epkFile, "", loadedFiles); loadEPK(epkFile, "", loadedFiles);
} }
public static final void loadEPK(ArrayBuffer epkFile, String path, Map<String, byte[]> loadedFiles) throws IOException { public static final void loadEPK(ArrayBuffer epkFile, String path, Map<String, byte[]> loadedFiles)
throws IOException {
int byteLength = epkFile.getByteLength(); int byteLength = epkFile.getByteLength();
int l = byteLength - 16; int l = byteLength - 16;
if(l < 1) { if (l < 1) {
throw new IOException("EPK file is incomplete"); throw new IOException("EPK file is incomplete");
} }
@ -45,22 +53,22 @@ public class EPKLoader {
is.read(header); is.read(header);
String type = readASCII(header); String type = readASCII(header);
if(!"EAGPKG$$".equals(type)) { if (!"EAGPKG$$".equals(type)) {
throw new IOException("Invalid EPK file type '" + type + "'"); throw new IOException("Invalid EPK file type '" + type + "'");
} }
Uint8Array readEndCode = Uint8Array.create(epkFile, byteLength - 8, 8); Uint8Array readEndCode = Uint8Array.create(epkFile, byteLength - 8, 8);
byte[] endCode = new byte[] { (byte)':', (byte)':', (byte)':', (byte)'Y', byte[] endCode = new byte[] { (byte) ':', (byte) ':', (byte) ':', (byte) 'Y',
(byte)'E', (byte)'E', (byte)':', (byte)'>' }; (byte) 'E', (byte) 'E', (byte) ':', (byte) '>' };
for(int i = 0; i < 8; ++i) { for (int i = 0; i < 8; ++i) {
if(readEndCode.get(i) != endCode[i]) { if (readEndCode.get(i) != endCode[i]) {
throw new IOException("EPK file is missing EOF code (:::YEE:>)"); throw new IOException("EPK file is missing EOF code (:::YEE:>)");
} }
} }
String vers = readASCII(is); String vers = readASCII(is);
if(!vers.startsWith("ver2.")) { if (!vers.startsWith("ver2.")) {
throw new IOException("Unknown or invalid EPK version: " + vers); throw new IOException("Unknown or invalid EPK version: " + vers);
} }
@ -70,62 +78,63 @@ public class EPKLoader {
int numFiles = loadInt(is); int numFiles = loadInt(is);
char compressionType = (char)is.read(); char compressionType = (char) is.read();
InputStream zis; InputStream zis;
switch(compressionType) { switch (compressionType) {
case 'G': case 'G':
zis = new GZIPInputStream(is); zis = new GZIPInputStream(is);
break; break;
case 'Z': case 'Z':
zis = new InflaterInputStream(is); zis = new InflaterInputStream(is);
break; break;
case '0': case '0':
zis = is; zis = is;
break; break;
default: default:
throw new IOException("Invalid or unsupported EPK compression: " + compressionType); throw new IOException("Invalid or unsupported EPK compression: " + compressionType);
} }
int blockFile = ('F' << 24) | ('I' << 16) | ('L' << 8) | 'E'; int blockFile = ('F' << 24) | ('I' << 16) | ('L' << 8) | 'E';
int blockEnd = ('E' << 24) | ('N' << 16) | ('D' << 8) | '$'; int blockEnd = ('E' << 24) | ('N' << 16) | ('D' << 8) | '$';
int blockHead = ('H' << 24) | ('E' << 16) | ('A' << 8) | 'D'; int blockHead = ('H' << 24) | ('E' << 16) | ('A' << 8) | 'D';
if(path.length() > 0 && !path.endsWith("/")) { if (path.length() > 0 && !path.endsWith("/")) {
path = path + "/"; path = path + "/";
} }
CRC32 crc32 = new CRC32(); CRC32 crc32 = new CRC32();
int blockType; int blockType;
for(int i = 0; i < numFiles; ++i) { for (int i = 0; i < numFiles; ++i) {
blockType = loadInt(zis); blockType = loadInt(zis);
if(blockType == blockEnd) { if (blockType == blockEnd) {
throw new IOException("Unexpected END when there are still " + (numFiles - i) + " files remaining"); throw new IOException("Unexpected END when there are still " + (numFiles - i) + " files remaining");
} }
String name = readASCII(zis); String name = readASCII(zis);
int len = loadInt(zis); int len = loadInt(zis);
if(i == 0) { if (i == 0) {
if(blockType == blockHead) { if (blockType == blockHead) {
byte[] readType = new byte[len]; byte[] readType = new byte[len];
zis.read(readType); zis.read(readType);
if(!"file-type".equals(name) || !"epk/resources".equals(readASCII(readType))) { if (!"file-type".equals(name) || !"epk/resources".equals(readASCII(readType))) {
throw new IOException("EPK is not of file-type 'epk/resources'!"); throw new IOException("EPK is not of file-type 'epk/resources'!");
} }
if(zis.read() != '>') { if (zis.read() != '>') {
throw new IOException("Object '" + name + "' is incomplete"); throw new IOException("Object '" + name + "' is incomplete");
} }
continue; continue;
}else { } else {
throw new IOException("File '" + name + "' did not have a file-type block as the first entry in the file"); throw new IOException(
"File '" + name + "' did not have a file-type block as the first entry in the file");
} }
} }
if(blockType == blockFile) { if (blockType == blockFile) {
if(len < 5) { if (len < 5) {
throw new IOException("File '" + name + "' is incomplete"); throw new IOException("File '" + name + "' is incomplete");
} }
@ -134,29 +143,29 @@ public class EPKLoader {
byte[] load = new byte[len - 5]; byte[] load = new byte[len - 5];
zis.read(load); zis.read(load);
if(len > 5) { if (len > 5) {
crc32.reset(); crc32.reset();
crc32.update(load, 0, load.length); crc32.update(load, 0, load.length);
if(expectedCRC != (int)crc32.getValue()) { if (expectedCRC != (int) crc32.getValue()) {
throw new IOException("File '" + name + "' has an invalid checksum"); throw new IOException("File '" + name + "' has an invalid checksum");
} }
} }
if(zis.read() != ':') { if (zis.read() != ':') {
throw new IOException("File '" + name + "' is incomplete"); throw new IOException("File '" + name + "' is incomplete");
} }
loadedFiles.put(path + name, load); loadedFiles.put(path + name, load);
}else { } else {
zis.skip(len); zis.skip(len);
} }
if(zis.read() != '>') { if (zis.read() != '>') {
throw new IOException("Object '" + name + "' is incomplete"); throw new IOException("Object '" + name + "' is incomplete");
} }
} }
if(loadInt(zis) != blockEnd) { if (loadInt(zis) != blockEnd) {
throw new IOException("EPK missing END$ object"); throw new IOException("EPK missing END$ object");
} }
@ -173,8 +182,8 @@ public class EPKLoader {
private static final String readASCII(byte[] bytesIn) throws IOException { private static final String readASCII(byte[] bytesIn) throws IOException {
char[] charIn = new char[bytesIn.length]; char[] charIn = new char[bytesIn.length];
for(int i = 0; i < bytesIn.length; ++i) { for (int i = 0; i < bytesIn.length; ++i) {
charIn[i] = (char)((int)bytesIn[i] & 0xFF); charIn[i] = (char) ((int) bytesIn[i] & 0xFF);
} }
return new String(charIn); return new String(charIn);
} }
@ -182,8 +191,8 @@ public class EPKLoader {
private static final String readASCII(InputStream bytesIn) throws IOException { private static final String readASCII(InputStream bytesIn) throws IOException {
int len = bytesIn.read(); int len = bytesIn.read();
char[] charIn = new char[len]; char[] charIn = new char[len];
for(int i = 0; i < len; ++i) { for (int i = 0; i < len; ++i) {
charIn[i] = (char)(bytesIn.read() & 0xFF); charIn[i] = (char) (bytesIn.read() & 0xFF);
} }
return new String(charIn); return new String(charIn);
} }