use of de.sanandrew.mods.claysoldiers.registry.upgrade.UpgradeEntry in project ClaySoldiersMod by SanAndreasP.
the class EntityClaySoldier method addUpgrade.
@Override
public ISoldierUpgradeInst addUpgrade(ISoldierUpgrade upgrade, EnumUpgradeType type, @Nonnull ItemStack stack) {
if (upgrade == null) {
return null;
}
ISoldierUpgradeInst upgInst = new SoldierUpgrade(upgrade, type, stack.copy().splitStack(1));
this.addUpgradeInternal(upgInst);
upgrade.onAdded(this, stack, upgInst);
this.callUpgradeFunc(EnumUpgFunctions.ON_UPGRADE_ADDED, upgInstCl -> upgInstCl.getUpgrade().onUpgradeAdded(this, upgInstCl, upgInst));
if (upgrade.syncData() && !this.world.isRemote) {
this.sendSyncUpgrades(true, new UpgradeEntry(upgrade, type));
}
return upgInst;
}
use of de.sanandrew.mods.claysoldiers.registry.upgrade.UpgradeEntry in project ClaySoldiersMod by SanAndreasP.
the class EntityClaySoldier method destroyUpgrade.
@Override
public void destroyUpgrade(ISoldierUpgrade upgrade, EnumUpgradeType type, boolean silent) {
UpgradeEntry entry = new UpgradeEntry(upgrade, type);
ISoldierUpgradeInst inst = this.upgradeMap.get(entry);
if (inst != null) {
this.upgradeMap.remove(entry);
this.upgradeSyncList.remove(inst);
this.upgradeFuncMap.forEach((key, val) -> {
if (Arrays.asList(UpgradeRegistry.getFuncCalls(upgrade)).contains(key)) {
val.get(upgrade.getPriority()).remove(inst);
}
});
switch(upgrade.getType(this)) {
case MAIN_HAND:
this.setMainhandUpg(false);
break;
case OFF_HAND:
this.setOffhandUpg(false);
break;
case BEHAVIOR:
this.setBehaviorUpg(false);
break;
}
upgrade.onDestroyed(this, inst);
this.callUpgradeFunc(EnumUpgFunctions.ON_OTHR_DESTROYED, othrInst -> othrInst.getUpgrade().onUpgradeDestroyed(this, othrInst, inst));
if (!this.world.isRemote) {
if (upgrade.syncData()) {
this.sendSyncUpgrades(false, new UpgradeEntry(upgrade, type));
}
}
if (!silent) {
if (this.world.isRemote || !upgrade.syncData()) {
ClaySoldiersMod.proxy.spawnParticle(EnumParticle.ITEM_BREAK, this.world.provider.getDimension(), this.posX, this.posY + this.getEyeHeight(), this.posZ, Item.getIdFromItem(inst.getSavedStack().getItem()));
}
}
}
}
use of de.sanandrew.mods.claysoldiers.registry.upgrade.UpgradeEntry in project ClaySoldiersMod by SanAndreasP.
the class PacketSyncUpgrades method toBytes.
@Override
public void toBytes(ByteBuf buf) {
buf.writeBoolean(this.add);
buf.writeInt(this.soldierId);
buf.writeInt(this.upgrades.length);
for (UpgradeEntry upg : upgrades) {
UUID id = UpgradeRegistry.INSTANCE.getId(upg.upgrade);
ByteBufUtils.writeUTF8String(buf, MiscUtils.defIfNull(id, UuidUtils.EMPTY_UUID).toString());
buf.writeByte(upg.type.ordinal());
if (this.add && this.upgradeNBT.containsKey(upg)) {
upg.upgrade.writeSyncData(buf, this.upgradeNBT.get(upg));
}
}
}
use of de.sanandrew.mods.claysoldiers.registry.upgrade.UpgradeEntry in project ClaySoldiersMod by SanAndreasP.
the class PacketSyncUpgrades method fromBytes.
@Override
public void fromBytes(ByteBuf buf) {
this.add = buf.readBoolean();
this.soldierId = buf.readInt();
this.upgrades = new UpgradeEntry[buf.readInt()];
for (int i = 0; i < this.upgrades.length; i++) {
String idStr = ByteBufUtils.readUTF8String(buf);
if (UuidUtils.isStringUuid(idStr)) {
this.upgrades[i] = new UpgradeEntry(UpgradeRegistry.INSTANCE.getUpgrade(UUID.fromString(idStr)), EnumUpgradeType.VALUES[buf.readByte()]);
if (this.add && this.upgrades[i].upgrade.syncNbtData()) {
NBTTagCompound newNbt = new NBTTagCompound();
this.upgrades[i].upgrade.readSyncData(buf, newNbt);
this.upgradeNBT.put(this.upgrades[i], newNbt);
}
}
}
}
use of de.sanandrew.mods.claysoldiers.registry.upgrade.UpgradeEntry in project ClaySoldiersMod by SanAndreasP.
the class EntityClaySoldier method addUpgradeInternal.
private void addUpgradeInternal(ISoldierUpgradeInst instance) {
ISoldierUpgrade upgrade = instance.getUpgrade();
UpgradeEntry entry = new UpgradeEntry(upgrade, upgrade.getType(this));
this.upgradeMap.put(entry, instance);
if (upgrade.syncData()) {
this.upgradeSyncList.add(instance);
}
Arrays.asList(UpgradeRegistry.getFuncCalls(upgrade)).forEach(func -> {
Queue<ISoldierUpgradeInst> upgList = this.upgradeFuncMap.get(func).computeIfAbsent(upgrade.getPriority(), k -> new ConcurrentLinkedQueue<>());
upgList.add(instance);
});
switch(upgrade.getType(this)) {
case MAIN_HAND:
this.setMainhandUpg(true);
break;
case OFF_HAND:
this.setOffhandUpg(true);
break;
case BEHAVIOR:
this.setBehaviorUpg(true);
break;
}
}
Aggregations