Skip to content

Commit

Permalink
1.13.1 - add map for identity ability cooldowns
Browse files Browse the repository at this point in the history
  • Loading branch information
Draylar committed Oct 9, 2021
1 parent 9443d3f commit e489d15
Show file tree
Hide file tree
Showing 19 changed files with 31 additions and 91 deletions.
2 changes: 1 addition & 1 deletion build.gradle
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
plugins {
id 'fabric-loom' version '0.5.9'
id 'fabric-loom' version '0.7-SNAPSHOT'
id 'maven-publish'
}

Expand Down
2 changes: 1 addition & 1 deletion gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ yarn_mappings=1.16.5+build.4
loader_version=0.11.1

# Mod Properties
mod_version=1.13.2
mod_version=1.13.3
maven_group=draylar
archives_base_name=identity

Expand Down
1 change: 0 additions & 1 deletion settings.gradle
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
pluginManagement {
repositories {
jcenter()
maven {
name = 'Fabric'
url = 'https://maven.fabricmc.net/'
Expand Down
7 changes: 7 additions & 0 deletions src/main/java/draylar/identity/Identity.java
Original file line number Diff line number Diff line change
Expand Up @@ -13,11 +13,13 @@
import net.fabricmc.api.ModInitializer;
import net.minecraft.advancement.Advancement;
import net.minecraft.advancement.AdvancementProgress;
import net.minecraft.entity.EntityType;
import net.minecraft.entity.LivingEntity;
import net.minecraft.entity.mob.GuardianEntity;
import net.minecraft.entity.mob.WaterCreatureEntity;
import net.minecraft.server.network.ServerPlayerEntity;
import net.minecraft.util.Identifier;
import net.minecraft.util.registry.Registry;

import java.util.List;

Expand Down Expand Up @@ -71,4 +73,9 @@ public static boolean hasFlyingPermissions(ServerPlayerEntity player) {
public static boolean isAquatic(LivingEntity entity) {
return entity instanceof WaterCreatureEntity || entity instanceof GuardianEntity;
}

public static int getCooldown(EntityType<?> type) {
String id = Registry.ENTITY_TYPE.getId(type).toString();
return CONFIG.abilityCooldownMap.getOrDefault(id, 20);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ public static void register() {
double d = client.getWindow().getScaleFactor();
int cd = Components.ABILITY.get(player).getCooldown();
float lerpedCooldown = MathHelper.lerp(delta, cd - 1, cd);
int max = identityAbility.getCooldown();
int max = AbilityRegistry.get(identity.getType()).getCooldown(identity);
float cooldownScale = 1 - cd / (float) max;

// CD has NOT updated since last tick. It is most likely full.
Expand Down
5 changes: 4 additions & 1 deletion src/main/java/draylar/identity/ability/IdentityAbility.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package draylar.identity.ability;

import draylar.identity.Identity;
import net.minecraft.entity.LivingEntity;
import net.minecraft.entity.player.PlayerEntity;
import net.minecraft.item.Item;
Expand All @@ -17,7 +18,9 @@ public abstract class IdentityAbility<E extends LivingEntity> {
/**
* @return cooldown of this ability, in ticks, after it is used.
*/
abstract public int getCooldown();
public int getCooldown(E entity) {
return Identity.getCooldown(entity.getType());
}

abstract public Item getIcon();
}
6 changes: 0 additions & 6 deletions src/main/java/draylar/identity/ability/impl/BlazeAbility.java
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
package draylar.identity.ability.impl;

import draylar.identity.Identity;
import draylar.identity.ability.IdentityAbility;
import net.minecraft.entity.mob.BlazeEntity;
import net.minecraft.entity.player.PlayerEntity;
Expand Down Expand Up @@ -30,11 +29,6 @@ public void onUse(PlayerEntity player, BlazeEntity identity, World world) {
world.playSoundFromEntity(null, player, SoundEvents.ENTITY_BLAZE_SHOOT, SoundCategory.HOSTILE, 2.0F, (world.random.nextFloat() - world.random.nextFloat()) * 0.2F + 1.0F);
}

@Override
public int getCooldown() {
return Identity.CONFIG.blazeAbilityCooldown;
}

@Override
public Item getIcon() {
return Items.BLAZE_POWDER;
Expand Down
5 changes: 0 additions & 5 deletions src/main/java/draylar/identity/ability/impl/CowAbility.java
Original file line number Diff line number Diff line change
Expand Up @@ -17,11 +17,6 @@ public void onUse(PlayerEntity player, CowEntity identity, World world) {
world.playSound(null, player.getX(), player.getY(), player.getZ(), SoundEvents.ENTITY_GENERIC_DRINK, SoundCategory.PLAYERS, 1.0F, 1.0F);
}

@Override
public int getCooldown() {
return 20 * 10;
}

@Override
public Item getIcon() {
return Items.MILK_BUCKET;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
package draylar.identity.ability.impl;

import draylar.identity.Identity;
import draylar.identity.ability.IdentityAbility;
import net.minecraft.entity.mob.CreeperEntity;
import net.minecraft.entity.player.PlayerEntity;
Expand All @@ -16,11 +15,6 @@ public void onUse(PlayerEntity player, CreeperEntity identity, World world) {
world.createExplosion(player, player.getX(), player.getY(), player.getZ(), 3.0f, Explosion.DestructionType.NONE);
}

@Override
public int getCooldown() {
return Identity.CONFIG.creeperAbilityCooldown;
}

@Override
public Item getIcon() {
return Items.TNT;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
package draylar.identity.ability.impl;

import draylar.identity.Identity;
import draylar.identity.ability.IdentityAbility;
import net.minecraft.entity.boss.dragon.EnderDragonEntity;
import net.minecraft.entity.player.PlayerEntity;
Expand All @@ -25,11 +24,6 @@ public void onUse(PlayerEntity player, EnderDragonEntity identity, World world)
world.spawnEntity(dragonFireball);
}

@Override
public int getCooldown() {
return Identity.CONFIG.dragonAbilityCooldown;
}

@Override
public Item getIcon() {
return Items.DRAGON_BREATH;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,12 +17,7 @@ public class EndermanAbility extends IdentityAbility<EndermanEntity> {
public void onUse(PlayerEntity player, EndermanEntity identity, World world) {
HitResult lookingAt = player.raycast(Identity.CONFIG.endermanAbilityTeleportDistance, 0, true);
player.requestTeleport(lookingAt.getPos().x, lookingAt.getPos().y, lookingAt.getPos().z);
player.playSound(SoundEvents.ENTITY_ENDERMAN_TELEPORT, SoundCategory.PLAYERS,1, 1);
}

@Override
public int getCooldown() {
return Identity.CONFIG.endermanAbilityCooldown;
player.playSound(SoundEvents.ENTITY_ENDERMAN_TELEPORT, SoundCategory.PLAYERS, 1, 1);
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@

import draylar.identity.ability.IdentityAbility;
import net.minecraft.entity.mob.EndermiteEntity;
import net.minecraft.entity.passive.FoxEntity;
import net.minecraft.entity.player.PlayerEntity;
import net.minecraft.item.Item;
import net.minecraft.item.Items;
Expand Down Expand Up @@ -41,11 +40,6 @@ public void onUse(PlayerEntity player, EndermiteEntity identity, World world) {
}
}

@Override
public int getCooldown() {
return 10 * 8;
}

@Override
public Item getIcon() {
return Items.CHORUS_FRUIT;
Expand Down
6 changes: 0 additions & 6 deletions src/main/java/draylar/identity/ability/impl/GhastAbility.java
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
package draylar.identity.ability.impl;

import draylar.identity.Identity;
import draylar.identity.ability.IdentityAbility;
import net.minecraft.entity.mob.GhastEntity;
import net.minecraft.entity.player.PlayerEntity;
Expand Down Expand Up @@ -30,11 +29,6 @@ public void onUse(PlayerEntity player, GhastEntity identity, World world) {
world.playSoundFromEntity(null, player, SoundEvents.ENTITY_GHAST_WARN, SoundCategory.HOSTILE, 10.0F, (world.random.nextFloat() - world.random.nextFloat()) * 0.2F + 1.0F);
}

@Override
public int getCooldown() {
return Identity.CONFIG.ghastAbilityCooldown;
}

@Override
public Item getIcon() {
return Items.FIRE_CHARGE;
Expand Down
5 changes: 0 additions & 5 deletions src/main/java/draylar/identity/ability/impl/LlamaAbility.java
Original file line number Diff line number Diff line change
Expand Up @@ -28,11 +28,6 @@ public void onUse(PlayerEntity player, LlamaEntity identity, World world) {
world.spawnEntity(spit);
}

@Override
public int getCooldown() {
return 10 * 5;
}

@Override
public Item getIcon() {
return Items.LEAD;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
package draylar.identity.ability.impl;

import draylar.identity.Identity;
import draylar.identity.ability.IdentityAbility;
import net.minecraft.entity.passive.SnowGolemEntity;
import net.minecraft.entity.player.PlayerEntity;
Expand Down Expand Up @@ -28,11 +27,6 @@ public void onUse(PlayerEntity player, SnowGolemEntity identity, World world) {
}
}

@Override
public int getCooldown() {
return Identity.CONFIG.snowGolemAbilityCooldown;
}

@Override
public Item getIcon() {
return Items.SNOWBALL;
Expand Down
5 changes: 0 additions & 5 deletions src/main/java/draylar/identity/ability/impl/WitchAbility.java
Original file line number Diff line number Diff line change
Expand Up @@ -34,11 +34,6 @@ public void onUse(PlayerEntity player, WitchEntity identity, World world) {
world.spawnEntity(potionEntity);
}

@Override
public int getCooldown() {
return 20 * 15;
}

@Override
public Item getIcon() {
return Items.POTION;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
package draylar.identity.ability.impl;

import draylar.identity.Identity;
import draylar.identity.ability.IdentityAbility;
import net.minecraft.entity.boss.WitherEntity;
import net.minecraft.entity.player.PlayerEntity;
Expand All @@ -27,11 +26,6 @@ public void onUse(PlayerEntity player, WitherEntity identity, World world) {
}
}

@Override
public int getCooldown() {
return Identity.CONFIG.witherAbilityCooldown;
}

@Override
public Item getIcon() {
return Items.WITHER_SKELETON_SKULL;
Expand Down
37 changes: 15 additions & 22 deletions src/main/java/draylar/identity/config/IdentityConfig.java
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,9 @@
import draylar.omegaconfig.api.Syncing;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

public class IdentityConfig implements Config {

Expand Down Expand Up @@ -74,30 +76,9 @@ public class IdentityConfig implements Config {
@Comment(value = "If set to false, only operators can switch identities. Used on the server; guaranteed to be authoritative.")
public boolean enableSwaps = true;

@Comment(value = "In ticks, how long until the Ghast can shoot a fireball again?")
public int ghastAbilityCooldown = 60;

@Comment(value = "In ticks, how long until the Blaze can shoot a mini fireball again?")
public int blazeAbilityCooldown = 20;

@Comment(value = "In ticks, how long until the Ender Dragon can shoot a dragon fireball again?")
public int dragonAbilityCooldown = 20;

@Comment(value = "In ticks, how long until the Enderman can teleport again?")
public int endermanAbilityCooldown = 100;

@Comment(value = "In blocks, how far can the Enderman ability teleport?")
public int endermanAbilityTeleportDistance = 32;

@Comment(value = "In ticks, how long until the Creeper can ka-boom again?")
public int creeperAbilityCooldown = 100;

@Comment(value = "In ticks, how long until the Wither can shoot a wither skull again?")
public int witherAbilityCooldown = 200;

@Comment(value = "Tick cooldown time of the Snow Golem ability")
public int snowGolemAbilityCooldown = 10;


@Syncing
@Comment(value = "Should player nametags render above players disguised with an identity? Note that the server is the authority for this config option.")
public boolean showPlayerNametag = false;
Expand All @@ -113,6 +94,18 @@ public class IdentityConfig implements Config {

public float flySpeed = 0.05f;

public Map<String, Integer> abilityCooldownMap = new HashMap<String, Integer>() {
{
put("minecraft:ghast", 60);
put("minecraft:blaze", 20);
put("minecraft:ender_dragon", 20);
put("minecraft:enderman", 100);
put("minecraft:creeper", 100);
put("minecraft:wither", 200);
put("minecraft:snow_golem", 10);
}
};

@Override
public String getName() {
return "identity";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ private static void registerUseAbilityPacketHandler() {
// Check cooldown
if(Components.ABILITY.get(player).canUseAbility()) {
AbilityRegistry.get(identityType).onUse(player, identity, player.world);
Components.ABILITY.get(player).setCooldown(AbilityRegistry.get(identityType).getCooldown());
Components.ABILITY.get(player).setCooldown(AbilityRegistry.get(identityType).getCooldown(identity));
}
}
}
Expand Down

0 comments on commit e489d15

Please sign in to comment.