Skip to content

Commit

Permalink
Added new effect for Atem's Protection & fixed issues with all artifa…
Browse files Browse the repository at this point in the history
…cts doing something on block
  • Loading branch information
GirafiStudios committed Mar 7, 2021
1 parent 1f02d45 commit 2cc4bb5
Show file tree
Hide file tree
Showing 5 changed files with 126 additions and 39 deletions.
Original file line number Diff line number Diff line change
@@ -1,21 +1,88 @@
package com.teammetallurgy.atum.items.artifacts.atem;

import com.teammetallurgy.atum.Atum;
import com.teammetallurgy.atum.api.God;
import com.teammetallurgy.atum.api.IArtifact;
import com.teammetallurgy.atum.init.AtumItems;
import com.teammetallurgy.atum.init.AtumParticles;
import com.teammetallurgy.atum.items.tools.AtumShieldItem;
import it.unimi.dsi.fastutil.objects.Object2BooleanMap;
import it.unimi.dsi.fastutil.objects.Object2BooleanOpenHashMap;
import it.unimi.dsi.fastutil.objects.Object2IntMap;
import it.unimi.dsi.fastutil.objects.Object2IntOpenHashMap;
import net.minecraft.entity.Entity;
import net.minecraft.entity.LivingEntity;
import net.minecraft.item.Item;
import net.minecraft.item.ItemStack;
import net.minecraft.item.Rarity;
import net.minecraft.world.World;
import net.minecraft.world.server.ServerWorld;
import net.minecraftforge.event.entity.living.LivingEvent;
import net.minecraftforge.event.entity.living.LivingHurtEvent;
import net.minecraftforge.eventbus.api.SubscribeEvent;
import net.minecraftforge.fml.common.Mod;

import javax.annotation.Nonnull;

