diff options
author | bartimaeusnek <33183715+bartimaeusnek@users.noreply.github.com> | 2021-03-10 18:21:44 +0100 |
---|---|---|
committer | bartimaeusnek <33183715+bartimaeusnek@users.noreply.github.com> | 2021-03-10 18:21:44 +0100 |
commit | f03e907ac73d92bfaf5948e1cae7848675439497 (patch) | |
tree | 194d69bd2c9e62813da4c74e49ba7ab968c79bc6 /src/main/java/gregtech/api/util | |
parent | 2d7fe3783011c605a90cf48c04bb575e0e75a72b (diff) | |
download | GT5-Unofficial-f03e907ac73d92bfaf5948e1cae7848675439497.tar.gz GT5-Unofficial-f03e907ac73d92bfaf5948e1cae7848675439497.tar.bz2 GT5-Unofficial-f03e907ac73d92bfaf5948e1cae7848675439497.zip |
Refactor World Events
World events have way to many parameters, so the code gets unreadable, this commit fixes that behavior.
Diffstat (limited to 'src/main/java/gregtech/api/util')
-rw-r--r-- | src/main/java/gregtech/api/util/GT_FoodStat.java | 7 | ||||
-rw-r--r-- | src/main/java/gregtech/api/util/PositionedWorldEvent.java | 144 |
2 files changed, 149 insertions, 2 deletions
diff --git a/src/main/java/gregtech/api/util/GT_FoodStat.java b/src/main/java/gregtech/api/util/GT_FoodStat.java index d0fe9bdbf4..da3b220845 100644 --- a/src/main/java/gregtech/api/util/GT_FoodStat.java +++ b/src/main/java/gregtech/api/util/GT_FoodStat.java @@ -68,7 +68,8 @@ public class GT_FoodStat implements IFoodStat { ItemStack tStack = GT_OreDictUnificator.get(GT_Utility.copy(mEmptyContainer)); if (tStack != null && !aPlayer.inventory.addItemStackToInventory(tStack)) aPlayer.dropPlayerItemWithRandomChoice(tStack, true); - aPlayer.worldObj.playSoundAtEntity(aPlayer, "random.burp", 0.5F, aPlayer.worldObj.rand.nextFloat() * 0.1F + 0.9F); + PositionedWorldEvent<Object> event = new PositionedWorldEvent<>(aPlayer.worldObj, "random.burp"); + event.playSoundAtEntity(aPlayer,0.5F, aPlayer.worldObj.rand.nextFloat() * 0.1F + 0.9F); if (!aPlayer.worldObj.isRemote) { if (mMilk) { aPlayer.curePotionEffects(new ItemStack(Items.milk_bucket, 1, 0)); @@ -79,7 +80,9 @@ public class GT_FoodStat implements IFoodStat { } } if (mExplosive) { - aPlayer.worldObj.newExplosion(aPlayer, aPlayer.posX, aPlayer.posY, aPlayer.posZ, 4, true, true); + event.setThing(aPlayer); + event.setPosition(aPlayer.posX, aPlayer.posY, aPlayer.posZ); + event.newExplosion(4,true, true); aPlayer.attackEntityFrom(GT_DamageSources.getExplodingDamage(), Float.MAX_VALUE); } } diff --git a/src/main/java/gregtech/api/util/PositionedWorldEvent.java b/src/main/java/gregtech/api/util/PositionedWorldEvent.java new file mode 100644 index 0000000000..ce5543b320 --- /dev/null +++ b/src/main/java/gregtech/api/util/PositionedWorldEvent.java @@ -0,0 +1,144 @@ +package gregtech.api.util; + +import net.minecraft.entity.Entity; +import net.minecraft.entity.player.EntityPlayer; +import net.minecraft.util.Vec3; +import net.minecraft.world.World; + +@SuppressWarnings("unused") +public class PositionedWorldEvent<T> { + + public PositionedWorldEvent() {} + + public PositionedWorldEvent(World world) { + this.world = world; + } + + public PositionedWorldEvent(Vec3 position) { + this.position = position; + } + + public PositionedWorldEvent(T thing) { + this.thing = thing; + } + + public PositionedWorldEvent(World world, T thing) { + this(world); + this.thing = thing; + } + + public PositionedWorldEvent(World world, Vec3 position) { + this(world); + this.position = position; + } + + public PositionedWorldEvent(Vec3 position, T thing) { + this(position); + this.thing = thing; + } + + public PositionedWorldEvent(T thing, Vec3 position) { + this(position, thing); + } + + public PositionedWorldEvent(World world, Vec3 position, T thing) { + this(world, position); + this.thing = thing; + } + + public PositionedWorldEvent(World world, T thing, Vec3 position) { + this(world, position, thing); + } + + private World world; + private Vec3 position; + private T thing; + + public World getWorld() { + return world; + } + + public void setWorld(World world) { + this.world = world; + } + + public Vec3 getPosition() { + return position; + } + + public void setPosition(Vec3 position) { + this.position = position; + } + + public void setPosition(double x, double y, double z) { + this.position = Vec3.createVectorHelper(x, y, z); + } + + public T getThing() { + return thing; + } + + public void setThing(T thing) { + this.thing = thing; + } + + public void spawnParticle(double motionX, double motionY, double motionZ) { + if (position == null || !(thing instanceof String) || world == null) + return; + + world.spawnParticle((String) thing, position.xCoord, position.yCoord, position.zCoord, motionX, motionY, motionZ); + } + + public void playSoundEffect(float volume, float pitch) { + if (position == null || !(thing instanceof String) || world == null) + return; + + world.playSoundEffect(position.xCoord, position.yCoord, position.zCoord, (String) thing, volume, pitch); + } + + public void playRecord() { + if (position == null || !(thing instanceof String) || world == null) + return; + + world.playRecord((String) thing, (int) position.xCoord, (int) position.yCoord, (int) position.zCoord); + } + + public void playSound(float volume, float pitch, boolean proximity) { + if (position == null || !(thing instanceof String) || world == null) + return; + + world.playSound(position.xCoord, position.yCoord, position.zCoord, (String) thing, volume, pitch, proximity); + } + + public void createExplosion(float strength, boolean isSmoking) { + newExplosion(strength, false, isSmoking); + } + + public void newExplosion(float strength, boolean isFlaming, boolean isSmoking) { + if (position == null || world == null) + return; + + world.newExplosion((Entity) thing, position.xCoord, position.yCoord, position.zCoord, strength, isFlaming, isSmoking); + } + + public boolean extinguishFire(int side) { + if (position == null || world == null) + return false; + + return world.extinguishFire((EntityPlayer) thing, (int) position.xCoord, (int) position.yCoord, (int) position.zCoord, side); + } + + public void playSoundAtEntity(Entity entity, float volume, float pitch) { + if (!(thing instanceof String)) { + return; + } + world.playSoundAtEntity(entity, (String) thing, volume, pitch); + } + + public void playSoundToNearExcept(EntityPlayer player, float volume, float pitch) { + if (!(thing instanceof String)) { + return; + } + world.playSoundToNearExcept(player, (String) thing, volume, pitch); + } +}
\ No newline at end of file |