use of com.cjm721.overloaded.storage.IGenericDataStorage in project Overloaded by CJ-MC-Mods.
the class ItemRailGun method handleFireMessage.
public void handleFireMessage(@Nonnull ServerPlayerEntity player, @Nonnull RailGunFireMessage message) {
ItemStack itemStack = player.getItemInHand(message.hand);
if (itemStack.getItem() != this) {
return;
}
LazyOptional<IEnergyStorage> opEnergy = itemStack.getCapability(ENERGY);
if (!opEnergy.isPresent()) {
Overloaded.logger.warn("RailGun has no Energy Capability? NBT: " + itemStack.getTag());
return;
}
IEnergyStorage energy = opEnergy.orElseThrow(() -> new RuntimeException("Impossible Condition"));
LazyOptional<IGenericDataStorage> opSettingCapability = itemStack.getCapability(GENERIC_DATA_STORAGE);
if (!opSettingCapability.isPresent()) {
Overloaded.logger.warn("RailGun has no GenericData Capability? NBT: " + itemStack.getTag());
return;
}
IGenericDataStorage settingCapability = opSettingCapability.orElseThrow(() -> new RuntimeException("Impossible Condition"));
settingCapability.suggestUpdate();
int energyRequired = settingCapability.getIntegerMap().getOrDefault(RAILGUN_POWER_KEY, OverloadedConfig.INSTANCE.railGun.minEnergy);
if (energy.getEnergyStored() < energyRequired) {
player.displayClientMessage(new StringTextComponent("Not enough power to fire."), true);
return;
}
int energyExtracted = energy.extractEnergy(energyRequired, false);
@Nullable Entity entity = player.level.getEntity(message.id);
if (entity == null || !entity.isAlive()) {
return;
} else if (player.distanceTo(entity) > OverloadedConfig.INSTANCE.rayGun.maxRange) {
player.displayClientMessage(new StringTextComponent("Target out of range."), true);
} else if (entity.hurt(DamageSource.playerAttack(player), (float) (OverloadedConfig.INSTANCE.railGun.damagePerRF * energyExtracted))) {
Vector3d knockback = message.moveVector.scale(energyExtracted * OverloadedConfig.INSTANCE.railGun.knockbackPerRF);
entity.push(knockback.x, knockback.y, knockback.z);
}
}
use of com.cjm721.overloaded.storage.IGenericDataStorage in project Overloaded by CJ-MC-Mods.
the class ArmorEventHandler method getHelmetDataStorage.
@Nonnull
private static IGenericDataStorage getHelmetDataStorage(PlayerEntity player) {
for (ItemStack stack : player.inventory.armor) {
if (stack.getItem() instanceof ItemMultiHelmet) {
IGenericDataStorage cap = stack.getCapability(GENERIC_DATA_STORAGE).orElse(new GenericDataStorage());
cap.suggestUpdate();
return cap;
}
}
return new GenericDataStorage();
}
use of com.cjm721.overloaded.storage.IGenericDataStorage in project Overloaded by CJ-MC-Mods.
the class ArmorEventHandler method setNoClip.
public static void setNoClip(PlayerEntity player, boolean enabled) {
IGenericDataStorage storage = getPlayerDataStorage(player);
final Map<String, Boolean> booleans = storage.getBooleanMap();
booleans.put(noClip, enabled);
}
use of com.cjm721.overloaded.storage.IGenericDataStorage in project Overloaded by CJ-MC-Mods.
the class ArmorEventHandler method toggleNoClip.
public static boolean toggleNoClip(ServerPlayerEntity player) {
IGenericDataStorage storage = getPlayerDataStorage(player);
final Map<String, Boolean> booleans = storage.getBooleanMap();
if (booleans.containsKey(noClip) && booleans.get(noClip)) {
booleans.remove(noClip);
return false;
} else {
booleans.put(noClip, true);
return true;
}
}
use of com.cjm721.overloaded.storage.IGenericDataStorage in project Overloaded by CJ-MC-Mods.
the class ArmorEventHandler method onPlayerTickEvent.
@SubscribeEvent
public void onPlayerTickEvent(@Nonnull TickEvent.PlayerTickEvent event) {
PlayerEntity player = event.player;
if (player == null || player.dead)
return;
IGenericDataStorage playerDataStorage = getPlayerDataStorage(player);
if (isMultiArmorSetEquipped(player) && hasEnergy(player)) {
IGenericDataStorage armorDataStorage = getHelmetDataStorage(player);
Map<String, Boolean> armorBooleans = armorDataStorage.getBooleanMap();
playerDataStorage.getBooleanMap().put(set, true);
AttributeModifier modifier = player.getAttribute(Attributes.MAX_HEALTH).getModifier(HEALTH_MODIFIER);
if (modifier == null) {
player.getAttribute(Attributes.MAX_HEALTH).addTransientModifier(new AttributeModifier(HEALTH_MODIFIER, "Max Health", 100, AttributeModifier.Operation.ADDITION));
}
if (armorBooleans.getOrDefault(DataKeys.FLIGHT, Default.FLIGHT)) {
tryEnableFlight(player, playerDataStorage, armorDataStorage, event.side);
} else {
disableFlight(player, event.side);
}
if (armorBooleans.getOrDefault(DataKeys.FEED, Default.FEED)) {
tryFeedPlayer(player, event.side);
}
if (armorBooleans.getOrDefault(DataKeys.HEAL, Default.HEAL)) {
tryHealPlayer(player, event.side);
}
if (armorBooleans.getOrDefault(DataKeys.REMOVE_HARMFUL, Default.REMOVE_HARMFUL)) {
tryRemoveHarmful(player, event.side);
}
if (armorBooleans.getOrDefault(DataKeys.EXTINGUISH, Default.EXTINGUISH)) {
tryExtinguish(player, event.side);
}
if (armorBooleans.getOrDefault(DataKeys.GIVE_AIR, Default.GIVE_AIR)) {
tryGiveAir(player, event.side);
}
tryGroundSpeed(player, armorDataStorage, event.side);
} else {
Map<String, Boolean> boolMap = playerDataStorage.getBooleanMap();
if (boolMap.containsKey(set) && boolMap.get(set)) {
boolMap.put(set, false);
disableFlight(player, event.side);
disableNoClip(player, playerDataStorage);
disableGroundSpeed(player, event.side);
player.getAttribute(Attributes.MAX_HEALTH).removeModifier(HEALTH_MODIFIER);
player.setHealth(Math.min(player.getHealth(), player.getMaxHealth()));
}
}
}
Aggregations