Jump to content
Search In
  • More options...
Find results that contain...
Find results in...

[1.7.10] Server mod Questions


DCNick3
 Share

Recommended Posts

I developing ServerOnly mod with some commands.

I need to save some data to world (from command), and I need to save data temply with attachment ot the player.

And part 2. How Make mod that installs only to server, without requirement it at Client. Help!

I'm Developing Some mods. It's all.

Link to comment
Share on other sites

  • Replies 53
  • Created
  • Last Reply

Top Posters In This Topic

class MyProps implements IExtendedEntityProperties { ... }

@SubscribeEvent
void onEntityConstruct(EntityEvent.EntityConstructing event) {
    if (event.entity instanceof EntityPlayer) {
        event.entity.registerExtendedProperties("<identifier>", new MyProps());
    }
}

 

Seriously, this is simple.

Link to comment
Share on other sites

I must register Event handler with

    	events = new RealEventHandler();
    	MinecraftForge.ORE_GEN_BUS.register(events);

in my preInit Event, must I register IExtendedEntityProperties?

ORE_GEN_BUS is the wrong EventBus for this event.

You must only register the IEEP in the event like I posted above.

Link to comment
Share on other sites

Ok, now I have This Load Mathod:

 

	@Override
public void readFromNBT(NBTTagCompound nbt) {
	nextQuestId = nbt.getInteger("nextId");
	NBTTagList tl = nbt.getTagList("areas", 0);
	for (int i = 0; i < tl.tagCount(); i++) {
		String name = tl.getCompoundTagAt(i).getString("name");
		List<String> owners = new ArrayList<String>();
		List<String> members = new ArrayList<String>();
		int x1 = tl.getCompoundTagAt(i).getInteger("pos1X");
		int y1 = tl.getCompoundTagAt(i).getInteger("pos1Y");
		int z1 = tl.getCompoundTagAt(i).getInteger("pos1Z");
		int x2 = tl.getCompoundTagAt(i).getInteger("pos2X");
		int y2 = tl.getCompoundTagAt(i).getInteger("pos2Y");
		int z2 = tl.getCompoundTagAt(i).getInteger("pos2Z");
		NBTTagList tlo = tl.getCompoundTagAt(i).getTagList("owners", 0);
		NBTTagList tlm = tl.getCompoundTagAt(i).getTagList("members", 0);
		for (int i1 = 0; i < tlo.tagCount(); i++) {
			owners.add(tl.getCompoundTagAt(i).getString("name"));
		}
		for (int i1 = 0; i < tlm.tagCount(); i++) {
			members.add(tl.getCompoundTagAt(i).getString("name"));
		}

		areas.add(new AreaData(name, owners, members, x1, y1, z1, x2, y2, z2));
	}
}

 

 

How should I save this? I don't find setTagList() in NBTTagCompoud? How I must Do This?

I'm Developing Some mods. It's all.

Link to comment
Share on other sites

My AreaWorldData class:

 

package com.dcnick.servmod;

import java.util.ArrayList;
import java.util.List;

import net.minecraft.nbt.NBTTagCompound;
import net.minecraft.nbt.NBTTagList;
import net.minecraft.world.World;
import net.minecraft.world.WorldSavedData;
import net.minecraftforge.common.util.Constants.NBT;

