More Core Class Conversion

This commit is contained in:
Kam committed 2026-03-13 16:59:00 -04:00
1 parent 27a9e4c808
commit 79b63efa19
36 files changed
+420 -102

No files matched your search

@@ -5,6 +5,7 @@ import cpw.mods.fml.relauncher.SideOnly;
import net.minecraft.nbt.NBTTagCompound;
import net.minecraft.nbt.NBTTagList;
import noppes.npcs.EventHooks;
import noppes.npcs.wrapper.nbt.MC1710NBTCompound;
import noppes.npcs.api.handler.data.IAnimation;
import noppes.npcs.api.handler.data.IAnimationData;
import noppes.npcs.api.handler.data.IFrame;
@@ -223,8 +224,9 @@ public class Animation implements IAnimation {
for (int i = 0; i < list.tagCount(); i++) {
NBTTagCompound item = list.getCompoundTagAt(i);
Frame frame = new Frame();
frame.parent = this;
frame.readFromNBT(item);
frame.parentSpeed = this.speed;
frame.parentSmooth = this.smooth;
frame.readFromNBT(new MC1710NBTCompound(item));
frames.add(frame);
}
this.frames = frames;
@@ -247,7 +249,7 @@ public class Animation implements IAnimation {
NBTTagList list = new NBTTagList();
for (Frame frame : frames) {
NBTTagCompound item = frame.writeToNBT();
NBTTagCompound item = ((MC1710NBTCompound) frame.writeToNBT()).getMCTag();
list.appendTag(item);
}
compound.setTag("Frames", list);
@@ -2,6 +2,7 @@ package noppes.npcs.controllers.data;
import net.minecraft.nbt.NBTTagCompound;
import noppes.npcs.api.handler.data.IAnimation;
import noppes.npcs.wrapper.nbt.MC1710NBTCompound;
/**
* A read-only animation loaded from mod assets.
@@ -78,8 +79,9 @@ public class BuiltInAnimation extends Animation {
for (int i = 0; i < list.tagCount(); i++) {
NBTTagCompound item = list.getCompoundTagAt(i);
Frame frame = new Frame();
frame.parent = this;
frame.readFromNBT(item);
frame.parentSpeed = this.speed;
frame.parentSmooth = this.smooth;
frame.readFromNBT(new MC1710NBTCompound(item));
frames.add(frame);
}
@@ -1,197 +0,0 @@
package noppes.npcs.controllers.data;
import net.minecraft.nbt.NBTTagCompound;
import net.minecraft.nbt.NBTTagList;
import noppes.npcs.api.handler.data.IFrame;
import noppes.npcs.api.handler.data.IFramePart;
import noppes.npcs.constants.EnumAnimationPart;
import java.util.HashMap;
import java.util.Map;
public class Frame implements IFrame {
public Animation parent;
public HashMap<EnumAnimationPart, FramePart> frameParts = new HashMap<>();
public int duration = 0;
boolean customized = false;
public float speed = 1.0F;
public byte smooth = 0;
private int colorMarker = 0xFFFFFF;
private String comment = "";
public Frame() {
}
public Frame(int duration) {
this.duration = duration;
}
public Frame(int duration, float speed, byte smooth) {
this.duration = duration;
this.speed = speed;
this.smooth = smooth;
this.customized = true;
}
public HashMap<EnumAnimationPart, FramePart> getFrameMap() {
return frameParts;
}
public IFramePart[] getParts() {
return frameParts.values().toArray(new IFramePart[0]);
}
public IFrame addPart(IFramePart partConfig) {
this.frameParts.put(((FramePart) partConfig).getPart(), (FramePart) partConfig);
return this;
}
public IFrame removePart(String partName) {
try {
this.frameParts.remove(EnumAnimationPart.valueOf(partName));
} catch (IllegalArgumentException ignored) {
}
return this;
}
public IFrame removePart(int partId) {
for (EnumAnimationPart part : EnumAnimationPart.values()) {
this.frameParts.remove(part);
}
return this;
}
public IFrame clearParts() {
frameParts.clear();
return this;
}
public int getDuration() {
return duration;
}
public IFrame setDuration(int duration) {
this.duration = duration;
return this;
}
public boolean isCustomized() {
return customized;
}
public IFrame setCustomized(boolean customized) {
this.customized = customized;
return this;
}
public float getSpeed() {
return speed;
}
public IFrame setSpeed(float speed) {
this.speed = speed;
return this;
}
public byte smoothType() {
return smooth;
}
public IFrame setSmooth(byte smooth) {
this.smooth = smooth;
return this;
}
public int getColorMarker() {
return this.colorMarker;
}
public void setColorMarker(int color) {
this.colorMarker = color;
}
public String getComment() {
return this.comment;
}
public void setComment(String comment) {
this.comment = comment;
}
public void readFromNBT(NBTTagCompound compound) {
duration = compound.getInteger("Duration");
if (compound.hasKey("ColorMarker")) {
this.setColorMarker(compound.getInteger("ColorMarker"));
}
if (compound.hasKey("Comment")) {
this.comment = compound.getString("Comment");
}
// Customized = TRUE if Speed or Smooth Exist
if (compound.hasKey("Speed")) {
customized = true;
speed = compound.getFloat("Speed");
}
if (compound.hasKey("Smooth")) {
customized = true;
smooth = compound.getByte("Smooth");
}
if (!customized && parent != null) {
this.speed = parent.speed;
this.smooth = parent.smooth;
}
HashMap<EnumAnimationPart, FramePart> frameParts = new HashMap<>();
NBTTagList list = compound.getTagList("FrameParts", 10);
for (int i = 0; i < list.tagCount(); i++) {
NBTTagCompound item = list.getCompoundTagAt(i);
FramePart framePart = new FramePart();
framePart.readFromNBT(item);
if (!framePart.customized) {
framePart.smooth = this.smooth;
framePart.speed = this.speed;
}
frameParts.put(framePart.part, framePart);
}
this.frameParts = frameParts;
}
public NBTTagCompound writeToNBT() {
NBTTagCompound compound = new NBTTagCompound();
compound.setInteger("Duration", duration);
compound.setInteger("ColorMarker", this.colorMarker);
compound.setString("Comment", this.comment);
if (customized) {
compound.setFloat("Speed", speed);
compound.setByte("Smooth", smooth);
}
NBTTagList list = new NBTTagList();
for (FramePart framePart : frameParts.values()) {
NBTTagCompound item = framePart.writeToNBT();
list.appendTag(item);
}
compound.setTag("FrameParts", list);
return compound;
}
public Frame copy() {
Frame frame = new Frame(this.duration);
HashMap<EnumAnimationPart, FramePart> frameParts = this.frameParts;
for (Map.Entry<EnumAnimationPart, FramePart> entry : frameParts.entrySet()) {
frame.frameParts.put(entry.getKey(), entry.getValue().copy());
}
frame.parent = this.parent;
frame.duration = this.duration;
frame.customized = this.customized;
frame.speed = this.speed;
frame.smooth = this.smooth;
frame.colorMarker = this.colorMarker;
return frame;
}
}
@@ -1,241 +0,0 @@
package noppes.npcs.controllers.data;
import cpw.mods.fml.relauncher.Side;
import cpw.mods.fml.relauncher.SideOnly;
import net.minecraft.nbt.NBTTagCompound;
import noppes.npcs.api.handler.data.IFramePart;
import noppes.npcs.client.ClientEventHandler;
import noppes.npcs.constants.EnumAnimationPart;
public class FramePart implements IFramePart {
public Animation parent;
public EnumAnimationPart part;
public float[] rotation = {0, 0, 0};
public float[] pivot = {0, 0, 0};
boolean customized = false;
public float speed = 1.0F;
//0 - Interpolated, 1 - Linear, 2 - None
public byte smooth = 0;
//Client-sided fields (unsaved)
public float[] prevRotations = {0, 0, 0};
public float[] prevPivots = {0, 0, 0};
public float partialRotationTick;
public float partialPivotTick;
public FramePart() {
}
public FramePart(EnumAnimationPart part) {
this.part = part;
}
public EnumAnimationPart getPart() {
return part;
}
public String getName() {
return part.name();
}
public int getPartId() {
return part.ordinal();
}
public void setPart(EnumAnimationPart part) {
this.part = part;
}
public IFramePart setPart(String name) {
try {
this.setPart(EnumAnimationPart.valueOf(name));
} catch (IllegalArgumentException ignored) {
}
return this;
}
public IFramePart setPart(int partId) {
for (EnumAnimationPart enumPart : EnumAnimationPart.values()) {
if (enumPart.ordinal() == partId) {
this.setPart(enumPart);
break;
}
}
return this;
}
public float[] getRotations() {
return rotation;
}
public IFramePart setRotations(float[] rotation) {
this.rotation = rotation;
return this;
}
public float[] getPivots() {
return pivot;
}
public IFramePart setPivots(float[] pivot) {
this.pivot = pivot;
return this;
}
public boolean isCustomized() {
return customized;
}
public IFramePart setCustomized(boolean customized) {
this.customized = customized;
return this;
}
public float getSpeed() {
return speed;
}
public IFramePart setSpeed(float speed) {
this.speed = speed;
return this;
}
public byte isSmooth() {
return smooth;
}
public IFramePart setSmooth(byte smooth) {
this.smooth = smooth;
return this;
}
public void readFromNBT(NBTTagCompound compound) {
part = EnumAnimationPart.valueOf(compound.getString("Part"));
for (int i = 0; i < 3; i++) {
rotation[i] = compound.getFloat("Rotation" + i);
}
for (int i = 0; i < 3; i++) {
pivot[i] = compound.getFloat("Pivot" + i);
}
// Customized = TRUE if Speed or Smooth Exist
if (compound.hasKey("Speed")) {
customized = true;
speed = compound.getFloat("Speed");
}
if (compound.hasKey("Smooth")) {
customized = true;
smooth = compound.getByte("Smooth");
}
}
public NBTTagCompound writeToNBT() {
NBTTagCompound compound = new NBTTagCompound();
compound.setString("Part", part.toString());
for (int i = 0; i < 3; i++) {
compound.setFloat("Rotation" + i, rotation[i]);
}
for (int i = 0; i < 3; i++) {
compound.setFloat("Pivot" + i, pivot[i]);
}
if (customized) {
compound.setFloat("Speed", speed);
compound.setByte("Smooth", smooth);
}
return compound;
}
public FramePart copy() {
FramePart part = new FramePart(this.part);
part.rotation = new float[]{this.rotation[0], this.rotation[1], this.rotation[2]};
part.pivot = new float[]{this.pivot[0], this.pivot[1], this.pivot[2]};
part.customized = this.customized;
part.speed = this.speed;
part.smooth = this.smooth;
return part;
}
@SideOnly(Side.CLIENT)
public void interpolateAngles() {
if (parent != null && parent.paused)
return;
float pi = (float) Math.PI / 180;
if (this.smooth == 2) {
this.prevRotations[0] = this.rotation[0] * pi;
this.prevRotations[1] = this.rotation[1] * pi;
this.prevRotations[2] = this.rotation[2] * pi;
} else if (this.partialRotationTick != ClientEventHandler.partialRenderTick) {
this.partialRotationTick = ClientEventHandler.partialRenderTick;
if (this.smooth == 0) {
this.prevRotations[0] = (this.rotation[0] * pi - this.prevRotations[0]) * Math.abs(this.speed) / 10f + this.prevRotations[0];
this.prevRotations[1] = (this.rotation[1] * pi - this.prevRotations[1]) * Math.abs(this.speed) / 10f + this.prevRotations[1];
this.prevRotations[2] = (this.rotation[2] * pi - this.prevRotations[2]) * Math.abs(this.speed) / 10f + this.prevRotations[2];
} else {
int directionX = Float.compare(this.rotation[0] * pi, this.prevRotations[0]);
this.prevRotations[0] += directionX * this.speed / 10f;
this.prevRotations[0] = directionX == 1 ?
Math.min(this.rotation[0] * pi, this.prevRotations[0]) : Math.max(this.rotation[0] * pi, this.prevRotations[0]);
int directionY = Float.compare(this.rotation[1] * pi, this.prevRotations[1]);
this.prevRotations[1] += directionY * this.speed / 10f;
this.prevRotations[1] = directionY == 1 ?
Math.min(this.rotation[1] * pi, this.prevRotations[1]) : Math.max(this.rotation[1] * pi, this.prevRotations[1]);
int directionZ = Float.compare(this.rotation[2] * pi, this.prevRotations[2]);
this.prevRotations[2] += directionZ * this.speed / 10f;
this.prevRotations[2] = directionZ == 1 ?
Math.min(this.rotation[2] * pi, this.prevRotations[2]) : Math.max(this.rotation[2] * pi, this.prevRotations[2]);
}
}
}
@SideOnly(Side.CLIENT)
public void interpolateOffset() {
if (parent != null && parent.paused)
return;
if (this.smooth == 2) {
this.prevPivots[0] = this.pivot[0];
this.prevPivots[1] = this.pivot[1];
this.prevPivots[2] = this.pivot[2];
} else if (this.partialPivotTick != ClientEventHandler.partialRenderTick) {
this.partialPivotTick = ClientEventHandler.partialRenderTick;
if (this.smooth == 0) {
this.prevPivots[0] = (this.pivot[0] - this.prevPivots[0]) * Math.abs(this.speed) / 10f + this.prevPivots[0];
this.prevPivots[1] = (this.pivot[1] - this.prevPivots[1]) * Math.abs(this.speed) / 10f + this.prevPivots[1];
this.prevPivots[2] = (this.pivot[2] - this.prevPivots[2]) * Math.abs(this.speed) / 10f + this.prevPivots[2];
} else {
int directionX = Float.compare(this.pivot[0], this.prevPivots[0]);
this.prevPivots[0] += directionX * this.speed / 10f;
this.prevPivots[0] = directionX == 1 ?
Math.min(this.pivot[0], this.prevPivots[0]) : Math.max(this.pivot[0], this.prevPivots[0]);
int directionY = Float.compare(this.pivot[1], this.prevPivots[1]);
this.prevPivots[1] += directionY * this.speed / 10f;
this.prevPivots[1] = directionY == 1 ?
Math.min(this.pivot[1], this.prevPivots[1]) : Math.max(this.pivot[1], this.prevPivots[1]);
int directionZ = Float.compare(this.pivot[2], this.prevPivots[2]);
this.prevPivots[2] += directionZ * this.speed / 10f;
this.prevPivots[2] = directionZ == 1 ?
Math.min(this.pivot[2], this.prevPivots[2]) : Math.max(this.pivot[2], this.prevPivots[2]);
}
}
}
@SideOnly(Side.CLIENT)
public void jumpToCurrentFrame() {
this.partialRotationTick = ClientEventHandler.partialRenderTick;
this.partialPivotTick = ClientEventHandler.partialRenderTick;
this.prevPivots[0] = this.pivot[0];
this.prevPivots[1] = this.pivot[1];
this.prevPivots[2] = this.pivot[2];
float pi = (float) Math.PI / 180;
this.prevRotations[0] = this.rotation[0] * pi;
this.prevRotations[1] = this.rotation[1] * pi;
this.prevRotations[2] = this.rotation[2] * pi;
}
}
@@ -49,10 +49,10 @@ import java.util.HashSet;
import java.util.UUID;
public class PlayerData implements IExtendedEntityProperties, IPlayerData {
public PlayerDialogData dialogData = new PlayerDialogData(this);
public PlayerDialogData dialogData = new PlayerDialogData();
public PlayerBankData bankData = new PlayerBankData(this);
public PlayerQuestData questData = new PlayerQuestData(this);
public PlayerTransportData transportData = new PlayerTransportData(this);
public PlayerTransportData transportData = new PlayerTransportData();
public PlayerFactionData factionData = new PlayerFactionData(this);
public PlayerItemGiverData itemgiverData = new PlayerItemGiverData(this);
public PlayerMailData mailData = new PlayerMailData(this);
@@ -141,10 +141,10 @@ public class PlayerData implements IExtendedEntityProperties, IPlayerData {
}
public void setNBT(NBTTagCompound data) {
dialogData.loadNBTData(data);
dialogData.loadNBTData(new MC1710NBTCompound(data));
bankData.loadNBTData(data);
questData.loadNBTData(data);
transportData.loadNBTData(data);
transportData.loadNBTData(new MC1710NBTCompound(data));
factionData.loadNBTData(data);
itemgiverData.loadNBTData(data);
mailData.loadNBTData(data);
@@ -186,10 +186,10 @@ public class PlayerData implements IExtendedEntityProperties, IPlayerData {
uuid = player.getPersistentID().toString();
}
NBTTagCompound compound = new NBTTagCompound();
dialogData.saveNBTData(compound);
dialogData.saveNBTData(new MC1710NBTCompound(compound));
bankData.saveNBTData(compound);
questData.saveNBTData(compound);
transportData.saveNBTData(compound);
transportData.saveNBTData(new MC1710NBTCompound(compound));
factionData.saveNBTData(compound);
itemgiverData.saveNBTData(compound);
mailData.saveNBTData(compound);
@@ -219,14 +219,14 @@ public class PlayerData implements IExtendedEntityProperties, IPlayerData {
public NBTTagCompound getSyncNBT() {
NBTTagCompound compound = new NBTTagCompound();
dialogData.saveNBTData(compound);
dialogData.saveNBTData(new MC1710NBTCompound(compound));
questData.saveNBTData(compound);
factionData.saveNBTData(compound);
return compound;
}
public void setSyncNBT(NBTTagCompound data) {
dialogData.loadNBTData(data);
dialogData.loadNBTData(new MC1710NBTCompound(data));
questData.loadNBTData(data);
factionData.loadNBTData(data);
}
@@ -247,10 +247,10 @@ public class PlayerData implements IExtendedEntityProperties, IPlayerData {
uuid = player.getPersistentID().toString();
}
NBTTagCompound compound = new NBTTagCompound();
dialogData.saveNBTData(compound);
dialogData.saveNBTData(new MC1710NBTCompound(compound));
bankData.saveNBTData(compound);
questData.saveNBTData(compound);
transportData.saveNBTData(compound);
transportData.saveNBTData(new MC1710NBTCompound(compound));
factionData.saveNBTData(compound);
mailData.saveNBTData(compound);
tradeData.writeToNBT(compound);
@@ -263,10 +263,10 @@ public class PlayerData implements IExtendedEntityProperties, IPlayerData {
}
public void setSyncNBTFull(NBTTagCompound data) {
dialogData.loadNBTData(data);
dialogData.loadNBTData(new MC1710NBTCompound(data));
bankData.loadNBTData(data);
questData.loadNBTData(data);
transportData.loadNBTData(data);
transportData.loadNBTData(new MC1710NBTCompound(data));
factionData.loadNBTData(data);
mailData.loadNBTData(data);
tradeData.readFromNBT(data);
@@ -1,55 +0,0 @@
package noppes.npcs.controllers.data;
import net.minecraft.nbt.NBTTagCompound;
import net.minecraft.nbt.NBTTagList;
import noppes.npcs.api.handler.IPlayerDialogData;
import java.util.HashSet;
public class PlayerDialogData implements IPlayerDialogData {
private final PlayerData parent;
public HashSet<Integer> dialogsRead = new HashSet<Integer>();
public PlayerDialogData(PlayerData parent) {
this.parent = parent;
}
public void loadNBTData(NBTTagCompound compound) {
HashSet<Integer> dialogsRead = new HashSet<Integer>();
if (compound == null)
return;
NBTTagList list = compound.getTagList("DialogData", 10);
if (list == null) {
return;
}
for (int i = 0; i < list.tagCount(); i++) {
NBTTagCompound nbttagcompound = list.getCompoundTagAt(i);
dialogsRead.add(nbttagcompound.getInteger("Dialog"));
}
this.dialogsRead = dialogsRead;
}
public void saveNBTData(NBTTagCompound compound) {
NBTTagList list = new NBTTagList();
for (int dia : dialogsRead) {
NBTTagCompound nbttagcompound = new NBTTagCompound();
nbttagcompound.setInteger("Dialog", dia);
list.appendTag(nbttagcompound);
}
compound.setTag("DialogData", list);
}
public boolean hasReadDialog(int id) {
return dialogsRead.contains(id);
}
public void readDialog(int id) {
dialogsRead.add(id);
}
public void unreadDialog(int id) {
dialogsRead.remove(id);
}
}
@@ -1,76 +0,0 @@
package noppes.npcs.controllers.data;
import net.minecraft.nbt.NBTTagCompound;
import net.minecraft.nbt.NBTTagList;
import noppes.npcs.api.handler.IPlayerTransportData;
import noppes.npcs.api.handler.data.ITransportLocation;
import noppes.npcs.controllers.TransportController;
import java.util.ArrayList;
import java.util.HashSet;
public class PlayerTransportData implements IPlayerTransportData {
private final PlayerData parent;
public HashSet<Integer> transports = new HashSet<Integer>();
public PlayerTransportData(PlayerData parent) {
this.parent = parent;
}
public void loadNBTData(NBTTagCompound compound) {
HashSet<Integer> dialogsRead = new HashSet<Integer>();
if (compound == null)
return;
NBTTagList list = compound.getTagList("TransportData", 10);
if (list == null) {
return;
}
for (int i = 0; i < list.tagCount(); i++) {
NBTTagCompound nbttagcompound = list.getCompoundTagAt(i);
dialogsRead.add(nbttagcompound.getInteger("Transport"));
}
this.transports = dialogsRead;
}
public void saveNBTData(NBTTagCompound compound) {
NBTTagList list = new NBTTagList();
for (int dia : transports) {
NBTTagCompound nbttagcompound = new NBTTagCompound();
nbttagcompound.setInteger("Transport", dia);
list.appendTag(nbttagcompound);
}
compound.setTag("TransportData", list);
}
public boolean hasTransport(int id) {
return transports.contains(id);
}
public void addTransport(int id) {
transports.add(id);
}
public void addTransport(ITransportLocation location) {
transports.add(location.getId());
}
public ITransportLocation getTransport(int id) {
return TransportController.getInstance().getTransport(id);
}
public ITransportLocation[] getTransports() {
ArrayList<ITransportLocation> list = new ArrayList<>();
for (int id : transports) {
ITransportLocation location = TransportController.getInstance().getTransport(id);
list.add(location);
}
return list.toArray(new ITransportLocation[0]);
}
public void removeTransport(int id) {
transports.remove(id);
}
}