mirror of
https://github.com/allaryin/FairyFactions.git
synced 2026-09-14 21:35:09 -05:00
Rename works, at least locally (#3). Need to verify on server.
This commit is contained in:
@@ -1895,7 +1895,7 @@ public class EntityFairy extends EntityAnimal {
|
||||
}
|
||||
|
||||
public String getActualName(int prefix, int suffix) {
|
||||
final String custom = "";// getCustomName();
|
||||
final String custom = getCustomName();
|
||||
if (custom != null && !custom.isEmpty())
|
||||
return custom;
|
||||
|
||||
|
||||
@@ -20,8 +20,8 @@ public class FairyEventListener {
|
||||
SET_FAIRY_NAME(0, PacketSetFairyName.class);
|
||||
|
||||
public final byte packet_id;
|
||||
protected final Class<?extends IFairyPacket> packet_class;
|
||||
private PacketType(final int id, Class<?extends IFairyPacket> clazz) {
|
||||
protected final Class<?extends FairyPacket> packet_class;
|
||||
private PacketType(final int id, Class<?extends FairyPacket> clazz) {
|
||||
packet_id = (byte)id;
|
||||
packet_class = clazz;
|
||||
}
|
||||
@@ -38,11 +38,6 @@ public class FairyEventListener {
|
||||
}
|
||||
}
|
||||
|
||||
public interface IFairyPacket {
|
||||
public void init(PacketBuffer buf);
|
||||
public void handle(NetworkManager networkManager);
|
||||
}
|
||||
|
||||
@SubscribeEvent
|
||||
public void onPacket(ServerCustomPacketEvent event) {
|
||||
if( event.packet.channel().equals(Version.CHANNEL) ) {
|
||||
@@ -63,7 +58,7 @@ public class FairyEventListener {
|
||||
return;
|
||||
}
|
||||
|
||||
final IFairyPacket packet;
|
||||
final FairyPacket packet;
|
||||
try {
|
||||
packet = type.packet_class.newInstance();
|
||||
} catch (Exception e) {
|
||||
|
||||
24
src/main/java/fairies/event/FairyPacket.java
Normal file
24
src/main/java/fairies/event/FairyPacket.java
Normal file
@@ -0,0 +1,24 @@
|
||||
package fairies.event;
|
||||
|
||||
import cpw.mods.fml.common.network.internal.FMLProxyPacket;
|
||||
import fairies.Version;
|
||||
import fairies.event.FairyEventListener.PacketType;
|
||||
import io.netty.buffer.ByteBuf;
|
||||
import io.netty.buffer.Unpooled;
|
||||
import net.minecraft.network.NetworkManager;
|
||||
import net.minecraft.network.PacketBuffer;
|
||||
|
||||
public abstract class FairyPacket extends FMLProxyPacket {
|
||||
|
||||
protected FairyPacket(PacketType packetType) {
|
||||
super( new PacketBuffer(Unpooled.buffer()), Version.CHANNEL );
|
||||
|
||||
final PacketBuffer buf = (PacketBuffer)this.payload();
|
||||
buf.writeByte(packetType.packet_id);
|
||||
}
|
||||
|
||||
protected abstract void pack();
|
||||
public abstract void init(PacketBuffer buf);
|
||||
public abstract void handle(NetworkManager networkManager);
|
||||
|
||||
}
|
||||
@@ -5,13 +5,13 @@ import java.io.IOException;
|
||||
import cpw.mods.fml.common.network.internal.FMLProxyPacket;
|
||||
import fairies.FairyFactions;
|
||||
import fairies.entity.EntityFairy;
|
||||
import fairies.event.FairyEventListener.IFairyPacket;
|
||||
import io.netty.buffer.Unpooled;
|
||||
import net.minecraft.entity.player.EntityPlayerMP;
|
||||
import net.minecraft.network.NetHandlerPlayServer;
|
||||
import net.minecraft.network.NetworkManager;
|
||||
import net.minecraft.network.PacketBuffer;
|
||||
|
||||
public class PacketSetFairyName implements IFairyPacket {
|
||||
public class PacketSetFairyName extends FairyPacket {
|
||||
|
||||
public static final int MIN_NAME_LENGTH = 3;
|
||||
public static final int MAX_NAME_LENGTH = 16;
|
||||
@@ -20,8 +20,22 @@ public class PacketSetFairyName implements IFairyPacket {
|
||||
private String name;
|
||||
|
||||
public PacketSetFairyName(final EntityFairy fairy, final String name) {
|
||||
super(FairyEventListener.PacketType.SET_FAIRY_NAME);
|
||||
this.fairyID = fairy.getEntityId();
|
||||
this.name = name;
|
||||
pack();
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void pack() {
|
||||
final PacketBuffer buf = (PacketBuffer)this.payload();
|
||||
buf.writeInt(this.fairyID);
|
||||
try {
|
||||
buf.writeStringToBuffer(this.name);
|
||||
} catch (IOException e) {
|
||||
// TODO Auto-generated catch block
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -97,7 +97,7 @@ public class CommonProxy {
|
||||
|
||||
public void sendFairyRename(final EntityFairy fairy, final String name) {
|
||||
final PacketSetFairyName packet = new PacketSetFairyName( fairy, name );
|
||||
//sendToServer( packet );
|
||||
sendToServer( packet );
|
||||
}
|
||||
|
||||
// Packet that handles fairy mounting.
|
||||
|
||||
Reference in New Issue
Block a user