public class AreaWorldData extends WorldSavedData {

public AreaWorldData(String indificator) {
	super(indificator);
}

private static final String IDENTIFIER = "Area";
private int nextQuestId = 0;
private List<AreaData> areas = new ArrayList<AreaData>();

public AreaWorldData() {
	super(IDENTIFIER);
}

@Override
public void readFromNBT(NBTTagCompound nbt) {
	NBTTagList tl = nbt.getTagList("areas",  NBT.TAG_ANY_NUMERIC);
	for (int i = 0; i < tl.tagCount(); i++) {
		String name = tl.getCompoundTagAt(i).getString("name");
		List<String> owners = new ArrayList<String>();
		List<String> members = new ArrayList<String>();
		int x1 = tl.getCompoundTagAt(i).getInteger("pos1X");
		int y1 = tl.getCompoundTagAt(i).getInteger("pos1Y");
		int z1 = tl.getCompoundTagAt(i).getInteger("pos1Z");
		int x2 = tl.getCompoundTagAt(i).getInteger("pos2X");
		int y2 = tl.getCompoundTagAt(i).getInteger("pos2Y");
		int z2 = tl.getCompoundTagAt(i).getInteger("pos2Z");
		NBTTagList tlo = tl.getCompoundTagAt(i).getTagList("owners",  NBT.TAG_ANY_NUMERIC);
		NBTTagList tlm = tl.getCompoundTagAt(i).getTagList("members",  NBT.TAG_ANY_NUMERIC);
		for (int i1 = 0; i < tlo.tagCount(); i++) {
			owners.add(tl.getCompoundTagAt(i).getString("name"));
		}
		for (int i1 = 0; i < tlm.tagCount(); i++) {
			members.add(tl.getCompoundTagAt(i).getString("name"));
		}

		areas.add(new AreaData(name, owners, members, x1, y1, z1, x2, y2, z2));
	}
}

@Override
public void writeToNBT(NBTTagCompound nbt) {
	nbt.setInteger("nextId", nextQuestId);
	NBTTagList tl = new NBTTagList();
	for (int i = 0; i < areas.size(); i++) {
		NBTTagCompound tag = new NBTTagCompound();
		tag.setString("name", this.areas.get(i).name);
		NBTTagList tagLOwner = new NBTTagList();
		NBTTagList tagLMember = new NBTTagList();
		tag.setInteger("pos1X", this.areas.get(i).x1);
		tag.setInteger("pos1Y", this.areas.get(i).y1);
		tag.setInteger("pos1Z", this.areas.get(i).z1);
		tag.setInteger("pos2X", this.areas.get(i).x2);
		tag.setInteger("pos2Y", this.areas.get(i).y2);
		tag.setInteger("pos2Z", this.areas.get(i).z2);
		for (int i1 = 0;
				i1 < this.areas.get(i).owners.size();
				i1++) {
			NBTTagCompound tagO = new NBTTagCompound();
			tagO.setString("name", this.areas.get(i).owners.get(i));
			tagLOwner.appendTag(tagO);
		}
		for (int i1 = 0; i1 < this.areas.get(i).members.size(); i1++) {
			NBTTagCompound tagM = new NBTTagCompound();
			tagM.setString("name", this.areas.get(i).owners.get(i));
			tagLOwner.appendTag(tagM);
		}
		tag.setTag("owners", tagLOwner);
		tag.setTag("members", tagLMember);
		tl.appendTag(tag);
	}
	nbt.setTag("areas", tl);
}

public int registerArea(AreaData area) {
	for (int i = 0; i < areas.size(); i++) {
		if (this.areas.get(i).name == area.name)
		{
			return 1;
		}
	}

	this.areas.add(area);
	this.markDirty();
	return 0;
}

public static AreaWorldData get(World world) {
	AreaWorldData data = (AreaWorldData) world.loadItemData(
			AreaWorldData.class, IDENTIFIER);
	if (data == null) {
		data = new AreaWorldData();
		world.setItemData(IDENTIFIER, data);
	}
	return data;
}

public AreaData getArea(String name) {
	for (int i = 0; i < areas.size(); i++) {
		if (this.areas.get(i).name.compareTo(name) == 0)
		{
			return this.areas.get(i);
		}
	}
	return null;
}

public AreaData getArea(int x, int y, int z) {
	for (int i = 0; i < areas.size(); i++) {
		if (  (((x < this.areas.get(i).x1) && (x > this.areas.get(i).x2)) || ((x > this.areas.get(i).x1) && (x < this.areas.get(i).x2))) 
				&& (((y < this.areas.get(i).y1) && (y > this.areas.get(i).y2)) || ((y > this.areas.get(i).y1) && (y < this.areas.get(i).y2))) 
				&& (((x < this.areas.get(i).z1) && (x > this.areas.get(i).z2)) || ((x > this.areas.get(i).z1) && (x < this.areas.get(i).z2))) )
		{
			return this.areas.get(i);
		}
	}

	return null;
}

}

 

 

I write data with registerArea() method, but getArea() returns null! Help!

I'm Developing Some mods. It's all.

Link to comment
Share on other sites

I use both versions. Class (command) which I use to call it:

 

package com.dcnick.servmod;

import java.util.ArrayList;
import java.util.List;

