aboutsummaryrefslogtreecommitdiff
path: root/src/main/java/gregtech/api
diff options
context:
space:
mode:
Diffstat (limited to 'src/main/java/gregtech/api')
-rw-r--r--src/main/java/gregtech/api/interfaces/tileentity/IEnergyConnected.java11
-rw-r--r--src/main/java/gregtech/api/metatileentity/MetaPipeEntity.java11
-rw-r--r--src/main/java/gregtech/api/metatileentity/implementations/GT_MetaPipeEntity_Fluid.java21
-rw-r--r--src/main/java/gregtech/api/metatileentity/implementations/GT_MetaTileEntity_BasicMachine_Bronze.java28
-rw-r--r--src/main/java/gregtech/api/metatileentity/implementations/GT_MetaTileEntity_BasicMachine_GT_Recipe.java19
-rw-r--r--src/main/java/gregtech/api/metatileentity/implementations/GT_MetaTileEntity_Hatch_Muffler.java23
-rw-r--r--src/main/java/gregtech/api/util/GT_FoodStat.java22
-rw-r--r--src/main/java/gregtech/api/util/PositionedWorldEvent.java172
-rw-r--r--src/main/java/gregtech/api/util/WorldSpawnedEventBuilder.java602
9 files changed, 688 insertions, 221 deletions
diff --git a/src/main/java/gregtech/api/interfaces/tileentity/IEnergyConnected.java b/src/main/java/gregtech/api/interfaces/tileentity/IEnergyConnected.java
index 813f31e62f..3a8bbdfd70 100644
--- a/src/main/java/gregtech/api/interfaces/tileentity/IEnergyConnected.java
+++ b/src/main/java/gregtech/api/interfaces/tileentity/IEnergyConnected.java
@@ -3,11 +3,10 @@ package gregtech.api.interfaces.tileentity;
import cofh.api.energy.IEnergyReceiver;
import gregtech.GT_Mod;
import gregtech.api.GregTech_API;
-import gregtech.api.util.PositionedWorldEvent;
+import gregtech.api.util.WorldSpawnedEventBuilder;
import gregtech.api.util.GT_Utility;
import gregtech.common.GT_Pollution;
import ic2.api.energy.tile.IEnergySink;
-import net.minecraft.entity.Entity;
import net.minecraft.init.Blocks;
import net.minecraft.tileentity.TileEntity;
import net.minecraft.world.World;
@@ -115,9 +114,11 @@ public interface IEnergyConnected extends IColoredTileEntity, IHasWorldObjectAnd
if (GT_Mod.gregtechproxy.mPollution)
GT_Pollution.addPollution(tWorld.getChunkFromBlockCoords(tX, tZ), 100000);
- new PositionedWorldEvent<>(tWorld)
- .setPosition(tX + 0.5, tY + 0.5, tZ + 0.5)
- .createExplosion(tStrength, true);
+ new WorldSpawnedEventBuilder.ExplosionEffectEventBuilder()
+ .setStrength(tStrength)
+ .setSmoking(true)
+ .setPosition(tX + 0.5, tY + 0.5, tZ + 0.5)
+ .setWorld(tWorld);
}
}
}
diff --git a/src/main/java/gregtech/api/metatileentity/MetaPipeEntity.java b/src/main/java/gregtech/api/metatileentity/MetaPipeEntity.java
index 4459b2203a..0716d84bd6 100644
--- a/src/main/java/gregtech/api/metatileentity/MetaPipeEntity.java
+++ b/src/main/java/gregtech/api/metatileentity/MetaPipeEntity.java
@@ -9,7 +9,7 @@ import gregtech.api.interfaces.tileentity.IColoredTileEntity;
import gregtech.api.interfaces.tileentity.ICoverable;
import gregtech.api.interfaces.tileentity.IGregTechTileEntity;
import gregtech.api.objects.GT_ItemStack;
-import gregtech.api.util.PositionedWorldEvent;
+import gregtech.api.util.WorldSpawnedEventBuilder;
import gregtech.api.util.GT_Config;
import gregtech.api.util.GT_CoverBehavior;
import gregtech.api.util.GT_LanguageManager;
@@ -699,9 +699,12 @@ public abstract class MetaPipeEntity implements IMetaTileEntity, IConnectable {
World tWorld = getBaseMetaTileEntity().getWorld();
tWorld.setBlock(tX, tY, tZ, Blocks.air);
if (GregTech_API.sMachineExplosions){
- new PositionedWorldEvent<>(tWorld)
- .setPosition(tX + 0.5, tY + 0.5, tZ + 0.5)
- .createExplosion(tStrength, true);
+ new WorldSpawnedEventBuilder.ExplosionEffectEventBuilder()
+ .setStrength(tStrength)
+ .setSmoking(true)
+ .setPosition(tX + 0.5, tY + 0.5, tZ + 0.5)
+ .setWorld(tWorld)
+ .run();
}
}
diff --git a/src/main/java/gregtech/api/metatileentity/implementations/GT_MetaPipeEntity_Fluid.java b/src/main/java/gregtech/api/metatileentity/implementations/GT_MetaPipeEntity_Fluid.java
index 8e0c010995..59011d27a8 100644
--- a/src/main/java/gregtech/api/metatileentity/implementations/GT_MetaPipeEntity_Fluid.java
+++ b/src/main/java/gregtech/api/metatileentity/implementations/GT_MetaPipeEntity_Fluid.java
@@ -17,7 +17,7 @@ import gregtech.api.objects.GT_RenderedTexture;
import gregtech.api.util.GT_CoverBehavior;
import gregtech.api.util.GT_Log;
import gregtech.api.util.GT_Utility;
-import gregtech.api.util.PositionedWorldEvent;
+import gregtech.api.util.WorldSpawnedEventBuilder;
import gregtech.common.GT_Client;
import gregtech.common.covers.GT_Cover_Drain;
import gregtech.common.covers.GT_Cover_FluidRegulator;
@@ -446,16 +446,21 @@ public class GT_MetaPipeEntity_Fluid extends MetaPipeEntity {
if (aIndex == 9) {
GT_Utility.doSoundAtClient(GregTech_API.sSoundList.get(4), 5, 1.0F, aX, aY, aZ);
- new PositionedWorldEvent<>(getBaseMetaTileEntity().getWorld(), "largesmoke")
- .times(6, (x, i) -> x.setPosition(
+ new WorldSpawnedEventBuilder.ParticleEventBuilder()
+ .setIdentifier("largesmoke")
+ .setWorld(getBaseMetaTileEntity().getWorld())
+ .<WorldSpawnedEventBuilder.ParticleEventBuilder>times(6, (x, i) -> x
+ .setMotion(
+ ForgeDirection.getOrientation(i).offsetX / 5.0,
+ ForgeDirection.getOrientation(i).offsetY / 5.0,
+ ForgeDirection.getOrientation(i).offsetZ / 5.0
+ )
+ .setPosition(
aX - 0.5 + XSTR_INSTANCE.nextFloat(),
aY - 0.5 + XSTR_INSTANCE.nextFloat(),
aZ - 0.5 + XSTR_INSTANCE.nextFloat()
- ).spawnParticle(
- ForgeDirection.getOrientation(i).offsetX / 5.0,
- ForgeDirection.getOrientation(i).offsetY / 5.0,
- ForgeDirection.getOrientation(i).offsetZ / 5.0
- ));
+ ).run()
+ );
}
}
diff --git a/src/main/java/gregtech/api/metatileentity/implementations/GT_MetaTileEntity_BasicMachine_Bronze.java b/src/main/java/gregtech/api/metatileentity/implementations/GT_MetaTileEntity_BasicMachine_Bronze.java
index 7d8d6dbba0..45df3c8d3c 100644
--- a/src/main/java/gregtech/api/metatileentity/implementations/GT_MetaTileEntity_BasicMachine_Bronze.java
+++ b/src/main/java/gregtech/api/metatileentity/implementations/GT_MetaTileEntity_BasicMachine_Bronze.java
@@ -8,7 +8,7 @@ import gregtech.api.objects.GT_ItemStack;
import gregtech.api.objects.GT_RenderedTexture;
import gregtech.api.util.GT_Log;
import gregtech.api.util.GT_Utility;
-import gregtech.api.util.PositionedWorldEvent;
+import gregtech.api.util.WorldSpawnedEventBuilder;
import net.minecraft.entity.EntityLivingBase;
import net.minecraft.nbt.NBTTagCompound;
import net.minecraft.util.AxisAlignedBB;
@@ -154,16 +154,22 @@ public abstract class GT_MetaTileEntity_BasicMachine_Bronze extends GT_MetaTileE
super.doSound(aIndex, aX, aY, aZ);
if (aIndex == 9) {
GT_Utility.doSoundAtClient(GregTech_API.sSoundList.get(4), 5, 1.0F, aX, aY, aZ);
- new PositionedWorldEvent<>(getBaseMetaTileEntity().getWorld(), "largesmoke")
- .times(8, x -> x.setPosition(
- aX - 0.5 + XSTR_INSTANCE.nextFloat(),
- aY - 0.5 + XSTR_INSTANCE.nextFloat(),
- aZ - 0.5 + XSTR_INSTANCE.nextFloat()
- ).spawnParticle(
- ForgeDirection.getOrientation(getBaseMetaTileEntity().getFrontFacing()).offsetX / 5.0,
- ForgeDirection.getOrientation(getBaseMetaTileEntity().getFrontFacing()).offsetY / 5.0,
- ForgeDirection.getOrientation(getBaseMetaTileEntity().getFrontFacing()).offsetZ / 5.0
- ));
+
+ new WorldSpawnedEventBuilder.ParticleEventBuilder()
+ .setIdentifier("largesmoke")
+ .setWorld(getBaseMetaTileEntity().getWorld())
+ .<WorldSpawnedEventBuilder.ParticleEventBuilder>times(8, x -> x
+ .setMotion(
+ ForgeDirection.getOrientation(getBaseMetaTileEntity().getFrontFacing()).offsetX / 5.0,
+ ForgeDirection.getOrientation(getBaseMetaTileEntity().getFrontFacing()).offsetY / 5.0,
+ ForgeDirection.getOrientation(getBaseMetaTileEntity().getFrontFacing()).offsetZ / 5.0
+ )
+ .setPosition(
+ aX - 0.5 + XSTR_INSTANCE.nextFloat(),
+ aY - 0.5 + XSTR_INSTANCE.nextFloat(),
+ aZ - 0.5 + XSTR_INSTANCE.nextFloat()
+ ).run()
+ );
}
}
diff --git a/src/main/java/gregtech/api/metatileentity/implementations/GT_MetaTileEntity_BasicMachine_GT_Recipe.java b/src/main/java/gregtech/api/metatileentity/implementations/GT_MetaTileEntity_BasicMachine_GT_Recipe.java
index c2e4fc441c..84b9fd9d5f 100644
--- a/src/main/java/gregtech/api/metatileentity/implementations/GT_MetaTileEntity_BasicMachine_GT_Recipe.java
+++ b/src/main/java/gregtech/api/metatileentity/implementations/GT_MetaTileEntity_BasicMachine_GT_Recipe.java
@@ -12,7 +12,7 @@ import gregtech.api.objects.GT_RenderedTexture;
import gregtech.api.util.GT_ModHandler;
import gregtech.api.util.GT_Recipe;
import gregtech.api.util.GT_Utility;
-import gregtech.api.util.PositionedWorldEvent;
+import gregtech.api.util.WorldSpawnedEventBuilder;
import ic2.core.Ic2Items;
import net.minecraft.entity.player.InventoryPlayer;
import net.minecraft.init.Blocks;
@@ -802,13 +802,16 @@ public class GT_MetaTileEntity_BasicMachine_GT_Recipe extends GT_MetaTileEntity_
if (aBaseMetaTileEntity.getFrontFacing() != 1 && aBaseMetaTileEntity.getCoverIDAtSide((byte) 1) == 0 && !aBaseMetaTileEntity.getOpacityAtSide((byte) 1)) {
Random tRandom = aBaseMetaTileEntity.getWorld().rand;
- new PositionedWorldEvent<>(aBaseMetaTileEntity.getWorld(), "smoke")
- .setPosition(
- aBaseMetaTileEntity.getXCoord() + 0.8F - tRandom.nextFloat() * 0.6F,
- aBaseMetaTileEntity.getYCoord() + 0.9F + tRandom.nextFloat() * 0.2F,
- aBaseMetaTileEntity.getZCoord() + 0.8F - tRandom.nextFloat() * 0.6F
- )
- .spawnParticle(0.0D, 0.0D, 0.0D);
+ new WorldSpawnedEventBuilder.ParticleEventBuilder()
+ .setMotion(0.0D, 0.0D, 0.0D)
+ .setIdentifier("smoke")
+ .setPosition(
+ aBaseMetaTileEntity.getXCoord() + 0.8F - tRandom.nextFloat() * 0.6F,
+ aBaseMetaTileEntity.getYCoord() + 0.9F + tRandom.nextFloat() * 0.2F,
+ aBaseMetaTileEntity.getZCoord() + 0.8F - tRandom.nextFloat() * 0.6F
+ )
+ .setWorld(aBaseMetaTileEntity.getWorld())
+ .run();
}
break;
}
diff --git a/src/main/java/gregtech/api/metatileentity/implementations/GT_MetaTileEntity_Hatch_Muffler.java b/src/main/java/gregtech/api/metatileentity/implementations/GT_MetaTileEntity_Hatch_Muffler.java
index 44567c96eb..9fbf880336 100644
--- a/src/main/java/gregtech/api/metatileentity/implementations/GT_MetaTileEntity_Hatch_Muffler.java
+++ b/src/main/java/gregtech/api/metatileentity/implementations/GT_MetaTileEntity_Hatch_Muffler.java
@@ -9,7 +9,7 @@ import gregtech.api.interfaces.tileentity.IGregTechTileEntity;
import gregtech.api.metatileentity.MetaTileEntity;
import gregtech.api.objects.GT_RenderedTexture;
import gregtech.api.util.GT_LanguageManager;
-import gregtech.api.util.PositionedWorldEvent;
+import gregtech.api.util.WorldSpawnedEventBuilder;
import gregtech.common.GT_Pollution;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.item.ItemStack;
@@ -141,19 +141,26 @@ public class GT_MetaTileEntity_Hatch_Muffler extends GT_MetaTileEntity_Hatch {
zSpd = aDir.offsetZ * (0.1F + 0.2F * XSTR_INSTANCE.nextFloat());
}
- PositionedWorldEvent<String> events = new PositionedWorldEvent<>(aWorld, name);
+ WorldSpawnedEventBuilder.ParticleEventBuilder events =
+ (WorldSpawnedEventBuilder.ParticleEventBuilder)
+ new WorldSpawnedEventBuilder.ParticleEventBuilder()
+ .setIdentifier(name)
+ .setWorld(aWorld);
if (chk1) {
- events.setPosition(xPos + ran1 * 0.5F, yPos + XSTR_INSTANCE.nextFloat() * 0.5F, zPos + XSTR_INSTANCE.nextFloat() * 0.5F)
- .spawnParticle(xSpd, ySpd, zSpd);
+ events.setMotion(xSpd, ySpd, zSpd)
+ .setPosition(xPos + ran1 * 0.5F, yPos + XSTR_INSTANCE.nextFloat() * 0.5F, zPos + XSTR_INSTANCE.nextFloat() * 0.5F)
+ .run();
}
if (chk2) {
- events.setPosition(xPos + ran2 * 0.5F, yPos + XSTR_INSTANCE.nextFloat() * 0.5F, zPos + XSTR_INSTANCE.nextFloat() * 0.5F)
- .spawnParticle(xSpd, ySpd, zSpd);
+ events.setMotion(xSpd, ySpd, zSpd)
+ .setPosition(xPos + ran2 * 0.5F, yPos + XSTR_INSTANCE.nextFloat() * 0.5F, zPos + XSTR_INSTANCE.nextFloat() * 0.5F)
+ .run();
}
if (chk3) {
- events.setPosition(xPos + ran3 * 0.5F, yPos + XSTR_INSTANCE.nextFloat() * 0.5F, zPos + XSTR_INSTANCE.nextFloat() * 0.5F)
- .spawnParticle(xSpd, ySpd, zSpd);
+ events.setMotion(xSpd, ySpd, zSpd)
+ .setPosition(xPos + ran3 * 0.5F, yPos + XSTR_INSTANCE.nextFloat() * 0.5F, zPos + XSTR_INSTANCE.nextFloat() * 0.5F)
+ .run();
}
}
diff --git a/src/main/java/gregtech/api/util/GT_FoodStat.java b/src/main/java/gregtech/api/util/GT_FoodStat.java
index 96345ef199..3d55291398 100644
--- a/src/main/java/gregtech/api/util/GT_FoodStat.java
+++ b/src/main/java/gregtech/api/util/GT_FoodStat.java
@@ -68,8 +68,15 @@ 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);
- PositionedWorldEvent<Object> event = new PositionedWorldEvent<>(aPlayer.worldObj, "random.burp");
- event.playSoundAtEntity(aPlayer,0.5F, aPlayer.worldObj.rand.nextFloat() * 0.1F + 0.9F);
+
+ new WorldSpawnedEventBuilder.SoundAtEntityEventBuilder()
+ .setIdentifier("random.burp")
+ .setVolume(0.5F)
+ .setPitch(aPlayer.worldObj.rand.nextFloat() * 0.1F + 0.9F)
+ .setEntity(aPlayer)
+ .setWorld(aPlayer.worldObj)
+ .run();
+
if (!aPlayer.worldObj.isRemote) {
if (mMilk) {
aPlayer.curePotionEffects(new ItemStack(Items.milk_bucket, 1, 0));
@@ -80,9 +87,14 @@ public class GT_FoodStat implements IFoodStat {
}
}
if (mExplosive) {
- event.setThing(aPlayer)
- .setPosition(aPlayer.posX, aPlayer.posY, aPlayer.posZ)
- .newExplosion(4,true, true);
+ new WorldSpawnedEventBuilder.ExplosionEffectEventBuilder()
+ .setSmoking(true)
+ .setFlaming(true)
+ .setStrength(4f)
+ .setPosition(aPlayer.posX, aPlayer.posY, aPlayer.posZ)
+ .setEntity(aPlayer)
+ .setWorld(aPlayer.worldObj)
+ .run();
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
deleted file mode 100644
index b615daabf5..0000000000
--- a/src/main/java/gregtech/api/util/PositionedWorldEvent.java
+++ /dev/null
@@ -1,172 +0,0 @@
-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;
-
-import java.util.Objects;
-import java.util.function.BiConsumer;
-import java.util.function.Consumer;
-
-@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 PositionedWorldEvent<T> setWorld(World world) {
- this.world = world;
- return this;
- }
-
- public Vec3 getPosition() {
- return position;
- }
-
- public PositionedWorldEvent<T> setPosition(Vec3 position) {
- this.position = position;
- return this;
- }
-
- public PositionedWorldEvent<T> setPosition(double x, double y, double z) {
- this.position = Vec3.createVectorHelper(x, y, z);
- return this;
- }
-
- public T getThing() {
- return thing;
- }
-
- public PositionedWorldEvent<T> setThing(T thing) {
- this.thing = thing;
- return this;
- }
-
- public void spawnParticle(double motionX, double motionY, double motionZ) {
- if (position == null || !(thing instanceof String) || world == null)
- throw new IllegalStateException("Position and world must be set, thing must be a string indicating the Particle to be spawned");
-
- 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)
- throw new IllegalStateException("Position and world must be set, thing must be a string indicating the SoundEffect to be spawned");
-
- world.playSoundEffect(position.xCoord, position.yCoord, position.zCoord, (String) thing, volume, pitch);
- }
-
- /**
- * Positional Data is rounded down due to this targeting a block.
- */
- public void playRecord() {
- if (position == null || !(thing instanceof String) || world == null)
- throw new IllegalStateException("Position and world must be set, thing must be a string indicating the Record to be spawned");
-
- 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)
- throw new IllegalStateException("Position and world must be set, thing must be a string indicating the Sound to be spawned");
-
- 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 || thing != null && !(thing instanceof Entity))
- throw new IllegalStateException("Position and world must be set, thing must either be null or an Entity");
-
- world.newExplosion((Entity) thing, position.xCoord, position.yCoord, position.zCoord, strength, isFlaming, isSmoking);
- }
-
- /**
- * Positional Data is rounded down due to this targeting a block.
- */
- public boolean extinguishFire(int side) {
- if (position == null || world == null || !(thing instanceof EntityPlayer))
- throw new IllegalStateException("Position and world must be set, thing must be a EntityPlayer");
-
- 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 (world == null || !(thing instanceof String))
- throw new IllegalStateException("World must be set, string indicating the Sound to be spawned");
-
- world.playSoundAtEntity(entity, (String) thing, volume, pitch);
- }
-
- public void playSoundToNearExcept(EntityPlayer player, float volume, float pitch) {
- if (world == null || !(thing instanceof String))
- throw new IllegalStateException("World must be set, string indicating the Sound to be spawned");
-
- world.playSoundToNearExcept(player, (String) thing, volume, pitch);
- }
-
- public void times(int times, Consumer<PositionedWorldEvent<T>> action) {
- Objects.requireNonNull(action);
- for (int i = 0; i < times; i++) {
- action.accept(this);
- }
- }
-
- public void times(int times, BiConsumer<PositionedWorldEvent<T>, Integer> action) {
- Objects.requireNonNull(action);
- for (int i = 0; i < times; i++) {
- action.accept(this, i);
- }
- }
-} \ No newline at end of file
diff --git a/src/main/java/gregtech/api/util/WorldSpawnedEventBuilder.java b/src/main/java/gregtech/api/util/WorldSpawnedEventBuilder.java
new file mode 100644
index 0000000000..7977892f06
--- /dev/null
+++ b/src/main/java/gregtech/api/util/WorldSpawnedEventBuilder.java
@@ -0,0 +1,602 @@
+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;
+
+import java.util.Objects;
+import java.util.function.BiConsumer;
+import java.util.function.Consumer;
+
+@SuppressWarnings("unused")
+public abstract class WorldSpawnedEventBuilder implements Runnable {
+
+ /* Variables */
+
+ private World world;
+
+ /* Getters, Setters */
+
+ public World getWorld() {
+ return world;
+ }
+
+ public WorldSpawnedEventBuilder setWorld(World world) {
+ this.world = world;
+ return this;
+ }
+
+ /* Methodes */
+
+ @SuppressWarnings("unchecked")
+ public <U extends WorldSpawnedEventBuilder> void times(int times, Consumer<U> action) {
+ Objects.requireNonNull(action);
+ for (int i = 0; i < times; i++) {
+ action.accept((U) this);
+ }
+ }
+
+ @SuppressWarnings("unchecked")
+ public <U extends WorldSpawnedEventBuilder> void times(int times, BiConsumer<U, Integer> action) {
+ Objects.requireNonNull(action);
+ for (int i = 0; i < times; i++) {
+ action.accept((U) this, i);
+ }
+ }
+
+ /* Interfaces */
+
+ private interface IPositionedWorldSpawnedEvent {
+ Vec3 getPosition();
+ IPositionedWorldSpawnedEvent setPosition(Vec3 position);
+ IPositionedWorldSpawnedEvent setPosition(double x, double y, double z);
+ }
+
+ private interface IEntityWorldSpawnedEvent {
+ Entity getEntity();
+ IEntityWorldSpawnedEvent setEntity(Entity entity);
+ }
+
+ private interface IEntityPlayerWorldSpawnedEvent {
+ EntityPlayer getEntityPlayer();
+ IEntityPlayerWorldSpawnedEvent setEntityPlayer(EntityPlayer entity);
+ }
+
+ private interface IStringIdentifierWorldSpawnedEvent {
+ String getIdentifier();
+ IStringIdentifierWorldSpawnedEvent setIdentifier(String identifier);
+ }
+
+ private interface ISoundWorldSpawnedEvent {
+ float getPitch();
+ float getVolume();
+ ISoundWorldSpawnedEvent setPitch(float pitch);
+ ISoundWorldSpawnedEvent setVolume(float volume);
+ }
+
+ /* Abstract Classes */
+
+ private static abstract class EntityWorldSpawnedEventBuilder extends WorldSpawnedEventBuilder implements IEntityWorldSpawnedEvent {
+
+ private Entity entity;
+
+ @Override
+ public Entity getEntity() {
+ return entity;
+ }
+
+ @Override
+ public EntityWorldSpawnedEventBuilder setEntity(Entity entity) {
+ this.entity = entity;
+ return this;
+ }
+ }
+
+ private static abstract class PositionedEntityWorldSpawnedEventBuilder extends EntityWorldSpawnedEventBuilder implements IPositionedWorldSpawnedEvent {
+
+ private Vec3 position;
+
+ @Override
+ public Vec3 getPosition() {
+ return position;
+ }
+
+ @Override
+ public PositionedEntityWorldSpawnedEventBuilder setPosition(Vec3 position) {
+ this.position = position;
+ return this;
+ }
+
+ @Override
+ public PositionedEntityWorldSpawnedEventBuilder setPosition(double x, double y, double z) {
+ this.position = Vec3.createVectorHelper(x, y, z);
+ return this;
+ }
+
+ }
+
+ private static abstract class PositionedWorldSpawnedEventBuilder extends WorldSpawnedEventBuilder implements IPositionedWorldSpawnedEvent {
+ private Vec3 position;
+
+ public Vec3 getPosition() {
+ return position;
+ }
+
+ public PositionedWorldSpawnedEventBuilder setPosition(Vec3 position) {
+ this.position = position;
+ return this;
+ }
+
+ public PositionedWorldSpawnedEventBuilder setPosition(double x, double y, double z) {
+ this.position = Vec3.createVectorHelper(x, y, z);
+ return this;
+ }
+ }
+
+ private static abstract class StringIdentifierPositionedWorldSpawnedEventBuilder extends PositionedWorldSpawnedEventBuilder implements IStringIdentifierWorldSpawnedEvent {
+ private String identifier;
+
+ @Override
+ public String getIdentifier() {
+ return identifier;
+ }
+
+ @Override
+ public StringIdentifierPositionedWorldSpawnedEventBuilder setIdentifier(String identifier) {
+ this.identifier = identifier;
+ return this;
+ }
+ }
+
+ private static abstract class SoundStringIdentifierPositionedWorldSpawnedEventBuilder extends StringIdentifierPositionedWorldSpawnedEventBuilder implements ISoundWorldSpawnedEvent {
+
+ private float pitch;
+ private float volume;
+
+ @Override
+ public float getPitch() {
+ return pitch;
+ }
+
+ @Override
+ public float getVolume() {
+ return volume;
+ }
+
+ @Override
+ public SoundStringIdentifierPositionedWorldSpawnedEventBuilder setPitch(float pitch) {
+ this.pitch = pitch;
+ return this;
+ }
+
+ @Override
+ public SoundStringIdentifierPositionedWorldSpawnedEventBuilder setVolume(float volume) {
+ this.volume = volume;
+ return this;
+ }
+ }
+
+ /* Implementations */
+
+ public final static class ParticleEventBuilder extends StringIdentifierPositionedWorldSpawnedEventBuilder {
+
+ private Vec3 motion;
+
+ public Vec3 getMotion() {
+ return motion;
+ }
+
+ public ParticleEventBuilder setMotion(double x, double y, double z) {
+ this.motion = Vec3.createVectorHelper(x, y, z);
+ return this;
+ }
+
+
+ public ParticleEventBuilder setMotion(Vec3 motion) {
+ this.motion = motion;
+ return this;
+ }
+
+ @Override
+ public ParticleEventBuilder setWorld(World world) {
+ return (ParticleEventBuilder) super.setWorld(world);
+ }
+
+ @Override
+ public ParticleEventBuilder setPosition(Vec3 position) {
+ return (ParticleEventBuilder) super.setPosition(position);
+ }
+
+ @Override
+ public ParticleEventBuilder setPosition(double x, double y, double z) {
+ return (ParticleEventBuilder) super.setPosition(x, y, z);
+ }
+
+ @Override
+ public ParticleEventBuilder setIdentifier(String identifier) {
+ return (ParticleEventBuilder) super.setIdentifier(identifier);
+ }
+
+ @Override
+ public void run() {
+ if (getPosition() == null || getIdentifier() == null || getMotion() == null || getWorld() == null)
+ throw new IllegalStateException("Position, identifier, motion and world must be set");
+
+ getWorld().spawnParticle(
+ getIdentifier(),
+ getPosition().xCoord, getPosition().yCoord, getPosition().zCoord,
+ getMotion().xCoord, getMotion().yCoord, getMotion().zCoord
+ );
+ }
+ }
+
+ public final static class SoundEffectEventBuilder extends SoundStringIdentifierPositionedWorldSpawnedEventBuilder {
+
+ @Override
+ public SoundEffectEventBuilder setWorld(World world) {
+ return (SoundEffectEventBuilder) super.setWorld(world);
+ }
+
+ @Override
+ public SoundEffectEventBuilder setPosition(Vec3 position) {
+ return (SoundEffectEventBuilder) super.setPosition(position);
+ }
+
+ @Override
+ public SoundEffectEventBuilder setPosition(double x, double y, double z) {
+ return (SoundEffectEventBuilder) super.setPosition(x, y, z);
+ }
+
+ @Override
+ public SoundEffectEventBuilder setIdentifier(String identifier) {
+ return (SoundEffectEventBuilder) super.setIdentifier(identifier);
+ }
+
+ @Override
+ public SoundEffectEventBuilder setPitch(float pitch) {
+ return (SoundEffectEventBuilder) super.setPitch(pitch);
+ }
+
+ @Override
+ public SoundEffectEventBuilder setVolume(float volume) {
+ return (SoundEffectEventBuilder) super.setVolume(volume);
+ }
+
+ @Override
+ public void run() {
+ if (getPosition() == null || getIdentifier() == null || getWorld() == null)
+ throw new IllegalStateException("Position, identifier and world must be set");
+
+ getWorld().playSoundEffect(
+ getPosition().xCoord, getPosition().yCoord, getPosition().zCoord,
+ getIdentifier(),
+ getPitch(), getVolume()
+ );
+ }
+ }
+
+ public final static class SoundEventBuilder extends SoundStringIdentifierPositionedWorldSpawnedEventBuilder {
+
+ private boolean proximity;
+
+ public boolean isProximity() {
+ return proximity;
+ }
+
+ @Override
+ public SoundEventBuilder setWorld(World world) {
+ return (SoundEventBuilder) super.setWorld(world);
+ }
+
+ @Override
+ public SoundEventBuilder setPosition(Vec3 position) {
+ return (SoundEventBuilder) super.setPosition(position);
+ }
+
+ @Override
+ public SoundEventBuilder setPosition(double x, double y, double z) {
+ return (SoundEventBuilder) super.setPosition(x, y, z);
+ }
+
+ @Override
+ public SoundEventBuilder setIdentifier(String identifier) {
+ return (SoundEventBuilder) super.setIdentifier(identifier);
+ }
+
+ @Override
+ public SoundEventBuilder setPitch(float pitch) {
+ return (SoundEventBuilder) super.setPitch(pitch);
+ }
+
+ @Override
+ public SoundEventBuilder setVolume(float volume) {
+ return (SoundEventBuilder) super.setVolume(volume);
+ }
+
+ public SoundEventBuilder setProximity(boolean proximity) {
+ this.proximity = proximity;
+ return this;
+ }
+
+ @Override
+ public void run() {
+ if (getPosition() == null || getIdentifier() == null || getWorld() == null)
+ throw new IllegalStateException("Position, identifier and world must be set");
+
+ getWorld().playSound(
+ getPosition().xCoord, getPosition().yCoord, getPosition().zCoord,
+ getIdentifier(),
+ getPitch(), getVolume(), isProximity()
+ );
+ }
+ }
+
+ /**
+ * Positional Data is rounded down due to this targeting a block.
+ */
+ public final static class RecordEffectEventBuilder extends StringIdentifierPositionedWorldSpawnedEventBuilder {
+
+ @Override
+ public RecordEffectEventBuilder setWorld(World world) {
+ return (RecordEffectEventBuilder) super.setWorld(world);
+ }
+
+ @Override
+ public RecordEffectEventBuilder setPosition(Vec3 position) {
+ return (RecordEffectEventBuilder) super.setPosition(position);
+ }
+
+ @Override
+ public RecordEffectEventBuilder setPosition(double x, double y, double z) {
+ return (RecordEffectEventBuilder) super.setPosition(x, y, z);
+ }
+
+ @Override
+ public RecordEffectEventBuilder setIdentifier(String identifier) {
+ return (RecordEffectEventBuilder) super.setIdentifier(identifier);
+ }
+
+ @Override
+ public void run() {
+ if (getPosition() == null || getIdentifier() == null || getWorld() == null)
+ throw new IllegalStateException("Position, identifier and world must be set");
+
+ getWorld().playRecord(
+ getIdentifier(),
+ (int) getPosition().xCoord,(int) getPosition().yCoord,(int) getPosition().zCoord
+ );
+ }
+ }
+
+ public final static class ExplosionEffectEventBuilder extends PositionedEntityWorldSpawnedEventBuilder {
+ private boolean isFlaming, isSmoking;
+ private float strength;
+
+
+ public float getStrength() {
+ return strength;
+ }
+
+ public ExplosionEffectEventBuilder setStrength(float strength) {
+ this.strength = strength;
+ return this;
+ }
+
+ public boolean isFlaming() {
+ return isFlaming;
+ }
+
+ public ExplosionEffectEventBuilder setFlaming(boolean flaming) {
+ isFlaming = flaming;
+ return this;
+ }
+
+ public boolean isSmoking() {
+ return isSmoking;
+ }
+
+ public ExplosionEffectEventBuilder setSmoking(boolean smoking) {
+ isSmoking = smoking;
+ return this;
+ }
+
+ @Override
+ public ExplosionEffectEventBuilder setWorld(World world) {
+ return (ExplosionEffectEventBuilder) super.setWorld(world);
+ }
+
+ @Override
+ public ExplosionEffectEventBuilder setEntity(Entity entity) {
+ return (ExplosionEffectEventBuilder) super.setEntity(entity);
+ }
+
+ @Override
+ public ExplosionEffectEventBuilder setPosition(double x, double y, double z) {
+ return (ExplosionEffectEventBuilder) super.setPosition(x, y, z);
+ }
+
+ @Override
+ public void run() {
+ if (getPosition() == null || getWorld() == null)
+ throw new IllegalStateException("Position and world must be set");
+
+ getWorld().newExplosion(getEntity(), getPosition().xCoord, getPosition().yCoord, getPosition().zCoord, strength, isFlaming, isSmoking);
+ }
+ }
+
+ /**
+ * Positional Data is rounded down due to this targeting a block.
+ */
+ public final static class ExtinguishFireEffectEventBuilder extends PositionedWorldSpawnedEventBuilder implements IEntityPlayerWorldSpawnedEvent {
+
+ private int side;
+ private EntityPlayer entityPlayer;
+
+ public int getSide() {
+ return side;
+ }
+
+ public ExtinguishFireEffectEventBuilder setSide(int side) {
+ this.side = side;
+ return this;
+ }
+
+ @Override
+ public EntityPlayer getEntityPlayer() {
+ return entityPlayer;
+ }
+
+ @Override
+ public ExtinguishFireEffectEventBuilder setEntityPlayer(EntityPlayer entity) {
+ this.entityPlayer = entity;
+ return this;
+ }
+
+ @Override
+ public ExtinguishFireEffectEventBuilder setWorld(World world) {
+ return (ExtinguishFireEffectEventBuilder) super.setWorld(world);
+ }
+
+ @Override
+ public ExtinguishFireEffectEventBuilder setPosition(Vec3 position) {
+ return (ExtinguishFireEffectEventBuilder) super.setPosition(position);
+ }
+
+ @Override
+ public ExtinguishFireEffectEventBuilder setPosition(double x, double y, double z) {
+ return (ExtinguishFireEffectEventBuilder) super.setPosition(x, y, z);
+ }
+
+ @Override
+ public void run() {
+ if (getEntityPlayer() == null || getPosition() == null || getWorld() == null)
+ throw new IllegalStateException("EntityPlayer, position and world must be set");
+
+ getWorld().extinguishFire(getEntityPlayer(), (int) getPosition().xCoord, (int) getPosition().yCoord, (int) getPosition().zCoord, side);
+ }
+ }
+
+ public final static class SoundAtEntityEventBuilder extends EntityWorldSpawnedEventBuilder implements ISoundWorldSpawnedEvent, IStringIdentifierWorldSpawnedEvent {
+
+ private float pitch;
+ private float volume;
+ private String identifier;
+
+ @Override
+ public String getIdentifier() {
+ return identifier;
+ }
+
+ @Override
+ public SoundAtEntityEventBuilder setIdentifier(String identifier) {
+ this.identifier = identifier;
+ return this;
+ }
+
+ @Override
+ public float getPitch() {
+ return pitch;
+ }
+
+ @Override
+ public float getVolume() {
+ return volume;
+ }
+
+ @Override
+ public SoundAtEntityEventBuilder setPitch(float pitch) {
+ this.pitch = pitch;
+ return this;
+ }
+
+ @Override
+ public SoundAtEntityEventBuilder setVolume(float volume) {
+ this.volume = volume;
+ return this;
+ }
+
+ @Override
+ public SoundAtEntityEventBuilder setWorld(World world) {
+ return (SoundAtEntityEventBuilder) super.setWorld(world);
+ }
+
+ @Override
+ public SoundAtEntityEventBuilder setEntity(Entity entity) {
+ return (SoundAtEntityEventBuilder) super.setEntity(entity);
+ }
+
+ @Override
+ public void run() {
+ if (getWorld() == null || getIdentifier() == null || getEntity() == null)
+ throw new IllegalStateException("World, Identifier and entity must be set!");
+
+ getWorld().playSoundAtEntity(getEntity(), getIdentifier(), volume, pitch);
+ }
+ }
+
+ public final static class SoundToNearExceptEventBuilder extends WorldSpawnedEventBuilder implements ISoundWorldSpawnedEvent, IStringIdentifierWorldSpawnedEvent, IEntityPlayerWorldSpawnedEvent {
+
+ private float pitch;
+ private float volume;
+ private String identifier;
+ private EntityPlayer entityPlayer;
+
+ @Override
+ public String getIdentifier() {
+ return identifier;
+ }
+
+ @Override
+ public SoundToNearExceptEventBuilder setIdentifier(String identifier) {
+ this.identifier = identifier;
+ return this;
+ }
+
+ @Override
+ public float getPitch() {
+ return pitch;
+ }
+
+ @Override
+ public float getVolume() {
+ return volume;
+ }
+
+ @Override
+ public SoundToNearExceptEventBuilder setPitch(float pitch) {
+ this.pitch = pitch;
+ return this;
+ }
+
+ @Override
+ public SoundToNearExceptEventBuilder setVolume(float volume) {
+ this.volume = volume;
+ return this;
+ }
+
+ @Override
+ public SoundToNearExceptEventBuilder setWorld(World world) {
+ return (SoundToNearExceptEventBuilder) super.setWorld(world);
+ }
+
+ @Override
+ public void run() {
+ if (getWorld() == null || getIdentifier() == null || getEntityPlayer() == null)
+ throw new IllegalStateException("World, Identifier and EntityPlayer must be set!");
+
+ getWorld().playSoundAtEntity(getEntityPlayer(), getIdentifier(), volume, pitch);
+ }
+
+ @Override
+ public EntityPlayer getEntityPlayer() {
+ return entityPlayer;
+ }
+
+ @Override
+ public SoundToNearExceptEventBuilder setEntityPlayer(EntityPlayer entity) {
+ entityPlayer = entity;
+ return this;
+ }
+ }
+} \ No newline at end of file