Skip to content

Commit

Permalink
Merge pull request #183 from Unknown025/wip_config_rewrite
Browse files Browse the repository at this point in the history
Config file handling rewrite.
  • Loading branch information
Unknown025 authored Jul 7, 2023
2 parents 51ed44d + 4afcaef commit 1df74bb
Show file tree
Hide file tree
Showing 57 changed files with 3,510 additions and 3,473 deletions.
2 changes: 1 addition & 1 deletion eclipse/Flan/Modern Weapons Pack/bullets/TRIGAT.txt
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ FallSpeed 1
//The maximum stack size
MaxStackSize 24
//The number of rounds each item has. Limited to 32000.
RoundsPerItem 0.5
RoundsPerItem 1
//The damage multiplier caused by the bullet on hitting an entity
DamageVsLiving 20
DamageVsVehicles 600
Expand Down
2 changes: 1 addition & 1 deletion eclipse/Flan/WW2 Pack/vehicles/Chi-Ha.txt
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ ShellSlots 5
//Driver and passenger positions
Driver 0 14 0 -360 360 -3 3.5
RotatedDriverOffset 5 0 1
Passengers 0
Passengers 1
Passenger 1 10 28 0 turret -360 360 -15 60 type99 Type-99
GunOrigin 1 10 24 0
RotatedPassengerOffset 1 0 0 0
Expand Down
2 changes: 1 addition & 1 deletion eclipse/Flan/WW2 Pack/vehicles/KV1.txt
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ ShellSlots 5
//Driver and passenger positions
Driver 0 28 0 -360 360 -10 20
RotatedDriverOffset -26 0 0
Passengers 0
Passengers 1
Passenger 1 0 16 0 turret -360 360 -15 60 dp28 DP28
GunOrigin 1 0 30 0
BarrelPosition 0 34 0
Expand Down
2 changes: 1 addition & 1 deletion eclipse/Flan/WW2 Pack/vehicles/Type4HoRo.txt
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ ShellSlots 5
//Driver and passenger positions
Driver 3 5 15 -1.5 1.5 -2 15
RotatedDriverOffset 13 0 -8
Passengers 0
Passengers 1
Passenger 1 10 28 0 turret -360 360 -15 60 type99 Type-99
GunOrigin 1 10 24 0
RotatedPassengerOffset 1 0 0 0
Expand Down
15 changes: 10 additions & 5 deletions src/main/java/com/flansmod/client/ClientProxy.java
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@
import org.lwjgl.input.Mouse;

