diff options
author | Blood-Asp <bloodasphendrik@gmail.com> | 2017-11-05 17:39:21 +0100 |
---|---|---|
committer | GitHub <noreply@github.com> | 2017-11-05 17:39:21 +0100 |
commit | 79821632818d1623276bf5b46960082f52a0f221 (patch) | |
tree | 0a60feeac0227c85372a1df6c9adae4d3510ec2b /src/main/java/gregtech/api/util | |
parent | 083b6b0b2cc92e8b19b23e71ced12f483d027f6c (diff) | |
parent | 0f9be5a4c90a0b08d1382fc4ef345d60c6cced9c (diff) | |
download | GT5-Unofficial-79821632818d1623276bf5b46960082f52a0f221.tar.gz GT5-Unofficial-79821632818d1623276bf5b46960082f52a0f221.tar.bz2 GT5-Unofficial-79821632818d1623276bf5b46960082f52a0f221.zip |
Merge pull request #1230 from Antifluxfield/driller_fix
Drillers fix
Diffstat (limited to 'src/main/java/gregtech/api/util')
-rw-r--r-- | src/main/java/gregtech/api/util/GT_Utility.java | 43 |
1 files changed, 42 insertions, 1 deletions
diff --git a/src/main/java/gregtech/api/util/GT_Utility.java b/src/main/java/gregtech/api/util/GT_Utility.java index f102cc4246..69f5b9783c 100644 --- a/src/main/java/gregtech/api/util/GT_Utility.java +++ b/src/main/java/gregtech/api/util/GT_Utility.java @@ -56,7 +56,12 @@ import net.minecraft.world.World; import net.minecraft.world.WorldServer; import net.minecraftforge.common.DimensionManager; import net.minecraftforge.common.MinecraftForge; +import net.minecraftforge.common.util.BlockSnapshot; +import net.minecraftforge.common.util.FakePlayer; +import net.minecraftforge.common.util.FakePlayerFactory; import net.minecraftforge.common.util.ForgeDirection; +import net.minecraftforge.event.ForgeEventFactory; +import net.minecraftforge.event.world.BlockEvent; import net.minecraftforge.fluids.*; import net.minecraftforge.fluids.FluidContainerRegistry.FluidContainerData; @@ -69,6 +74,8 @@ import java.text.NumberFormat; import java.util.*; import java.util.Map.Entry; +import com.mojang.authlib.GameProfile; + import static gregtech.api.enums.GT_Values.*; import static gregtech.common.GT_Proxy.GTPOLLUTION; import static gregtech.common.GT_UndergroundOil.undergroundOilReadInformation; @@ -1994,7 +2001,41 @@ public class GT_Utility { public static ItemStack getIntegratedCircuit(int config){ return ItemList.Circuit_Integrated.getWithDamage(0, config, new Object[0]); } - + + public static float getBlockHardnessAt(World aWorld, int aX, int aY, int aZ) { + return aWorld.getBlock(aX, aY, aZ).getBlockHardness(aWorld, aX, aY, aZ); + } + + public static FakePlayer getFakePlayer(IGregTechTileEntity aBaseMetaTileEntity) { + if (aBaseMetaTileEntity.getWorld() instanceof WorldServer) { + return FakePlayerFactory.get((WorldServer) aBaseMetaTileEntity.getWorld(), new GameProfile(null, aBaseMetaTileEntity.getOwnerName())); + } + return null; + } + + public static boolean eraseBlockByFakePlayer(FakePlayer aPlayer, int aX, int aY, int aZ, boolean isSimulate) { + if (aPlayer == null) return false; + World aWorld = aPlayer.worldObj; + BlockEvent.BreakEvent event = new BlockEvent.BreakEvent(aX, aY, aZ, aWorld, aWorld.getBlock(aX, aY, aZ), aWorld.getBlockMetadata(aX, aY, aZ), aPlayer); + MinecraftForge.EVENT_BUS.post(event); + if (!event.isCanceled()) { + if (!isSimulate) return aWorld.setBlockToAir(aX, aY, aZ); + return true; + } + return false; + } + + public static boolean setBlockByFakePlayer(FakePlayer aPlayer, int aX, int aY, int aZ, Block aBlock, int aMeta, boolean isSimulate) { + if (aPlayer == null) return false; + World aWorld = aPlayer.worldObj; + BlockEvent.PlaceEvent event = ForgeEventFactory.onPlayerBlockPlace(aPlayer, new BlockSnapshot(aWorld, aX, aY, aZ, aBlock, aMeta), ForgeDirection.UNKNOWN); + if (!event.isCanceled()) { + if (!isSimulate) return aWorld.setBlock(aX, aY, aZ, aBlock, aMeta, 3); + return true; + } + return false; + } + public static class ItemNBT { public static void setNBT(ItemStack aStack, NBTTagCompound aNBT) { if (aNBT == null) { |