Skip to content

Commit

Permalink
Perform some minor cleanups & tell Gradle to strip debug information
Browse files Browse the repository at this point in the history
I hadn’t expected stripping the debug information would lead to such a drastic reduction in file size! I've now realised that I probably should’ve tried that earlier haha.
  • Loading branch information
NeRdTheNed committed Nov 14, 2020
1 parent 3e29c1c commit 6ced777
Show file tree
Hide file tree
Showing 9 changed files with 37 additions and 51 deletions.
4 changes: 3 additions & 1 deletion build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -74,9 +74,11 @@ processResources {
}
}

// Ensures that the encoding of source files is set to UTF-8, see http://yodaconditions.net/blog/fix-for-java-file-encoding-problems-with-gradle.html
tasks.withType(JavaCompile) {
// Ensures that the encoding of source files is set to UTF-8, see http://yodaconditions.net/blog/fix-for-java-file-encoding-problems-with-gradle.html
options.encoding = "UTF-8"
// Tells Gradle not to include debug information in the compiled .class files. This reduces the file size.
options.debug = false
}

// This task creates a .jar file containing the javadoc for the code of this mod.
Expand Down
8 changes: 4 additions & 4 deletions src/main/java/iDiamondhunter/morebows/Client.java
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ public final class Client extends MoreBows implements IModGuiFactory {
* Hack used by RenderBow. This value is set to the partialTicks of a RenderHandEvent.
* This value is needed by RenderBow to render the bow!
*/
public static float partTicks = 0;
public static float partialTicks = 0;

/**
* Poses the arms of a player to display the "bow aiming" action on drawing back a bow TODO finish documenting
Expand All @@ -45,8 +45,8 @@ public void bowPose(Pre event) {

/**
* Hack to store the amount of partial ticks to use in bow rendering.
* In RenderBow, partTicks is needed, but it is never passed to it.
* partTicks is roughly equivalent to (Minecraft.getMinecraft().entityRenderer.renderEndNanoTime + (long)(1000000000 / Minecraft.getMinecraft().gameSettings.limitFramerate))),
* In RenderBow, partialTicks is needed, but it is never passed to it.
* partialTicks is roughly equivalent to (Minecraft.getMinecraft().entityRenderer.renderEndNanoTime + (long)(1000000000 / Minecraft.getMinecraft().gameSettings.limitFramerate))),
* however renderEndNanoTime is a private field.
* However, this paticular value is passed through a whole bunch of places.
* RenderHandEvent happens to be the closest to rendering items, as it's posted just before any item rendering is done.
Expand All @@ -56,7 +56,7 @@ public void bowPose(Pre event) {
*/
@SubscribeEvent
public void bowTicks(RenderHandEvent event) {
partTicks = event.partialTicks;
partialTicks = event.partialTicks;
}

/**
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/iDiamondhunter/morebows/Config.java
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ public final class Config extends GuiConfig {
* This might break in the future, at which point something like this should be implemented:
*
* <pre>{@code
* private static String[] wantedProperties = new String[] { "oldArrRender" };
* private static String[] wantedProperties = new String[] { "oldFrostArrowRendering" };
*
* private static List<IConfigElement> getConfigElements() {
* final List<IConfigElement> list = new ArrayList<IConfigElement>();
Expand Down
13 changes: 5 additions & 8 deletions src/main/java/iDiamondhunter/morebows/MoreBows.java
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,6 @@
import net.minecraft.world.WorldServer;
import net.minecraftforge.common.MinecraftForge;
import net.minecraftforge.common.config.Configuration;
import net.minecraftforge.common.config.Property;
import net.minecraftforge.event.entity.living.LivingAttackEvent;
import net.minecraftforge.event.entity.living.LivingHurtEvent;

Expand Down Expand Up @@ -56,7 +55,7 @@ public class MoreBows {
* MoreBows config setting.
* If true, render frost arrows as snow cubes. If false, render as snowballs.
*/
public static boolean oldArrRender;
public static boolean oldFrostArrowRendering;

/*
* Hardcoded magic numbers, because Enums (as they're classes) require a large amount of file space, and I'm targeting 64kb as the compiled .jar size.
Expand Down Expand Up @@ -122,18 +121,16 @@ public class MoreBows {

/** Syncs the config file TODO documentation */
public static void conf() {
// config.load();
Property prop;
prop = config.get(Configuration.CATEGORY_GENERAL, "oldFrostArrowRendering", false);
oldArrRender = prop.getBoolean();
oldFrostArrowRendering = config.get(Configuration.CATEGORY_GENERAL, "oldFrostArrowRendering", false).getBoolean();

if (config.hasChanged()) {
config.save();
}
}

/**
* Checks if the provided world is a client or a server. If it is a client world, it doesn't do anything.
* This method attempts to spawn a particle on the server world.
* It first checks if the provided world is a client or a server. If it is a client world, it doesn't do anything.
* If it is a server world, it calls the server world specific method to spawn a particle on the server.
* This particle will be sent to connected clients.
* The parameter randDisp can be set, which sets the particles position to somewhere random close to the entity.
Expand Down Expand Up @@ -252,7 +249,7 @@ public final void arrHurt(LivingHurtEvent event) {
}

/**
* Initualises mod TODO documentation
* Initializes mod TODO documentation
*
* @param event the event
*/
Expand Down
35 changes: 14 additions & 21 deletions src/main/java/iDiamondhunter/morebows/bows/CustomBow.java
Original file line number Diff line number Diff line change
Expand Up @@ -130,48 +130,41 @@ public final void onPlayerStoppedUsing(ItemStack stack, World world, EntityPlaye
// Get the arrows to fire
final EntityArrow[] arrs = setArrows(world, player, shotVelocity);
// Set up flags for adding enchantment effects / other modifiers
final boolean shouldCrit = (shotVelocity == 1.0F);
final int powerEnchResult = EnchantmentHelper.getEnchantmentLevel(Enchantment.power.effectId, stack);
final boolean powerEnch = (powerEnchResult > 0);
final int power = EnchantmentHelper.getEnchantmentLevel(Enchantment.power.effectId, stack);
final int knockback = EnchantmentHelper.getEnchantmentLevel(Enchantment.punch.effectId, stack);
final boolean punchEnch = (knockback > 0);
final boolean flameEnch = (EnchantmentHelper.getEnchantmentLevel(Enchantment.flame.effectId, stack) > 0);
final boolean isFireArr = (arrowType == ARROW_TYPE_FIRE);
final boolean shouldMulti = (damageMult != 1);
final boolean flame = (EnchantmentHelper.getEnchantmentLevel(Enchantment.flame.effectId, stack) > 0);

// Add enchantment effects / other modifiers to each arrow
for (final EntityArrow arr : arrs) {
if (shouldCrit) { /* setIsCritical calls dataWatcher methods, avoid this unless needed with the check. */
if (shotVelocity == 1.0F) { /* setIsCritical calls dataWatcher methods, avoid this unless needed with the check. */
arr.setIsCritical(true);
}

if (powerEnch) {
arr.setDamage(arr.getDamage() + (powerEnchResult * 0.5D) + 0.5D);
if (power > 0) {
arr.setDamage(arr.getDamage() + (power * 0.5D) + 0.5D);
}

if (punchEnch) {
if (knockback > 0) {
arr.setKnockbackStrength(knockback);
}

if (flameEnch) {
if (flame) {
arr.setFire(flameTime);

if (isFireArr) {
if (arrowType == ARROW_TYPE_FIRE) {
arr.setDamage(arr.getDamage() * 1.25D); // TODO: Verify
}
}

if (isFireArr) {
if (arrowType == ARROW_TYPE_FIRE) {
arr.setFire(50); // TODO: Verify. I'm pretty sure the original mod did this.
}

if (allwaysShoots) {
arr.canBePickedUp = 2;
}

if (shouldMulti) {
arr.setDamage(arr.getDamage() * damageMult);
}
arr.setDamage(arr.getDamage() * damageMult);
}

stack.damageItem(1, player);
Expand All @@ -190,7 +183,7 @@ public final void onPlayerStoppedUsing(ItemStack stack, World world, EntityPlaye

/**
* This method plays the bow releasing noise for a given release of the bow. TODO Remove this?
*
*
* @param world The world that the arrows are in.
* @param player The player shooting the arrows.
* @param arrs The arrows that a bow is shooting.
Expand All @@ -217,11 +210,11 @@ public final void registerIcons(IIconRegister iconReg) {

/**
* This method creates the arrows for a given release of the bow. TODO Remove this.
*
*
* @param world The world that the arrows are in.
* @param player The player shooting the arrows.
* @param shotVelocity The velocity of the arrows.
*
*
* @return The arrows to shoot.
*/
protected EntityArrow[] setArrows(World world, EntityPlayer player, float shotVelocity) { // TODO rename later
Expand All @@ -234,7 +227,7 @@ protected EntityArrow[] setArrows(World world, EntityPlayer player, float shotVe

/**
* This method spawns the arrows for a given release of the bow. TODO Remove this.
*
*
* @param world The world that the arrows are in.
* @param player The player shooting the arrows.
* @param shotVelocity The velocity of the arrows.
Expand Down
7 changes: 2 additions & 5 deletions src/main/java/iDiamondhunter/morebows/bows/MultiBow.java
Original file line number Diff line number Diff line change
Expand Up @@ -23,14 +23,11 @@ public MultiBow() {
@Override
protected void playNoise(World world, EntityPlayer player, EntityArrow[] arrs, float shotVelocity) {
// TODO: Clean this up
final double xpos = player.posX;
final double ypos = player.posY;
final double zpos = player.posZ;
world.playSoundAtEntity(player, "random.bow", 1.0F, (1.0F / ((itemRand.nextFloat() * 0.4F) + 1.2F)) + (shotVelocity * 0.5F));
world.playSoundEffect(xpos + (player.rotationYaw / 180), ypos, zpos, "random.bow", 1.0F, (1.0F / ((itemRand.nextFloat() * 0.4F) + 1.2F)) + (shotVelocity * 0.5F));
world.playSoundEffect(player.posX + (player.rotationYaw / 180), player.posY, player.posZ, "random.bow", 1.0F, (1.0F / ((itemRand.nextFloat() * 0.4F) + 1.2F)) + (shotVelocity * 0.5F));

if (arrs.length > 2) {
world.playSoundEffect(xpos - (player.rotationYaw / 180), ypos, zpos, "random.bow", 1.0F, (1.0F / ((itemRand.nextFloat() * 0.4F) + 1.2F)) + (shotVelocity * 0.5F));
world.playSoundEffect(player.posX - (player.rotationYaw / 180), player.posY, player.posZ, "random.bow", 1.0F, (1.0F / ((itemRand.nextFloat() * 0.4F) + 1.2F)) + (shotVelocity * 0.5F));
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -165,14 +165,11 @@ public void onUpdate() {

/** Responsible for adding snow layers on top the block the arrow hits, or "freezing" the water it's in by setting the block to ice. */
if (inTicks == 64) {
final int arrX = MathHelper.floor_double(posX);
final int arrY = MathHelper.floor_double(posY);
final int arrZ = MathHelper.floor_double(posZ);
/*
* TODO Verify that this is the right block!
* Also, why does this sometimes set multiple blocks? It's the correct behavior of the original mod, but it's concerning...
*/
final Block inBlock = worldObj.getBlock(arrX, arrY, arrZ);
final Block inBlock = worldObj.getBlock(MathHelper.floor_double(posX), MathHelper.floor_double(posY), MathHelper.floor_double(posZ));

/*
* Possibly unused code?
Expand All @@ -181,15 +178,15 @@ public void onUpdate() {

/** TODO Possibly implement incrementing snow layers. */
if (Block.isEqualTo(inBlock, Blocks.air)) {
worldObj.setBlock(arrX, arrY, arrZ, Blocks.snow_layer);
worldObj.setBlock(MathHelper.floor_double(posX), MathHelper.floor_double(posY), MathHelper.floor_double(posZ), Blocks.snow_layer);
}

if (Block.isEqualTo(inBlock, Blocks.water)) {
/*
* TODO Check if the earlier event or this one is the correct one.
* Also: bouncy arrow on ice, a bit like stone skimming? Could be cool.
*/
worldObj.setBlock(arrX, arrY, arrZ, Blocks.ice);
worldObj.setBlock(MathHelper.floor_double(posX), MathHelper.floor_double(posY), MathHelper.floor_double(posZ), Blocks.ice);
}

setDead();
Expand Down
6 changes: 3 additions & 3 deletions src/main/java/iDiamondhunter/morebows/render/RenderBow.java
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
package iDiamondhunter.morebows.render;

import static iDiamondhunter.morebows.Client.partTicks;
import static iDiamondhunter.morebows.Client.partialTicks;

import org.lwjgl.opengl.GL11;

Expand Down Expand Up @@ -56,9 +56,9 @@ public void renderItem(ItemRenderType type, ItemStack stack, Object... data) {
GL11.glRotatef(-12.0F, 0.0F, 1.0F, 0.0F);
GL11.glRotatef(-8.0F, 1.0F, 0.0F, 0.0F);
GL11.glTranslatef(-0.9F, 0.2F, 0.0F);
final float ticks = stack.getMaxItemUseDuration() - ((useTicks - partTicks) + 1.0F);
final float ticks = stack.getMaxItemUseDuration() - ((useTicks - partialTicks) + 1.0F);
/**
* In the normal first person renderer, this is hardcoded to be "float divTicks = partTicks / 20.0F".
* In the normal first person renderer, this is hardcoded to be "float divTicks = partialTicks / 20.0F".
* I've used the same code as I did in the custom FOV zoom (see iDiamondhunter.morebows.Client.fov).
*/
float divTicks = ticks / ((((CustomBow) stack.getItem()).iconTimes[0] * 10) / 9);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@

/**
* Handles rendering the entities added by this mod.
* If the entity is a CustomArrow, and the CustomArrow is of type FROST, it renders as a snowball or a default cube depending on the value of MoreBows.oldArrRender.
* If the entity is a CustomArrow, and the CustomArrow is of type FROST, it renders as a snowball or a default cube depending on the value of MoreBows.oldFrostArrowRendering.
* If it's not of type FROST, it renders as an arrow.
* If it's not a CustomArrow, it doesn't render anything! This is deliberately used to not render any ArrowSpawners.
*/
Expand All @@ -27,7 +27,7 @@ public final class RenderModEntity extends RenderEntity {
public void doRender(Entity e, double a, double b, double c, float d, float f) {
if (e.getClass() == CustomArrow.class) {
if (((CustomArrow) e).getType() == ARROW_TYPE_FROST) {
if (!MoreBows.oldArrRender) {
if (!MoreBows.oldFrostArrowRendering) {
snow.doRender(e, a, b, c, d, f);
} else {
super.doRender(e, a, b, c, d, f);
Expand Down

0 comments on commit 6ced777

Please sign in to comment.