mirror of
https://github.com/GTNewHorizons/Gadomancy.git
synced 2026-11-25 22:34:28 +00:00
- Achromatic data syncing
This commit is contained in:
1 parent
09a51aea71
commit
8223d2a379
5 files changed
+150
-2
No files matched your search
@@ -0,0 +1,133 @@
|
||||
package makeo.gadomancy.common.data;
|
||||
|
||||
import makeo.gadomancy.common.registration.RegisteredPotions;
|
||||
import net.minecraft.entity.EntityLivingBase;
|
||||
import net.minecraft.entity.player.EntityPlayerMP;
|
||||
import net.minecraft.nbt.NBTTagCompound;
|
||||
import net.minecraft.nbt.NBTTagIntArray;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* This class is part of the CycloneEnchantments Plugin for the CycloneNetwork
|
||||
* <p/>
|
||||
* Created by HellFirePvP @ 18.12.2015 20:21
|
||||
*/
|
||||
public class DataAchromatic extends AbstractData {
|
||||
|
||||
private List<Integer> achromaticEntities = new ArrayList<Integer>();
|
||||
|
||||
private List<Integer> addClientQueue = new ArrayList<Integer>();
|
||||
private List<Integer> removeClientQueue = new ArrayList<Integer>();
|
||||
|
||||
public void handleApplication(EntityLivingBase entity) {
|
||||
if(entity.worldObj.isRemote) return;
|
||||
|
||||
int entityId = entity.getEntityId();
|
||||
|
||||
boolean needsUpdate = false;
|
||||
if(!addClientQueue.contains(entityId)) {
|
||||
addClientQueue.add(entityId);
|
||||
needsUpdate = true;
|
||||
}
|
||||
if(!achromaticEntities.contains(entityId)) {
|
||||
achromaticEntities.add(entityId);
|
||||
needsUpdate = true;
|
||||
}
|
||||
if(needsUpdate) {
|
||||
markDirty();
|
||||
}
|
||||
}
|
||||
|
||||
public void handleRemoval(EntityLivingBase entity) {
|
||||
if(entity.worldObj.isRemote) return;
|
||||
|
||||
int entityId = entity.getEntityId();
|
||||
|
||||
boolean needsUpdate = false;
|
||||
if(!removeClientQueue.contains(entityId)) {
|
||||
removeClientQueue.add(entityId);
|
||||
needsUpdate = true;
|
||||
}
|
||||
if(achromaticEntities.contains(entityId)) {
|
||||
achromaticEntities.remove(entityId);
|
||||
needsUpdate = true;
|
||||
}
|
||||
|
||||
if(needsUpdate) {
|
||||
markDirty();
|
||||
}
|
||||
}
|
||||
|
||||
public void checkPotionEffect(EntityPlayerMP p) {
|
||||
if(p.isPotionActive(RegisteredPotions.ACHROMATIC)) {
|
||||
handleApplication(p);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void writeAllDataToPacket(NBTTagCompound compound) {
|
||||
int[] array = new int[achromaticEntities.size()];
|
||||
for (int i = 0; i < achromaticEntities.size(); i++) {
|
||||
array[i] = achromaticEntities.get(i);
|
||||
}
|
||||
compound.setTag("additions", new NBTTagIntArray(array));
|
||||
compound.setTag("removals", new NBTTagIntArray(new int[0]));
|
||||
}
|
||||
|
||||
@Override
|
||||
public void writeToPacket(NBTTagCompound compound) {
|
||||
int[] array = new int[removeClientQueue.size()];
|
||||
for (int i = 0; i < removeClientQueue.size(); i++) {
|
||||
array[i] = removeClientQueue.get(i);
|
||||
}
|
||||
compound.setTag("removals", new NBTTagIntArray(array));
|
||||
array = new int[addClientQueue.size()];
|
||||
for (int i = 0; i < addClientQueue.size(); i++) {
|
||||
array[i] = addClientQueue.get(i);
|
||||
}
|
||||
compound.setTag("additions", new NBTTagIntArray(array));
|
||||
|
||||
removeClientQueue.clear();
|
||||
addClientQueue.clear();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void readRawFromPacket(NBTTagCompound compound) {
|
||||
int[] array = compound.getIntArray("removals");
|
||||
if(array != null && array.length > 0) {
|
||||
for(int i : array) {
|
||||
removeClientQueue.add(i);
|
||||
}
|
||||
}
|
||||
array = compound.getIntArray("additions");
|
||||
if(array != null && array.length > 0) {
|
||||
for(int i : array) {
|
||||
addClientQueue.add(i);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void handleIncomingData(AbstractData serverData) {
|
||||
DataAchromatic achromatic = (DataAchromatic) serverData;
|
||||
List<Integer> toAdd = achromatic.addClientQueue;
|
||||
achromaticEntities.addAll(toAdd);
|
||||
List<Integer> toRemove = achromatic.removeClientQueue;
|
||||
achromaticEntities.removeAll(toRemove);
|
||||
}
|
||||
|
||||
public static class Provider extends ProviderAutoAllocate<DataAchromatic> {
|
||||
|
||||
public Provider(String key) {
|
||||
super(key);
|
||||
}
|
||||
|
||||
@Override
|
||||
public DataAchromatic provideNewInstance() {
|
||||
return new DataAchromatic();
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
@@ -82,6 +82,7 @@ public class SyncDataHolder {
|
||||
|
||||
public static void initialize() {
|
||||
register(new DataFamiliar.Provider("FamiliarData"));
|
||||
register(new DataAchromatic.Provider("AchromaticData"));
|
||||
}
|
||||
|
||||
}
|
||||
@@ -8,12 +8,16 @@ 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.DataAchromatic;
|
||||
import makeo.gadomancy.common.data.SyncDataHolder;
|
||||
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;
|
||||
import makeo.gadomancy.common.registration.RegisteredPotions;
|
||||
import makeo.gadomancy.common.utils.NBTHelper;
|
||||
import net.minecraft.entity.Entity;
|
||||
import net.minecraft.entity.EntityLivingBase;
|
||||
import net.minecraft.entity.item.EntityItem;
|
||||
import net.minecraft.entity.player.EntityPlayer;
|
||||
import net.minecraft.item.ItemStack;
|
||||
@@ -96,6 +100,12 @@ public class EventHandlerGolem {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if(!event.world.isRemote && event.entity instanceof EntityLivingBase) {
|
||||
if(((EntityLivingBase) event.entity).isPotionActive(RegisteredPotions.ACHROMATIC)) {
|
||||
((DataAchromatic) SyncDataHolder.getDataServer("AchromaticData")).handleApplication((EntityLivingBase) event.entity);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@SubscribeEvent(priority = EventPriority.LOWEST)
|
||||
|
||||
@@ -2,6 +2,7 @@ package makeo.gadomancy.common.events;
|
||||
|
||||
import cpw.mods.fml.common.eventhandler.SubscribeEvent;
|
||||
import cpw.mods.fml.common.gameevent.PlayerEvent;
|
||||
import makeo.gadomancy.common.data.DataAchromatic;
|
||||
import makeo.gadomancy.common.data.DataFamiliar;
|
||||
import makeo.gadomancy.common.data.SyncDataHolder;
|
||||
import makeo.gadomancy.common.network.PacketHandler;
|
||||
@@ -29,6 +30,7 @@ public class EventHandlerNetwork {
|
||||
if(!p.playerNetServerHandler.netManager.isLocalChannel()) {
|
||||
PacketHandler.INSTANCE.sendTo(new PacketUpdateGolemTypeOrder(GolemEnumHelper.getCurrentMapping()), p);
|
||||
((DataFamiliar) SyncDataHolder.getDataServer("FamiliarData")).checkPlayerEquipment(p);
|
||||
((DataAchromatic) SyncDataHolder.getDataServer("AchromaticData")).checkPotionEffect(p);
|
||||
SyncDataHolder.syncAllDataTo(p);
|
||||
PacketHandler.INSTANCE.sendTo(new PacketSyncConfigs(), p);
|
||||
}
|
||||
|
||||
@@ -1,5 +1,7 @@
|
||||
package makeo.gadomancy.common.potions;
|
||||
|
||||
import makeo.gadomancy.common.data.DataAchromatic;
|
||||
import makeo.gadomancy.common.data.SyncDataHolder;
|
||||
import net.minecraft.entity.EntityLivingBase;
|
||||
import net.minecraft.entity.ai.attributes.BaseAttributeMap;
|
||||
import thaumcraft.api.aspects.Aspect;
|
||||
@@ -22,13 +24,13 @@ public class PotionAchromatic extends PotionCustomTexture {
|
||||
public void applyAttributesModifiersToEntity(EntityLivingBase entity, BaseAttributeMap p_111185_2_, int p_111185_3_) {
|
||||
super.applyAttributesModifiersToEntity(entity, p_111185_2_, p_111185_3_);
|
||||
|
||||
|
||||
((DataAchromatic) SyncDataHolder.getDataServer("AchromaticData")).handleApplication(entity);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void removeAttributesModifiersFromEntity(EntityLivingBase entity, BaseAttributeMap p_111187_2_, int p_111187_3_) {
|
||||
super.removeAttributesModifiersFromEntity(entity, p_111187_2_, p_111187_3_);
|
||||
|
||||
|
||||
((DataAchromatic) SyncDataHolder.getDataServer("AchromaticData")).handleRemoval(entity);
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user