Skip to content

Commit

Permalink
Add Kinetic Girdle of Shielding
Browse files Browse the repository at this point in the history
  • Loading branch information
IcarussOne committed Aug 28, 2024
1 parent 3cf9c53 commit 450745a
Show file tree
Hide file tree
Showing 7 changed files with 119 additions and 44 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
package mod.icarus.crimsonrevelations.events;

import mod.icarus.crimsonrevelations.NewCrimsonRevelations;
import mod.icarus.crimsonrevelations.item.CRItemBow;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.item.Item;
import net.minecraftforge.client.event.FOVUpdateEvent;
import net.minecraftforge.fml.common.Mod.EventBusSubscriber;
import net.minecraftforge.fml.common.eventhandler.SubscribeEvent;
import net.minecraftforge.fml.common.registry.GameRegistry;
import net.minecraftforge.fml.relauncher.Side;
import net.minecraftforge.fml.relauncher.SideOnly;

@SideOnly(Side.CLIENT)
@EventBusSubscriber(modid = NewCrimsonRevelations.MODID)
@GameRegistry.ObjectHolder(NewCrimsonRevelations.MODID)
public class CRClientEvents {
// Courtesy of NeRdTheNed
@SubscribeEvent
public void FOV(FOVUpdateEvent event) {
final EntityPlayer eventPlayer = event.getEntity();
final Item eventItem = eventPlayer.getActiveItemStack().getItem();

if (eventItem instanceof CRItemBow) {
float finalFov = event.getFov();
final float itemUseCount = ((CRItemBow) eventItem).getMaxItemUseDuration(eventPlayer.getActiveItemStack()) - eventPlayer.getItemInUseCount();
/*
* First, we have to reverse the standard bow zoom.
* Minecraft helpfully applies the standard bow zoom
* to any item that is an instance of a ItemBow.
* However, our custom bows draw back at different speeds,
* so the standard zoom is not at the right speed.
* To compensate for this, we just calculate the standard bow zoom,
* and apply it in reverse.
*/
float realBow = itemUseCount / 20.0F;

if (realBow > 1.0F) {
realBow = 1.0F;
} else {
realBow *= realBow;
}

/*
* Minecraft uses finalFov *= 1.0F - (realBow * 0.15F)
* to calculate the standard bow zoom.
* To reverse this, we just divide it instead.
*/
finalFov /= 1.0F - (realBow * 0.15F);
/*
* We now calculate and apply our custom bow zoom.
* The only difference between standard bow zoom and custom bow zoom
* is that we change the hardcoded value of 20.0F to
* whatever drawTime is.
*/
float drawTime = 20 * ((CRItemBow) eventItem).drawTimeMult;
float customBow = itemUseCount / drawTime;

if (customBow > 1.0F) {
customBow = 1.0F;
} else {
customBow *= customBow;
}

finalFov *= 1.0F - (customBow * 0.15F);
event.setNewfov(finalFov);
}
}
}
77 changes: 34 additions & 43 deletions src/main/java/mod/icarus/crimsonrevelations/events/CREvents.java
Original file line number Diff line number Diff line change
@@ -1,66 +1,57 @@
package mod.icarus.crimsonrevelations.events;

import java.util.List;

import baubles.api.BaublesApi;
import mod.icarus.crimsonrevelations.NewCrimsonRevelations;
import mod.icarus.crimsonrevelations.init.CRItems;
import mod.icarus.crimsonrevelations.item.CRItemBow;
import net.minecraft.entity.Entity;
import net.minecraft.entity.EntityLivingBase;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.item.Item;
import net.minecraft.item.ItemStack;
import net.minecraft.stats.StatList;
import net.minecraft.util.SoundCategory;
import net.minecraft.world.World;
import net.minecraftforge.client.event.FOVUpdateEvent;
import net.minecraftforge.event.entity.living.LivingHurtEvent;
import net.minecraftforge.fml.common.Mod.EventBusSubscriber;
import net.minecraftforge.fml.common.eventhandler.SubscribeEvent;
import net.minecraftforge.fml.common.registry.GameRegistry;
import thaumcraft.common.lib.SoundsTC;
import thaumcraft.common.lib.events.PlayerEvents;

