mirror of
https://github.com/GTNewHorizons/ThaumicTinkerer.git
synced 2026-11-28 16:06:07 +00:00
123 lines
4.8 KiB
Java
123 lines
4.8 KiB
Java
package thaumic.tinkerer.common.potion;
|
|
|
|
import java.util.HashMap;
|
|
import java.util.Iterator;
|
|
import java.util.Random;
|
|
|
|
import net.minecraft.entity.Entity;
|
|
import net.minecraft.entity.player.EntityPlayer;
|
|
import net.minecraft.init.Blocks;
|
|
import net.minecraftforge.event.entity.living.LivingAttackEvent;
|
|
|
|
import cpw.mods.fml.common.eventhandler.SubscribeEvent;
|
|
import cpw.mods.fml.common.gameevent.TickEvent;
|
|
import cpw.mods.fml.relauncher.Side;
|
|
import thaumic.tinkerer.common.ThaumicTinkerer;
|
|
|
|
public final class PotionEffectHandlerClient {
|
|
|
|
private final HashMap<Entity, Long> airPotionHitClient = new HashMap<>();
|
|
private final HashMap<Entity, Long> firePotionHitClient = new HashMap<>();
|
|
|
|
@SubscribeEvent
|
|
public void onLivingHurt(LivingAttackEvent e) {
|
|
if (e.source.getSourceOfDamage() instanceof EntityPlayer p && p.worldObj.isRemote) {
|
|
if (p.isPotionActive(ModPotions.potionAir)) {
|
|
airPotionHitClient.put(e.entity, e.entity.worldObj.getTotalWorldTime());
|
|
}
|
|
if (p.isPotionActive(ModPotions.potionFire)) {
|
|
firePotionHitClient.put(e.entity, e.entity.worldObj.getTotalWorldTime());
|
|
}
|
|
if (p.isPotionActive(ModPotions.potionEarth)) {
|
|
boolean xAxis = Math.abs(e.entity.posZ - p.posZ) < Math.abs(e.entity.posX - p.posX);
|
|
int centerX = (int) ((e.entity.posX + p.posX) / 2);
|
|
|
|
int centerY = (int) (p.posY + 2);
|
|
int centerZ = (int) ((e.entity.posZ + p.posZ) / 2);
|
|
|
|
for (int i = -2; i < 3; i++) {
|
|
for (int j = -2; j < 3; j++) {
|
|
if (xAxis) {
|
|
ThaumicTinkerer.tcProxy
|
|
.blockSparkle(p.worldObj, centerX, centerY + i, centerZ + j, 100, 100);
|
|
} else {
|
|
ThaumicTinkerer.tcProxy
|
|
.blockSparkle(p.worldObj, centerX + j, centerY + i, centerZ, 100, 100);
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
@SubscribeEvent
|
|
public void onPlayerTick(TickEvent.PlayerTickEvent e) {
|
|
if (e.side == Side.CLIENT && e.player.isPotionActive(ModPotions.potionWater)) {
|
|
for (int x = (int) (e.player.posX - 2); x < e.player.posX + 2; x++) {
|
|
for (int y = (int) (e.player.posY - 2); y < e.player.posY + 2; y++) {
|
|
for (int z = (int) (e.player.posZ - 2); z < e.player.posZ + 2; z++) {
|
|
if (e.player.worldObj.getBlock(x, y, z) == Blocks.lava
|
|
|| e.player.worldObj.getBlock(x, y, z) == Blocks.flowing_lava) {
|
|
ThaumicTinkerer.tcProxy.burst(e.player.worldObj, x + .5, y + .5, z + .5, 1.2F);
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
@SubscribeEvent
|
|
public void onTickClient(TickEvent.ClientTickEvent e) {
|
|
|
|
Iterator<Entity> iter = airPotionHitClient.keySet().iterator();
|
|
while (iter.hasNext()) {
|
|
Entity target = iter.next();
|
|
if (target.isEntityAlive()) {
|
|
if (target.worldObj.getTotalWorldTime() % 5 == 0) {
|
|
ThaumicTinkerer.tcProxy.burst(target.worldObj, target.posX, target.posY, target.posZ, .5F);
|
|
}
|
|
}
|
|
if (target.worldObj.getTotalWorldTime() > airPotionHitClient.get(target) + 20) {
|
|
iter.remove();
|
|
}
|
|
}
|
|
|
|
iter = firePotionHitClient.keySet().iterator();
|
|
while (iter.hasNext()) {
|
|
Entity target = iter.next();
|
|
if (target.isEntityAlive()) {
|
|
if (target.worldObj.getTotalWorldTime() % 5 == 0) {
|
|
Random rand = new Random();
|
|
|
|
for (int i = 0; i < 30; i++) {
|
|
double theta = rand.nextFloat() * 2 * Math.PI;
|
|
|
|
double phi = rand.nextFloat() * 2 * Math.PI;
|
|
double r = 2.5;
|
|
|
|
double x = r * Math.sin(theta) * Math.cos(phi);
|
|
|
|
double y = r * Math.sin(theta) * Math.sin(phi);
|
|
|
|
double z = r * Math.cos(theta);
|
|
|
|
ThaumicTinkerer.tcProxy.wispFX2(
|
|
target.worldObj,
|
|
target.posX + x,
|
|
target.posY + y + 1,
|
|
target.posZ + z,
|
|
.1F,
|
|
4,
|
|
true,
|
|
true,
|
|
1F);
|
|
}
|
|
}
|
|
}
|
|
if (target.worldObj.getTotalWorldTime() > firePotionHitClient.get(target) + 6000) {
|
|
iter.remove();
|
|
}
|
|
}
|
|
}
|
|
}
|