@Mod.EventBusSubscriber(modid = Atum.MOD_ID)
public class AtemsProtectionItem extends AtumShieldItem implements IArtifact {
private static final Object2BooleanMap<LivingEntity> IS_BLOCKING = new Object2BooleanOpenHashMap<>();
protected static final Object2IntMap<LivingEntity> TIMER = new Object2IntOpenHashMap<>();

public AtemsProtectionItem() {
super(500, new Item.Properties().rarity(Rarity.RARE));
super(600, new Item.Properties().rarity(Rarity.RARE));
this.setRepairItem(AtumItems.NEBU_INGOT);
}

@Override
public God getGod() {
return God.ATEM;
}

@Override
public void onUse(@Nonnull World world, @Nonnull LivingEntity livingEntity, @Nonnull ItemStack stack, int count) {
super.onUse(world, livingEntity, stack, count);
IS_BLOCKING.putIfAbsent(livingEntity, true);
}

@Override
public void onPlayerStoppedUsing(@Nonnull ItemStack stack, @Nonnull World world, @Nonnull LivingEntity livingEntity, int timeLeft) {
super.onPlayerStoppedUsing(stack, world, livingEntity, timeLeft);
IS_BLOCKING.removeBoolean(livingEntity);
}

@SubscribeEvent
public static void onLivingTick(LivingEvent.LivingUpdateEvent event) {
if (TIMER.containsKey(event.getEntityLiving())) {
LivingEntity livingEntity = event.getEntityLiving();
int timer = TIMER.getInt(livingEntity);
if (timer == 0) {
TIMER.removeInt(livingEntity);
}

if (timer > 0) {
TIMER.replace(livingEntity, timer - 1);
}
}
}

@SubscribeEvent
public static void onLivingDamage(LivingHurtEvent event) {
Entity source = event.getSource().getImmediateSource();
LivingEntity livingEntity = event.getEntityLiving();
if (source instanceof LivingEntity && IS_BLOCKING.containsKey(livingEntity) && IS_BLOCKING.getBoolean(livingEntity)) {
if (random.nextDouble() <= 0.20D) {
TIMER.put(livingEntity, 200);
if (livingEntity.world instanceof ServerWorld) {
ServerWorld serverWorld = (ServerWorld) livingEntity.world;
serverWorld.spawnParticle(AtumParticles.LIGHT_SPARKLE, livingEntity.getPosX(), livingEntity.getPosY() + 1.0D, livingEntity.getPosZ(), 40, 0.1D, 0.0D, 0.1D, 0.01D);
}
}
IS_BLOCKING.removeBoolean(livingEntity);
}

if (TIMER.containsKey(livingEntity)) {
event.setAmount(0.0F);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -6,22 +6,26 @@
import com.teammetallurgy.atum.init.AtumItems;
import com.teammetallurgy.atum.init.AtumParticles;
import com.teammetallurgy.atum.items.tools.AtumShieldItem;
import it.unimi.dsi.fastutil.objects.Object2BooleanMap;
import it.unimi.dsi.fastutil.objects.Object2BooleanOpenHashMap;
import net.minecraft.entity.CreatureAttribute;
import net.minecraft.entity.Entity;
import net.minecraft.entity.LivingEntity;
import net.minecraft.entity.player.PlayerEntity;
import net.minecraft.item.Item;
import net.minecraft.item.ItemStack;
import net.minecraft.item.Rarity;
import net.minecraft.util.DamageSource;
import net.minecraft.world.World;
import net.minecraft.world.server.ServerWorld;
import net.minecraftforge.event.entity.living.LivingEntityUseItemEvent;
import net.minecraftforge.event.entity.living.LivingHurtEvent;
import net.minecraftforge.eventbus.api.SubscribeEvent;
import net.minecraftforge.fml.common.Mod;

import javax.annotation.Nonnull;

@Mod.EventBusSubscriber(modid = Atum.MOD_ID)
public class NepthysConsecrationItem extends AtumShieldItem implements IArtifact {
private static boolean isBlocking = false;
private static final Object2BooleanMap<LivingEntity> IS_BLOCKING = new Object2BooleanOpenHashMap<>();

public NepthysConsecrationItem() {
super(500, new Item.Properties().rarity(Rarity.RARE));
Expand All @@ -33,26 +37,30 @@ public God getGod() {
return God.NEPTHYS;
}

@SubscribeEvent
public static void onUse(LivingEntityUseItemEvent.Tick event) {
LivingEntity entity = event.getEntityLiving();
if (entity instanceof PlayerEntity && entity.getHeldItem(entity.getActiveHand()).getItem() == AtumItems.ATEMS_PROTECTION) {
isBlocking = true;
}
@Override
public void onUse(@Nonnull World world, @Nonnull LivingEntity livingEntity, @Nonnull ItemStack stack, int count) {
super.onUse(world, livingEntity, stack, count);
IS_BLOCKING.putIfAbsent(livingEntity, true);
}

@Override
public void onPlayerStoppedUsing(@Nonnull ItemStack stack, @Nonnull World world, @Nonnull LivingEntity livingEntity, int timeLeft) {
super.onPlayerStoppedUsing(stack, world, livingEntity, timeLeft);
IS_BLOCKING.removeBoolean(livingEntity);
}

@SubscribeEvent
public static void onHurt(LivingHurtEvent event) {
Entity source = event.getSource().getImmediateSource();
if (source instanceof LivingEntity && isBlocking && ((LivingEntity) source).getCreatureAttribute() == CreatureAttribute.UNDEAD /*&& random.nextFloat() <= 0.50F*/) {
LivingEntity entity = event.getEntityLiving();
LivingEntity livingEntity = event.getEntityLiving();
if (source instanceof LivingEntity && IS_BLOCKING.containsKey(livingEntity) && ((LivingEntity) source).getCreatureAttribute() == CreatureAttribute.UNDEAD /*&& random.nextFloat() <= 0.50F*/) {
source.setFire(8);
source.attackEntityFrom(DamageSource.GENERIC, 2.0F);
if (entity.world instanceof ServerWorld) {
ServerWorld serverWorld = (ServerWorld) entity.world;
serverWorld.spawnParticle(AtumParticles.LIGHT_SPARKLE, entity.getPosX(), entity.getPosY() + 1.0D, entity.getPosZ(), 40, 0.1D, 0.0D, 0.1D, 0.01D);
if (livingEntity.world instanceof ServerWorld) {
ServerWorld serverWorld = (ServerWorld) livingEntity.world;
serverWorld.spawnParticle(AtumParticles.LIGHT_SPARKLE, livingEntity.getPosX(), livingEntity.getPosY() + 1.0D, livingEntity.getPosZ(), 40, 0.1D, 0.0D, 0.1D, 0.01D);
}
isBlocking = false;
IS_BLOCKING.removeBoolean(livingEntity);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@
import com.teammetallurgy.atum.init.AtumItems;
import com.teammetallurgy.atum.init.AtumParticles;
import com.teammetallurgy.atum.items.tools.KhopeshItem;
import it.unimi.dsi.fastutil.objects.Object2BooleanMap;
import it.unimi.dsi.fastutil.objects.Object2BooleanOpenHashMap;
import net.minecraft.entity.Entity;
import net.minecraft.entity.LivingEntity;
import net.minecraft.entity.player.PlayerEntity;
Expand All @@ -21,7 +23,6 @@
import net.minecraft.util.Hand;
import net.minecraft.world.World;
import net.minecraft.world.server.ServerWorld;
import net.minecraftforge.event.entity.living.LivingEntityUseItemEvent;
import net.minecraftforge.event.entity.living.LivingHurtEvent;
import net.minecraftforge.eventbus.api.SubscribeEvent;
import net.minecraftforge.fml.common.Mod;
Expand All @@ -32,7 +33,7 @@
@Mod.EventBusSubscriber(modid = Atum.MOD_ID)
public class NuitsIreItem extends KhopeshItem implements IArtifact {
private boolean isOffhand = false;
private static boolean isBlocking = false;
private static final Object2BooleanMap<LivingEntity> IS_BLOCKING = new Object2BooleanOpenHashMap<>();

public NuitsIreItem() {
super(AtumMats.NEBU, new Item.Properties().rarity(Rarity.RARE));
Expand Down Expand Up @@ -79,20 +80,25 @@ public boolean hitEntity(@Nonnull ItemStack stack, @Nonnull LivingEntity target,
return super.hitEntity(stack, target, attacker);
}

@SubscribeEvent
public static void onUse(LivingEntityUseItemEvent.Tick event) {
LivingEntity entity = event.getEntityLiving();
if (entity instanceof PlayerEntity && entity.getHeldItem(Hand.OFF_HAND).getItem() == AtumItems.NUITS_IRE) {
isBlocking = true;
}
@Override
public void onUse(@Nonnull World world, @Nonnull LivingEntity livingEntity, @Nonnull ItemStack stack, int count) {
super.onUse(world, livingEntity, stack, count);
IS_BLOCKING.putIfAbsent(livingEntity, true);
}

@Override
public void onPlayerStoppedUsing(@Nonnull ItemStack stack, @Nonnull World world, @Nonnull LivingEntity livingEntity, int timeLeft) {
super.onPlayerStoppedUsing(stack, world, livingEntity, timeLeft);
IS_BLOCKING.removeBoolean(livingEntity);
}

@SubscribeEvent
public static void onHurt(LivingHurtEvent event) {
Entity trueSource = event.getSource().getImmediateSource();
if (trueSource instanceof LivingEntity && event.getEntityLiving() instanceof PlayerEntity && isBlocking && random.nextFloat() <= 0.25F) {
LivingEntity livingEntity = event.getEntityLiving();
if (trueSource instanceof LivingEntity && livingEntity instanceof PlayerEntity && IS_BLOCKING.getBoolean(livingEntity) && random.nextFloat() <= 0.25F) {
applyWither((LivingEntity) trueSource, event.getEntityLiving(), event.getEntityLiving().getHeldItemMainhand().getItem() == AtumItems.NUITS_QUARTER);
isBlocking = false;
IS_BLOCKING.removeBoolean(livingEntity);
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@
import com.teammetallurgy.atum.init.AtumItems;
import com.teammetallurgy.atum.init.AtumParticles;
import com.teammetallurgy.atum.items.tools.KhopeshItem;
import it.unimi.dsi.fastutil.objects.Object2BooleanMap;
import it.unimi.dsi.fastutil.objects.Object2BooleanOpenHashMap;
import net.minecraft.entity.Entity;
import net.minecraft.entity.LivingEntity;
import net.minecraft.entity.player.PlayerEntity;
Expand All @@ -21,7 +23,6 @@
import net.minecraft.util.Hand;
import net.minecraft.world.World;
import net.minecraft.world.server.ServerWorld;
import net.minecraftforge.event.entity.living.LivingEntityUseItemEvent;
import net.minecraftforge.event.entity.living.LivingHurtEvent;
import net.minecraftforge.eventbus.api.SubscribeEvent;
import net.minecraftforge.fml.common.Mod;
Expand All @@ -32,7 +33,7 @@
@Mod.EventBusSubscriber(modid = Atum.MOD_ID)
public class NuitsQuarterItem extends KhopeshItem implements IArtifact {
private boolean isOffhand = false;
private static boolean isBlocking = false;
private static final Object2BooleanMap<LivingEntity> IS_BLOCKING = new Object2BooleanOpenHashMap<>();

public NuitsQuarterItem() {
super(AtumMats.NEBU, new Item.Properties().rarity(Rarity.RARE));
Expand Down Expand Up @@ -79,20 +80,25 @@ public boolean hitEntity(@Nonnull ItemStack stack, @Nonnull LivingEntity target,
return super.hitEntity(stack, target, attacker);
}

@SubscribeEvent
public static void onUse(LivingEntityUseItemEvent.Tick event) {
LivingEntity entity = event.getEntityLiving();
if (entity instanceof PlayerEntity && entity.getHeldItem(Hand.OFF_HAND).getItem() == AtumItems.NUITS_QUARTER) {
isBlocking = true;
}
@Override
public void onUse(@Nonnull World world, @Nonnull LivingEntity livingEntity, @Nonnull ItemStack stack, int count) {
super.onUse(world, livingEntity, stack, count);
IS_BLOCKING.putIfAbsent(livingEntity, true);
}

@Override
public void onPlayerStoppedUsing(@Nonnull ItemStack stack, @Nonnull World world, @Nonnull LivingEntity livingEntity, int timeLeft) {
super.onPlayerStoppedUsing(stack, world, livingEntity, timeLeft);
IS_BLOCKING.removeBoolean(livingEntity);
}

@SubscribeEvent
public static void onHurt(LivingHurtEvent event) {
Entity trueSource = event.getSource().getImmediateSource();
if (trueSource instanceof LivingEntity && event.getEntityLiving() instanceof PlayerEntity && isBlocking && random.nextFloat() <= 0.25F) {
LivingEntity livingEntity = event.getEntityLiving();
if (trueSource instanceof LivingEntity && livingEntity instanceof PlayerEntity && IS_BLOCKING.getBoolean(livingEntity) && random.nextFloat() <= 0.25F) {
applyWeakness((LivingEntity) trueSource, event.getEntityLiving(), event.getEntityLiving().getHeldItemMainhand().getItem() == AtumItems.NUITS_IRE);
isBlocking = false;
IS_BLOCKING.removeBoolean(livingEntity);
}
}

Expand Down
6 changes: 3 additions & 3 deletions src/main/resources/assets/atum/lang/en_us.json
Original file line number Diff line number Diff line change
Expand Up @@ -685,9 +685,9 @@
"atum.atems_will.tooltip.line2": "",
"atum.atems_will.tooltip.title": "TODO",

"atum.atems_protection.tooltip.line1": "",
"atum.atems_protection.tooltip.line2": "",
"atum.atems_protection.tooltip.title": "TODO",
"atum.atems_protection.tooltip.line1": "20% chance to negate all",
"atum.atems_protection.tooltip.line2": "damage for 10 seconds, when blocking",
"atum.atems_protection.tooltip.title": "Safeguard",

"atum.osiris_blessing.tooltip.line1": "Tilled ground is blessed,",
"atum.osiris_blessing.tooltip.line2": "with increased growth rate",
Expand Down

0 comments on commit 2cc4bb5

Please sign in to comment.