添加VehicleData
This commit is contained in:
parent
fb7ef5d258
commit
dd322621ae
8 changed files with 147 additions and 20 deletions
|
@ -0,0 +1,25 @@
|
||||||
|
package com.atsuishio.superbwarfare.data.vehicle;
|
||||||
|
|
||||||
|
import com.atsuishio.superbwarfare.config.server.VehicleConfig;
|
||||||
|
import com.google.gson.annotations.SerializedName;
|
||||||
|
|
||||||
|
public class DefaultVehicleData {
|
||||||
|
@SerializedName("ID")
|
||||||
|
public String id = "";
|
||||||
|
|
||||||
|
@SerializedName("MaxHealth")
|
||||||
|
public float maxHealth = 50;
|
||||||
|
|
||||||
|
@SerializedName("RepairCooldown")
|
||||||
|
public int repairCooldown = VehicleConfig.REPAIR_COOLDOWN.get();
|
||||||
|
|
||||||
|
@SerializedName("RepairAmount")
|
||||||
|
public float repairAmount = VehicleConfig.REPAIR_AMOUNT.get().floatValue();
|
||||||
|
|
||||||
|
@SerializedName("MaxEnergy")
|
||||||
|
public int maxEnergy = 100000;
|
||||||
|
|
||||||
|
// TODO damage modifier
|
||||||
|
// @SerializedName("DamageModifier")
|
||||||
|
// private List<DamageModify> damageModifier;
|
||||||
|
}
|
|
@ -0,0 +1,50 @@
|
||||||
|
package com.atsuishio.superbwarfare.data.vehicle;
|
||||||
|
|
||||||
|
import com.atsuishio.superbwarfare.entity.vehicle.base.VehicleEntity;
|
||||||
|
import com.google.common.cache.CacheBuilder;
|
||||||
|
import com.google.common.cache.CacheLoader;
|
||||||
|
import com.google.common.cache.LoadingCache;
|
||||||
|
import net.minecraft.world.entity.EntityType;
|
||||||
|
import org.jetbrains.annotations.NotNull;
|
||||||
|
|
||||||
|
public class VehicleData {
|
||||||
|
|
||||||
|
public final String id;
|
||||||
|
private final DefaultVehicleData data;
|
||||||
|
|
||||||
|
private VehicleData(VehicleEntity entity) {
|
||||||
|
this.id = EntityType.getKey(entity.getType()).toString();
|
||||||
|
this.data = VehicleDataTool.vehicleData.getOrDefault(id, new DefaultVehicleData());
|
||||||
|
|
||||||
|
System.out.println(111);
|
||||||
|
}
|
||||||
|
|
||||||
|
private static final LoadingCache<VehicleEntity, VehicleData> dataCache = CacheBuilder.newBuilder()
|
||||||
|
.weakKeys()
|
||||||
|
.build(new CacheLoader<>() {
|
||||||
|
public @NotNull VehicleData load(@NotNull VehicleEntity entity) {
|
||||||
|
return new VehicleData(entity);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
public static VehicleData from(VehicleEntity entity) {
|
||||||
|
return dataCache.getUnchecked(entity);
|
||||||
|
}
|
||||||
|
|
||||||
|
public float maxHealth() {
|
||||||
|
return data.maxHealth;
|
||||||
|
}
|
||||||
|
|
||||||
|
public int repairCooldown() {
|
||||||
|
return data.repairCooldown;
|
||||||
|
}
|
||||||
|
|
||||||
|
public float repairAmount() {
|
||||||
|
return data.repairAmount;
|
||||||
|
}
|
||||||
|
|
||||||
|
public int maxEnergy() {
|
||||||
|
return data.maxEnergy;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
|
@ -0,0 +1,47 @@
|
||||||
|
package com.atsuishio.superbwarfare.data.vehicle;
|
||||||
|
|
||||||
|
import com.atsuishio.superbwarfare.Mod;
|
||||||
|
import com.google.gson.Gson;
|
||||||
|
import net.minecraft.server.packs.resources.ResourceManager;
|
||||||
|
import net.neoforged.bus.api.SubscribeEvent;
|
||||||
|
import net.neoforged.fml.common.EventBusSubscriber;
|
||||||
|
import net.neoforged.neoforge.event.OnDatapackSyncEvent;
|
||||||
|
import net.neoforged.neoforge.event.server.ServerStartedEvent;
|
||||||
|
|
||||||
|
import java.io.InputStreamReader;
|
||||||
|
import java.util.HashMap;
|
||||||
|
|
||||||
|
@EventBusSubscriber(modid = Mod.MODID)
|
||||||
|
public class VehicleDataTool {
|
||||||
|
public static HashMap<String, DefaultVehicleData> vehicleData = new HashMap<>();
|
||||||
|
|
||||||
|
public static final String VEHICLE_DATA_FOLDER = "vehicles";
|
||||||
|
|
||||||
|
public static void initJsonData(ResourceManager manager) {
|
||||||
|
vehicleData.clear();
|
||||||
|
for (var entry : manager.listResources(VEHICLE_DATA_FOLDER, file -> file.getPath().endsWith(".json")).entrySet()) {
|
||||||
|
var attribute = entry.getValue();
|
||||||
|
|
||||||
|
try {
|
||||||
|
Gson gson = new Gson();
|
||||||
|
var data = gson.fromJson(new InputStreamReader(attribute.open()), DefaultVehicleData.class);
|
||||||
|
|
||||||
|
if (!vehicleData.containsKey(data.id)) {
|
||||||
|
vehicleData.put(data.id, data);
|
||||||
|
}
|
||||||
|
} catch (Exception e) {
|
||||||
|
Mod.LOGGER.error(e.getMessage());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@SubscribeEvent
|
||||||
|
public static void serverStarted(ServerStartedEvent event) {
|
||||||
|
initJsonData(event.getServer().getResourceManager());
|
||||||
|
}
|
||||||
|
|
||||||
|
@SubscribeEvent
|
||||||
|
public static void onDataPackSync(OnDatapackSyncEvent event) {
|
||||||
|
initJsonData(event.getPlayerList().getServer().getResourceManager());
|
||||||
|
}
|
||||||
|
}
|
|
@ -353,16 +353,6 @@ public class Tom6Entity extends MobileVehicleEntity implements GeoEntity {
|
||||||
return this.cache;
|
return this.cache;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
|
||||||
public float getMaxHealth() {
|
|
||||||
return VehicleConfig.TOM_6_HP.get();
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public int getMaxEnergy() {
|
|
||||||
return VehicleConfig.TOM_6_MAX_ENERGY.get();
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public ResourceLocation getVehicleIcon() {
|
public ResourceLocation getVehicleIcon() {
|
||||||
return Mod.loc("textures/vehicle_icon/tom_6_icon.png");
|
return Mod.loc("textures/vehicle_icon/tom_6_icon.png");
|
||||||
|
|
|
@ -1,6 +1,7 @@
|
||||||
package com.atsuishio.superbwarfare.entity.vehicle.base;
|
package com.atsuishio.superbwarfare.entity.vehicle.base;
|
||||||
|
|
||||||
import com.atsuishio.superbwarfare.capability.energy.SyncedEntityEnergyStorage;
|
import com.atsuishio.superbwarfare.capability.energy.SyncedEntityEnergyStorage;
|
||||||
|
import com.atsuishio.superbwarfare.data.vehicle.VehicleData;
|
||||||
import net.minecraft.nbt.CompoundTag;
|
import net.minecraft.nbt.CompoundTag;
|
||||||
import net.minecraft.nbt.IntTag;
|
import net.minecraft.nbt.IntTag;
|
||||||
import net.minecraft.network.syncher.EntityDataAccessor;
|
import net.minecraft.network.syncher.EntityDataAccessor;
|
||||||
|
@ -75,7 +76,7 @@ public abstract class EnergyVehicleEntity extends VehicleEntity {
|
||||||
}
|
}
|
||||||
|
|
||||||
public int getMaxEnergy() {
|
public int getMaxEnergy() {
|
||||||
return 100000;
|
return VehicleData.from(this).maxEnergy();
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,7 +1,7 @@
|
||||||
package com.atsuishio.superbwarfare.entity.vehicle.base;
|
package com.atsuishio.superbwarfare.entity.vehicle.base;
|
||||||
|
|
||||||
import com.atsuishio.superbwarfare.Mod;
|
import com.atsuishio.superbwarfare.Mod;
|
||||||
import com.atsuishio.superbwarfare.config.server.VehicleConfig;
|
import com.atsuishio.superbwarfare.data.vehicle.VehicleData;
|
||||||
import com.atsuishio.superbwarfare.entity.vehicle.DroneEntity;
|
import com.atsuishio.superbwarfare.entity.vehicle.DroneEntity;
|
||||||
import com.atsuishio.superbwarfare.entity.vehicle.damage.DamageModifier;
|
import com.atsuishio.superbwarfare.entity.vehicle.damage.DamageModifier;
|
||||||
import com.atsuishio.superbwarfare.entity.vehicle.weapon.VehicleWeapon;
|
import com.atsuishio.superbwarfare.entity.vehicle.weapon.VehicleWeapon;
|
||||||
|
@ -501,7 +501,7 @@ public abstract class VehicleEntity extends Entity {
|
||||||
}
|
}
|
||||||
|
|
||||||
public float getMaxHealth() {
|
public float getMaxHealth() {
|
||||||
return 50;
|
return VehicleData.from(this).maxHealth();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -546,14 +546,14 @@ public abstract class VehicleEntity extends Entity {
|
||||||
* 呼吸回血冷却时长(单位:tick),设为小于0的值以禁用呼吸回血
|
* 呼吸回血冷却时长(单位:tick),设为小于0的值以禁用呼吸回血
|
||||||
*/
|
*/
|
||||||
public int maxRepairCoolDown() {
|
public int maxRepairCoolDown() {
|
||||||
return VehicleConfig.REPAIR_COOLDOWN.get();
|
return VehicleData.from(this).repairCooldown();
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 呼吸回血回血量
|
* 呼吸回血回血量
|
||||||
*/
|
*/
|
||||||
public float repairAmount() {
|
public float repairAmount() {
|
||||||
return VehicleConfig.REPAIR_AMOUNT.get().floatValue();
|
return VehicleData.from(this).repairAmount();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|
|
@ -1,5 +1,6 @@
|
||||||
package com.atsuishio.superbwarfare.entity.vehicle.damage;
|
package com.atsuishio.superbwarfare.entity.vehicle.damage;
|
||||||
|
|
||||||
|
import com.google.gson.annotations.SerializedName;
|
||||||
import net.minecraft.resources.ResourceKey;
|
import net.minecraft.resources.ResourceKey;
|
||||||
import net.minecraft.tags.TagKey;
|
import net.minecraft.tags.TagKey;
|
||||||
import net.minecraft.world.damagesource.DamageSource;
|
import net.minecraft.world.damagesource.DamageSource;
|
||||||
|
@ -9,17 +10,25 @@ import java.util.function.Function;
|
||||||
|
|
||||||
public class DamageModify {
|
public class DamageModify {
|
||||||
public enum ModifyType {
|
public enum ModifyType {
|
||||||
|
@SerializedName("Immunity")
|
||||||
IMMUNITY, // 完全免疫
|
IMMUNITY, // 完全免疫
|
||||||
|
@SerializedName("Reduce")
|
||||||
REDUCE, // 固定数值减伤
|
REDUCE, // 固定数值减伤
|
||||||
|
@SerializedName("Multiply")
|
||||||
MULTIPLY, // 乘以指定倍数
|
MULTIPLY, // 乘以指定倍数
|
||||||
}
|
}
|
||||||
|
|
||||||
private final float value;
|
@SerializedName("Value")
|
||||||
private final ModifyType type;
|
private float value;
|
||||||
|
@SerializedName("Type")
|
||||||
|
private ModifyType type;
|
||||||
|
|
||||||
private TagKey<DamageType> sourceTagKey = null;
|
@SerializedName("Source")
|
||||||
private ResourceKey<DamageType> sourceKey = null;
|
private String source;
|
||||||
private Function<DamageSource, Boolean> condition = null;
|
|
||||||
|
private transient TagKey<DamageType> sourceTagKey = null;
|
||||||
|
private transient ResourceKey<DamageType> sourceKey = null;
|
||||||
|
private transient Function<DamageSource, Boolean> condition = null;
|
||||||
|
|
||||||
public DamageModify(ModifyType type, float value) {
|
public DamageModify(ModifyType type, float value) {
|
||||||
this.type = type;
|
this.type = type;
|
||||||
|
|
|
@ -0,0 +1,5 @@
|
||||||
|
{
|
||||||
|
"ID": "superbwarfare:tom_6",
|
||||||
|
"MaxHealth": 40,
|
||||||
|
"MaxEnergy": 100000
|
||||||
|
}
|
Loading…
Add table
Reference in a new issue