Skip to content

Commit

Permalink
1.11 building
Browse files Browse the repository at this point in the history
- Added a config option to allow for editing other players.
  • Loading branch information
Jay113355 committed Nov 19, 2016
1 parent 08bb04a commit ea98752
Show file tree
Hide file tree
Showing 29 changed files with 1,278 additions and 1,420 deletions.
11 changes: 5 additions & 6 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -20,19 +20,18 @@ repositories {

apply plugin: 'net.minecraftforge.gradle.forge'

version = "1.10.2-2.0.0"
group= "com.mcf.davidee.nbtedit"
version = "1.11.2-2.0.0"
group = "com.mcf.davidee.nbtedit"
archivesBaseName = "NBTEdit"

sourceCompatibility = 1.7
targetCompatibility = 1.7
sourceCompatibility = targetCompatibility = 1.7

idea { module { inheritOutputDirs = true } }

minecraft {
version = "1.10.2-12.18.1.2011"
version = "1.11-13.19.0.2153"
runDir = "run"
mappings = "snapshot_20160518"
mappings = "snapshot_20161111"
//makeObfSourceJar = false // an Srg named sources jar is made by default. uncomment this to disable.
}

Expand Down
9 changes: 5 additions & 4 deletions src/main/java/com/mcf/davidee/nbtedit/CommandNBTEdit.java
Original file line number Diff line number Diff line change
Expand Up @@ -17,15 +17,16 @@ public class CommandNBTEdit extends CommandBase {
public String getCommandName() {
return "nbtedit";
}

@Override
public String getCommandUsage(ICommandSender par1ICommandSender) {
public String getCommandUsage(ICommandSender sender) {
return "/nbtedit OR /nbtedit <EntityId> OR /nbtedit <TileX> <TileY> <TileZ>";
}

@Override
public void execute(MinecraftServer server, ICommandSender sender, String[] args) throws CommandException {
if (sender instanceof EntityPlayerMP) {
EntityPlayerMP player = (EntityPlayerMP)sender;
EntityPlayerMP player = (EntityPlayerMP) sender;

if (args.length == 3) {
int x = parseInt(args[0]);
Expand All @@ -36,7 +37,7 @@ public void execute(MinecraftServer server, ICommandSender sender, String[] args

} else if (args.length == 1) {
int entityID = (args[0].equalsIgnoreCase("me")) ? player.getEntityId() : parseInt(args[0], 0);
NBTEdit.log(Level.TRACE, sender.getName() + " issued command \"/nbtedit " + entityID + "\"");
NBTEdit.log(Level.TRACE, sender.getName() + " issued command \"/nbtedit " + entityID + "\"");
NBTEdit.NETWORK.sendEntity(player, entityID);

} else if (args.length == 0) {
Expand All @@ -45,7 +46,7 @@ public void execute(MinecraftServer server, ICommandSender sender, String[] args

} else {
String s = "";
for (int i =0; i < args.length; ++i) {
for (int i = 0; i < args.length; ++i) {
s += args[i];
if (i != args.length - 1)
s += " ";
Expand Down
18 changes: 10 additions & 8 deletions src/main/java/com/mcf/davidee/nbtedit/NBTEdit.java
Original file line number Diff line number Diff line change
Expand Up @@ -28,9 +28,9 @@

@Mod(modid = NBTEdit.MODID, name = NBTEdit.NAME, version = NBTEdit.VERSION, acceptableRemoteVersions = "*")
public class NBTEdit {
public static final String MODID = "NBTEdit";
public static final String MODID = "nbtedit";
public static final String NAME = "In-game NBTEdit";
public static final String VERSION = "1.10.2-2.0.0";
public static final String VERSION = "1.11.2-2.0.1";

public static final NBTNodeSorter SORTER = new NBTNodeSorter();
public static final PacketHandler NETWORK = new PacketHandler();
Expand All @@ -39,6 +39,7 @@ public class NBTEdit {

public static NamedNBT clipboard = null;
public static boolean opOnly = true;
public static boolean editOtherPlayers = false;

@Instance(MODID)
private static NBTEdit instance;
Expand All @@ -53,6 +54,7 @@ public void preInit(FMLPreInitializationEvent event) {
Configuration config = new Configuration(event.getSuggestedConfigurationFile());
config.load();
opOnly = config.get("General", "opOnly", true, "true if only Ops can NBTEdit; false allows users in creative mode to NBTEdit").getBoolean(true);
editOtherPlayers = config.get("General", "editOtherPlayers", false, "true if editing players other then your self is allowed. false by default. USE AT YOUR OWN RISK").getBoolean(false);
if (config.hasChanged()) {
config.save();
}
Expand Down Expand Up @@ -83,8 +85,7 @@ public void preInit(FMLPreInitializationEvent event) {
@EventHandler
public void init(FMLInitializationEvent event) {
logger.trace("NBTEdit Initalized");
saves = new SaveStates(new File(new File(proxy.getMinecraftDirectory(),"saves"), "NBTEdit.dat"));
//DISPATCHER.initialize();
saves = new SaveStates(new File(new File(proxy.getMinecraftDirectory(), "saves"), "NBTEdit.dat"));
NETWORK.initialize();
}

Expand All @@ -95,7 +96,7 @@ public void postInit(FMLPostInitializationEvent event) {

@EventHandler
public void serverStarting(FMLServerStartingEvent event) {
MinecraftServer server= event.getServer();
MinecraftServer server = event.getServer();
ServerCommandManager serverCommandManager = (ServerCommandManager) server.getCommandManager();
serverCommandManager.registerCommand(new CommandNBTEdit());
logger.trace("Server Starting -- Added \"/nbtedit\" command");
Expand All @@ -110,16 +111,17 @@ public static void throwing(String cls, String mthd, Throwable thr) {
}

static final String SEP = System.getProperty("line.separator");

public static void logTag(NBTTagCompound tag) {
NBTTree tree = new NBTTree(tag);
String sb = "";
for (String s : tree.toStrings()){
sb += SEP + "\t\t\t"+ s;
for (String s : tree.toStrings()) {
sb += SEP + "\t\t\t" + s;
}
NBTEdit.log(Level.TRACE, sb);
}

public static SaveStates getSaveStates(){
public static SaveStates getSaveStates() {
return instance.saves;
}
}
10 changes: 5 additions & 5 deletions src/main/java/com/mcf/davidee/nbtedit/NBTHelper.java
Original file line number Diff line number Diff line change
Expand Up @@ -14,19 +14,19 @@
import java.util.Map;

public class NBTHelper {

public static NBTTagCompound nbtRead(DataInputStream in) throws IOException {
return CompressedStreamTools.read(in);
}

public static void nbtWrite(NBTTagCompound compound, DataOutput out) throws IOException {
CompressedStreamTools.write(compound, out);
}
public static Map<String,NBTBase> getMap(NBTTagCompound tag){

public static Map<String, NBTBase> getMap(NBTTagCompound tag) {
return ReflectionHelper.getPrivateValue(NBTTagCompound.class, tag, 0);
}

public static NBTBase getTagAt(NBTTagList tag, int index) {
List<NBTBase> list = ReflectionHelper.getPrivateValue(NBTTagList.class, tag, 1);
return list.get(index);
Expand Down
183 changes: 91 additions & 92 deletions src/main/java/com/mcf/davidee/nbtedit/NBTStringHelper.java
Original file line number Diff line number Diff line change
Expand Up @@ -21,119 +21,118 @@ public class NBTStringHelper {

public static final char SECTION_SIGN = '\u00A7';

public static String getNBTName(NamedNBT namedNBT){
public static String getNBTName(NamedNBT namedNBT) {
String name = namedNBT.getName();
NBTBase obj = namedNBT.getNBT();

String s = toString(obj);
return Strings.isNullOrEmpty(name) ? "" + s : name + ": " + s;
}

public static String getNBTNameSpecial(NamedNBT namedNBT){
public static String getNBTNameSpecial(NamedNBT namedNBT) {
String name = namedNBT.getName();
NBTBase obj = namedNBT.getNBT();

String s = toString(obj);
return Strings.isNullOrEmpty(name) ? "" + s : name + ": " + s + SECTION_SIGN + 'r';
}

public static NBTBase newTag(byte type){
switch (type)
{
case 0:
return new NBTTagEnd();
case 1:
return new NBTTagByte((byte) 0);
case 2:
return new NBTTagShort();
case 3:
return new NBTTagInt(0);
case 4:
return new NBTTagLong(0);
case 5:
return new NBTTagFloat(0);
case 6:
return new NBTTagDouble(0);
case 7:
return new NBTTagByteArray(new byte[0]);
case 8:
return new NBTTagString("");
case 9:
return new NBTTagList();
case 10:
return new NBTTagCompound();
case 11:
return new NBTTagIntArray(new int[0]);
default:
return null;
public static NBTBase newTag(byte type) {
switch (type) {
case 0:
return new NBTTagEnd();
case 1:
return new NBTTagByte((byte) 0);
case 2:
return new NBTTagShort();
case 3:
return new NBTTagInt(0);
case 4:
return new NBTTagLong(0);
case 5:
return new NBTTagFloat(0);
case 6:
return new NBTTagDouble(0);
case 7:
return new NBTTagByteArray(new byte[0]);
case 8:
return new NBTTagString("");
case 9:
return new NBTTagList();
case 10:
return new NBTTagCompound();
case 11:
return new NBTTagIntArray(new int[0]);
default:
return null;
}
}

public static String toString(NBTBase base) {
switch(base.getId()) {
case 1:
return "" + ((NBTTagByte)base).getByte();
case 2:
return "" + ((NBTTagShort)base).getShort();
case 3:
return "" + ((NBTTagInt)base).getInt();
case 4:
return "" + ((NBTTagLong)base).getLong();
case 5:
return "" + ((NBTTagFloat)base).getFloat();
case 6:
return "" + ((NBTTagDouble)base).getDouble();
case 7:
return base.toString();
case 8:
return ((NBTTagString)base).getString();
case 9:
return "(TagList)";
case 10:
return "(TagCompound)";
case 11:
return base.toString();
default:
return "?";
switch (base.getId()) {
case 1:
return "" + ((NBTTagByte) base).getByte();
case 2:
return "" + ((NBTTagShort) base).getShort();
case 3:
return "" + ((NBTTagInt) base).getInt();
case 4:
return "" + ((NBTTagLong) base).getLong();
case 5:
return "" + ((NBTTagFloat) base).getFloat();
case 6:
return "" + ((NBTTagDouble) base).getDouble();
case 7:
return base.toString();
case 8:
return ((NBTTagString) base).getString();
case 9:
return "(TagList)";
case 10:
return "(TagCompound)";
case 11:
return base.toString();
default:
return "?";
}
}

public static String getButtonName(byte id){
switch(id){
case 1 :
return "Byte";
case 2:
return "Short";
case 3:
return "Int";
case 4:
return "Long";
case 5:
return "Float";
case 6:
return "Double";
case 7:
return "Byte[]";
case 8:
return "String";
case 9:
return "List";
case 10:
return "Compound";
case 11:
return "Int[]";
case 12:
return "Edit";
case 13:
return "Delete";
case 14:
return "Copy";
case 15:
return "Cut";
case 16:
return "Paste";
default:
return "Unknown";
public static String getButtonName(byte id) {
switch (id) {
case 1:
return "Byte";
case 2:
return "Short";
case 3:
return "Int";
case 4:
return "Long";
case 5:
return "Float";
case 6:
return "Double";
case 7:
return "Byte[]";
case 8:
return "String";
case 9:
return "List";
case 10:
return "Compound";
case 11:
return "Int[]";
case 12:
return "Edit";
case 13:
return "Delete";
case 14:
return "Copy";
case 15:
return "Cut";
case 16:
return "Paste";
default:
return "Unknown";
}
}
}
14 changes: 7 additions & 7 deletions src/main/java/com/mcf/davidee/nbtedit/TileEntityHelper.java
Original file line number Diff line number Diff line change
Expand Up @@ -9,24 +9,24 @@
import net.minecraft.tileentity.TileEntity;

public class TileEntityHelper {
public static <T extends TileEntity> void copyData(T from, T into) throws Exception{

public static <T extends TileEntity> void copyData(T from, T into) throws Exception {
Class<?> clazz = from.getClass();
Set<Field> fields = asSet(clazz.getFields(),clazz.getDeclaredFields());
Set<Field> fields = asSet(clazz.getFields(), clazz.getDeclaredFields());
Field modifiers = Field.class.getDeclaredField("modifiers");
modifiers.setAccessible(true);
for (Field field : fields){
for (Field field : fields) {
field.setAccessible(true);
modifiers.setInt(field, field.getModifiers() & ~Modifier.FINAL);
field.set(into, field.get(from));
}
}
public static Set<Field> asSet(Field[] a, Field[] b){

public static Set<Field> asSet(Field[] a, Field[] b) {
HashSet<Field> s = new HashSet<>();
Collections.addAll(s, a);
Collections.addAll(s, b);
return s;
}

}
Loading

0 comments on commit ea98752

Please sign in to comment.