import java.io.File;
import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;
import java.util.ArrayList;
import java.util.HashMap;
Expand Down Expand Up @@ -122,11 +123,11 @@ public List<File> getContentList(Method method, ClassLoader classloader) {
FMLClientHandler.instance().addModAsResource(container);

} catch (Exception e) {
FlansMod.log("Failed to load images for content pack : " + file.getName());
FlansMod.log("Failed to register content pack : " + file.getName());
e.printStackTrace();
}
// Add the directory to the content pack list
FlansMod.log("Loaded content pack : " + file.getName());
FlansMod.log("Loaded content pack: " + file.getName());
contentPacks.add(file);
}
}
Expand Down Expand Up @@ -323,12 +324,16 @@ else if (split.length > 1) {
*/
@Override
public <T> T loadModel(String s, String shortName, Class<T> typeClass) {
if (s == null || shortName == null)
if (s == null || s.equalsIgnoreCase("None") || shortName == null)
return null;
try {
return typeClass.cast(Class.forName(getModelName(s)).getConstructor().newInstance());
} catch (Exception e) {
FlansMod.logger.error("Failed to load model : " + shortName + " (" + s + ")", e);
} catch (InvocationTargetException ex) {
FlansMod.logPackError("?", "?", shortName, "Model is incompatible, or you are in a dev environment", null, ex.getCause());
} catch (ClassNotFoundException ex) {
FlansMod.logPackError("?", "?", shortName, "Model (probably) not found", null, ex);
} catch (Exception ex) {
FlansMod.logPackError("?", "?", shortName, "Failed to load model (unknown cause)", null, ex);
}
return null;
}
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/com/flansmod/client/FlansModClient.java
Original file line number Diff line number Diff line change
Expand Up @@ -385,7 +385,7 @@ public static void tick() {
} else {
stanceProgress = 1F - (1F - stanceProgress) * 0.66F;
}
//FlansMod.log(zoomProgress);

if (minecraft.thePlayer.ridingEntity instanceof IControllable) {
inPlane = true;
try {
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/com/flansmod/client/TickHandlerClient.java
Original file line number Diff line number Diff line change
Expand Up @@ -732,7 +732,7 @@ public void renderTickEnd(Minecraft mc) {
GL11.glEnable(2929 /* GL_DEPTH_TEST */);
GL11.glEnable(3008 /* GL_ALPHA_TEST */);
GL11.glColor4f(1.0F, 1.0F, 1.0F, 1.0F);
//FlansMod.log(mc.gameSettings.hideGUI);

tickCountFlash++;
} else {
isInFlash = false;
Expand Down
28 changes: 15 additions & 13 deletions src/main/java/com/flansmod/client/gui/GuiArmourBox.java
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,6 @@ public void drawScreen(int i, int j, float f)

//No idea why this works, but it makes the text bind its texture correctly
//mc.renderEngine.bindTexture("/terrain.png");
//TODO : Investigate

drawCenteredString(fontRendererObj, type.name, k / 2, n + 5, 0xffffff);
mc.renderEngine.bindTexture(texture);
Expand Down Expand Up @@ -116,19 +115,22 @@ private void drawRecipe(FontRenderer fontrenderer, int m, int n, int q)
//Iterate over y
for(int j = 0; j < 2; j++)
{
drawSlotInventory(new ItemStack(page.armours[i * 2 + j].item), m + 9 + 83 * i, n + 44 + 22 * j);
int numParts = page.requiredStacks[i * 2 + j].size();
//Find which 3 parts to render
int startPart = 0;
if (numParts >= 4)
{
startPart = (scroll / 40) % (numParts - 2);
}

for(int p = 0; p < (numParts < 3 ? numParts : 3); p++)
{
drawSlotInventory(page.requiredStacks[i * 2 + j].get(startPart + p), m + 30 + p * 19 + 83 * i, n + 44 + 22 * j);
if (page.armours[i * 2 +j] != null) {
drawSlotInventory(new ItemStack(page.armours[i * 2 + j].item), m + 9 + 83 * i, n + 44 + 22 * j);
int numParts = page.requiredStacks[i * 2 + j].size();
//Find which 3 parts to render
int startPart = 0;
if (numParts >= 4)
{
startPart = (scroll / 40) % (numParts - 2);
}

for(int p = 0; p < (Math.min(numParts, 3)); p++)
{
drawSlotInventory(page.requiredStacks[i * 2 + j].get(startPart + p), m + 30 + p * 19 + 83 * i, n + 44 + 22 * j);
}
}

}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -139,12 +139,10 @@ protected void drawGuiContainerForegroundLayer(int x, int y) {
if (x >= this.guiLeft + 10 && x < this.guiLeft + 180 - 10 &&
y >= this.guiTop + 20 && y < this.guiTop + 90) {
if (driveable.getDriveableType().ammo.size() > 0) {
listHoveringText.add("[Missiles]");
listHoveringText.add("[Missiles/Shells]");
for (BulletType ammo : driveable.getDriveableType().ammo) {
if (ammo != null) {
if (ammo != null && ammo.weaponType != EnumWeaponType.BOMB) {
listHoveringText.add("> " + ammo.name);
}
if (ammo != null && ammo.weaponType != EnumWeaponType.BOMB) {
listHoveringText.add("> " + ammo.name);
}
}
}
Expand Down
2 changes: 0 additions & 2 deletions src/main/java/com/flansmod/client/gui/GuiTeamScores.java
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,6 @@ public void renderTwoTeamGUI(PacketTeamInfo teamInfo)

//No idea why this works, but it makes the text bind its texture correctly
//mc.renderEngine.bindTexture("/terrain.png");
//TODO : Investiagate this

drawString(fontRendererObj, teamInfo.map, m + 6, n + 6, 0xffffff);
drawString(fontRendererObj, teamInfo.gametype, m + 312 - 6 - fontRendererObj.getStringWidth(teamInfo.gametype), n + 6, 0xffffff);
Expand Down Expand Up @@ -169,7 +168,6 @@ public void renderDMGUI(PacketTeamInfo teamInfo)

//No idea why this works, but it makes the text bind its texture correctly
//mc.renderEngine.bindTexture("/terrain.png");
//TODO : Investiagate this

drawCenteredString(fontRendererObj, teamInfo.gametype, k / 2, n + 4, 0xffffff);
drawString(fontRendererObj, "Name", m + 8, n + 14, 0xffffff);
Expand Down
1 change: 0 additions & 1 deletion src/main/java/com/flansmod/client/gui/GuiTeamSelect.java
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,6 @@ public void initGui()
@Override
public void drawScreen(int i, int j, float f)
{
//TODO : Draw the inventory BG and slots for the class menu
GL11.glColor4f(1.0F, 1.0F, 1.0F, 1.0F);
mc.renderEngine.bindTexture(texture);
drawTexturedModalRect(width / 2 - 128, height / 2 - guiHeight / 2, 0, 0, 256, 22);
Expand Down
24 changes: 20 additions & 4 deletions src/main/java/com/flansmod/client/model/RenderGun.java
Original file line number Diff line number Diff line change
Expand Up @@ -604,7 +604,7 @@ private void renderGunAndComponents(ModelGun model, GunType type, ItemStack item

//Handle muzzle flash stuffs
renderMuzzleFlash(animations, model, type, barrelAttachment, item, f);

// Render the slide and charge action
if (slideAttachment == null)
renderSlideModels(scopeAttachment, type, animations, model, f, item);
Expand Down Expand Up @@ -994,7 +994,6 @@ private void renderAmmo(ModelGun model, GunType type, AttachmentType gripAttachm

break;
}
//TODO
case SHOTGUN: case STRIKER: case CUSTOMSHOTGUN: case CUSTOMSTRIKER:
{
float maxBullets = getNumBulletsInReload(animations, gripAttachment, type, item);
Expand Down Expand Up @@ -1103,7 +1102,7 @@ else if (effectiveReloadAnimationProgress > 0.5 && model.stagedReload)
}
GL11.glPopMatrix();
}

private void renderMuzzleFlash(GunAnimations animations, ModelGun model, GunType type, AttachmentType barrelAttachment, ItemStack item, float f) {
boolean isFlashEnabled = barrelAttachment == null || !barrelAttachment.disableMuzzleFlash;

Expand Down Expand Up @@ -1217,6 +1216,24 @@ private void renderAttachmentAmmo(float f, AttachmentType grip, ModelGun model,
renderEngine.bindTexture(FlansModResourceHandler.getPaintjobTexture(otherAmmo));
}

/** Load the corresponding casing model and texture */
// private void renderCasingModel(float f, AttachmentType grip, GunType gun, ItemStack gunStack)
// {

// }

/** Load the corresponding flash model and texture */
// private void renderFlashModel()
// {
//
// }

// Part of arms cleanup to rewrite into one method
private void renderArms(EntityPlayer player, ModelGun model, GunType type, GunAnimations anim)
{

}

private void renderFirstPersonArm(EntityPlayer player, ModelGun model, GunAnimations anim) {
Minecraft mc = Minecraft.getMinecraft();
ModelBiped modelBipedMain = new ModelBiped(0.0F);
Expand Down Expand Up @@ -1351,7 +1368,6 @@ private float getEndLoadedDistance(AttachmentType grip, GunType gun, ItemStack g
* Get the number of bullets to reload in animation, based on ammo type to
* reload
*/
//TODO
private float getNumBulletsInReload(GunAnimations animations, AttachmentType grip, GunType gun, ItemStack gunStack)
{
// If this is a singles reload, we want to know the number of bullets already in the gun
Expand Down
1 change: 0 additions & 1 deletion src/main/java/com/flansmod/client/model/RenderPlane.java
Original file line number Diff line number Diff line change
Expand Up @@ -349,7 +349,6 @@ public Vector3f Interpolate(Vector3f current, Vector3f prev, float f1)
}

//Broken method to try and rotate playermodel, will fix later.
//TODO: Make this work
/**
@SubscribeEvent
public void preRenderLiving(RenderPlayerEvent.Pre event)
Expand Down
66 changes: 48 additions & 18 deletions src/main/java/com/flansmod/common/FlansMod.java
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,10 @@
import com.flansmod.client.FlansCrash;
import com.flansmod.client.FlansModClient;
import com.flansmod.client.model.GunAnimations;
import com.flansmod.common.driveables.*;
import com.flansmod.common.driveables.mechas.*;
import com.flansmod.common.eventhandlers.*;
import com.flansmod.common.guns.*;
import com.flansmod.common.driveables.EntityPlane;
import com.flansmod.common.driveables.EntitySeat;
import com.flansmod.common.driveables.EntityVehicle;
Expand Down Expand Up @@ -192,15 +196,15 @@ public class FlansMod {
public static float nameTagRenderRange = 64F;
public static float nameTagSneakRenderRange = 32F;
public static float maxHealth = 20;

public static boolean allowCombiningAmmoOnReload = true;

public static boolean enableBlockPenetration = false;
public static float masterBlockPenetrationModifier = 0F;
public static String[] penetrableBlocksArray = {"ID=20,HARDNESS=1.0,BREAKS=false", "ID=98:2,HARDNESS=2.0,BREAKS=false"};

public static ArrayList<PenetrableBlock> penetrableBlocks = new ArrayList<>();


public static int armourSpawnRate = 20;

Expand Down Expand Up @@ -760,7 +764,7 @@ public static void syncCommonConfig() {
bonusRegenFoodLimit = configFile.getInt("Bonus regen food limit", "Gameplay Settings (synced)", bonusRegenFoodLimit, 0, 20, "Amount of food required to activate this regen, vanilla is 18");

allowCombiningAmmoOnReload = configFile.getBoolean("Allow Combining Ammo on Reload", "Gameplay Settings (synced)", allowCombiningAmmoOnReload, "If this is set to 'false', players will not be able to combine their ammo on reload");

enableBlockPenetration = configFile.getBoolean("Enable Block Penetration", "Gameplay Settings (synced)", enableBlockPenetration, "This will enable the block penetration system to be used");
masterBlockPenetrationModifier = configFile.getFloat("Master Block Penetration Modifier", "Gameplay Settings (synced)", masterBlockPenetrationModifier, 0, 100, "Default block penetration modifier power. Individual bullets will override");
penetrableBlocksArray = configFile.getStringList("Penetrable Blocks", "Gameplay Settings (synced)", penetrableBlocksArray, "Blocks that can be penetrated with bullets that have the required block penetrating power. (BREAKS = whether the block should break when hit)");
Expand All @@ -785,35 +789,35 @@ public static void syncCommonConfig() {
if (configFile.hasChanged())
configFile.save();
}

/*
* Converts the String[] from the config to an ArrayList which can be used in the code more easily
*/
public static void convertPenetrableBlocksArray(String[] penetrableBlocksArray) {
ArrayList<PenetrableBlock> list = new ArrayList<>();
//ID=20,HARDNESS=1,BREAKS=false

for(String s : penetrableBlocksArray) {
try {
String[] split = s.split(",");

String[] blockData = split[0].substring(3).split(":");

int metadata = -1;
if(blockData.length > 1) metadata = Integer.parseInt(blockData[1]);
Block block = Block.getBlockById(Integer.parseInt(blockData[0]));
float hardness = Float.parseFloat( split[1].substring(9) );
Block block = Block.getBlockById(Integer.parseInt(blockData[0]));

float hardness = Float.parseFloat( split[1].substring(9) );
boolean breaks = Boolean.parseBoolean( split[2].substring(7) );

PenetrableBlock pB = new PenetrableBlock(block, metadata, hardness, breaks);

list.add(pB);
} catch(Exception e) {
System.out.println("ERROR! - '" + s + "' couldn't be recognized as a penetrable block!");
e.printStackTrace();
}
}
}
}
FlansMod.penetrableBlocks = list;
}

Expand Down Expand Up @@ -848,11 +852,11 @@ public static void syncClientConfig() {
log(String.format("The fire button type '%s' does not exist.", aimTypeInput));
FlansModClient.fireButton = FlanMouseButton.RIGHT;
}

FlansModClient.combineAmmoOnReload = configFile.getBoolean("Combine Ammo On Reload", "Input Settings", true, "Whether or not to combine unloaded ammo with damaged ammo in the inventory");

FlansModClient.ammoToUpperInventoryOnReload = configFile.getBoolean("Ammo To Upper Inventory On Reload", "Input Settings", false, "Whether or not to first try to put unloaded ammo in the upper inventory instead of the hotbar");

if (configFile.hasChanged())
configFile.save();
}
Expand All @@ -878,6 +882,32 @@ public static void log(Object obj) {
}
}

public static void logException(String message, Throwable ex) {
if (printStackTrace) {
logger.info(message, ex);
}
}

// To display validation, parsing errors e.t.c.
public static void logPackError(String fileName, String pack, String shortname, String message, String[] split, Throwable ex) {
FlansMod.log("Error caused by file: %s pack: %s shortname: %s", fileName, pack, shortname);
FlansMod.log("\t%s", message);

if (split != null) {
StringBuilder b = new StringBuilder();

for (String sp : split) {
b.append(sp);
b.append(" ");
}
FlansMod.log("\tCaused by line: %s", b.toString());
}

if (ex != null && FlansMod.printStackTrace) {
logException("\tRelated Exception: ", ex);
}
}

public static void log(String format, Object... args) {
log(String.format(format, args));
}
Expand Down
Loading

0 comments on commit 1df74bb

Please sign in to comment.