Skip to content
This repository has been archived by the owner on Mar 9, 2020. It is now read-only.

Commit

Permalink
Fixed #2
Browse files Browse the repository at this point in the history
  • Loading branch information
EdwinMindcraft committed Oct 5, 2016
1 parent 96456d1 commit 65a33a0
Show file tree
Hide file tree
Showing 10 changed files with 59 additions and 45 deletions.
2 changes: 1 addition & 1 deletion build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ apply plugin: 'net.minecraftforge.gradle.forge'
sourceCompatibility = JavaVersion.VERSION_1_8
targetCompatibility = JavaVersion.VERSION_1_8

version = "2.0.1"
version = "2.0.2"
group= "am2" // http://maven.apache.org/guides/mini/guide-naming-conventions.html
archivesBaseName = "ArsMagica2"

Expand Down
2 changes: 1 addition & 1 deletion src/main/java/am2/api/extensions/IDataSyncExtension.java
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ public void readNBT(Capability<IDataSyncExtension> capability, IDataSyncExtensio
* @param data
* @param defaultValue
*/
public <T> void register(SavedObject<T> data, T defaultValue);
public <T> void setWithSync(SavedObject<T> data, T defaultValue);
public byte[] createUpdatePacket();
public void handleUpdatePacket(AMDataReader in);

Expand Down
10 changes: 5 additions & 5 deletions src/main/java/am2/extensions/AffinityData.java
Original file line number Diff line number Diff line change
Expand Up @@ -60,11 +60,11 @@ public void init(EntityPlayer entity, IDataSyncExtension ext) {
for (Affinity DEPTH : ArsMagicaAPI.getAffinityRegistry().getValues())
map.put(DEPTH, 0D);
map.put(Affinity.NONE, 0D);
ext.register(DataDefinitions.AFFINITY_DATA, map);
ext.register(DataDefinitions.ABILITY_BOOLEAN, new HashMap<>());
ext.register(DataDefinitions.ABILITY_FLOAT, new HashMap<>());
ext.register(DataDefinitions.DIMINISHING_RETURNS, 1.0F);
ext.register(DataDefinitions.COOLDOWNS, new HashMap<>());
ext.setWithSync(DataDefinitions.AFFINITY_DATA, map);
ext.setWithSync(DataDefinitions.ABILITY_BOOLEAN, new HashMap<>());
ext.setWithSync(DataDefinitions.ABILITY_FLOAT, new HashMap<>());
ext.setWithSync(DataDefinitions.DIMINISHING_RETURNS, 1.0F);
ext.setWithSync(DataDefinitions.COOLDOWNS, new HashMap<>());
}

@Override
Expand Down
56 changes: 28 additions & 28 deletions src/main/java/am2/extensions/EntityExtension.java
Original file line number Diff line number Diff line change
Expand Up @@ -327,36 +327,36 @@ public AMVector2 getOriginalSize(){
public void init(EntityLivingBase entity, IDataSyncExtension ext) {
this.addEntityReference(entity);
if (this.entity instanceof EntityPlayer) {
ext.register(CURRENT_LEVEL, 0);
ext.register(CURRENT_MANA, 0F);
ext.register(CURRENT_MANA_FATIGUE, 0F);
ext.register(CURRENT_XP, 0F);
ext.register(CURRENT_SUMMONS, 0);
ext.setWithSync(CURRENT_LEVEL, 0);
ext.setWithSync(CURRENT_MANA, 0F);
ext.setWithSync(CURRENT_MANA_FATIGUE, 0F);
ext.setWithSync(CURRENT_XP, 0F);
ext.setWithSync(CURRENT_SUMMONS, 0);
} else {
ext.register(CURRENT_LEVEL, 0);
ext.register(CURRENT_MANA, 100F);
ext.register(CURRENT_MANA_FATIGUE, 0F);
ext.register(CURRENT_XP, 0F);
ext.register(CURRENT_SUMMONS, 0);
ext.setWithSync(CURRENT_LEVEL, 0);
ext.setWithSync(CURRENT_MANA, 100F);
ext.setWithSync(CURRENT_MANA_FATIGUE, 0F);
ext.setWithSync(CURRENT_XP, 0F);
ext.setWithSync(CURRENT_SUMMONS, 0);
}
ext.register(HEAL_COOLDOWN, 0);
ext.register(AFFINITY_HEAL_COOLDOWN, 0);
ext.register(MARK_X, 0D);
ext.register(MARK_Y, 0D);
ext.register(MARK_Z, 0D);
ext.register(MARK_DIMENSION, -512);
ext.register(CONTENGENCY_STACK, Optional.absent());
ext.register(CONTENGENCY_TYPE, "NULL");
ext.register(FALL_PROTECTION, 0.0f);
ext.register(IS_INVERTED, false);
ext.register(IS_SHRUNK, false);
ext.register(FLIP_ROTATION, 0.0f);
ext.register(PREV_FLIP_ROTATION, 0.0f);
ext.register(SHRINK_PCT, 0.0f);
ext.register(PREV_SHRINK_PCT, 0.0f);
ext.register(TK_DISTANCE, 8.0f);
ext.register(DataDefinitions.DISABLE_GRAVITY, false);
ext.register(MANA_SHIELD, 0f);
ext.setWithSync(HEAL_COOLDOWN, 0);
ext.setWithSync(AFFINITY_HEAL_COOLDOWN, 0);
ext.setWithSync(MARK_X, 0D);
ext.setWithSync(MARK_Y, 0D);
ext.setWithSync(MARK_Z, 0D);
ext.setWithSync(MARK_DIMENSION, -512);
ext.setWithSync(CONTENGENCY_STACK, Optional.absent());
ext.setWithSync(CONTENGENCY_TYPE, "NULL");
ext.setWithSync(FALL_PROTECTION, 0.0f);
ext.setWithSync(IS_INVERTED, false);
ext.setWithSync(IS_SHRUNK, false);
ext.setWithSync(FLIP_ROTATION, 0.0f);
ext.setWithSync(PREV_FLIP_ROTATION, 0.0f);
ext.setWithSync(SHRINK_PCT, 0.0f);
ext.setWithSync(PREV_SHRINK_PCT, 0.0f);
ext.setWithSync(TK_DISTANCE, 8.0f);
ext.setWithSync(DataDefinitions.DISABLE_GRAVITY, false);
ext.setWithSync(MANA_SHIELD, 0f);
}

@Override
Expand Down
8 changes: 4 additions & 4 deletions src/main/java/am2/extensions/SkillData.java
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ public void unlockSkill (String name) {
setSkillPoint(skill.getPoint(), getSkillPoint(skill.getPoint()) - 1);
HashMap<Skill, Boolean> map = DataSyncExtension.For(player).get(DataDefinitions.SKILL);
map.put(skill, true);
DataSyncExtension.For(player).set(DataDefinitions.SKILL, map);
DataSyncExtension.For(player).setWithSync(DataDefinitions.SKILL, map);
}

public HashMap<SkillPoint, Integer> getSkillPoints() {
Expand All @@ -95,7 +95,7 @@ public int getSkillPoint(SkillPoint skill) {
public void setSkillPoint(SkillPoint point, int num) {
HashMap<SkillPoint, Integer> map = DataSyncExtension.For(player).get(DataDefinitions.POINT_TIER);
map.put(point, num);
DataSyncExtension.For(player).set(DataDefinitions.POINT_TIER, map);
DataSyncExtension.For(player).setWithSync(DataDefinitions.POINT_TIER, map);
}

public void init(EntityPlayer entity, IDataSyncExtension ext) {
Expand All @@ -109,8 +109,8 @@ public void init(EntityPlayer entity, IDataSyncExtension ext) {
pointMap.put(aff, 0);
}
pointMap.put(SkillPoint.SKILL_POINT_1, 3);
ext.register(DataDefinitions.SKILL, skillMap);
ext.register(DataDefinitions.POINT_TIER, pointMap);
ext.setWithSync(DataDefinitions.SKILL, skillMap);
ext.setWithSync(DataDefinitions.POINT_TIER, pointMap);
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -57,12 +57,13 @@ public <T> T get(SavedObject<T> data) {
public <T> void set(SavedObject<T> data, T object) {
fillWithNull(data.getId());
Object checkObj = internalData.get(data.getId());
hasChanged.set(data.getId(), object != null && !object.equals(checkObj));
boolean isSame = object != null && !object.equals(checkObj);
hasChanged.set(data.getId(), isSame);
internalData.set(data.getId(), object);
}

@Override
public <T> void register(SavedObject<T> data, T defaultValue) {
public <T> void setWithSync(SavedObject<T> data, T defaultValue) {
fillWithNull(data.getId());
hasChanged.set(data.getId(), true);
internalData.set(data.getId(), defaultValue);
Expand Down
7 changes: 4 additions & 3 deletions src/main/java/am2/gui/GuiOcculus.java
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,9 @@
import am2.extensions.AffinityData;
import am2.extensions.SkillData;
import am2.gui.controls.GuiButtonSkillTree;
import am2.lore.ArcaneCompendium;
import am2.packet.AMDataWriter;
import am2.packet.AMNetHandler;
import am2.packet.AMPacketIDs;
import am2.texture.SpellIconManager;
import am2.utils.RenderUtils;
import net.minecraft.client.Minecraft;
Expand Down Expand Up @@ -102,8 +104,7 @@ protected void mouseClicked(int mouseX, int mouseY, int mouseButton) throws IOEx
if (hoverItem != null && !SkillData.For(player).hasSkill(hoverItem.getID())) {
ISkillData data = SkillData.For(player);
if (data.canLearn(hoverItem.getID())) {
data.unlockSkill(hoverItem.getID());
ArcaneCompendium.For(player).unlockEntry(hoverItem.getID());
AMNetHandler.INSTANCE.sendPacketToServer(AMPacketIDs.UNLOCK_OCCULUS_ENTRY, new AMDataWriter().add(hoverItem.getID()).generate());
}
}
else if (this.currentTree != SkillDefs.TREE_AFFINITY)
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/am2/lore/ArcaneCompendium.java
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ public boolean isUnlocked(String name) {

public void init(EntityPlayer player, IDataSyncExtension ext) {
this.player = player;
ext.register(DataDefinitions.COMPENDIUM, new ArrayList<String>());
ext.setWithSync(DataDefinitions.COMPENDIUM, new ArrayList<String>());
}

public static IArcaneCompendium For(EntityPlayer entityPlayer) {
Expand Down
1 change: 1 addition & 0 deletions src/main/java/am2/packet/AMPacketIDs.java
Original file line number Diff line number Diff line change
Expand Up @@ -50,4 +50,5 @@ public class AMPacketIDs{
public static final byte MANA_LINK_UPDATE = 60;
public static final byte PLAYER_FLIP = 61;
public static final byte SYNC_CLIENT = 62;
public static final byte UNLOCK_OCCULUS_ENTRY = 63;
}
11 changes: 11 additions & 0 deletions src/main/java/am2/packet/AMPacketProcessorServer.java
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,9 @@
import am2.container.ContainerSpellCustomization;
import am2.defs.ItemDefs;
import am2.extensions.EntityExtension;
import am2.extensions.SkillData;
import am2.items.ItemSpellBook;
import am2.lore.ArcaneCompendium;
import am2.power.PowerNodeRegistry;
import am2.utils.SpellUtils;
import io.netty.buffer.ByteBufInputStream;
Expand Down Expand Up @@ -111,6 +113,8 @@ public void onServerPacketData(ServerCustomPacketEvent event){
case AMPacketIDs.PLAYER_FLIP:
handlePlayerFlip(remaining, player);
break;
case AMPacketIDs.UNLOCK_OCCULUS_ENTRY:
handleOcculusUnlock(remaining, player);
}
}catch (Throwable t){
LogHelper.error("Server Packet Failed to Handle!");
Expand All @@ -126,6 +130,13 @@ public void onServerPacketData(ServerCustomPacketEvent event){
}
}

private void handleOcculusUnlock(byte[] remaining, EntityPlayerMP player) {
String str = new AMDataReader(remaining, false).getString();
System.out.println(str);
SkillData.For(player).unlockSkill(str);
ArcaneCompendium.For(player).unlockEntry(str);
}

private void handlePlayerFlip(byte[] remaining, EntityPlayerMP player) {
EntityExtension.For(player).setInverted(new AMDataReader(remaining, false).getBoolean());
}
Expand Down

0 comments on commit 65a33a0

Please sign in to comment.