mirror of
https://github.com/GTNewHorizons/Gadomancy.git
synced 2026-11-21 20:42:12 +00:00
- Created dynamic Server-Client synchronization framework
- Moved Familiar-Handling to new framework
This commit is contained in:
1 parent
4730d251a1
commit
cc8c9e88ec
42 files changed
+598
-358
No files matched your search
@@ -1,7 +1,7 @@
|
||||
package makeo.gadomancy.client.effect.fx;
|
||||
|
||||
import makeo.gadomancy.client.effect.EffectHandler;
|
||||
import makeo.gadomancy.common.data.ModConfig;
|
||||
import makeo.gadomancy.common.data.config.ModConfig;
|
||||
import makeo.gadomancy.common.utils.MiscUtils;
|
||||
import makeo.gadomancy.common.utils.SimpleResourceLocation;
|
||||
import makeo.gadomancy.common.utils.Vector3;
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
package makeo.gadomancy.client.effect.fx;
|
||||
|
||||
import makeo.gadomancy.client.effect.EffectHandler;
|
||||
import makeo.gadomancy.common.data.ModConfig;
|
||||
import makeo.gadomancy.common.data.config.ModConfig;
|
||||
import makeo.gadomancy.common.utils.MiscUtils;
|
||||
import makeo.gadomancy.common.utils.Vector3;
|
||||
import net.minecraft.client.Minecraft;
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
package makeo.gadomancy.client.renderers.tile;
|
||||
|
||||
import makeo.gadomancy.common.data.ModConfig;
|
||||
import makeo.gadomancy.common.data.config.ModConfig;
|
||||
import net.minecraft.tileentity.TileEntity;
|
||||
import thaumcraft.client.renderers.tile.TileEldritchCapRenderer;
|
||||
import thaumcraft.common.config.Config;
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
package makeo.gadomancy.client.renderers.tile;
|
||||
|
||||
import makeo.gadomancy.common.data.ModConfig;
|
||||
import makeo.gadomancy.common.data.config.ModConfig;
|
||||
import net.minecraft.tileentity.TileEntity;
|
||||
import thaumcraft.client.renderers.tile.TileEldritchObeliskRenderer;
|
||||
import thaumcraft.common.config.Config;
|
||||
|
||||
@@ -4,7 +4,7 @@ import baubles.api.BaublesApi;
|
||||
import cpw.mods.fml.relauncher.Side;
|
||||
import cpw.mods.fml.relauncher.SideOnly;
|
||||
import makeo.gadomancy.common.items.baubles.ItemFamiliar;
|
||||
import makeo.gadomancy.common.network.packets.PacketFamiliar;
|
||||
import makeo.gadomancy.common.network.packets.PacketFamiliarBolt;
|
||||
import makeo.gadomancy.common.utils.world.fake.FakeWorld;
|
||||
import net.minecraft.client.Minecraft;
|
||||
import net.minecraft.client.renderer.entity.RenderManager;
|
||||
@@ -19,7 +19,6 @@ import thaumcraft.client.renderers.entity.RenderWisp;
|
||||
import thaumcraft.common.entities.monster.EntityWisp;
|
||||
|
||||
import java.lang.ref.WeakReference;
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
@@ -33,59 +32,40 @@ import java.util.Map;
|
||||
* Created by HellFirePvP @ 31.10.2015 12:13
|
||||
*/
|
||||
public class FamiliarHandlerClient {
|
||||
|
||||
private static final EntityWisp ENTITY_WISP;
|
||||
|
||||
private static RenderWisp fallbackRenderer;
|
||||
|
||||
private static Map<String, PartialEntityFamiliar> clientFamiliars = new HashMap<String, PartialEntityFamiliar>();
|
||||
private static List<String> familiarPlayers = new ArrayList<String>();
|
||||
|
||||
@SideOnly(Side.CLIENT)
|
||||
public static void processPacket(PacketFamiliar packet) {
|
||||
if(packet instanceof PacketFamiliar.PacketFamiliarBolt) {
|
||||
PacketFamiliar.PacketFamiliarBolt pkt = (PacketFamiliar.PacketFamiliarBolt) packet;
|
||||
EntityPlayer p = Minecraft.getMinecraft().theWorld.getPlayerEntityByName(pkt.owner);
|
||||
if(p == null || p.getDistanceSqToEntity(Minecraft.getMinecraft().thePlayer) > 1024) return; //32^2
|
||||
PartialEntityFamiliar fam = clientFamiliars.get(p.getCommandSenderName());
|
||||
if(fam == null) return;
|
||||
FXLightningBolt bolt = new FXLightningBolt(Minecraft.getMinecraft().theWorld, (float) fam.posX, (float) fam.posY, (float) fam.posZ, pkt.targetX, pkt.targetY, pkt.targetZ, Minecraft.getMinecraft().theWorld.rand.nextLong(), 10, 4.0F, 5);
|
||||
bolt.defaultFractal();
|
||||
bolt.setType(pkt.type);
|
||||
bolt.finalizeBolt();
|
||||
} else if(packet instanceof PacketFamiliar.PacketFamiliarSyncCompletely) {
|
||||
PacketFamiliar.PacketFamiliarSyncCompletely sync = (PacketFamiliar.PacketFamiliarSyncCompletely) packet;
|
||||
familiarPlayers = sync.playerNamesWithFamiliars;
|
||||
} else if(packet instanceof PacketFamiliar.PacketFamiliarSyncSingle) {
|
||||
PacketFamiliar.PacketFamiliarSyncSingle sync = (PacketFamiliar.PacketFamiliarSyncSingle) packet;
|
||||
String value = sync.name;
|
||||
if(sync.status) {
|
||||
if(!familiarPlayers.contains(value)) {
|
||||
familiarPlayers.add(value);
|
||||
clientFamiliars.put(value, new PartialEntityFamiliar(Minecraft.getMinecraft().theWorld.getPlayerEntityByName(value), value));
|
||||
}
|
||||
} else {
|
||||
clientFamiliars.remove(value);
|
||||
familiarPlayers.remove(value);
|
||||
}
|
||||
}
|
||||
public static void processBoltPacket(PacketFamiliarBolt pkt) {
|
||||
EntityPlayer p = Minecraft.getMinecraft().theWorld.getPlayerEntityByName(pkt.owner);
|
||||
if(p == null || p.getDistanceSqToEntity(Minecraft.getMinecraft().thePlayer) > 1024) return; //32^2
|
||||
PartialEntityFamiliar fam = clientFamiliars.get(p.getCommandSenderName());
|
||||
if(fam == null) return;
|
||||
FXLightningBolt bolt = new FXLightningBolt(Minecraft.getMinecraft().theWorld, (float) fam.posX, (float) fam.posY, (float) fam.posZ, pkt.targetX, pkt.targetY, pkt.targetZ, Minecraft.getMinecraft().theWorld.rand.nextLong(), 10, 4.0F, 5);
|
||||
bolt.defaultFractal();
|
||||
bolt.setType(pkt.type);
|
||||
bolt.finalizeBolt();
|
||||
}
|
||||
|
||||
@SideOnly(Side.CLIENT)
|
||||
public static void playerRenderEvent(EntityPlayer player, float partialTicks) {
|
||||
for(String ownerName : clientFamiliars.keySet()) {
|
||||
PartialEntityFamiliar fam = clientFamiliars.get(ownerName);
|
||||
String ownerName = player.getCommandSenderName();
|
||||
if(!clientFamiliars.containsKey(ownerName)) return;
|
||||
|
||||
if(!ownerName.equals(player.getCommandSenderName())) continue;
|
||||
PartialEntityFamiliar fam = clientFamiliars.get(ownerName);
|
||||
|
||||
ItemStack stack = BaublesApi.getBaubles(player).getStackInSlot(0);
|
||||
if(stack == null || !(stack.getItem() instanceof ItemFamiliar)) return;
|
||||
if(((ItemFamiliar) stack.getItem()).hasAspect(stack)) {
|
||||
ENTITY_WISP.setType(((ItemFamiliar) stack.getItem()).getAspect(stack).getTag());
|
||||
ENTITY_WISP.ticksExisted = fam.dummyEntity.ticksExisted;
|
||||
GL11.glPushMatrix();
|
||||
fallbackRenderer.doRender(ENTITY_WISP, fam.renderX, fam.renderY, fam.renderZ, 0, partialTicks);
|
||||
GL11.glPopMatrix();
|
||||
}
|
||||
ItemStack stack = BaublesApi.getBaubles(player).getStackInSlot(0);
|
||||
if(stack == null || !(stack.getItem() instanceof ItemFamiliar)) return;
|
||||
if(((ItemFamiliar) stack.getItem()).hasAspect(stack)) {
|
||||
ENTITY_WISP.setType(((ItemFamiliar) stack.getItem()).getAspect(stack).getTag());
|
||||
ENTITY_WISP.ticksExisted = fam.dummyEntity.ticksExisted;
|
||||
GL11.glPushMatrix();
|
||||
fallbackRenderer.doRender(ENTITY_WISP, fam.renderX, fam.renderY, fam.renderZ, 0, partialTicks);
|
||||
GL11.glPopMatrix();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -102,6 +82,18 @@ public class FamiliarHandlerClient {
|
||||
ENTITY_WISP = new EntityWisp(new FakeWorld());
|
||||
}
|
||||
|
||||
public static void handleAdditions(List<String> toAdd) {
|
||||
for(String plName : toAdd) {
|
||||
clientFamiliars.put(plName, new PartialEntityFamiliar(Minecraft.getMinecraft().theWorld.getPlayerEntityByName(plName), plName));
|
||||
}
|
||||
}
|
||||
|
||||
public static void handleRemovals(List<String> toRemove) {
|
||||
for(String plName : toRemove) {
|
||||
clientFamiliars.remove(plName);
|
||||
}
|
||||
}
|
||||
|
||||
public static class DummyEntityFamiliar extends Entity {
|
||||
|
||||
public DummyEntityFamiliar(World p_i1582_1_) {
|
||||
|
||||
@@ -8,12 +8,12 @@ import makeo.gadomancy.client.ClientProxy;
|
||||
import makeo.gadomancy.common.aura.AuraEffects;
|
||||
import makeo.gadomancy.common.containers.ContainerArcanePackager;
|
||||
import makeo.gadomancy.common.containers.ContainerInfusionClaw;
|
||||
import makeo.gadomancy.common.data.ModConfig;
|
||||
import makeo.gadomancy.common.data.SyncDataHolder;
|
||||
import makeo.gadomancy.common.data.config.ModConfig;
|
||||
import makeo.gadomancy.common.events.EventHandlerEntity;
|
||||
import makeo.gadomancy.common.events.EventHandlerGolem;
|
||||
import makeo.gadomancy.common.events.EventHandlerNetwork;
|
||||
import makeo.gadomancy.common.events.EventHandlerWorld;
|
||||
import makeo.gadomancy.common.familiar.FamiliarHandlerServer;
|
||||
import makeo.gadomancy.common.network.PacketHandler;
|
||||
import makeo.gadomancy.common.registration.ModSubstitutions;
|
||||
import makeo.gadomancy.common.registration.RegisteredBlocks;
|
||||
@@ -50,7 +50,6 @@ import java.util.List;
|
||||
*/
|
||||
public class CommonProxy implements IGuiHandler {
|
||||
public static final EventHandlerGolem EVENT_HANDLER_GOLEM = new EventHandlerGolem();
|
||||
public FamiliarHandlerServer familiarHandler;
|
||||
|
||||
public void onConstruct() { }
|
||||
|
||||
@@ -67,8 +66,6 @@ public class CommonProxy implements IGuiHandler {
|
||||
}
|
||||
|
||||
public void initalize() {
|
||||
familiarHandler = new FamiliarHandlerServer();
|
||||
|
||||
NetworkRegistry.INSTANCE.registerGuiHandler(Gadomancy.instance, this);
|
||||
|
||||
MinecraftForge.EVENT_BUS.register(EVENT_HANDLER_GOLEM);
|
||||
@@ -82,6 +79,7 @@ public class CommonProxy implements IGuiHandler {
|
||||
|
||||
RegisteredRecipes.init();
|
||||
|
||||
SyncDataHolder.initialize();
|
||||
ModSubstitutions.init();
|
||||
|
||||
RegisteredPotions.init();
|
||||
@@ -101,8 +99,6 @@ public class CommonProxy implements IGuiHandler {
|
||||
RegisteredItems.postInit();
|
||||
|
||||
ModSubstitutions.postInit();
|
||||
|
||||
familiarHandler.setupPostInit();
|
||||
}
|
||||
|
||||
public static void unregisterWandHandler(String modid, Block block, int metadata) {
|
||||
|
||||
@@ -9,8 +9,8 @@ import cpw.mods.fml.common.event.FMLPostInitializationEvent;
|
||||
import cpw.mods.fml.common.event.FMLPreInitializationEvent;
|
||||
import makeo.gadomancy.api.GadomancyApi;
|
||||
import makeo.gadomancy.common.api.DefaultApiHandler;
|
||||
import makeo.gadomancy.common.data.ModConfig;
|
||||
import makeo.gadomancy.common.data.ModData;
|
||||
import makeo.gadomancy.common.data.config.ModConfig;
|
||||
import makeo.gadomancy.common.data.config.ModData;
|
||||
import org.apache.logging.log4j.LogManager;
|
||||
import org.apache.logging.log4j.Logger;
|
||||
import thaumcraft.common.Thaumcraft;
|
||||
|
||||
@@ -7,7 +7,7 @@ import makeo.gadomancy.api.golems.AdditionalGolemType;
|
||||
import makeo.gadomancy.api.golems.cores.AdditionalGolemCore;
|
||||
import makeo.gadomancy.api.internal.IApiHandler;
|
||||
import makeo.gadomancy.common.Gadomancy;
|
||||
import makeo.gadomancy.common.data.ModConfig;
|
||||
import makeo.gadomancy.common.data.config.ModConfig;
|
||||
import makeo.gadomancy.common.entities.golems.ItemAdditionalGolemPlacer;
|
||||
import makeo.gadomancy.common.entities.golems.nbt.ExtendedGolemProperties;
|
||||
import makeo.gadomancy.common.registration.RegisteredBlocks;
|
||||
|
||||
@@ -357,7 +357,7 @@ public class AuraEffects {
|
||||
public static final AuraEffect HERBA = new AuraEffect.BlockAuraEffect() {
|
||||
@Override
|
||||
public int getBlockCount(Random random) {
|
||||
return 120;
|
||||
return 90;
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -373,7 +373,7 @@ public class AuraEffects {
|
||||
public static final AuraEffect ARBOR = new AuraEffect.BlockAuraEffect() {
|
||||
@Override
|
||||
public int getBlockCount(Random random) {
|
||||
return 80;
|
||||
return 60;
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
package makeo.gadomancy.common.blocks.tiles;
|
||||
|
||||
import makeo.gadomancy.common.data.ModConfig;
|
||||
import makeo.gadomancy.common.data.config.ModConfig;
|
||||
import makeo.gadomancy.common.utils.world.TCMazeHandler;
|
||||
import net.minecraft.entity.player.EntityPlayer;
|
||||
import net.minecraft.entity.player.EntityPlayerMP;
|
||||
|
||||
@@ -0,0 +1,85 @@
|
||||
package makeo.gadomancy.common.data;
|
||||
|
||||
import net.minecraft.nbt.NBTTagCompound;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
* This class is part of the Gadomancy Mod
|
||||
* Gadomancy is Open Source and distributed under the
|
||||
* GNU LESSER GENERAL PUBLIC LICENSE
|
||||
* for more read the LICENSE file
|
||||
*
|
||||
* Created by HellFirePvP @ 13.12.2015 16:06
|
||||
*/
|
||||
public abstract class AbstractData {
|
||||
|
||||
private byte providerId;
|
||||
|
||||
public void markDirty() {
|
||||
AbstractDataProvider<? extends AbstractData> provider = Registry.getProvider(getProviderID());
|
||||
if(provider != null) {
|
||||
SyncDataHolder.markForUpdate(provider.getKey());
|
||||
}
|
||||
}
|
||||
|
||||
public void setProviderId(byte id) {
|
||||
this.providerId = id;
|
||||
}
|
||||
|
||||
public byte getProviderID() {
|
||||
return providerId;
|
||||
}
|
||||
|
||||
public abstract void writeAllDataToPacket(NBTTagCompound compound);
|
||||
|
||||
public abstract void writeToPacket(NBTTagCompound compound);
|
||||
|
||||
public abstract void readRawFromPacket(NBTTagCompound compound);
|
||||
|
||||
public abstract void handleIncomingData(AbstractData serverData);
|
||||
|
||||
public static class Registry {
|
||||
|
||||
private static Map<Byte, AbstractDataProvider<? extends AbstractData>> registry = new HashMap<Byte, AbstractDataProvider<? extends AbstractData>>();
|
||||
|
||||
public static void register(AbstractDataProvider<? extends AbstractData> provider) {
|
||||
registry.put(provider.getProviderId(), provider);
|
||||
}
|
||||
|
||||
public static AbstractDataProvider<? extends AbstractData> getProvider(Byte id) {
|
||||
return registry.get(id);
|
||||
}
|
||||
}
|
||||
|
||||
public abstract static class AbstractDataProvider<T extends AbstractData> {
|
||||
|
||||
private String key;
|
||||
private byte providerId;
|
||||
|
||||
protected AbstractDataProvider(String key, byte providerId) {
|
||||
this.key = key;
|
||||
this.providerId = providerId;
|
||||
}
|
||||
|
||||
public abstract T provideNewInstance();
|
||||
|
||||
public String getKey() {
|
||||
return key;
|
||||
}
|
||||
|
||||
public byte getProviderId() {
|
||||
return providerId;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
public abstract static class ProviderAutoAllocate<T extends AbstractData> extends AbstractDataProvider<T> {
|
||||
|
||||
protected ProviderAutoAllocate(String key) {
|
||||
super(key, SyncDataHolder.allocateNewId());
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,148 @@
|
||||
package makeo.gadomancy.common.data;
|
||||
|
||||
import baubles.api.BaublesApi;
|
||||
import makeo.gadomancy.client.util.FamiliarHandlerClient;
|
||||
import makeo.gadomancy.common.familiar.FamiliarAIController;
|
||||
import net.minecraft.entity.player.EntityPlayer;
|
||||
import net.minecraft.inventory.IInventory;
|
||||
import net.minecraft.nbt.NBTTagCompound;
|
||||
import net.minecraft.nbt.NBTTagList;
|
||||
import net.minecraft.nbt.NBTTagString;
|
||||
import net.minecraft.world.World;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
* This class is part of the Gadomancy Mod
|
||||
* Gadomancy is Open Source and distributed under the
|
||||
* GNU LESSER GENERAL PUBLIC LICENSE
|
||||
* for more read the LICENSE file
|
||||
* <p/>
|
||||
* Created by HellFirePvP @ 14.12.2015 22:06
|
||||
*/
|
||||
public class DataFamiliar extends AbstractData {
|
||||
|
||||
private List<String> playersWithFamiliar = new ArrayList<String>();
|
||||
private Map<EntityPlayer, FamiliarAIController> familiarAI = new HashMap<EntityPlayer, FamiliarAIController>();
|
||||
|
||||
private List<String> addClientQueue = new ArrayList<String>();
|
||||
private List<String> removeClientQueue = new ArrayList<String>();
|
||||
|
||||
public void handleEquip(World world, EntityPlayer player) {
|
||||
if(world.isRemote) return;
|
||||
|
||||
String playerName = player.getCommandSenderName();
|
||||
|
||||
if(!addClientQueue.contains(playerName)) addClientQueue.add(playerName);
|
||||
if(!playersWithFamiliar.contains(playerName)) playersWithFamiliar.add(playerName);
|
||||
markDirty();
|
||||
|
||||
if(!familiarAI.containsKey(player)) {
|
||||
FamiliarAIController controller = new FamiliarAIController(player);
|
||||
controller.registerDefaultTasks();
|
||||
familiarAI.put(player, controller);
|
||||
}
|
||||
}
|
||||
|
||||
public void handleUnequip(World world, EntityPlayer player) {
|
||||
if(world.isRemote) return;
|
||||
|
||||
String playerName = player.getCommandSenderName();
|
||||
|
||||
if(!removeClientQueue.contains(playerName)) removeClientQueue.add(playerName);
|
||||
if(playersWithFamiliar.contains(playerName)) playersWithFamiliar.remove(playerName);
|
||||
markDirty();
|
||||
|
||||
familiarAI.remove(player);
|
||||
}
|
||||
|
||||
public void equipTick(World world, EntityPlayer player) {
|
||||
if(world.isRemote) return;
|
||||
|
||||
IInventory baublesInv = BaublesApi.getBaubles(player);
|
||||
if(baublesInv.getStackInSlot(0) == null) {
|
||||
handleUnequip(world, player);
|
||||
return;
|
||||
}
|
||||
|
||||
if(familiarAI.get(player) == null || !playersWithFamiliar.contains(player.getCommandSenderName())) {
|
||||
handleEquip(world, player);
|
||||
}
|
||||
|
||||
familiarAI.get(player).scheduleTick();
|
||||
}
|
||||
|
||||
public void checkPlayerEquipment(EntityPlayer p) {
|
||||
IInventory baublesInv = BaublesApi.getBaubles(p);
|
||||
if(baublesInv.getStackInSlot(0) != null) {
|
||||
handleEquip(p.worldObj, p);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void writeAllDataToPacket(NBTTagCompound compound) {
|
||||
NBTTagList list = new NBTTagList();
|
||||
for(String s : playersWithFamiliar) {
|
||||
list.appendTag(new NBTTagString(s));
|
||||
}
|
||||
compound.setTag("additions", list);
|
||||
compound.setTag("removals", new NBTTagList());
|
||||
}
|
||||
|
||||
@Override
|
||||
public void writeToPacket(NBTTagCompound compound) {
|
||||
NBTTagList removal = new NBTTagList();
|
||||
for(String s : removeClientQueue) {
|
||||
removal.appendTag(new NBTTagString(s));
|
||||
}
|
||||
compound.setTag("removals", removal);
|
||||
|
||||
NBTTagList additions = new NBTTagList();
|
||||
for(String s : addClientQueue) {
|
||||
additions.appendTag(new NBTTagString(s));
|
||||
}
|
||||
compound.setTag("additions", additions);
|
||||
|
||||
removeClientQueue.clear();
|
||||
addClientQueue.clear();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void readRawFromPacket(NBTTagCompound compound) {
|
||||
NBTTagList remove = compound.getTagList("removals", new NBTTagString().getId());
|
||||
for (int i = 0; i < remove.tagCount(); i++) {
|
||||
removeClientQueue.add(remove.getStringTagAt(i));
|
||||
}
|
||||
NBTTagList additions = compound.getTagList("additions", new NBTTagString().getId());
|
||||
for (int i = 0; i < additions.tagCount(); i++) {
|
||||
addClientQueue.add(additions.getStringTagAt(i));
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void handleIncomingData(AbstractData serverData) {
|
||||
DataFamiliar familiarData = (DataFamiliar) serverData;
|
||||
List<String> toAdd = familiarData.addClientQueue;
|
||||
playersWithFamiliar.addAll(toAdd);
|
||||
FamiliarHandlerClient.handleAdditions(toAdd);
|
||||
List<String> toRemove = familiarData.removeClientQueue;
|
||||
playersWithFamiliar.removeAll(toRemove);
|
||||
FamiliarHandlerClient.handleRemovals(toRemove);
|
||||
}
|
||||
|
||||
public static class Provider extends ProviderAutoAllocate<DataFamiliar> {
|
||||
|
||||
public Provider(String key) {
|
||||
super(key);
|
||||
}
|
||||
|
||||
@Override
|
||||
public DataFamiliar provideNewInstance() {
|
||||
return new DataFamiliar();
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,87 @@
|
||||
package makeo.gadomancy.common.data;
|
||||
|
||||
import makeo.gadomancy.common.network.PacketHandler;
|
||||
import makeo.gadomancy.common.network.packets.PacketSyncData;
|
||||
import net.minecraft.entity.player.EntityPlayer;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
* This class is part of the Gadomancy Mod
|
||||
* Gadomancy is Open Source and distributed under the
|
||||
* GNU LESSER GENERAL PUBLIC LICENSE
|
||||
* for more read the LICENSE file
|
||||
*
|
||||
* Created by HellFirePvP @ 13.12.2015 15:53
|
||||
*/
|
||||
public class SyncDataHolder {
|
||||
|
||||
private static Map<String, AbstractData> serverData = new HashMap<String, AbstractData>();
|
||||
private static Map<String, AbstractData> clientData = new HashMap<String, AbstractData>();
|
||||
|
||||
private static List<String> dirtyData = new ArrayList<String>();
|
||||
private static byte providerCounter = 0;
|
||||
|
||||
public static void register(AbstractData.AbstractDataProvider<? extends AbstractData> provider) {
|
||||
AbstractData.Registry.register(provider);
|
||||
AbstractData ad = provider.provideNewInstance();
|
||||
ad.setProviderId(provider.getProviderId());
|
||||
serverData.put(provider.getKey(), ad);
|
||||
ad = provider.provideNewInstance();
|
||||
ad.setProviderId(provider.getProviderId());
|
||||
clientData.put(provider.getKey(), ad);
|
||||
}
|
||||
|
||||
public static byte allocateNewId() {
|
||||
byte pId = providerCounter;
|
||||
providerCounter++;
|
||||
return pId;
|
||||
}
|
||||
|
||||
public static <T extends AbstractData> T getDataServer(String key) {
|
||||
return (T) serverData.get(key);
|
||||
}
|
||||
|
||||
public static <T extends AbstractData> T getDataClient(String key) {
|
||||
return (T) clientData.get(key);
|
||||
}
|
||||
|
||||
public static void markForUpdate(String key) {
|
||||
if(!dirtyData.contains(key)) {
|
||||
dirtyData.add(key);
|
||||
}
|
||||
}
|
||||
|
||||
public static void syncAllDataTo(EntityPlayer player) {
|
||||
PacketSyncData dataSync = new PacketSyncData(serverData, true);
|
||||
PacketHandler.INSTANCE.sendTo(dataSync, (net.minecraft.entity.player.EntityPlayerMP) player);
|
||||
}
|
||||
|
||||
public static void recieveServerPacket(Map<String, AbstractData> data) {
|
||||
for(String key : data.keySet()) {
|
||||
AbstractData dat = clientData.get(key);
|
||||
if(dat != null) {
|
||||
dat.handleIncomingData(data.get(key));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public static void doNecessaryUpdates() {
|
||||
if(dirtyData.isEmpty()) return;
|
||||
Map<String, AbstractData> pktData = new HashMap<String, AbstractData>();
|
||||
for(String s : dirtyData) {
|
||||
AbstractData d = getDataServer(s);
|
||||
pktData.put(s, d);
|
||||
}
|
||||
PacketSyncData dataSync = new PacketSyncData(pktData, false);
|
||||
PacketHandler.INSTANCE.sendToAll(dataSync);
|
||||
}
|
||||
|
||||
public static void initialize() {
|
||||
register(new DataFamiliar.Provider("FamiliarData"));
|
||||
}
|
||||
|
||||
}
|
||||
+1
-1
@@ -1,4 +1,4 @@
|
||||
package makeo.gadomancy.common.data;
|
||||
package makeo.gadomancy.common.data.config;
|
||||
|
||||
import net.minecraftforge.common.config.Configuration;
|
||||
|
||||
+1
-1
@@ -1,4 +1,4 @@
|
||||
package makeo.gadomancy.common.data;
|
||||
package makeo.gadomancy.common.data.config;
|
||||
|
||||
import com.google.gson.Gson;
|
||||
import cpw.mods.fml.common.FMLLog;
|
||||
+1
-1
@@ -1,4 +1,4 @@
|
||||
package makeo.gadomancy.common.data;
|
||||
package makeo.gadomancy.common.data.config;
|
||||
|
||||
import java.lang.annotation.Retention;
|
||||
import java.lang.annotation.RetentionPolicy;
|
||||
@@ -6,7 +6,7 @@ import makeo.gadomancy.client.effect.EffectHandler;
|
||||
import makeo.gadomancy.client.effect.fx.EntityFXFlowPolicy;
|
||||
import makeo.gadomancy.client.effect.fx.FXFlow;
|
||||
import makeo.gadomancy.client.effect.fx.Orbital;
|
||||
import makeo.gadomancy.common.data.ModConfig;
|
||||
import makeo.gadomancy.common.data.config.ModConfig;
|
||||
import makeo.gadomancy.common.items.ItemAuraCore;
|
||||
import makeo.gadomancy.common.network.PacketHandler;
|
||||
import makeo.gadomancy.common.network.packets.PacketStartAnimation;
|
||||
|
||||
@@ -1,19 +1,16 @@
|
||||
package makeo.gadomancy.common.entities;
|
||||
|
||||
import makeo.gadomancy.common.blocks.tiles.TileAuraPylon;
|
||||
import makeo.gadomancy.common.data.ModConfig;
|
||||
import makeo.gadomancy.common.data.config.ModConfig;
|
||||
import net.minecraft.entity.item.EntityItem;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.nbt.NBTTagCompound;
|
||||
import net.minecraft.tileentity.TileEntity;
|
||||
import net.minecraft.util.AxisAlignedBB;
|
||||
import net.minecraft.util.ChunkCoordinates;
|
||||
import net.minecraft.util.DamageSource;
|
||||
import net.minecraft.world.World;
|
||||
import thaumcraft.common.entities.EntityPermanentItem;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* This class is part of the Gadomancy Mod
|
||||
* Gadomancy is Open Source and distributed under the
|
||||
|
||||
+1
-1
@@ -4,7 +4,7 @@ import makeo.gadomancy.api.GadomancyApi;
|
||||
import makeo.gadomancy.api.golems.AdditionalGolemType;
|
||||
import makeo.gadomancy.api.golems.cores.AdditionalGolemCore;
|
||||
import makeo.gadomancy.common.Gadomancy;
|
||||
import makeo.gadomancy.common.data.ModConfig;
|
||||
import makeo.gadomancy.common.data.config.ModConfig;
|
||||
import makeo.gadomancy.common.entities.golems.cores.EntityAITasksWrapper;
|
||||
import makeo.gadomancy.common.utils.NBTHelper;
|
||||
import net.minecraft.entity.Entity;
|
||||
|
||||
@@ -4,7 +4,7 @@ import cpw.mods.fml.common.eventhandler.SubscribeEvent;
|
||||
import makeo.gadomancy.common.aura.AuraEffects;
|
||||
import makeo.gadomancy.common.blocks.tiles.TileAuraPylon;
|
||||
import makeo.gadomancy.common.blocks.tiles.TileBlockProtector;
|
||||
import makeo.gadomancy.common.data.ModConfig;
|
||||
import makeo.gadomancy.common.data.config.ModConfig;
|
||||
import makeo.gadomancy.common.entities.EntityPermNoClipItem;
|
||||
import makeo.gadomancy.common.familiar.FamiliarAIController;
|
||||
import makeo.gadomancy.common.registration.RegisteredPotions;
|
||||
|
||||
@@ -8,7 +8,7 @@ import makeo.gadomancy.api.golems.cores.AdditionalGolemCore;
|
||||
import makeo.gadomancy.api.golems.events.GolemDropPlacerEvent;
|
||||
import makeo.gadomancy.api.golems.events.PlacerCreateGolemEvent;
|
||||
import makeo.gadomancy.common.Gadomancy;
|
||||
import makeo.gadomancy.common.data.ModConfig;
|
||||
import makeo.gadomancy.common.data.config.ModConfig;
|
||||
import makeo.gadomancy.common.entities.golems.ItemAdditionalGolemPlacer;
|
||||
import makeo.gadomancy.common.entities.golems.nbt.ExtendedGolemProperties;
|
||||
import makeo.gadomancy.common.registration.RegisteredGolemStuff;
|
||||
|
||||
@@ -2,9 +2,9 @@ package makeo.gadomancy.common.events;
|
||||
|
||||
import cpw.mods.fml.common.eventhandler.SubscribeEvent;
|
||||
import cpw.mods.fml.common.gameevent.PlayerEvent;
|
||||
import makeo.gadomancy.common.Gadomancy;
|
||||
import makeo.gadomancy.common.data.DataFamiliar;
|
||||
import makeo.gadomancy.common.data.SyncDataHolder;
|
||||
import makeo.gadomancy.common.network.PacketHandler;
|
||||
import makeo.gadomancy.common.network.packets.PacketFamiliar;
|
||||
import makeo.gadomancy.common.network.packets.PacketSyncConfigs;
|
||||
import makeo.gadomancy.common.network.packets.PacketUpdateGolemTypeOrder;
|
||||
import makeo.gadomancy.common.utils.GolemEnumHelper;
|
||||
@@ -28,8 +28,8 @@ public class EventHandlerNetwork {
|
||||
EntityPlayerMP p = (EntityPlayerMP) e.player;
|
||||
if(!p.playerNetServerHandler.netManager.isLocalChannel()) {
|
||||
PacketHandler.INSTANCE.sendTo(new PacketUpdateGolemTypeOrder(GolemEnumHelper.getCurrentMapping()), p);
|
||||
Gadomancy.proxy.familiarHandler.checkPlayerEquipment(p);
|
||||
PacketHandler.INSTANCE.sendTo(new PacketFamiliar.PacketFamiliarSyncCompletely(Gadomancy.proxy.familiarHandler.getCurrentActiveFamiliars()), p);
|
||||
((DataFamiliar) SyncDataHolder.getDataServer("FamiliarData")).checkPlayerEquipment(p);
|
||||
SyncDataHolder.syncAllDataTo(p);
|
||||
PacketHandler.INSTANCE.sendTo(new PacketSyncConfigs(), p);
|
||||
}
|
||||
}
|
||||
@@ -37,7 +37,7 @@ public class EventHandlerNetwork {
|
||||
@SubscribeEvent
|
||||
public void on(PlayerEvent.PlayerLoggedOutEvent e) {
|
||||
EntityPlayer player = e.player;
|
||||
Gadomancy.proxy.familiarHandler.notifyUnequip(player.worldObj, player);
|
||||
((DataFamiliar) SyncDataHolder.getDataServer("FamiliarData")).handleUnequip(player.worldObj, player);
|
||||
|
||||
TCMazeHandler.closeSession(e.player, true);
|
||||
}
|
||||
|
||||
@@ -7,7 +7,8 @@ import makeo.gadomancy.common.Gadomancy;
|
||||
import makeo.gadomancy.common.blocks.tiles.TileBlockProtector;
|
||||
import makeo.gadomancy.common.blocks.tiles.TileNodeManipulator;
|
||||
import makeo.gadomancy.common.blocks.tiles.TileStickyJar;
|
||||
import makeo.gadomancy.common.data.ModConfig;
|
||||
import makeo.gadomancy.common.data.SyncDataHolder;
|
||||
import makeo.gadomancy.common.data.config.ModConfig;
|
||||
import makeo.gadomancy.common.registration.RegisteredBlocks;
|
||||
import makeo.gadomancy.common.registration.RegisteredItems;
|
||||
import makeo.gadomancy.common.utils.GolemEnumHelper;
|
||||
@@ -100,6 +101,7 @@ public class EventHandlerWorld {
|
||||
if(event.phase != TickEvent.Phase.END) return;
|
||||
|
||||
TCMazeHandler.scheduleTick();
|
||||
SyncDataHolder.doNecessaryUpdates();
|
||||
serverTick++;
|
||||
if((serverTick & 15) == 0) {
|
||||
EventHandlerEntity.registeredLuxPylons.clear();
|
||||
|
||||
@@ -1,98 +0,0 @@
|
||||
package makeo.gadomancy.common.familiar;
|
||||
|
||||
import baubles.api.BaublesApi;
|
||||
import makeo.gadomancy.common.network.PacketHandler;
|
||||
import makeo.gadomancy.common.network.packets.PacketFamiliar;
|
||||
import net.minecraft.entity.player.EntityPlayer;
|
||||
import net.minecraft.inventory.IInventory;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.server.MinecraftServer;
|
||||
import net.minecraft.world.World;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
* This class is part of the Gadomancy Mod
|
||||
* Gadomancy is Open Source and distributed under the
|
||||
* GNU LESSER GENERAL PUBLIC LICENSE
|
||||
* for more read the LICENSE file
|
||||
*
|
||||
* Created by HellFirePvP @ 31.10.2015 12:10
|
||||
*/
|
||||
public class FamiliarHandlerServer {
|
||||
|
||||
private List<String> activeFamiliars = new ArrayList<String>();
|
||||
private Map<EntityPlayer, FamiliarAIController> familiarAI;
|
||||
|
||||
public void setupPostInit() {
|
||||
familiarAI = new HashMap<EntityPlayer, FamiliarAIController>();
|
||||
}
|
||||
|
||||
public void notifyEquip(World world, ItemStack itemStack, EntityPlayer player) {
|
||||
if(!world.isRemote) {
|
||||
if(!familiarAI.containsKey(player)) {
|
||||
FamiliarAIController controller = new FamiliarAIController(player);
|
||||
controller.registerDefaultTasks();
|
||||
familiarAI.put(player, controller);
|
||||
}
|
||||
|
||||
if(!activeFamiliars.contains(player.getCommandSenderName())) activeFamiliars.add(player.getCommandSenderName());
|
||||
|
||||
PacketFamiliar.PacketFamiliarSyncSingle pkt;
|
||||
List entityPlayers = MinecraftServer.getServer().getConfigurationManager().playerEntityList;
|
||||
for(Object playerEntity : entityPlayers) {
|
||||
if(!(playerEntity instanceof EntityPlayer)) continue;
|
||||
|
||||
pkt = new PacketFamiliar.PacketFamiliarSyncSingle(true, player.getCommandSenderName());
|
||||
PacketHandler.INSTANCE.sendTo(pkt, (net.minecraft.entity.player.EntityPlayerMP) playerEntity);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public void notifyUnequip(World world, EntityPlayer player) {
|
||||
if(!world.isRemote) {
|
||||
familiarAI.remove(player);
|
||||
|
||||
activeFamiliars.remove(player.getCommandSenderName());
|
||||
|
||||
PacketFamiliar.PacketFamiliarSyncSingle pkt;
|
||||
List entityPlayers = MinecraftServer.getServer().getConfigurationManager().playerEntityList;
|
||||
for(Object playerEntity : entityPlayers) {
|
||||
if(!(playerEntity instanceof EntityPlayer)) continue;
|
||||
|
||||
pkt = new PacketFamiliar.PacketFamiliarSyncSingle(false, player.getCommandSenderName());
|
||||
PacketHandler.INSTANCE.sendTo(pkt, (net.minecraft.entity.player.EntityPlayerMP) playerEntity);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public void equippedTick(World world, ItemStack itemStack, EntityPlayer player) {
|
||||
if(!world.isRemote) {
|
||||
IInventory baublesInv = BaublesApi.getBaubles(player);
|
||||
if(baublesInv.getStackInSlot(0) == null) {
|
||||
notifyUnequip(world, player);
|
||||
return;
|
||||
}
|
||||
|
||||
if(familiarAI.get(player) == null || !activeFamiliars.contains(player.getCommandSenderName())) {
|
||||
notifyEquip(world, itemStack, player);
|
||||
}
|
||||
|
||||
familiarAI.get(player).scheduleTick();
|
||||
}
|
||||
}
|
||||
|
||||
public List<String> getCurrentActiveFamiliars() {
|
||||
return activeFamiliars;
|
||||
}
|
||||
|
||||
public void checkPlayerEquipment(EntityPlayer p) {
|
||||
IInventory baublesInv = BaublesApi.getBaubles(p);
|
||||
if(baublesInv.getStackInSlot(0) != null) {
|
||||
notifyEquip(p.worldObj, baublesInv.getStackInSlot(0), p);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -3,6 +3,8 @@ package makeo.gadomancy.common.items.baubles;
|
||||
import baubles.api.BaubleType;
|
||||
import baubles.api.IBauble;
|
||||
import makeo.gadomancy.common.Gadomancy;
|
||||
import makeo.gadomancy.common.data.DataFamiliar;
|
||||
import makeo.gadomancy.common.data.SyncDataHolder;
|
||||
import makeo.gadomancy.common.registration.RegisteredItems;
|
||||
import makeo.gadomancy.common.utils.NBTHelper;
|
||||
import net.minecraft.creativetab.CreativeTabs;
|
||||
@@ -124,7 +126,8 @@ public class ItemFamiliar extends Item implements IBauble {
|
||||
public void onWornTick(ItemStack itemStack, EntityLivingBase entity) {
|
||||
if(itemStack == null) return;
|
||||
if(entity instanceof EntityPlayer && itemStack.getItem() instanceof ItemFamiliar) {
|
||||
Gadomancy.proxy.familiarHandler.equippedTick(((EntityPlayer) entity).worldObj, itemStack, (EntityPlayer) entity);
|
||||
DataFamiliar familiarData = SyncDataHolder.getDataServer("FamiliarData");
|
||||
familiarData.equipTick(((EntityPlayer) entity).worldObj, (EntityPlayer) entity);
|
||||
|
||||
if(((EntityPlayer) entity).worldObj.isRemote) return;
|
||||
|
||||
@@ -144,7 +147,8 @@ public class ItemFamiliar extends Item implements IBauble {
|
||||
public void onEquipped(ItemStack itemStack, EntityLivingBase entity) {
|
||||
if(itemStack == null) return;
|
||||
if(entity instanceof EntityPlayer && itemStack.getItem() instanceof ItemFamiliar) {
|
||||
Gadomancy.proxy.familiarHandler.notifyEquip(((EntityPlayer) entity).worldObj, itemStack, (EntityPlayer) entity);
|
||||
DataFamiliar familiarData = SyncDataHolder.getDataServer("FamiliarData");
|
||||
familiarData.handleEquip(((EntityPlayer) entity).worldObj, (EntityPlayer) entity);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -152,7 +156,8 @@ public class ItemFamiliar extends Item implements IBauble {
|
||||
public void onUnequipped(ItemStack itemStack, EntityLivingBase entity) {
|
||||
if(itemStack == null) return;
|
||||
if(entity instanceof EntityPlayer && itemStack.getItem() instanceof ItemFamiliar) {
|
||||
Gadomancy.proxy.familiarHandler.notifyUnequip(((EntityPlayer) entity).worldObj, (EntityPlayer) entity);
|
||||
DataFamiliar familiarData = SyncDataHolder.getDataServer("FamiliarData");
|
||||
familiarData.handleUnequip(((EntityPlayer) entity).worldObj, (EntityPlayer) entity);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -31,11 +31,10 @@ public class PacketHandler {
|
||||
INSTANCE.registerMessage(PacketTCNotificationText.class, PacketTCNotificationText.class, id++, Side.CLIENT);
|
||||
|
||||
//Familiar
|
||||
INSTANCE.registerMessage(PacketFamiliar.PacketFamiliarBolt.class, PacketFamiliar.PacketFamiliarBolt.class, id++, Side.CLIENT);
|
||||
INSTANCE.registerMessage(PacketFamiliar.PacketFamiliarSyncCompletely.class, PacketFamiliar.PacketFamiliarSyncCompletely.class, id++, Side.CLIENT);
|
||||
INSTANCE.registerMessage(PacketFamiliar.PacketFamiliarSyncSingle.class, PacketFamiliar.PacketFamiliarSyncSingle.class, id++, Side.CLIENT);
|
||||
INSTANCE.registerMessage(PacketFamiliarBolt.class, PacketFamiliarBolt.class, id++, Side.CLIENT);
|
||||
|
||||
//Sync data
|
||||
INSTANCE.registerMessage(PacketSyncConfigs.class, PacketSyncConfigs.class, id++, Side.CLIENT);
|
||||
INSTANCE.registerMessage(PacketSyncData.class, PacketSyncData.class, id++, Side.CLIENT);
|
||||
}
|
||||
}
|
||||
@@ -1,150 +0,0 @@
|
||||
package makeo.gadomancy.common.network.packets;
|
||||
|
||||
import cpw.mods.fml.common.network.simpleimpl.IMessage;
|
||||
import cpw.mods.fml.common.network.simpleimpl.IMessageHandler;
|
||||
import cpw.mods.fml.common.network.simpleimpl.MessageContext;
|
||||
import io.netty.buffer.ByteBuf;
|
||||
import makeo.gadomancy.client.util.FamiliarHandlerClient;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* This class is part of the Gadomancy Mod
|
||||
* Gadomancy is Open Source and distributed under the
|
||||
* GNU LESSER GENERAL PUBLIC LICENSE
|
||||
* for more read the LICENSE file
|
||||
* <p/>
|
||||
* Created by HellFirePvP @ 31.10.2015 14:36
|
||||
*/
|
||||
public abstract class PacketFamiliar {
|
||||
|
||||
public static class PacketFamiliarBolt extends PacketFamiliar implements IMessage, IMessageHandler<PacketFamiliarBolt, IMessage> {
|
||||
|
||||
public float targetX, targetY, targetZ;
|
||||
public int type;
|
||||
public boolean mightGetLong;
|
||||
public String owner;
|
||||
|
||||
public PacketFamiliarBolt() {}
|
||||
|
||||
public PacketFamiliarBolt(String whoseFamiliar, float targetX, float targetY, float targetZ, int type, boolean mightGetLong) {
|
||||
this.targetX = targetX;
|
||||
this.targetY = targetY;
|
||||
this.targetZ = targetZ;
|
||||
this.owner = whoseFamiliar;
|
||||
this.type = type;
|
||||
this.mightGetLong = mightGetLong;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void fromBytes(ByteBuf buf) {
|
||||
this.targetX = buf.readFloat();
|
||||
this.targetY = buf.readFloat();
|
||||
this.targetZ = buf.readFloat();
|
||||
|
||||
this.type = buf.readInt();
|
||||
this.mightGetLong = buf.readBoolean();
|
||||
|
||||
int length = buf.readInt();
|
||||
byte[] strBytes = new byte[length];
|
||||
buf.readBytes(strBytes, 0, length);
|
||||
owner = new String(strBytes);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void toBytes(ByteBuf buf) {
|
||||
buf.writeFloat(targetX);
|
||||
buf.writeFloat(targetY);
|
||||
buf.writeFloat(targetZ);
|
||||
|
||||
buf.writeInt(type);
|
||||
buf.writeBoolean(mightGetLong);
|
||||
|
||||
byte[] str = owner.getBytes();
|
||||
buf.writeInt(str.length);
|
||||
buf.writeBytes(str);
|
||||
}
|
||||
|
||||
@Override
|
||||
public IMessage onMessage(PacketFamiliarBolt message, MessageContext ctx) {
|
||||
FamiliarHandlerClient.processPacket(message);
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
public static class PacketFamiliarSyncCompletely extends PacketFamiliar implements IMessage, IMessageHandler<PacketFamiliarSyncCompletely, IMessage> {
|
||||
|
||||
public List<String> playerNamesWithFamiliars = new ArrayList<String>();
|
||||
|
||||
public PacketFamiliarSyncCompletely() {}
|
||||
|
||||
public PacketFamiliarSyncCompletely(List<String> playerNamesWithFamiliars) {
|
||||
this.playerNamesWithFamiliars = playerNamesWithFamiliars;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void fromBytes(ByteBuf buf) {
|
||||
int cnt = buf.readInt();
|
||||
for (int i = 0; i < cnt; i++) {
|
||||
int length = buf.readInt();
|
||||
byte[] strBytes = new byte[length];
|
||||
buf.readBytes(strBytes, 0, length);
|
||||
playerNamesWithFamiliars.add(new String(strBytes));
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void toBytes(ByteBuf buf) {
|
||||
buf.writeInt(playerNamesWithFamiliars.size());
|
||||
for(String str : playerNamesWithFamiliars) {
|
||||
byte[] strBytes = str.getBytes();
|
||||
buf.writeInt(strBytes.length);
|
||||
buf.writeBytes(strBytes);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public IMessage onMessage(PacketFamiliarSyncCompletely message, MessageContext ctx) {
|
||||
FamiliarHandlerClient.processPacket(message);
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
public static class PacketFamiliarSyncSingle extends PacketFamiliar implements IMessage, IMessageHandler<PacketFamiliarSyncSingle, IMessage> {
|
||||
|
||||
//True=add, False=remove
|
||||
public boolean status;
|
||||
public String name;
|
||||
|
||||
public PacketFamiliarSyncSingle() {}
|
||||
|
||||
public PacketFamiliarSyncSingle(boolean status, String name) {
|
||||
this.status = status;
|
||||
this.name = name;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void fromBytes(ByteBuf buf) {
|
||||
status = buf.readBoolean();
|
||||
int length = buf.readInt();
|
||||
byte[] strBytes = new byte[length];
|
||||
buf.readBytes(strBytes, 0, length);
|
||||
name = new String(strBytes);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void toBytes(ByteBuf buf) {
|
||||
buf.writeBoolean(status);
|
||||
byte[] str = name.getBytes();
|
||||
buf.writeInt(str.length);
|
||||
buf.writeBytes(str);
|
||||
}
|
||||
|
||||
@Override
|
||||
public IMessage onMessage(PacketFamiliarSyncSingle message, MessageContext ctx) {
|
||||
FamiliarHandlerClient.processPacket(message);
|
||||
return null;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,65 @@
|
||||
package makeo.gadomancy.common.network.packets;
|
||||
|
||||
import cpw.mods.fml.common.network.simpleimpl.IMessage;
|
||||
import cpw.mods.fml.common.network.simpleimpl.IMessageHandler;
|
||||
import cpw.mods.fml.common.network.simpleimpl.MessageContext;
|
||||
import io.netty.buffer.ByteBuf;
|
||||
import makeo.gadomancy.client.util.FamiliarHandlerClient;
|
||||
import makeo.gadomancy.common.utils.StringHelper;
|
||||
|
||||
/**
|
||||
* This class is part of the Gadomancy Mod
|
||||
* Gadomancy is Open Source and distributed under the
|
||||
* GNU LESSER GENERAL PUBLIC LICENSE
|
||||
* for more read the LICENSE file
|
||||
* <p/>
|
||||
* Created by HellFirePvP @ 31.10.2015 14:36
|
||||
*/
|
||||
public class PacketFamiliarBolt implements IMessage, IMessageHandler<PacketFamiliarBolt, IMessage> {
|
||||
|
||||
public float targetX, targetY, targetZ;
|
||||
public int type;
|
||||
public boolean mightGetLong;
|
||||
public String owner;
|
||||
|
||||
public PacketFamiliarBolt() {}
|
||||
|
||||
public PacketFamiliarBolt(String whoseFamiliar, float targetX, float targetY, float targetZ, int type, boolean mightGetLong) {
|
||||
this.targetX = targetX;
|
||||
this.targetY = targetY;
|
||||
this.targetZ = targetZ;
|
||||
this.owner = whoseFamiliar;
|
||||
this.type = type;
|
||||
this.mightGetLong = mightGetLong;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void fromBytes(ByteBuf buf) {
|
||||
this.targetX = buf.readFloat();
|
||||
this.targetY = buf.readFloat();
|
||||
this.targetZ = buf.readFloat();
|
||||
|
||||
this.type = buf.readInt();
|
||||
this.mightGetLong = buf.readBoolean();
|
||||
|
||||
owner = StringHelper.readFromBuffer(buf);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void toBytes(ByteBuf buf) {
|
||||
buf.writeFloat(targetX);
|
||||
buf.writeFloat(targetY);
|
||||
buf.writeFloat(targetZ);
|
||||
|
||||
buf.writeInt(type);
|
||||
buf.writeBoolean(mightGetLong);
|
||||
|
||||
StringHelper.writeToBuffer(buf, owner);
|
||||
}
|
||||
|
||||
@Override
|
||||
public IMessage onMessage(PacketFamiliarBolt message, MessageContext ctx) {
|
||||
FamiliarHandlerClient.processBoltPacket(message);
|
||||
return null;
|
||||
}
|
||||
}
|
||||
@@ -4,8 +4,8 @@ import cpw.mods.fml.common.network.simpleimpl.IMessage;
|
||||
import cpw.mods.fml.common.network.simpleimpl.IMessageHandler;
|
||||
import cpw.mods.fml.common.network.simpleimpl.MessageContext;
|
||||
import io.netty.buffer.ByteBuf;
|
||||
import makeo.gadomancy.common.data.ModConfig;
|
||||
import makeo.gadomancy.common.data.Sync;
|
||||
import makeo.gadomancy.common.data.config.ModConfig;
|
||||
import makeo.gadomancy.common.data.config.Sync;
|
||||
|
||||
import java.io.*;
|
||||
import java.lang.reflect.Field;
|
||||
|
||||
@@ -0,0 +1,107 @@
|
||||
package makeo.gadomancy.common.network.packets;
|
||||
|
||||
import cpw.mods.fml.common.network.simpleimpl.IMessage;
|
||||
import cpw.mods.fml.common.network.simpleimpl.IMessageHandler;
|
||||
import cpw.mods.fml.common.network.simpleimpl.MessageContext;
|
||||
import io.netty.buffer.ByteBuf;
|
||||
import makeo.gadomancy.common.Gadomancy;
|
||||
import makeo.gadomancy.common.data.AbstractData;
|
||||
import makeo.gadomancy.common.data.SyncDataHolder;
|
||||
import makeo.gadomancy.common.utils.StringHelper;
|
||||
import net.minecraft.nbt.CompressedStreamTools;
|
||||
import net.minecraft.nbt.NBTSizeTracker;
|
||||
import net.minecraft.nbt.NBTTagCompound;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
* This class is part of the Gadomancy Mod
|
||||
* Gadomancy is Open Source and distributed under the
|
||||
* GNU LESSER GENERAL PUBLIC LICENSE
|
||||
* for more read the LICENSE file
|
||||
*
|
||||
* Created by HellFirePvP @ 13.12.2015 15:54
|
||||
*/
|
||||
public class PacketSyncData implements IMessage, IMessageHandler<PacketSyncData, IMessage> {
|
||||
|
||||
private Map<String, AbstractData> data = new HashMap<String, AbstractData>();
|
||||
private boolean shouldSyncAll = false;
|
||||
|
||||
public PacketSyncData() {}
|
||||
|
||||
public PacketSyncData(Map<String, AbstractData> dataToSend, boolean shouldSyncAll) {
|
||||
this.data = dataToSend;
|
||||
this.shouldSyncAll = shouldSyncAll;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void fromBytes(ByteBuf buf) {
|
||||
int size = buf.readInt();
|
||||
|
||||
for (int i = 0; i < size; i++) {
|
||||
String key = StringHelper.readFromBuffer(buf);
|
||||
|
||||
byte providerId = buf.readByte();
|
||||
AbstractData.AbstractDataProvider<? extends AbstractData> provider = AbstractData.Registry.getProvider(providerId);
|
||||
if(provider == null) {
|
||||
Gadomancy.log.warn("Provider for ID " + providerId + " doesn't exist! Skipping...");
|
||||
continue;
|
||||
}
|
||||
|
||||
NBTTagCompound cmp;
|
||||
short compoundLength = buf.readShort();
|
||||
byte[] abyte = new byte[compoundLength];
|
||||
buf.readBytes(abyte);
|
||||
try {
|
||||
cmp = CompressedStreamTools.func_152457_a(abyte, new NBTSizeTracker(2097152L));
|
||||
} catch (IOException e) {
|
||||
Gadomancy.log.warn("Provider Compound of " + providerId + " threw an IOException! Skipping...");
|
||||
continue;
|
||||
}
|
||||
|
||||
AbstractData dat = provider.provideNewInstance();
|
||||
dat.readRawFromPacket(cmp);
|
||||
|
||||
data.put(key, dat);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void toBytes(ByteBuf buf) {
|
||||
buf.writeInt(data.size());
|
||||
|
||||
for(String key : data.keySet()) {
|
||||
AbstractData dat = data.get(key);
|
||||
NBTTagCompound cmp = new NBTTagCompound();
|
||||
if(shouldSyncAll) {
|
||||
dat.writeAllDataToPacket(cmp);
|
||||
} else {
|
||||
dat.writeToPacket(cmp);
|
||||
}
|
||||
|
||||
StringHelper.writeToBuffer(buf, key);
|
||||
|
||||
byte providerId = dat.getProviderID();
|
||||
buf.writeByte(providerId);
|
||||
|
||||
byte[] abyte;
|
||||
try {
|
||||
abyte = CompressedStreamTools.compress(cmp);
|
||||
} catch (IOException e) {
|
||||
Gadomancy.log.warn("Compressing the NBTTagCompound of " + providerId + " threw an IOException! Skipping...");
|
||||
continue;
|
||||
}
|
||||
buf.writeShort((short) abyte.length);
|
||||
buf.writeBytes(abyte);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public IMessage onMessage(PacketSyncData message, MessageContext ctx) {
|
||||
SyncDataHolder.recieveServerPacket(message.data);
|
||||
return null;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -4,6 +4,7 @@ import cpw.mods.fml.common.network.simpleimpl.IMessage;
|
||||
import cpw.mods.fml.common.network.simpleimpl.IMessageHandler;
|
||||
import cpw.mods.fml.common.network.simpleimpl.MessageContext;
|
||||
import io.netty.buffer.ByteBuf;
|
||||
import makeo.gadomancy.common.utils.StringHelper;
|
||||
import net.minecraft.util.EnumChatFormatting;
|
||||
import net.minecraft.util.ResourceLocation;
|
||||
import net.minecraft.util.StatCollector;
|
||||
@@ -50,30 +51,20 @@ public class PacketTCNotificationText implements IMessage, IMessageHandler<Packe
|
||||
public void fromBytes(ByteBuf buf) {
|
||||
color = buf.readInt();
|
||||
|
||||
int length = buf.readInt();
|
||||
byte[] strBytes = new byte[length];
|
||||
buf.readBytes(strBytes, 0, length);
|
||||
text = new String(strBytes);
|
||||
text = StringHelper.readFromBuffer(buf);
|
||||
|
||||
length = buf.readInt();
|
||||
strBytes = new byte[length];
|
||||
buf.readBytes(strBytes, 0, length);
|
||||
additionalInfo = new String(strBytes);
|
||||
additionalInfo = StringHelper.readFromBuffer(buf);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void toBytes(ByteBuf buf) {
|
||||
buf.writeInt(color);
|
||||
|
||||
byte[] str = text.getBytes();
|
||||
buf.writeInt(str.length);
|
||||
buf.writeBytes(str);
|
||||
StringHelper.writeToBuffer(buf, text);
|
||||
|
||||
if(additionalInfo == null) additionalInfo = "";
|
||||
|
||||
str = additionalInfo.getBytes();
|
||||
buf.writeInt(str.length);
|
||||
buf.writeBytes(str);
|
||||
StringHelper.writeToBuffer(buf, additionalInfo);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -11,7 +11,7 @@ import thaumcraft.api.aspects.Aspect;
|
||||
* Created by makeo @ 11.12.2015 17:32
|
||||
*/
|
||||
public class PotionAchromatic extends PotionCustomTexture {
|
||||
protected PotionAchromatic(int id) {
|
||||
public PotionAchromatic(int id) {
|
||||
super(id, false, Aspect.CRYSTAL.getColor(), Aspect.CRYSTAL.getImage());
|
||||
setPotionName("potion.achromatic");
|
||||
}
|
||||
|
||||
@@ -24,7 +24,6 @@ public class PotionBuffGolem extends PotionCustomTexture {
|
||||
public static final double HEALTH_INCREASE = 0.5;
|
||||
public static final double DAMAGE_INCREASE = 1;
|
||||
|
||||
//Golem runs 40% faster. Operation 1 == Multiply with current value
|
||||
public static final AttributeModifier SPEED_INC_PERCENT = new AttributeModifier(UUID.fromString("9f76335f-2952-46e9-b91a-c555ca983ada"), "POTION_GOLEM_SPEED", SPEED_INCREASE, 1);
|
||||
public static final AttributeModifier HEALTH_INC_PERCENT = new AttributeModifier(UUID.fromString("fafcbdc2-9c24-45a1-b832-4b6c4a5df9c7"), "POTION_GOLEM_HEALTH", HEALTH_INCREASE, 1);
|
||||
public static final AttributeModifier DAMAGE_INC_PERCENT = new AttributeModifier(UUID.fromString("6e562261-dccf-4421-ac6f-c742989c7dfb"), "POTION_GOLEM_DAMAGE", DAMAGE_INCREASE, 1);
|
||||
|
||||
@@ -5,7 +5,7 @@ import makeo.gadomancy.common.familiar.FamiliarAIController;
|
||||
import makeo.gadomancy.common.familiar.FamiliarAIProcess;
|
||||
import makeo.gadomancy.common.items.baubles.ItemFamiliar;
|
||||
import makeo.gadomancy.common.network.PacketHandler;
|
||||
import makeo.gadomancy.common.network.packets.PacketFamiliar;
|
||||
import makeo.gadomancy.common.network.packets.PacketFamiliarBolt;
|
||||
import net.minecraft.entity.EntityLivingBase;
|
||||
import net.minecraft.entity.player.EntityPlayer;
|
||||
import net.minecraft.item.ItemStack;
|
||||
@@ -70,7 +70,7 @@ public class RegisteredFamiliarAI {
|
||||
|
||||
world.playSoundEffect(mob.posX + 0.5, mob.posY + 0.5, mob.posZ + 0.5, "thaumcraft:zap", 0.8F, 1.0F);
|
||||
|
||||
PacketFamiliar.PacketFamiliarBolt bolt = new PacketFamiliar.PacketFamiliarBolt(parent.getCommandSenderName(), (float) mob.posX, (float) mob.posY, (float) mob.posZ, 6, true);
|
||||
PacketFamiliarBolt bolt = new PacketFamiliarBolt(parent.getCommandSenderName(), (float) mob.posX, (float) mob.posY, (float) mob.posZ, 6, true);
|
||||
PacketHandler.INSTANCE.sendToAllAround(bolt, new NetworkRegistry.TargetPoint(mob.worldObj.provider.dimensionId, mob.posX, mob.posY, mob.posZ, 32));
|
||||
FamiliarAIController.cleanTargetterList(parent);
|
||||
}
|
||||
|
||||
@@ -5,7 +5,7 @@ import makeo.gadomancy.api.golems.AdditionalGolemType;
|
||||
import makeo.gadomancy.common.Gadomancy;
|
||||
import makeo.gadomancy.common.crafting.InfusionUpgradeRecipe;
|
||||
import makeo.gadomancy.common.crafting.RecipeStickyJar;
|
||||
import makeo.gadomancy.common.data.ModConfig;
|
||||
import makeo.gadomancy.common.data.config.ModConfig;
|
||||
import makeo.gadomancy.common.items.ItemAuraCore;
|
||||
import makeo.gadomancy.common.items.baubles.ItemFamiliar;
|
||||
import makeo.gadomancy.common.research.SimpleResearchItem;
|
||||
|
||||
@@ -2,7 +2,7 @@ package makeo.gadomancy.common.registration;
|
||||
|
||||
import makeo.gadomancy.common.Gadomancy;
|
||||
import makeo.gadomancy.common.aura.AuraResearchManager;
|
||||
import makeo.gadomancy.common.data.ModConfig;
|
||||
import makeo.gadomancy.common.data.config.ModConfig;
|
||||
import makeo.gadomancy.common.items.ItemAuraCore;
|
||||
import makeo.gadomancy.common.research.AlternatingResearchItem;
|
||||
import makeo.gadomancy.common.research.MultiResearchPage;
|
||||
|
||||
@@ -1,5 +1,7 @@
|
||||
package makeo.gadomancy.common.utils;
|
||||
|
||||
import io.netty.buffer.ByteBuf;
|
||||
|
||||
/**
|
||||
* This class is part of the Gadomancy Mod
|
||||
* Gadomancy is Open Source and distributed under the
|
||||
@@ -16,4 +18,18 @@ public class StringHelper {
|
||||
return Character.toUpperCase(input.charAt(0)) + input.substring(1);
|
||||
return input;
|
||||
}
|
||||
|
||||
public static void writeToBuffer(ByteBuf buf, String toWrite) {
|
||||
byte[] str = toWrite.getBytes();
|
||||
buf.writeInt(str.length);
|
||||
buf.writeBytes(str);
|
||||
}
|
||||
|
||||
public static String readFromBuffer(ByteBuf buf) {
|
||||
int length = buf.readInt();
|
||||
byte[] strBytes = new byte[length];
|
||||
buf.readBytes(strBytes, 0, length);
|
||||
return new String(strBytes);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,7 +1,7 @@
|
||||
package makeo.gadomancy.common.utils.world;
|
||||
|
||||
import makeo.gadomancy.common.blocks.tiles.TileAdditionalEldritchPortal;
|
||||
import makeo.gadomancy.common.data.ModConfig;
|
||||
import makeo.gadomancy.common.data.config.ModConfig;
|
||||
import makeo.gadomancy.common.registration.RegisteredBlocks;
|
||||
import makeo.gadomancy.common.utils.world.fake.FakeWorldTCGeneration;
|
||||
import net.minecraft.entity.Entity;
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
package makeo.gadomancy.common.utils.world;
|
||||
|
||||
import makeo.gadomancy.common.data.ModConfig;
|
||||
import makeo.gadomancy.common.data.config.ModConfig;
|
||||
import net.minecraft.entity.player.EntityPlayer;
|
||||
import net.minecraft.entity.player.EntityPlayerMP;
|
||||
import net.minecraft.server.MinecraftServer;
|
||||
@@ -9,7 +9,6 @@ import net.minecraft.util.EnumChatFormatting;
|
||||
import net.minecraft.util.Vec3;
|
||||
import net.minecraft.world.ChunkCoordIntPair;
|
||||
import net.minecraft.world.WorldServer;
|
||||
import net.minecraftforge.common.DimensionManager;
|
||||
import org.apache.logging.log4j.LogManager;
|
||||
import thaumcraft.common.lib.world.dim.Cell;
|
||||
import thaumcraft.common.lib.world.dim.CellLoc;
|
||||
|
||||
@@ -2,7 +2,7 @@ package makeo.gadomancy.common.utils.world;
|
||||
|
||||
import cpw.mods.fml.relauncher.Side;
|
||||
import cpw.mods.fml.relauncher.SideOnly;
|
||||
import makeo.gadomancy.common.data.ModConfig;
|
||||
import makeo.gadomancy.common.data.config.ModConfig;
|
||||
import net.minecraft.util.ChunkCoordinates;
|
||||
import net.minecraft.util.MathHelper;
|
||||
import net.minecraft.util.Vec3;
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
package makeo.gadomancy.common.utils.world;
|
||||
|
||||
import cpw.mods.fml.common.FMLCommonHandler;
|
||||
import makeo.gadomancy.common.data.ModConfig;
|
||||
import makeo.gadomancy.common.data.config.ModConfig;
|
||||
import net.minecraft.entity.player.EntityPlayerMP;
|
||||
import net.minecraft.server.MinecraftServer;
|
||||
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
package makeo.gadomancy.common.utils.world.fake;
|
||||
|
||||
import makeo.gadomancy.common.data.ModConfig;
|
||||
import makeo.gadomancy.common.data.config.ModConfig;
|
||||
import net.minecraft.block.Block;
|
||||
import net.minecraft.entity.Entity;
|
||||
import net.minecraft.init.Blocks;
|
||||
|
||||
Reference in new issue
Block a user