diff options
| author | Antifluxfield <lyj_299792458@163.com> | 2017-09-21 20:33:23 +0800 |
|---|---|---|
| committer | Dream-Master <dream-master@gmx.net> | 2017-10-07 00:17:05 +0200 |
| commit | 0eba296ed625694258f94dfa2cf92dd8ce2f1425 (patch) | |
| tree | 00b56cae8ba8decdfa04afe2bff202f556401df1 /src/main/java/gregtech/api | |
| parent | 935cb5820e332d4abba2a42a6cd63e08aa34aca7 (diff) | |
| download | GT5-Unofficial-0eba296ed625694258f94dfa2cf92dd8ce2f1425.tar.gz GT5-Unofficial-0eba296ed625694258f94dfa2cf92dd8ce2f1425.tar.bz2 GT5-Unofficial-0eba296ed625694258f94dfa2cf92dd8ce2f1425.zip | |
cherry pick
0802fdbd0272c4251c4615026643c8eadcf7fe70
9d8ac82535b0099ef70e8995bca51f62f39f9f94
e725c455b3d9025caeebdbf12cc9d25f238f74bb
3db38a5c53a771aeb37a8cf2568f79c49bb38c21
aef60bbf3b6752963b51c9c4e27b6ba03f75ba8c
ef41455fe59f2915c94c204b97cee19aa2ddcd3b
4372034ff4edc9e58629d63123b84c29e6e0e516
Drillers fix #1230
https://github.com/Blood-Asp/GT5-Unofficial/pull/1230
Diffstat (limited to 'src/main/java/gregtech/api')
| -rw-r--r-- | src/main/java/gregtech/api/util/GT_Utility.java | 42 |
1 files changed, 41 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 8b8e169ce5..72dd398171 100644 --- a/src/main/java/gregtech/api/util/GT_Utility.java +++ b/src/main/java/gregtech/api/util/GT_Utility.java @@ -1,6 +1,7 @@ package gregtech.api.util; import cofh.api.transport.IItemDuct; +import com.mojang.authlib.GameProfile; import cpw.mods.fml.common.FMLCommonHandler; import gregtech.api.GregTech_API; import gregtech.api.damagesources.GT_DamageSources; @@ -56,7 +57,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; @@ -1949,7 +1955,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) { |
