forked from MobiusFlip/CrimsonRevelations
-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
3cf9c53
commit 450745a
Showing
7 changed files
with
119 additions
and
44 deletions.
There are no files selected for viewing
69 changes: 69 additions & 0 deletions
69
src/main/java/mod/icarus/crimsonrevelations/events/CRClientEvents.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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
77
src/main/java/mod/icarus/crimsonrevelations/events/CREvents.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | ||
} | ||
} | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
6 changes: 6 additions & 0 deletions
6
src/main/resources/assets/crimsonrevelations/models/item/runic_girdle_kinetic.json
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
{ | ||
"parent": "item/generated", | ||
"textures": { | ||
"layer0": "crimsonrevelations:items/runic_girdle_kinetic" | ||
} | ||
} |
Binary file added
BIN
+981 Bytes
...ain/resources/assets/crimsonrevelations/textures/items/runic_girdle_kinetic.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
5 changes: 5 additions & 0 deletions
5
src/main/resources/assets/crimsonrevelations/textures/items/runic_girdle_kinetic.png.mcmeta
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
{ | ||
"animation": { | ||
"frametime": 2 | ||
} | ||
} |