Skip to content

Commit

Permalink
fire events on some special AE items used, such as Wrench and MemoryC…
Browse files Browse the repository at this point in the history
…ard. #6
  • Loading branch information
xsun committed Apr 13, 2017
1 parent 439ae2e commit 87d82d6
Show file tree
Hide file tree
Showing 8 changed files with 33 additions and 2 deletions.
5 changes: 5 additions & 0 deletions src/main/java/appeng/block/AEBaseTileBlock.java
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@
import net.minecraft.world.IBlockAccess;
import net.minecraft.world.World;
import net.minecraftforge.common.util.ForgeDirection;
import net.minecraftforge.event.ForgeEventFactory;

import javax.annotation.Nonnull;
import javax.annotation.Nullable;
Expand Down Expand Up @@ -243,6 +244,8 @@ public final boolean onBlockActivated( final World w, final int x, final int y,
{
if( Platform.isWrench( player, is, x, y, z ) && player.isSneaking() )
{
if( ForgeEventFactory.onItemUseStart( player, is, 1 ) <= 0 )
return false;
final Block id = w.getBlock( x, y, z );
if( id != null )
{
Expand Down Expand Up @@ -284,6 +287,8 @@ public final boolean onBlockActivated( final World w, final int x, final int y,

if( is.getItem() instanceof IMemoryCard && !( this instanceof BlockCableBus ) )
{
if( ForgeEventFactory.onItemUseStart( player, is, 1 ) <= 0 )
return false;
final IMemoryCard memoryCard = (IMemoryCard) is.getItem();
if( player.isSneaking() )
{
Expand Down
3 changes: 2 additions & 1 deletion src/main/java/appeng/items/tools/ToolBiometricCard.java
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@
import net.minecraft.nbt.NBTUtil;
import net.minecraft.world.World;
import net.minecraftforge.client.MinecraftForgeClient;
import net.minecraftforge.event.ForgeEventFactory;

import java.util.EnumSet;
import java.util.List;
Expand All @@ -57,7 +58,7 @@ public ToolBiometricCard()
@Override
public ItemStack onItemRightClick( final ItemStack is, final World w, final EntityPlayer p )
{
if( p.isSneaking() )
if( ForgeEventFactory.onItemUseStart( p, is, 1 ) > 0 && p.isSneaking() )
{
this.encode( is, p );
p.swingItem();
Expand Down
3 changes: 3 additions & 0 deletions src/main/java/appeng/items/tools/ToolMemoryCard.java
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@
import net.minecraft.nbt.NBTTagCompound;
import net.minecraft.util.StatCollector;
import net.minecraft.world.World;
import net.minecraftforge.event.ForgeEventFactory;

import java.util.EnumSet;
import java.util.List;
Expand Down Expand Up @@ -140,6 +141,8 @@ public boolean onItemUse( final ItemStack is, final EntityPlayer player, final W
{
if( player.isSneaking() && !w.isRemote )
{
if( ForgeEventFactory.onItemUseStart( player, is, 1 ) <= 0 )
return false;
final IMemoryCard mem = (IMemoryCard) is.getItem();
mem.notifyUser( player, MemoryCardMessages.SETTINGS_CLEARED );
is.setTagCompound( null );
Expand Down
4 changes: 4 additions & 0 deletions src/main/java/appeng/items/tools/ToolNetworkTool.java
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@
import net.minecraft.util.Vec3;
import net.minecraft.world.World;
import net.minecraftforge.common.util.ForgeDirection;
import net.minecraftforge.event.ForgeEventFactory;

import java.util.EnumSet;

Expand Down Expand Up @@ -102,6 +103,9 @@ public ItemStack onItemRightClick( final ItemStack it, final World w, final Enti
@Override
public boolean onItemUseFirst( final ItemStack is, final EntityPlayer player, final World world, final int x, final int y, final int z, final int side, final float hitX, final float hitY, final float hitZ )
{
if( ForgeEventFactory.onItemUseStart( player, is, 1 ) <= 0 )
return false;

final MovingObjectPosition mop = new MovingObjectPosition( x, y, z, side, Vec3.createVectorHelper( hitX, hitY, hitZ ) );
final TileEntity te = world.getTileEntity( x, y, z );
if( te instanceof IPartHost )
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,10 @@
import appeng.util.Platform;
import com.google.common.base.Optional;
import net.minecraft.entity.EntityLivingBase;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.item.ItemStack;
import net.minecraft.util.DamageSource;
import net.minecraftforge.event.ForgeEventFactory;

import java.util.EnumSet;

Expand All @@ -45,6 +47,9 @@ public ToolChargedStaff()
@Override
public boolean hitEntity( final ItemStack item, final EntityLivingBase target, final EntityLivingBase hitter )
{
if( hitter instanceof EntityPlayer && ForgeEventFactory.onItemUseStart( (EntityPlayer) hitter, item, 1 ) <= 0 )
return false;

if( this.getAECurrentPower( item ) > 300 )
{
this.extractAEPower( item, 300 );
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@
import net.minecraft.nbt.NBTTagCompound;
import net.minecraft.util.StatCollector;
import net.minecraft.world.World;
import net.minecraftforge.event.ForgeEventFactory;

import java.util.EnumSet;
import java.util.List;
Expand All @@ -58,7 +59,8 @@ public ToolWirelessTerminal()
@Override
public ItemStack onItemRightClick( final ItemStack item, final World w, final EntityPlayer player )
{
AEApi.instance().registries().wireless().openWirelessTerminalGui( item, w, player );
if( ForgeEventFactory.onItemUseStart( player, item, 1 ) > 0 )
AEApi.instance().registries().wireless().openWirelessTerminalGui( item, w, player );
return item;
}

Expand Down
4 changes: 4 additions & 0 deletions src/main/java/appeng/items/tools/quartz/ToolQuartzWrench.java
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@
import net.minecraft.item.ItemStack;
import net.minecraft.world.World;
import net.minecraftforge.common.util.ForgeDirection;
import net.minecraftforge.event.ForgeEventFactory;

import java.util.EnumSet;

Expand All @@ -53,6 +54,9 @@ public ToolQuartzWrench( final AEFeature type )
@Override
public boolean onItemUseFirst( final ItemStack is, final EntityPlayer player, final World world, final int x, final int y, final int z, final int side, final float hitX, final float hitY, final float hitZ )
{
if( ForgeEventFactory.onItemUseStart( player, is, 1 ) <= 0 )
return false;

final Block b = world.getBlock( x, y, z );
if( b != null && !player.isSneaking() && Platform.hasPermissions( new DimensionalCoord( world, x, y, z ), player ) )
{
Expand Down
7 changes: 7 additions & 0 deletions src/main/java/appeng/parts/p2p/PartP2PTunnel.java
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@
import net.minecraft.util.IIcon;
import net.minecraft.util.Vec3;
import net.minecraftforge.common.util.ForgeDirection;
import net.minecraftforge.event.ForgeEventFactory;

import java.util.ArrayList;
import java.util.Collection;
Expand Down Expand Up @@ -229,6 +230,9 @@ public boolean onPartActivate( final EntityPlayer player, final Vec3 pos )
final TunnelType tt = AEApi.instance().registries().p2pTunnel().getTunnelTypeByItem( is );
if( is != null && is.getItem() instanceof IMemoryCard )
{
if( ForgeEventFactory.onItemUseStart( player, is, 1 ) <= 0 )
return false;

final IMemoryCard mc = (IMemoryCard) is.getItem();
final NBTTagCompound data = mc.getData( is );

Expand Down Expand Up @@ -386,6 +390,9 @@ public boolean onPartShiftActivate( final EntityPlayer player, final Vec3 pos )
final ItemStack is = player.inventory.getCurrentItem();
if( is != null && is.getItem() instanceof IMemoryCard )
{
if( ForgeEventFactory.onItemUseStart( player, is, 1 ) <= 0 )
return false;

final IMemoryCard mc = (IMemoryCard) is.getItem();
final NBTTagCompound data = new NBTTagCompound();

Expand Down

0 comments on commit 87d82d6

Please sign in to comment.