@EventBusSubscriber(modid = NewCrimsonRevelations.MODID)
@GameRegistry.ObjectHolder(NewCrimsonRevelations.MODID)
public class CREvents {
// Courtesy of NeRdTheNed
@SubscribeEvent
public void FOV(FOVUpdateEvent event) {
final EntityPlayer eventPlayer = event.getEntity();
final Item eventItem = eventPlayer.getActiveItemStack().getItem();
public static void onHurtEvent(LivingHurtEvent event) {
World world = event.getEntity().world;
Entity source = event.getSource().getTrueSource();

if (eventItem instanceof CRItemBow) {
float finalFov = event.getFov();
final float itemUseCount = ((CRItemBow) eventItem).getMaxItemUseDuration(eventPlayer.getActiveItemStack()) - eventPlayer.getItemInUseCount();
/*
* First, we have to reverse the standard bow zoom.
* Minecraft helpfully applies the standard bow zoom
* to any item that is an instance of a ItemBow.
* However, our custom bows draw back at different speeds,
* so the standard zoom is not at the right speed.
* To compensate for this, we just calculate the standard bow zoom,
* and apply it in reverse.
*/
float realBow = itemUseCount / 20.0F;
if (event.getEntityLiving() instanceof EntityPlayer && source instanceof EntityLivingBase && !world.isRemote) {
EntityPlayer player = (EntityPlayer) event.getEntityLiving();
int charge = (int) player.getAbsorptionAmount();

if (realBow > 1.0F) {
realBow = 1.0F;
} else {
realBow *= realBow;
}
if (charge > 0) {
if (BaublesApi.isBaubleEquipped(player, CRItems.runicGirdleKinetic) > 0 && !(player.getCooldownTracker().hasCooldown(CRItems.runicGirdleKinetic))) {
player.world.playSound(null, player.posX, player.posY, player.posZ, SoundsTC.poof, SoundCategory.PLAYERS, 1.0F, 1.0F + (float) player.getEntityWorld().rand.nextGaussian() * 0.05F);
player.world.createExplosion(player, player.posX, player.posY + player.height / 2.0F, player.posZ, 2.0F, false);

/*
* Minecraft uses finalFov *= 1.0F - (realBow * 0.15F)
* to calculate the standard bow zoom.
* To reverse this, we just divide it instead.
*/
finalFov /= 1.0F - (realBow * 0.15F);
/*
* We now calculate and apply our custom bow zoom.
* The only difference between standard bow zoom and custom bow zoom
* is that we change the hardcoded value of 20.0F to
* whatever drawTime is.
*/
float drawTime = 20 * ((CRItemBow) eventItem).drawTimeMult;
float customBow = itemUseCount / drawTime;
List<Entity> entities = player.world.getEntitiesWithinAABBExcludingEntity(player, player.getEntityBoundingBox().grow(3.0D, 3.0D, 3.0D));

if (customBow > 1.0F) {
customBow = 1.0F;
} else {
customBow *= customBow;
}
for (Entity entity : entities) {
if (entity instanceof EntityLivingBase) {
EntityLivingBase mob = (EntityLivingBase) entity;
mob.knockBack(player, 2.0F, player.posX - mob.posX, player.posZ - mob.posZ);
}
}

finalFov *= 1.0F - (customBow * 0.15F);
event.setNewfov(finalFov);
((EntityPlayer) player).addStat(StatList.getObjectUseStats(CRItems.runicGirdleKinetic));
((EntityPlayer) player).getCooldownTracker().setCooldown(CRItems.runicGirdleKinetic, 15 * 20);
}
}
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,8 @@ public class CRItems {
public static Item runicAmulet;
@GameRegistry.ObjectHolder("runic_girdle")
public static Item runicGirdle;
@GameRegistry.ObjectHolder("runic_girdle_kinetic")
public static Item runicGirdleKinetic;
@GameRegistry.ObjectHolder("runic_ring")
public static Item runicRing;

Expand Down Expand Up @@ -101,7 +103,8 @@ public static void registerItems(@Nonnull final RegistryEvent.Register<Item> eve

CRRegistry.setup(new CRItemRunicBauble(BaubleType.RING, EnumRarity.UNCOMMON, 5), "runic_ring"),
CRRegistry.setup(new CRItemRunicBauble(BaubleType.AMULET, EnumRarity.UNCOMMON, 8), "runic_amulet"),
CRRegistry.setup(new CRItemRunicBauble(BaubleType.BELT, EnumRarity.UNCOMMON, 10), "runic_girdle")
CRRegistry.setup(new CRItemRunicBauble(BaubleType.BELT, EnumRarity.UNCOMMON, 10), "runic_girdle"),
CRRegistry.setup(new CRItemRunicBauble(BaubleType.BELT, EnumRarity.RARE, 9), "runic_girdle_kinetic")
);

// Item Blocks
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ item.crimsonrevelations.ordo_arrow.name=Ordo Arrow
item.crimsonrevelations.perditio_arrow.name=Perditio Arrow
item.crimsonrevelations.runic_amulet.name=Amulet of Runic Shielding
item.crimsonrevelations.runic_girdle.name=Belt of Runic Shielding
item.crimsonrevelations.runic_girdle_kinetic.name=Kinetic Girdle of Shielding
item.crimsonrevelations.runic_ring.name=Ring of Runic Shielding
item.crimsonrevelations.terra_arrow.name=Terra Arrow

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
{
"parent": "item/generated",
"textures": {
"layer0": "crimsonrevelations:items/runic_girdle_kinetic"
}
}
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{
"animation": {
"frametime": 2
}
}

0 comments on commit 450745a

Please sign in to comment.