import scala.actors.threadpool.Arrays;
import net.minecraft.command.ICommand;
import net.minecraft.command.ICommandSender;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.util.ChatComponentText;
import net.minecraft.util.ChunkCoordinates;

public class AreaCommand implements ICommand {

private List<String> aliases;

protected AreaCommand() {
	aliases = new ArrayList<String>();
	aliases.add("area");
	aliases.add("ar");
}

@Override
public int compareTo(Object arg0) {
	return 0;
}

@Override
public String getCommandName() {
	return "area";
}

@Override
public String getCommandUsage(ICommandSender cs) {
	return "Using: /area [create] [name]";
}

@Override
public List getCommandAliases() {
	return aliases;
}

@Override
public void processCommand(ICommandSender cs, String[] arg) {
	EntityPlayer player;

	if (arg.length < 1) {
		cs.addChatMessage(new ChatComponentText("§4Not Enought Arguments§f"));
		return;
	}

	if (cs instanceof EntityPlayer) {
		player = (EntityPlayer) cs;
	} else {
		cs.addChatMessage(new ChatComponentText("§4Player Only Command§f"));
		return;
	}
	if (arg[0].compareTo("create") == 0)
	{
		if (arg.length < 2) {
			cs.addChatMessage(new ChatComponentText(
					"§4Not Enought Arguments§f"));
			return;
		}
		if (player.getEntityData().getBoolean("pos1") && player.getEntityData().getBoolean("pos2"))
		{
			int x1 = player.getEntityData().getInteger("pos1X");
			int y1 = player.getEntityData().getInteger("pos1Y");
			int z1 = player.getEntityData().getInteger("pos1Z");
			int x2 = player.getEntityData().getInteger("pos2X");
			int y2 = player.getEntityData().getInteger("pos2Y");
			int z2 = player.getEntityData().getInteger("pos2Z");
			String name = arg[1];
			cs.addChatMessage(new ChatComponentText(
					"§fCreating Region named '§e" + name
					+ "§f' with Point1 at (§e" + x1 + "§f,§e" + y1
					+ "§f,§e" + z1 + "§f) and Point2 at (§e" + x2
					+ "§f,§e" + y2 + "§f,§e" + z2 + "§f) ..." + "§f"));
			List<String> owners = new ArrayList<String>();
			owners.add(name);
			AreaWorldData.get(cs.getEntityWorld()).registerArea(new AreaData(name, owners , owners, x1, y1, z1, x2, y2, z2));
		}
		else
		{
			cs.addChatMessage(new ChatComponentText(
					"§4Positions not setted! Use /pos command to do this§f"));
			return;
		}
	}
	else
	if (arg[0].compareTo("info") == 0)
	{
		if (arg.length < 2) {
			cs.addChatMessage(new ChatComponentText(
					"§4Not Enought Arguments§f"));
			return;
		}

		ChunkCoordinates cc = cs.getPlayerCoordinates();
		AreaData ad = AreaWorldData.get(cs.getEntityWorld()).getArea(cc.posX, cc.posY, cc.posZ);
		if (ad != null)
			cs.addChatMessage(new ChatComponentText(
					"§fHere is Region Named '§e" + ad.name + "§f'"));
		else
			cs.addChatMessage(new ChatComponentText(
					"§4Here is No Regions §f"));	
		if ((ad = AreaWorldData.get(cs.getEntityWorld()).getArea(arg[1])) != null)
			cs.addChatMessage(new ChatComponentText(
					"§fHere is Region Named '§e" + ad.name + "§f'"));
		else
			cs.addChatMessage(new ChatComponentText(
					"§4Here is No Regions §f"));
	}
	else
	{
		cs.addChatMessage(new ChatComponentText(
				"§4Error at argument 1 it can be: create, remove, info§f"));
		return;
	}
}

@Override
public boolean canCommandSenderUseCommand(ICommandSender cs) {
	return true;
}

@Override
public List addTabCompletionOptions(ICommandSender cs, String[] ar) {
	return null;
}

@Override
public boolean isUsernameIndex(String[] p_82358_1_, int p_82358_2_) {
	return false;
}

}

 

I'm Developing Some mods. It's all.

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

 Share




×
×
  • Create New...

Important Information

By using this site, you agree to our Privacy Policy.