Added TeleporterUsingEvent.
In multiplayer players can teleport to "restricted" areas (like closed dimensions or WorldEdit regions), need to handle it.
This commit is contained in:
parent
221f98bbcd
commit
7f68c17736
2 changed files with 26 additions and 1 deletions
21
src/main/java/gregtech/api/events/TeleporterUsingEvent.java
Normal file
21
src/main/java/gregtech/api/events/TeleporterUsingEvent.java
Normal file
|
@ -0,0 +1,21 @@
|
||||||
|
package gregtech.api.events;
|
||||||
|
|
||||||
|
import net.minecraft.entity.Entity;
|
||||||
|
|
||||||
|
@cpw.mods.fml.common.eventhandler.Cancelable
|
||||||
|
public class TeleporterUsingEvent extends net.minecraftforge.event.entity.EntityEvent {
|
||||||
|
|
||||||
|
public final Entity mEntity;
|
||||||
|
public final int mTargetX, mTargetY, mTargetZ, mTargetD;
|
||||||
|
public final boolean mHasEgg;
|
||||||
|
|
||||||
|
public TeleporterUsingEvent(Entity aEntity, int aTargetX, int aTargetY, int aTargetZ, int aTargetD, boolean aHasEgg) {
|
||||||
|
super(aEntity);
|
||||||
|
mEntity = aEntity;
|
||||||
|
mTargetX = aTargetX;
|
||||||
|
mTargetY = aTargetY;
|
||||||
|
mTargetZ = aTargetZ;
|
||||||
|
mTargetD = aTargetD;
|
||||||
|
mHasEgg = aHasEgg;
|
||||||
|
}
|
||||||
|
}
|
|
@ -3,6 +3,7 @@ package gregtech.common.tileentities.machines.basic;
|
||||||
import gregtech.api.enums.ConfigCategories;
|
import gregtech.api.enums.ConfigCategories;
|
||||||
import gregtech.api.enums.Materials;
|
import gregtech.api.enums.Materials;
|
||||||
import gregtech.api.enums.Textures;
|
import gregtech.api.enums.Textures;
|
||||||
|
import gregtech.api.events.TeleporterUsingEvent;
|
||||||
import gregtech.api.interfaces.ITexture;
|
import gregtech.api.interfaces.ITexture;
|
||||||
import gregtech.api.interfaces.metatileentity.IMetaTileEntity;
|
import gregtech.api.interfaces.metatileentity.IMetaTileEntity;
|
||||||
import gregtech.api.interfaces.tileentity.IGregTechTileEntity;
|
import gregtech.api.interfaces.tileentity.IGregTechTileEntity;
|
||||||
|
@ -34,6 +35,7 @@ import net.minecraft.tileentity.TileEntity;
|
||||||
import net.minecraft.util.AxisAlignedBB;
|
import net.minecraft.util.AxisAlignedBB;
|
||||||
import net.minecraft.world.World;
|
import net.minecraft.world.World;
|
||||||
import net.minecraftforge.common.DimensionManager;
|
import net.minecraftforge.common.DimensionManager;
|
||||||
|
import net.minecraftforge.common.MinecraftForge;
|
||||||
import net.minecraftforge.fluids.FluidStack;
|
import net.minecraftforge.fluids.FluidStack;
|
||||||
|
|
||||||
import static gregtech.api.enums.GT_Values.V;
|
import static gregtech.api.enums.GT_Values.V;
|
||||||
|
@ -281,7 +283,9 @@ public class GT_MetaTileEntity_Teleporter extends GT_MetaTileEntity_BasicTank {
|
||||||
if (((tObject instanceof Entity)) && (!((Entity) tObject).isDead)) {
|
if (((tObject instanceof Entity)) && (!((Entity) tObject).isDead)) {
|
||||||
Entity tEntity = (Entity) tObject;
|
Entity tEntity = (Entity) tObject;
|
||||||
// System.out.println("teleport"+(Math.pow(tDistance, 1.5)));
|
// System.out.println("teleport"+(Math.pow(tDistance, 1.5)));
|
||||||
if (getBaseMetaTileEntity().decreaseStoredEnergyUnits((int) (Math.pow(tDistance, 1.5) * weightCalculation(tEntity) * sFPowerMultiplyer), false)) {
|
TeleporterUsingEvent tEvent = new TeleporterUsingEvent(tEntity, mTargetX, mTargetY, mTargetZ, mTargetD, hasEgg);
|
||||||
|
MinecraftForge.EVENT_BUS.post(tEvent);
|
||||||
|
if (!tEvent.isCanceled() && getBaseMetaTileEntity().decreaseStoredEnergyUnits((int) (Math.pow(tDistance, 1.5) * weightCalculation(tEntity) * sFPowerMultiplyer), false)) {
|
||||||
if (hasDimensionalTeleportCapability() && this.mTargetD != getBaseMetaTileEntity().getWorld().provider.dimensionId && (hasEgg || mFluid.isFluidEqual(Materials.Nitrogen.getPlasma(1)))) {
|
if (hasDimensionalTeleportCapability() && this.mTargetD != getBaseMetaTileEntity().getWorld().provider.dimensionId && (hasEgg || mFluid.isFluidEqual(Materials.Nitrogen.getPlasma(1)))) {
|
||||||
mFluid.amount = mFluid.amount - ((int) Math.min(10, (Math.pow(tDistance, 1.5) * weightCalculation(tEntity) / 8192)));
|
mFluid.amount = mFluid.amount - ((int) Math.min(10, (Math.pow(tDistance, 1.5) * weightCalculation(tEntity) / 8192)));
|
||||||
if (mFluid.amount < 1) {
|
if (mFluid.amount < 1) {
|
||||||
|
|
Loading…
Reference in a new issue