Search in sources :

Example 1 with UpgradeEntry

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;
}
Also used : ISoldierUpgradeInst(de.sanandrew.mods.claysoldiers.api.soldier.upgrade.ISoldierUpgradeInst) ISoldierUpgrade(de.sanandrew.mods.claysoldiers.api.soldier.upgrade.ISoldierUpgrade) UpgradeEntry(de.sanandrew.mods.claysoldiers.registry.upgrade.UpgradeEntry)

Example 2 with UpgradeEntry

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()));
            }
        }
    }
}
Also used : ISoldierUpgradeInst(de.sanandrew.mods.claysoldiers.api.soldier.upgrade.ISoldierUpgradeInst) UpgradeEntry(de.sanandrew.mods.claysoldiers.registry.upgrade.UpgradeEntry)

Example 3 with UpgradeEntry

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));
        }
    }
}
Also used : UpgradeEntry(de.sanandrew.mods.claysoldiers.registry.upgrade.UpgradeEntry) UUID(java.util.UUID)

Example 4 with UpgradeEntry

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);
            }
        }
    }
}
Also used : NBTTagCompound(net.minecraft.nbt.NBTTagCompound) UpgradeEntry(de.sanandrew.mods.claysoldiers.registry.upgrade.UpgradeEntry)

Example 5 with UpgradeEntry

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;
    }
}
Also used : ISoldierUpgrade(de.sanandrew.mods.claysoldiers.api.soldier.upgrade.ISoldierUpgrade) ISoldierUpgradeInst(de.sanandrew.mods.claysoldiers.api.soldier.upgrade.ISoldierUpgradeInst) UpgradeEntry(de.sanandrew.mods.claysoldiers.registry.upgrade.UpgradeEntry)

Aggregations

UpgradeEntry (de.sanandrew.mods.claysoldiers.registry.upgrade.UpgradeEntry)6 ISoldierUpgradeInst (de.sanandrew.mods.claysoldiers.api.soldier.upgrade.ISoldierUpgradeInst)3 ISoldierUpgrade (de.sanandrew.mods.claysoldiers.api.soldier.upgrade.ISoldierUpgrade)2 ISoldierEffectInst (de.sanandrew.mods.claysoldiers.api.soldier.effect.ISoldierEffectInst)1 PacketSyncEffects (de.sanandrew.mods.claysoldiers.network.packet.PacketSyncEffects)1 PacketSyncUpgrades (de.sanandrew.mods.claysoldiers.network.packet.PacketSyncUpgrades)1 UUID (java.util.UUID)1 NBTTagCompound (net.minecraft.nbt.NBTTagCompound)1