Skip to content

Commit

Permalink
replaced System.out.println with LOGGER
Browse files Browse the repository at this point in the history
  • Loading branch information
1whohears committed Jan 8, 2024
1 parent f2cc0d8 commit 1caf3b9
Show file tree
Hide file tree
Showing 14 changed files with 101 additions and 55 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,10 @@

import javax.annotation.Nullable;

import org.slf4j.Logger;

import com.google.gson.JsonObject;
import com.mojang.logging.LogUtils;
import com.onewhohears.dscombat.client.renderer.EntityScreenRenderer;
import com.onewhohears.dscombat.util.UtilParse;

Expand All @@ -20,6 +23,7 @@

public class ObjEntityModels implements ResourceManagerReloadListener {

private static final Logger LOGGER = LogUtils.getLogger();
private static ObjEntityModels instance;

public static ObjEntityModels get() {
Expand Down Expand Up @@ -60,19 +64,19 @@ public CompositeRenderable getBakedModel(String name) {
}

public void bakeModels() {
System.out.println("BAKING OBJ MODELS");
LOGGER.info("BAKING OBJ MODELS");
models.clear();
unbakedModels.forEach((key, obj) -> {
StandaloneGeometryBakingContext ctx = StandaloneGeometryBakingContext.create(obj.modelLocation);
CompositeRenderable comp = obj.bakeRenderable(ctx);
models.put(key, comp);
System.out.println("BAKED "+key+" "+obj.getRootComponentNames().size()+" "+obj.getConfigurableComponentNames().size());
LOGGER.debug("BAKED "+key+" "+obj.getRootComponentNames().size()+" "+obj.getConfigurableComponentNames().size());
});
}

@Override
public void onResourceManagerReload(ResourceManager manager) {
System.out.println("RELOAD ASSET: "+DIRECTORY);
LOGGER.info("RELOAD ASSET: "+DIRECTORY);
readUnbakedModels(manager);
readModelOverrides(manager);
bakeModels();
Expand All @@ -87,7 +91,7 @@ public void readUnbakedModels(ResourceManager manager) {
try {
String name = new File(key.getPath()).getName().replace(MODEL_FILE_TYPE, "");
if (unbakedModels.containsKey(name)) {
System.out.println("ERROR: Can't have 2 models with the same name! "+key);
LOGGER.warn("ERROR: Can't have 2 models with the same name! "+key);
return;
}
ObjTokenizer tokenizer = new ObjTokenizer(resource.open());
Expand All @@ -97,11 +101,9 @@ public void readUnbakedModels(ResourceManager manager) {
null));
tokenizer.close();
unbakedModels.putIfAbsent(name, model);
System.out.println("ADDING = "+key);
//model.getConfigurableComponentNames().forEach((n) -> {System.out.println(n);});
//System.out.println(" ");
LOGGER.debug("ADDING MODEL = "+key);
} catch (Exception e) {
System.out.println("ERROR: SKIPPING "+key);
LOGGER.warn("ERROR: SKIPPING "+key);
e.printStackTrace();
}
});
Expand All @@ -115,14 +117,14 @@ public void readModelOverrides(ResourceManager manager) {
try {
String name = new File(key.getPath()).getName().replace(OVERRIDE_FILE_TYPE, "");
if (modelOverrides.containsKey(name)) {
System.out.println("ERROR: Can't have 2 model overrides with the same name! "+key);
LOGGER.warn("ERROR: Can't have 2 model overrides with the same name! "+key);
return;
}
JsonObject json = UtilParse.GSON.fromJson(resource.openAsReader(), JsonObject.class);
modelOverrides.put(name, new ModelOverrides(json));
System.out.println("ADDING OVERRIDE = "+key);
LOGGER.debug("ADDING OVERRIDE = "+key);
} catch (Exception e) {
System.out.println("ERROR: SKIPPING "+key.toString());
LOGGER.warn("ERROR: SKIPPING "+key.toString());
e.printStackTrace();
}
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,21 @@

import java.util.function.Supplier;

import org.slf4j.Logger;

import com.mojang.logging.LogUtils;

import net.minecraft.network.FriendlyByteBuf;
import net.minecraftforge.network.NetworkEvent;

public abstract class IPacket {

protected static final Logger LOGGER = LogUtils.getLogger();

public IPacket() {}

public IPacket(FriendlyByteBuf buffer) {
System.out.println("DECODING PACKET "+getClass().getName());
LOGGER.debug("DECODING PACKET "+getClass().getName());
}

public abstract void encode(FriendlyByteBuf buffer);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,10 @@

import javax.annotation.Nullable;

import org.slf4j.Logger;

import com.mojang.logging.LogUtils;

import net.minecraft.resources.ResourceLocation;
import net.minecraft.server.packs.resources.Resource;
import net.minecraft.server.packs.resources.ResourceManager;
Expand All @@ -22,6 +26,7 @@
*/
public abstract class JsonPresetAssetReader<T extends JsonPreset> implements ResourceManagerReloadListener {

protected final Logger LOGGER = LogUtils.getLogger();
protected final Map<String, T> presetMap = new HashMap<>();
protected final String directory;

Expand All @@ -31,20 +36,20 @@ public JsonPresetAssetReader(String directory) {

@Override
public void onResourceManagerReload(ResourceManager manager) {
System.out.println("RELOAD ASSET: "+directory);
LOGGER.info("RELOAD ASSET: "+directory);
presetMap.clear();
manager.listResources(directory, (key) -> {
return key.getPath().endsWith(".json");
}).forEach((key, resource) -> {
System.out.println("key = "+key);
LOGGER.debug("key = "+key);
try {
T data = getPresetFromResource(key, resource);
if (!presetMap.containsKey(data.getId())) presetMap.put(data.getId(), data);
else {
System.out.println("ERROR: Can't have 2 presets with the same name! "+key.toString());
LOGGER.warn("ERROR: Can't have 2 presets with the same name! "+key.toString());
}
} catch (IOException e) {
System.out.println("ERROR: SKIPPING "+key.toString());
LOGGER.warn("ERROR: SKIPPING "+key.toString());
e.printStackTrace();
}
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,10 @@
import java.util.Set;
import java.util.function.Consumer;

import org.slf4j.Logger;

import com.google.common.collect.Sets;
import com.mojang.logging.LogUtils;

import net.minecraft.data.CachedOutput;
import net.minecraft.data.DataGenerator;
Expand All @@ -31,6 +34,7 @@
*/
public abstract class JsonPresetGenerator<T extends JsonPreset> implements DataProvider {

protected final Logger LOGGER = LogUtils.getLogger();
protected final DataGenerator.PathProvider pathProvider;
private final Map<ResourceLocation, T> gen_map = new HashMap<>();

Expand Down Expand Up @@ -58,7 +62,7 @@ public void run(CachedOutput cache) throws IOException {
registerPresets();
Set<ResourceLocation> set = Sets.newHashSet();
Consumer<T> consumer = (preset) -> {
System.out.println("ADD: "+preset.getKey().toString());
LOGGER.debug("GENERATING: "+preset.getKey().toString());
if (!set.add(preset.getKey())) {
throw new IllegalStateException("Duplicate Preset! " + preset.getKey());
} else {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,11 @@

import javax.annotation.Nullable;

import org.slf4j.Logger;

import com.google.gson.JsonElement;
import com.google.gson.JsonObject;
import com.mojang.logging.LogUtils;
import com.onewhohears.dscombat.util.UtilParse;

import net.minecraft.network.FriendlyByteBuf;
Expand All @@ -32,6 +35,7 @@
*/
public abstract class JsonPresetReloadListener<T extends JsonPreset> extends SimpleJsonResourceReloadListener {

protected final Logger LOGGER = LogUtils.getLogger();
protected final Map<String, T> presetMap = new HashMap<>();
protected boolean setup = false;

Expand Down Expand Up @@ -74,23 +78,23 @@ public boolean isSetup() {

@Override
protected void apply(Map<ResourceLocation, JsonElement> map, ResourceManager manager, ProfilerFiller profiler) {
System.out.println("APPLYING PRESETS TO COMMON CACHE "+getName());
LOGGER.info("APPLYING PRESETS TO COMMON CACHE "+getName());
setup = false;
presetMap.clear();
map.forEach((key, je) -> { try {
System.out.println("ADD: "+key.toString()/*+" "+je.toString()*/);
LOGGER.info("ADD: "+key.toString()/*+" "+je.toString()*/);
JsonObject json = UtilParse.GSON.fromJson(je, JsonObject.class);
T data = getFromJson(key, json);
if (data == null) {
System.out.println("ERROR: failed to parse preset "+key.toString());
LOGGER.warn("ERROR: failed to parse preset "+key.toString());
return;
}
if (!presetMap.containsKey(data.getId())) presetMap.put(data.getId(), data);
else {
System.out.println("ERROR: Can't have 2 presets with the same name! "+key.toString());
LOGGER.warn("ERROR: Can't have 2 presets with the same name! "+key.toString());
}
} catch (Exception e) {
System.out.println("ERROR: SKIPPING "+key.toString());
LOGGER.warn("ERROR: SKIPPING "+key.toString());
e.printStackTrace();
}});
resetCache();
Expand All @@ -108,7 +112,7 @@ public void writeToBuffer(FriendlyByteBuf buffer) {
}

public void readBuffer(FriendlyByteBuf buffer) {
System.out.println("RECIEVING DATA FROM SERVER "+getName());
LOGGER.debug("RECIEVING DATA FROM SERVER "+getName());
setup = false;
int length = buffer.readInt();
for (int i = 0; i < length; ++i) {
Expand All @@ -117,7 +121,7 @@ public void readBuffer(FriendlyByteBuf buffer) {
ResourceLocation key = new ResourceLocation(key_string);
JsonObject json = UtilParse.GSON.fromJson(json_string, JsonObject.class);
T data = getFromJson(key, json);
System.out.println("ADD: "+key.toString());
LOGGER.debug("ADD: "+key.toString());
presetMap.put(data.getId(), data);
}
resetCache();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,7 @@ public void setFlares(int flares) {
this.flares = flares;
}

@Override
public int getFlares() {
return flares;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -115,6 +115,10 @@ public float getAdditionalArmor() {
return 0;
}

public int getFlares() {
return 0;
}

public EntityVehicle getParent() {
return parent;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,9 @@

import javax.annotation.Nullable;

import org.slf4j.Logger;

import com.mojang.logging.LogUtils;
import com.onewhohears.dscombat.common.network.PacketHandler;
import com.onewhohears.dscombat.common.network.toclient.ToClientAircraftFuel;
import com.onewhohears.dscombat.data.parts.EngineData.EngineType;
Expand Down Expand Up @@ -37,6 +40,7 @@
*/
public class PartsManager {

private static final Logger LOGGER = LogUtils.getLogger();
public static final int SLOT_VERSION = 1;

private final EntityVehicle parent;
Expand Down Expand Up @@ -109,7 +113,7 @@ public ItemStack removeItem(int i, int count) {

private void inventorySetItem(int i, ItemStack stack) {
if (i < 0 || i >= slots.size()) {
System.out.println("WARNING! INDEX "+i+" IS OUT OF BOUNDS IN PARTS MANAGER "+this);
LOGGER.warn("WARNING! INDEX "+i+" IS OUT OF BOUNDS IN PARTS MANAGER "+this);
return;
}
PartSlot slot = slots.get(i);
Expand All @@ -125,7 +129,7 @@ private void inventorySetItem(int i, ItemStack stack) {
} else {
PartData data = UtilParse.parsePartFromItem(stack);
if (data == null) {
System.out.println("ERROR! COULD NOT GET PART DATA FROM "+stack+" "+stack.getTag());
LOGGER.warn("ERROR! COULD NOT GET PART DATA FROM "+stack+" "+stack.getTag());
return;
}
if (slot.filled()) slot.removePartData(parent);
Expand All @@ -138,7 +142,7 @@ private void inventorySetItem(int i, ItemStack stack) {

private void inventoryRemoveItem(int i, int count) {
if (i < 0 || i >= slots.size()) {
System.out.println("WARNING! INDEX "+i+" IS OUT OF BOUNDS IN PARTS MANAGER "+this);
LOGGER.warn("WARNING! INDEX "+i+" IS OUT OF BOUNDS IN PARTS MANAGER "+this);
return;
}
Entity pilot = null;
Expand Down Expand Up @@ -228,7 +232,7 @@ public float getPartsWeight() {
for (PartSlot p : slots) if (p.filled()) {
float w = p.getPartData().getWeight();
if (Float.isNaN(w)) {
System.out.println("ERROR: PART WEIGHT IS NAN "+p.toString());
LOGGER.warn("ERROR: PART WEIGHT IS NAN "+p.toString());
continue;
}
total += w;
Expand Down Expand Up @@ -362,8 +366,8 @@ public boolean useFlares(boolean consume) {

public int getNumFlares() {
int num = 0;
for (PartSlot p : getFlares())
num += ((FlareDispenserData)p.getPartData()).getFlares();
for (PartSlot p : slots) if (p.filled())
num += p.getPartData().getFlares();
return num;
}

Expand Down
Loading

0 comments on commit 1caf3b9

Please sign in to comment.