Jump to content

[1.7.10] Server mod Questions


DCNick3

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

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

Ow, I have other questions now:

[*]

  I need this server Side Events:

 

  [*]Event, when player breaks block

  [*]Event, when player places block

  [*]Event, when player uses block

  [*]Event, when player places minecart

  [*]Event, when player fires TNT (with acces to activatedTNT entity)

 

 

[*]Where I can find server Events?

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
Unfortunately, your content contains terms that we do not allow. Please edit your content to remove the highlighted words below.
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.

Announcements



  • Recently Browsing

    • No registered users viewing this page.
  • Posts

    • They were already updated, and just to double check I even did a cleanup and fresh update from that same page. I'm quite sure drivers are not the problem here. 
    • i tried downloading the drivers but it says no AMD graphics hardware has been detected    
    • Update your AMD/ATI drivers - get the drivers from their website - do not update via system  
    • As the title says i keep on crashing on forge 1.20.1 even without any mods downloaded, i have the latest drivers (nvidia) and vanilla minecraft works perfectly fine for me logs: https://pastebin.com/5UR01yG9
    • Hello everyone, I'm making this post to seek help for my modded block, It's a special block called FrozenBlock supposed to take the place of an old block, then after a set amount of ticks, it's supposed to revert its Block State, Entity, data... to the old block like this :  The problem I have is that the system breaks when handling multi blocks (I tried some fix but none of them worked) :  The bug I have identified is that the function "setOldBlockFields" in the item's "setFrozenBlock" function gets called once for the 1st block of multiblock getting frozen (as it should), but gets called a second time BEFORE creating the first FrozenBlock with the data of the 1st block, hence giving the same data to the two FrozenBlock :   Old Block Fields set BlockState : Block{minecraft:black_bed}[facing=east,occupied=false,part=head] BlockEntity : net.minecraft.world.level.block.entity.BedBlockEntity@73681674 BlockEntityData : id:"minecraft:bed",x:3,y:-60,z:-6} Old Block Fields set BlockState : Block{minecraft:black_bed}[facing=east,occupied=false,part=foot] BlockEntity : net.minecraft.world.level.block.entity.BedBlockEntity@6d1aa3da BlockEntityData : {id:"minecraft:bed",x:2,y:-60,z:-6} Frozen Block Entity set BlockState : Block{minecraft:black_bed}[facing=east,occupied=false,part=foot] BlockPos{x=3, y=-60, z=-6} BlockEntity : net.minecraft.world.level.block.entity.BedBlockEntity@6d1aa3da BlockEntityData : {id:"minecraft:bed",x:2,y:-60,z:-6} Frozen Block Entity set BlockState : Block{minecraft:black_bed}[facing=east,occupied=false,part=foot] BlockPos{x=2, y=-60, z=-6} BlockEntity : net.minecraft.world.level.block.entity.BedBlockEntity@6d1aa3da BlockEntityData : {id:"minecraft:bed",x:2,y:-60,z:-6} here is the code inside my custom "freeze" item :    @Override     public @NotNull InteractionResult useOn(@NotNull UseOnContext pContext) {         if (!pContext.getLevel().isClientSide() && pContext.getHand() == InteractionHand.MAIN_HAND) {             BlockPos blockPos = pContext.getClickedPos();             BlockPos secondBlockPos = getMultiblockPos(blockPos, pContext.getLevel().getBlockState(blockPos));             if (secondBlockPos != null) {                 createFrozenBlock(pContext, secondBlockPos);             }             createFrozenBlock(pContext, blockPos);             return InteractionResult.SUCCESS;         }         return super.useOn(pContext);     }     public static void createFrozenBlock(UseOnContext pContext, BlockPos blockPos) {         BlockState oldState = pContext.getLevel().getBlockState(blockPos);         BlockEntity oldBlockEntity = oldState.hasBlockEntity() ? pContext.getLevel().getBlockEntity(blockPos) : null;         CompoundTag oldBlockEntityData = oldState.hasBlockEntity() ? oldBlockEntity.serializeNBT() : null;         if (oldBlockEntity != null) {             pContext.getLevel().removeBlockEntity(blockPos);         }         BlockState FrozenBlock = setFrozenBlock(oldState, oldBlockEntity, oldBlockEntityData);         pContext.getLevel().setBlockAndUpdate(blockPos, FrozenBlock);     }     public static BlockState setFrozenBlock(BlockState blockState, @Nullable BlockEntity blockEntity, @Nullable CompoundTag blockEntityData) {         BlockState FrozenBlock = BlockRegister.FROZEN_BLOCK.get().defaultBlockState();         ((FrozenBlock) FrozenBlock.getBlock()).setOldBlockFields(blockState, blockEntity, blockEntityData);         return FrozenBlock;     }  
  • Topics

×
×
  • Create New...

Important Information

By using this site, you agree to our Terms of Use.