Initial commit
This commit is contained in:
@@ -0,0 +1,70 @@
|
||||
package electroblob.wizardry.packet;
|
||||
|
||||
import electroblob.wizardry.Wizardry;
|
||||
import electroblob.wizardry.packet.PacketCastContinuousSpell.Message;
|
||||
import electroblob.wizardry.util.SpellModifiers;
|
||||
import io.netty.buffer.ByteBuf;
|
||||
import net.minecraftforge.fml.common.network.simpleimpl.IMessage;
|
||||
import net.minecraftforge.fml.common.network.simpleimpl.IMessageHandler;
|
||||
import net.minecraftforge.fml.common.network.simpleimpl.MessageContext;
|
||||
|
||||
/** <b>[Server -> Client]</b> This packet is sent when the /cast command is used with a continuous spell, in order to
|
||||
* sync the relevant variables in {@link electroblob.wizardry.WizardData WizardData}. */
|
||||
public class PacketCastContinuousSpell implements IMessageHandler<Message, IMessage> {
|
||||
|
||||
@Override
|
||||
public IMessage onMessage(Message message, MessageContext ctx){
|
||||
|
||||
// Just to make sure that the side is correct
|
||||
if(ctx.side.isClient()){
|
||||
// Using a fully qualified name is a good course of action here; we don't really want to clutter the proxy
|
||||
// methods any more than necessary.
|
||||
net.minecraft.client.Minecraft.getMinecraft().addScheduledTask(new Runnable(){
|
||||
@Override
|
||||
public void run() {
|
||||
Wizardry.proxy.handleCastContinuousSpellPacket(message);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
public static class Message implements IMessage {
|
||||
|
||||
// Note that range and blast multipliers are the only two that affect particle spawning, so they are the
|
||||
// only two that need to be sent.
|
||||
|
||||
/** EntityID of the caster */
|
||||
public int casterID;
|
||||
/** ID of the spell being cast */
|
||||
public int spellID;
|
||||
/** SpellModifiers for the spell */
|
||||
public SpellModifiers modifiers;
|
||||
|
||||
// This constructor is required otherwise you'll get errors (used somewhere in fml through reflection)
|
||||
public Message(){}
|
||||
|
||||
public Message(int casterID, int spellID, SpellModifiers modifiers){
|
||||
this.casterID = casterID;
|
||||
this.spellID = spellID;
|
||||
this.modifiers = modifiers;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void fromBytes(ByteBuf buf){
|
||||
// The order is important
|
||||
this.casterID = buf.readInt();
|
||||
this.spellID = buf.readInt();
|
||||
this.modifiers = new SpellModifiers();
|
||||
modifiers.read(buf);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void toBytes(ByteBuf buf){
|
||||
buf.writeInt(casterID);
|
||||
buf.writeInt(spellID);
|
||||
this.modifiers.write(buf);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,80 @@
|
||||
package electroblob.wizardry.packet;
|
||||
|
||||
import electroblob.wizardry.Wizardry;
|
||||
import electroblob.wizardry.packet.PacketCastSpell.Message;
|
||||
import electroblob.wizardry.util.SpellModifiers;
|
||||
import io.netty.buffer.ByteBuf;
|
||||
import net.minecraft.item.Item;
|
||||
import net.minecraft.util.EnumHand;
|
||||
import net.minecraftforge.fml.common.network.simpleimpl.IMessage;
|
||||
import net.minecraftforge.fml.common.network.simpleimpl.IMessageHandler;
|
||||
import net.minecraftforge.fml.common.network.simpleimpl.MessageContext;
|
||||
|
||||
/** <b>[Server -> Client]</b> This packet is sent when a spell is cast by a player and returns true, and is sent to other
|
||||
* clients so they can spawn the particles themselves. What sending this packet effectively does is make the
|
||||
* {@link Item#onItemRightClick} method client-consistent just for the item that sends it. Interestingly,
|
||||
* {@link Item#onUsingTick} is client-consistent already, so continuous spells don't need to send packets from there
|
||||
* (this is probably something to do with eating particles or usage actions). */
|
||||
public class PacketCastSpell implements IMessageHandler<Message, IMessage> {
|
||||
|
||||
@Override
|
||||
public IMessage onMessage(Message message, MessageContext ctx){
|
||||
|
||||
// Just to make sure that the side is correct
|
||||
if(ctx.side.isClient()){
|
||||
// Using a fully qualified name is a good course of action here; we don't really want to clutter the proxy
|
||||
// methods any more than necessary.
|
||||
net.minecraft.client.Minecraft.getMinecraft().addScheduledTask(new Runnable(){
|
||||
@Override
|
||||
public void run(){
|
||||
Wizardry.proxy.handleCastSpellPacket(message);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
public static class Message implements IMessage {
|
||||
|
||||
/** EntityID of the caster */
|
||||
public int casterID;
|
||||
/** ID of the spell being cast */
|
||||
public int spellID;
|
||||
/** SpellModifiers for the spell */
|
||||
public SpellModifiers modifiers;
|
||||
/** The hand that is holding the itemstack used to cast the spell. Defaults to MAIN_HAND. */
|
||||
public EnumHand hand;
|
||||
|
||||
// This constructor is required otherwise you'll get errors (used somewhere in fml through reflection)
|
||||
public Message(){}
|
||||
|
||||
public Message(int casterID, EnumHand hand, int spellID, SpellModifiers modifiers){
|
||||
|
||||
this.casterID = casterID;
|
||||
this.spellID = spellID;
|
||||
this.modifiers = modifiers;
|
||||
this.hand = hand == null ? EnumHand.MAIN_HAND : hand;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void fromBytes(ByteBuf buf){
|
||||
|
||||
// The order is important
|
||||
this.casterID = buf.readInt();
|
||||
this.spellID = buf.readInt();
|
||||
this.modifiers = new SpellModifiers();
|
||||
this.modifiers.read(buf);
|
||||
this.hand = buf.readBoolean() ? EnumHand.OFF_HAND : EnumHand.MAIN_HAND;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void toBytes(ByteBuf buf){
|
||||
|
||||
buf.writeInt(casterID);
|
||||
buf.writeInt(spellID);
|
||||
this.modifiers.write(buf);
|
||||
buf.writeBoolean(this.hand == EnumHand.OFF_HAND);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,81 @@
|
||||
package electroblob.wizardry.packet;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
import electroblob.wizardry.Wizardry;
|
||||
import electroblob.wizardry.packet.PacketClairvoyance.Message;
|
||||
import io.netty.buffer.ByteBuf;
|
||||
import net.minecraft.pathfinding.Path;
|
||||
import net.minecraft.pathfinding.PathPoint;
|
||||
import net.minecraftforge.fml.common.network.simpleimpl.IMessage;
|
||||
import net.minecraftforge.fml.common.network.simpleimpl.IMessageHandler;
|
||||
import net.minecraftforge.fml.common.network.simpleimpl.MessageContext;
|
||||
|
||||
/** <b>[Server -> Client]</b> This packet is sent when a player casts the clairvoyance spell to allow pathing to chunks
|
||||
* outside the render distance. */
|
||||
public class PacketClairvoyance implements IMessageHandler<Message, IMessage> {
|
||||
|
||||
@Override
|
||||
public IMessage onMessage(Message message, MessageContext ctx)
|
||||
{
|
||||
// Just to make sure that the side is correct
|
||||
if(ctx.side.isClient()){
|
||||
// Using a fully qualified name is a good course of action here; we don't really want to clutter the proxy
|
||||
// methods any more than necessary.
|
||||
net.minecraft.client.Minecraft.getMinecraft().addScheduledTask(new Runnable(){
|
||||
@Override
|
||||
public void run(){
|
||||
Wizardry.proxy.handleClairvoyancePacket(message);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
public static class Message implements IMessage {
|
||||
|
||||
public Path path;
|
||||
public float durationMultiplier;
|
||||
|
||||
// This constructor is required otherwise you'll get errors (used somewhere in fml through reflection)
|
||||
public Message() {}
|
||||
|
||||
public Message(Path path, float durationMultiplier){
|
||||
|
||||
this.path = path;
|
||||
this.durationMultiplier = durationMultiplier;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void fromBytes(ByteBuf buf){
|
||||
|
||||
// The order is important
|
||||
this.durationMultiplier = buf.readFloat();
|
||||
|
||||
List<PathPoint> points = new ArrayList<PathPoint>();
|
||||
|
||||
while(buf.isReadable()){
|
||||
points.add(new PathPoint(buf.readInt(), buf.readInt(), buf.readInt()));
|
||||
}
|
||||
|
||||
this.path = new Path(points.toArray(new PathPoint[0]));
|
||||
}
|
||||
|
||||
@Override
|
||||
public void toBytes(ByteBuf buf){
|
||||
|
||||
buf.writeFloat(durationMultiplier);
|
||||
|
||||
for(int i=0; i<path.getCurrentPathLength(); i++){
|
||||
|
||||
PathPoint point = path.getPathPointFromIndex(i);
|
||||
|
||||
buf.writeInt(point.xCoord);
|
||||
buf.writeInt(point.yCoord);
|
||||
buf.writeInt(point.zCoord);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,102 @@
|
||||
package electroblob.wizardry.packet;
|
||||
|
||||
import electroblob.wizardry.item.ItemWand;
|
||||
import electroblob.wizardry.packet.PacketControlInput.Message;
|
||||
import electroblob.wizardry.tileentity.ContainerArcaneWorkbench;
|
||||
import electroblob.wizardry.tileentity.TileEntityArcaneWorkbench;
|
||||
import electroblob.wizardry.util.WandHelper;
|
||||
import io.netty.buffer.ByteBuf;
|
||||
import net.minecraft.entity.player.EntityPlayerMP;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraftforge.fml.common.network.simpleimpl.IMessage;
|
||||
import net.minecraftforge.fml.common.network.simpleimpl.IMessageHandler;
|
||||
import net.minecraftforge.fml.common.network.simpleimpl.MessageContext;
|
||||
|
||||
/** <b>[Client -> Server]</b> This packet is for control events such as buttons in GUIs and key presses. */
|
||||
public class PacketControlInput implements IMessageHandler<Message, IMessage> {
|
||||
|
||||
@Override
|
||||
public IMessage onMessage(Message message, MessageContext ctx){
|
||||
|
||||
// Just to make sure that the side is correct
|
||||
if(ctx.side.isServer()){
|
||||
|
||||
final EntityPlayerMP player = ctx.getServerHandler().playerEntity;
|
||||
|
||||
player.getServerWorld().addScheduledTask(new Runnable(){
|
||||
|
||||
public void run() {
|
||||
|
||||
ItemStack wand = player.getHeldItemMainhand();
|
||||
|
||||
if(wand == null || !(wand.getItem() instanceof ItemWand)){
|
||||
wand = player.getHeldItemOffhand();
|
||||
}
|
||||
|
||||
switch(message.controlType){
|
||||
|
||||
case APPLY_BUTTON:
|
||||
|
||||
TileEntityArcaneWorkbench tileentity = ((ContainerArcaneWorkbench)player.openContainer).tileEntityArcaneWorkbench;
|
||||
tileentity.onApplyButtonPressed(player);
|
||||
break;
|
||||
|
||||
case NEXT_SPELL_KEY:
|
||||
|
||||
if(wand != null && wand.getItem() instanceof ItemWand){
|
||||
|
||||
WandHelper.selectNextSpell(wand);
|
||||
// This line fixes the bug with continuous spells casting when they shouldn't be
|
||||
player.stopActiveHand();
|
||||
}
|
||||
|
||||
break;
|
||||
|
||||
case PREVIOUS_SPELL_KEY:
|
||||
|
||||
if(wand != null && wand.getItem() instanceof ItemWand){
|
||||
|
||||
WandHelper.selectPreviousSpell(wand);
|
||||
// This line fixes the bug with continuous spells casting when they shouldn't be
|
||||
player.stopActiveHand();
|
||||
}
|
||||
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
);
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
public static enum ControlType {
|
||||
APPLY_BUTTON,
|
||||
NEXT_SPELL_KEY,
|
||||
PREVIOUS_SPELL_KEY;
|
||||
}
|
||||
|
||||
public static class Message implements IMessage {
|
||||
|
||||
private ControlType controlType;
|
||||
|
||||
// This constructor is required otherwise you'll get errors (used somewhere in fml through reflection)
|
||||
public Message() {}
|
||||
|
||||
public Message(ControlType type){
|
||||
this.controlType = type;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void fromBytes(ByteBuf buf){
|
||||
// The order is important
|
||||
this.controlType = ControlType.values()[buf.readInt()];
|
||||
}
|
||||
|
||||
@Override
|
||||
public void toBytes(ByteBuf buf){
|
||||
buf.writeInt(controlType.ordinal());
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,70 @@
|
||||
package electroblob.wizardry.packet;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
import electroblob.wizardry.Wizardry;
|
||||
import electroblob.wizardry.packet.PacketGlyphData.Message;
|
||||
import io.netty.buffer.ByteBuf;
|
||||
import net.minecraftforge.fml.common.network.ByteBufUtils;
|
||||
import net.minecraftforge.fml.common.network.simpleimpl.IMessage;
|
||||
import net.minecraftforge.fml.common.network.simpleimpl.IMessageHandler;
|
||||
import net.minecraftforge.fml.common.network.simpleimpl.MessageContext;
|
||||
|
||||
/** <b>[Server -> Client]</b> This packet is sent each time a player joins a world to synchronise the client-side spell
|
||||
* glyph names with the server-side ones. */
|
||||
public class PacketGlyphData implements IMessageHandler<Message, IMessage> {
|
||||
|
||||
@Override
|
||||
public IMessage onMessage(Message message, MessageContext ctx)
|
||||
{
|
||||
// Just to make sure that the side is correct
|
||||
if(ctx.side.isClient()){
|
||||
// Using a fully qualified name is a good course of action here; we don't really want to clutter the proxy
|
||||
// methods any more than necessary.
|
||||
net.minecraft.client.Minecraft.getMinecraft().addScheduledTask(new Runnable(){
|
||||
@Override
|
||||
public void run(){
|
||||
Wizardry.proxy.handleGlyphDataPacket(message);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
public static class Message implements IMessage {
|
||||
|
||||
/** The list of randomised spell names. */
|
||||
public List<String> names;
|
||||
/** The list of randomised spell descriptions. */
|
||||
public List<String> descriptions;
|
||||
|
||||
// This constructor is required otherwise you'll get errors (used somewhere in fml through reflection)
|
||||
public Message() {}
|
||||
|
||||
public Message(List<String> names, List<String> descriptions)
|
||||
{
|
||||
this.names = names;
|
||||
this.descriptions = descriptions;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void fromBytes(ByteBuf buf){
|
||||
names = new ArrayList<String>();
|
||||
descriptions = new ArrayList<String>();
|
||||
while(buf.isReadable()){
|
||||
names.add(ByteBufUtils.readUTF8String(buf));
|
||||
descriptions.add(ByteBufUtils.readUTF8String(buf));
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void toBytes(ByteBuf buf){
|
||||
for(int i=0; i<names.size(); i++){
|
||||
ByteBufUtils.writeUTF8String(buf, names.get(i) == null ? "error" : names.get(i));
|
||||
ByteBufUtils.writeUTF8String(buf, descriptions.get(i) == null ? "error" : descriptions.get(i));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,80 @@
|
||||
package electroblob.wizardry.packet;
|
||||
|
||||
import electroblob.wizardry.Wizardry;
|
||||
import electroblob.wizardry.entity.living.ISpellCaster;
|
||||
import electroblob.wizardry.packet.PacketNPCCastSpell.Message;
|
||||
import electroblob.wizardry.util.SpellModifiers;
|
||||
import io.netty.buffer.ByteBuf;
|
||||
import net.minecraft.util.EnumHand;
|
||||
import net.minecraftforge.fml.common.network.simpleimpl.IMessage;
|
||||
import net.minecraftforge.fml.common.network.simpleimpl.IMessageHandler;
|
||||
import net.minecraftforge.fml.common.network.simpleimpl.MessageContext;
|
||||
|
||||
/** <b>[Server -> Client]</b> This packet is sent when an {@link ISpellCaster} casts a spell which returns true, and is
|
||||
* sent to clients so they can spawn the particles. Unlike the player packets, this is for both continuous <b>and</b>
|
||||
* non-continuous spells. */
|
||||
public class PacketNPCCastSpell implements IMessageHandler<Message, IMessage> {
|
||||
|
||||
@Override
|
||||
public IMessage onMessage(Message message, MessageContext ctx){
|
||||
|
||||
// Just to make sure that the side is correct
|
||||
if(ctx.side.isClient()){
|
||||
// Using a fully qualified name is a good course of action here; we don't really want to clutter the proxy
|
||||
// methods any more than necessary.
|
||||
net.minecraft.client.Minecraft.getMinecraft().addScheduledTask(new Runnable(){
|
||||
@Override
|
||||
public void run(){
|
||||
Wizardry.proxy.handleNPCCastSpellPacket(message);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
public static class Message implements IMessage {
|
||||
|
||||
/** EntityID of the caster */
|
||||
public int casterID;
|
||||
/** EntityID of the target, or -1 if there is none */
|
||||
public int targetID;
|
||||
/** ID of the spell being cast */
|
||||
public int spellID;
|
||||
/** SpellModifiers for the spell */
|
||||
public SpellModifiers modifiers;
|
||||
/** The hand that is holding the itemstack used to cast the spell. Defaults to MAIN_HAND. */
|
||||
public EnumHand hand;
|
||||
|
||||
// This constructor is required otherwise you'll get errors (used somewhere in fml through reflection)
|
||||
public Message(){}
|
||||
|
||||
public Message(int casterID, int targetID, EnumHand hand, int spellID, SpellModifiers modifiers){
|
||||
this.casterID = casterID;
|
||||
this.targetID = targetID;
|
||||
this.spellID = spellID;
|
||||
this.modifiers = modifiers;
|
||||
this.hand = hand == null ? EnumHand.MAIN_HAND : hand;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void fromBytes(ByteBuf buf){
|
||||
// The order is important
|
||||
this.casterID = buf.readInt();
|
||||
this.targetID = buf.readInt();
|
||||
this.spellID = buf.readInt();
|
||||
this.modifiers = new SpellModifiers();
|
||||
this.modifiers.read(buf);
|
||||
this.hand = buf.readBoolean() ? EnumHand.OFF_HAND : EnumHand.MAIN_HAND;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void toBytes(ByteBuf buf){
|
||||
buf.writeInt(casterID);
|
||||
buf.writeInt(targetID);
|
||||
buf.writeInt(spellID);
|
||||
this.modifiers.write(buf);
|
||||
buf.writeBoolean(this.hand == EnumHand.OFF_HAND);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,71 @@
|
||||
package electroblob.wizardry.packet;
|
||||
|
||||
import java.util.HashSet;
|
||||
import java.util.Set;
|
||||
|
||||
import electroblob.wizardry.Wizardry;
|
||||
import electroblob.wizardry.packet.PacketPlayerSync.Message;
|
||||
import electroblob.wizardry.spell.Spell;
|
||||
import io.netty.buffer.ByteBuf;
|
||||
import net.minecraftforge.fml.common.network.simpleimpl.IMessage;
|
||||
import net.minecraftforge.fml.common.network.simpleimpl.IMessageHandler;
|
||||
import net.minecraftforge.fml.common.network.simpleimpl.MessageContext;
|
||||
|
||||
/** <b>[Server -> Client]</b> This packet is sent to synchronise any fields that need synchronising in
|
||||
* {@link electroblob.wizardry.WizardData WizardData}. This packet is not sent often enough and is too small to warrant
|
||||
* having separate packets for each field that needs synchronising. */
|
||||
public class PacketPlayerSync implements IMessageHandler<Message, IMessage> {
|
||||
|
||||
@Override
|
||||
public IMessage onMessage(Message message, MessageContext ctx)
|
||||
{
|
||||
// Just to make sure that the side is correct
|
||||
if(ctx.side.isClient()){
|
||||
// Using a fully qualified name is a good course of action here; we don't really want to clutter the proxy
|
||||
// methods any more than necessary.
|
||||
net.minecraft.client.Minecraft.getMinecraft().addScheduledTask(new Runnable(){
|
||||
@Override
|
||||
public void run(){
|
||||
Wizardry.proxy.handlePlayerSyncPacket(message);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
public static class Message implements IMessage {
|
||||
|
||||
public Set<Spell> spellsDiscovered;
|
||||
public int selectedMinionID;
|
||||
|
||||
// This constructor is required otherwise you'll get errors (used somewhere in fml through reflection)
|
||||
public Message() {}
|
||||
|
||||
public Message(Set<Spell> spellsDiscovered2, int selectedMinionID){
|
||||
this.spellsDiscovered = spellsDiscovered2;
|
||||
this.selectedMinionID = selectedMinionID;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void fromBytes(ByteBuf buf){
|
||||
this.selectedMinionID = buf.readInt();
|
||||
this.spellsDiscovered = new HashSet<Spell>();
|
||||
while(buf.isReadable()){
|
||||
this.spellsDiscovered.add(Spell.get(buf.readInt()));
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void toBytes(ByteBuf buf){
|
||||
|
||||
buf.writeInt(selectedMinionID);
|
||||
|
||||
if(this.spellsDiscovered == null) return;
|
||||
|
||||
for(Spell spell : this.spellsDiscovered){
|
||||
buf.writeInt(spell.id());
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,90 @@
|
||||
package electroblob.wizardry.packet;
|
||||
|
||||
import electroblob.wizardry.Settings;
|
||||
import electroblob.wizardry.Wizardry;
|
||||
import electroblob.wizardry.packet.PacketSyncSettings.Message;
|
||||
import io.netty.buffer.ByteBuf;
|
||||
import net.minecraftforge.fml.common.network.simpleimpl.IMessage;
|
||||
import net.minecraftforge.fml.common.network.simpleimpl.IMessageHandler;
|
||||
import net.minecraftforge.fml.common.network.simpleimpl.MessageContext;
|
||||
|
||||
/** <b>[Server -> Client]</b> This packet is sent to synchronise the config settings with clients on player login.
|
||||
* @see Settings */
|
||||
public class PacketSyncSettings implements IMessageHandler<Message, IMessage> {
|
||||
|
||||
@Override
|
||||
public IMessage onMessage(Message message, MessageContext ctx){
|
||||
|
||||
if(ctx.side.isClient()){
|
||||
// Using a fully qualified name is a good course of action here; we don't really want to clutter the proxy
|
||||
// any more than necessary.
|
||||
net.minecraft.client.Minecraft.getMinecraft().addScheduledTask(new Runnable(){
|
||||
@Override
|
||||
public void run(){
|
||||
copySettings(message);
|
||||
}
|
||||
});
|
||||
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
private static void copySettings(Message message){
|
||||
Wizardry.settings.firebombIsCraftable = message.settings.firebombIsCraftable;
|
||||
Wizardry.settings.poisonBombIsCraftable = message.settings.poisonBombIsCraftable;
|
||||
Wizardry.settings.smokeBombIsCraftable = message.settings.smokeBombIsCraftable;
|
||||
Wizardry.settings.useAlternateScrollRecipe = message.settings.useAlternateScrollRecipe;
|
||||
Wizardry.settings.discoveryMode = message.settings.discoveryMode;
|
||||
// Wizardry.settings.maxSpellCommandMultiplier = message.settings.maxSpellCommandMultiplier;
|
||||
// Wizardry.settings.castCommandName = message.settings.castCommandName;
|
||||
// Wizardry.settings.discoverspellCommandName = message.settings.discoverspellCommandName;
|
||||
// Wizardry.settings.allyCommandName = message.settings.allyCommandName;
|
||||
// Wizardry.settings.alliesCommandName = message.settings.alliesCommandName;
|
||||
}
|
||||
|
||||
public static class Message implements IMessage {
|
||||
|
||||
/** EntityID of the caster */
|
||||
public Settings settings;
|
||||
|
||||
// This constructor is required otherwise you'll get errors (used somewhere in fml through reflection)
|
||||
public Message(){}
|
||||
|
||||
public Message(Settings settings){
|
||||
this.settings = settings;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void fromBytes(ByteBuf buf){
|
||||
// I'm guessing the settings field will be null here, so it needs initialising.
|
||||
// This is also a great reason to have the settings as an actual object.
|
||||
settings = new Settings();
|
||||
// The order is important
|
||||
settings.firebombIsCraftable = buf.readBoolean();
|
||||
settings.poisonBombIsCraftable = buf.readBoolean();
|
||||
settings.smokeBombIsCraftable = buf.readBoolean();
|
||||
settings.useAlternateScrollRecipe = buf.readBoolean();
|
||||
settings.discoveryMode = buf.readBoolean();
|
||||
// settings.maxSpellCommandMultiplier = buf.readDouble();
|
||||
// settings.castCommandName = ByteBufUtils.readUTF8String(buf);
|
||||
// settings.discoverspellCommandName = ByteBufUtils.readUTF8String(buf);
|
||||
// settings.allyCommandName = ByteBufUtils.readUTF8String(buf);
|
||||
// settings.alliesCommandName = ByteBufUtils.readUTF8String(buf);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void toBytes(ByteBuf buf){
|
||||
buf.writeBoolean(settings.firebombIsCraftable);
|
||||
buf.writeBoolean(settings.poisonBombIsCraftable);
|
||||
buf.writeBoolean(settings.smokeBombIsCraftable);
|
||||
buf.writeBoolean(settings.useAlternateScrollRecipe);
|
||||
buf.writeBoolean(settings.discoveryMode);
|
||||
// buf.writeDouble(settings.maxSpellCommandMultiplier);
|
||||
// ByteBufUtils.writeUTF8String(buf, settings.castCommandName);
|
||||
// ByteBufUtils.writeUTF8String(buf, settings.discoverspellCommandName);
|
||||
// ByteBufUtils.writeUTF8String(buf, settings.allyCommandName);
|
||||
// ByteBufUtils.writeUTF8String(buf, settings.alliesCommandName);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,58 @@
|
||||
package electroblob.wizardry.packet;
|
||||
|
||||
import electroblob.wizardry.Wizardry;
|
||||
import electroblob.wizardry.packet.PacketTransportation.Message;
|
||||
import io.netty.buffer.ByteBuf;
|
||||
import net.minecraftforge.fml.common.network.simpleimpl.IMessage;
|
||||
import net.minecraftforge.fml.common.network.simpleimpl.IMessageHandler;
|
||||
import net.minecraftforge.fml.common.network.simpleimpl.MessageContext;
|
||||
|
||||
/** <b>[Server -> Client]</b> This packet is sent when a player is teleported due to the transportation spell to spawn
|
||||
* the particles. */
|
||||
public class PacketTransportation implements IMessageHandler<Message, IMessage> {
|
||||
|
||||
@Override
|
||||
public IMessage onMessage(Message message, MessageContext ctx)
|
||||
{
|
||||
// Just to make sure that the side is correct
|
||||
if(ctx.side.isClient()){
|
||||
// Using a fully qualified name is a good course of action here; we don't really want to clutter the proxy
|
||||
// methods any more than necessary.
|
||||
net.minecraft.client.Minecraft.getMinecraft().addScheduledTask(new Runnable(){
|
||||
@Override
|
||||
public void run(){
|
||||
Wizardry.proxy.handleTransportationPacket(message);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
public static class Message implements IMessage
|
||||
{
|
||||
/** EntityID of the caster */
|
||||
public int casterID;
|
||||
|
||||
// This constructor is required otherwise you'll get errors (used somewhere in fml through reflection)
|
||||
public Message() {}
|
||||
|
||||
public Message(int casterID)
|
||||
{
|
||||
this.casterID = casterID;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void fromBytes(ByteBuf buf)
|
||||
{
|
||||
// The order is important
|
||||
this.casterID = buf.readInt();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void toBytes(ByteBuf buf)
|
||||
{
|
||||
buf.writeInt(casterID);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,36 @@
|
||||
package electroblob.wizardry.packet;
|
||||
|
||||
import electroblob.wizardry.Wizardry;
|
||||
import net.minecraftforge.fml.common.network.NetworkRegistry;
|
||||
import net.minecraftforge.fml.common.network.simpleimpl.IMessage;
|
||||
import net.minecraftforge.fml.common.network.simpleimpl.IMessageHandler;
|
||||
import net.minecraftforge.fml.common.network.simpleimpl.SimpleNetworkWrapper;
|
||||
import net.minecraftforge.fml.relauncher.Side;
|
||||
|
||||
public class WizardryPacketHandler {
|
||||
|
||||
public static SimpleNetworkWrapper net;
|
||||
|
||||
public static void initPackets()
|
||||
{
|
||||
net = NetworkRegistry.INSTANCE.newSimpleChannel(Wizardry.MODID.toUpperCase());
|
||||
registerMessage(PacketControlInput.class, PacketControlInput.Message.class);
|
||||
registerMessage(PacketCastSpell.class, PacketCastSpell.Message.class);
|
||||
registerMessage(PacketTransportation.class, PacketTransportation.Message.class);
|
||||
registerMessage(PacketPlayerSync.class, PacketPlayerSync.Message.class);
|
||||
registerMessage(PacketGlyphData.class, PacketGlyphData.Message.class);
|
||||
registerMessage(PacketCastContinuousSpell.class, PacketCastContinuousSpell.Message.class);
|
||||
registerMessage(PacketClairvoyance.class, PacketClairvoyance.Message.class);
|
||||
registerMessage(PacketSyncSettings.class, PacketSyncSettings.Message.class);
|
||||
registerMessage(PacketNPCCastSpell.class, PacketNPCCastSpell.Message.class);
|
||||
}
|
||||
|
||||
private static int nextPacketId = 0;
|
||||
|
||||
private static <REQ extends IMessage, REPLY extends IMessage> void registerMessage(Class<? extends IMessageHandler<REQ, REPLY>> packet, Class<REQ> message)
|
||||
{
|
||||
net.registerMessage(packet, message, nextPacketId, Side.CLIENT);
|
||||
net.registerMessage(packet, message, nextPacketId, Side.SERVER);
|
||||
nextPacketId++;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user