public void persistVehicleTypes() { persistIncidents(); JSONArray jsonVehicleTypes = new JSONArray(); for (VehicleType vehicleType : vehicleTypes) { jsonVehicleTypes.add(vehicleType.jsonify()); } json.put("vehicleTypes", jsonVehicleTypes); }
public VehicleType getVehicleType(int id) { for (VehicleType type : vehicleTypes) { if (type.getId() == id) { return type; } } return null; }
public void beforeReadEntityFromNBT(NBTTagCompound tags) { if (player.worldObj.isRemote) return; NBTTagCompound customData = new NBTTagCompound(); try { // Load the data File file = new File(FlansModHandler.getSaveDirectory(player.worldObj), "Flan.dat"); customData = CompressedStreamTools.readCompressed(new FileInputStream(file)); // Fill the unlocks list NBTTagList unlocks = customData.getTagList("Unlocks"); for (int i = 0; i < unlocks.tagCount(); ++i) { NBTTagString string = (NBTTagString) unlocks.tagAt(i); FlansMod.blueprintsUnlocked = new ArrayList<PlaneType>(); FlansMod.blueprintsUnlocked.add(PlaneType.getPlane(string.toString())); } NBTTagList vehicleUnlocks = customData.getTagList("VehicleUnlocks"); for (int i = 0; i < vehicleUnlocks.tagCount(); ++i) { NBTTagString string = (NBTTagString) vehicleUnlocks.tagAt(i); FlansMod.vehicleBlueprintsUnlocked = new ArrayList<VehicleType>(); FlansMod.vehicleBlueprintsUnlocked.add(VehicleType.getVehicle(string.toString())); } FlansMod.doneTutorial = customData.getBoolean("DoneTutorial"); } catch (IOException ioexception) { System.out.println("Failed to read data for Flan's mod. Using defaults."); } }
/* (non-Javadoc) * @see java.lang.Object#hashCode() */ @Override public int hashCode() { final int prime = 31; int result = 1; result = prime * result + ((id == null) ? 0 : id.hashCode()); result = prime * result + ((type == null) ? 0 : type.hashCode()); return result; }
private void restoreVehicleTypes() { JSONArray jsonVehicleTypes = (JSONArray) json.get("vehicleTypes"); int size = jsonVehicleTypes.size(); for (int i = 0; i < size; ++i) { JSONObject jsonVehicleType = (JSONObject) jsonVehicleTypes.get(i); VehicleType vehicleType = VehicleType.createFromJSON(jsonVehicleType); vehicleTypes.add(vehicleType); } }
/** Two vehicles are equal if they have the same id and if their types are equal. */ @Override public boolean equals(Object obj) { if (this == obj) return true; if (obj == null) return false; if (getClass() != obj.getClass()) return false; VehicleImpl other = (VehicleImpl) obj; if (id == null) { if (other.id != null) return false; } else if (!id.equals(other.id)) return false; if (type == null) { if (other.type != null) return false; } else if (!type.equals(other.type)) return false; return true; }
private VehicleImpl(Builder builder) { id = builder.id; type = builder.type; earliestDeparture = builder.earliestStart; latestArrival = builder.latestArrival; returnToDepot = builder.returnToDepot; skills = builder.skills; endLocation = builder.endLocation; startLocation = builder.startLocation; setVehicleIdentifier( new VehicleTypeKey( type.getTypeId(), startLocation.getId(), endLocation.getId(), earliestDeparture, latestArrival, skills)); }