Skip to content

Commit

Permalink
Merge branch 'fix-wrench' into rv3-1.7.10
Browse files Browse the repository at this point in the history
  • Loading branch information
xsun2001 committed Dec 31, 2017
2 parents cf1f039 + b8f9d19 commit bc50afa
Show file tree
Hide file tree
Showing 2 changed files with 56 additions and 33 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,11 @@
import net.minecraft.util.MovingObjectPosition;
import net.minecraft.util.MovingObjectPosition.MovingObjectType;
import net.minecraft.world.World;
import net.minecraftforge.common.MinecraftForge;
import net.minecraftforge.common.util.ForgeDirection;
import net.minecraftforge.event.ForgeEventFactory;
import net.minecraftforge.event.entity.player.PlayerInteractEvent;
import net.minecraftforge.event.world.BlockEvent;
import net.minecraftforge.oredict.OreDictionary;

import java.util.*;
Expand Down Expand Up @@ -120,10 +124,11 @@ public boolean equals( final Object obj )
}
}

private void heat( final Block blockID, final int metadata, final World w, final int x, final int y, final int z )
private boolean heat( final Block blockID,final EntityPlayer p,final int metadata, final World w, final int x, final int y, final int z )
{
InWorldToolOperationResult r = this.heatUp.get( new InWorldToolOperationIngredient( blockID, metadata ) );

if(!breakBlockWithCheck( w,p,x,y,z ))return false;
if( r == null )
{
r = this.heatUp.get( new InWorldToolOperationIngredient( blockID, OreDictionary.WILDCARD_VALUE ) );
Expand All @@ -133,15 +138,14 @@ private void heat( final Block blockID, final int metadata, final World w, final
{
w.setBlock( x, y, z, Block.getBlockFromItem( r.getBlockItem().getItem() ), r.getBlockItem().getItemDamage(), 3 );
}
else
{
w.setBlock( x, y, z, Platform.AIR_BLOCK, 0, 3 );
}


if( r.getDrops() != null )
{
Platform.spawnDrops( w, x, y, z, r.getDrops() );
}

return true;
}

private boolean canHeat( final Block blockID, final int metadata )
Expand All @@ -156,7 +160,7 @@ private boolean canHeat( final Block blockID, final int metadata )
return r != null;
}

private void cool( final Block blockID, final int metadata, final World w, final int x, final int y, final int z )
private boolean cool( final Block blockID,final EntityPlayer p, final int metadata, final World w, final int x, final int y, final int z )
{
InWorldToolOperationResult r = this.coolDown.get( new InWorldToolOperationIngredient( blockID, metadata ) );

Expand All @@ -165,19 +169,18 @@ private void cool( final Block blockID, final int metadata, final World w, final
r = this.coolDown.get( new InWorldToolOperationIngredient( blockID, OreDictionary.WILDCARD_VALUE ) );
}

if(!breakBlockWithCheck( w,p,x,y,z ))return false;
if( r.getBlockItem() != null )
{
w.setBlock( x, y, z, Block.getBlockFromItem( r.getBlockItem().getItem() ), r.getBlockItem().getItemDamage(), 3 );
}
else
{
w.setBlock( x, y, z, Platform.AIR_BLOCK, 0, 3 );
}

if( r.getDrops() != null )
{
Platform.spawnDrops( w, x, y, z, r.getDrops() );
}

return true;
}

private boolean canCool( final Block blockID, final int metadata )
Expand Down Expand Up @@ -247,36 +250,46 @@ public boolean onItemUse( final ItemStack item, final EntityPlayer p, final Worl
final Block blockID = w.getBlock( x, y, z );
final int metadata = w.getBlockMetadata( x, y, z );

if( blockID == null || ForgeEventFactory.onPlayerInteract( p,
blockID.isAir( w, x, y, z ) ? PlayerInteractEvent.Action.RIGHT_CLICK_AIR : PlayerInteractEvent.Action.RIGHT_CLICK_BLOCK,
x, y, z, side, w ).isCanceled() ) return false;

if( p.isSneaking() )
{
if( this.canCool( blockID, metadata ) )
{
this.extractAEPower( item, 1600 );
this.cool( blockID, metadata, w, x, y, z );
return true;
if(this.cool( blockID, p, metadata, w, x, y, z ))
{
this.extractAEPower( item, 1600 );
return true;
}
return false;
}
}
else
{
if( blockID instanceof BlockTNT )
{
w.setBlock( x, y, z, Platform.AIR_BLOCK, 0, 3 );
if(!breakBlockWithCheck( w,p,x,y,z )) return false;
( (BlockTNT) blockID ).func_150114_a( w, x, y, z, 1, p );
return true;
}

if( blockID instanceof BlockTinyTNT )
{
w.setBlock( x, y, z, Platform.AIR_BLOCK, 0, 3 );
if(!breakBlockWithCheck( w,p,x,y,z )) return false;
( (BlockTinyTNT) blockID ).startFuse( w, x, y, z, p );
return true;
}

if( this.canHeat( blockID, metadata ) )
{
this.extractAEPower( item, 1600 );
this.heat( blockID, metadata, w, x, y, z );
return true;
if(this.heat( blockID, p, metadata, w, x, y, z ))
{
this.extractAEPower( item, 1600 );
return true;
}
return false;
}

final ItemStack[] stack = Platform.getBlockDrops( w, x, y, z );
Expand Down Expand Up @@ -313,11 +326,8 @@ public boolean onItemUse( final ItemStack item, final EntityPlayer p, final Worl
final InWorldToolOperationResult or = InWorldToolOperationResult.getBlockOperationResult( out.toArray( new ItemStack[out.size()] ) );
w.playSoundEffect( x + 0.5D, y + 0.5D, z + 0.5D, "fire.ignite", 1.0F, itemRand.nextFloat() * 0.4F + 0.8F );

if( or.getBlockItem() == null )
{
w.setBlock( x, y, z, Platform.AIR_BLOCK, 0, 3 );
}
else
if(!breakBlockWithCheck( w,p,x,y,z )) return false;
if( or.getBlockItem() != null )
{
w.setBlock( x, y, z, Block.getBlockFromItem( or.getBlockItem().getItem() ), or.getBlockItem().getItemDamage(), 3 );
}
Expand Down Expand Up @@ -355,4 +365,12 @@ public boolean onItemUse( final ItemStack item, final EntityPlayer p, final Worl

return false;
}

private static final boolean breakBlockWithCheck(final World w,final EntityPlayer p,final int x,final int y,final int z)
{
BlockEvent.BreakEvent event = new BlockEvent.BreakEvent( x, y, z, w, w.getBlock( x, y, z ), w.getBlockMetadata( x, y, z ), p );
MinecraftForge.EVENT_BUS.post( event );
return !event.isCanceled() && w.setBlockToAir( x, y, z );
}

}
25 changes: 15 additions & 10 deletions src/main/java/appeng/parts/PartPlacement.java
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@
import net.minecraftforge.event.entity.player.PlayerDestroyItemEvent;
import net.minecraftforge.event.entity.player.PlayerInteractEvent;
import net.minecraftforge.event.entity.player.PlayerInteractEvent.Action;
import net.minecraftforge.event.world.BlockEvent;

import java.util.LinkedList;
import java.util.List;
Expand Down Expand Up @@ -102,6 +103,10 @@ public static boolean place( final ItemStack held, final int x, final int y, fin
final List<ItemStack> is = new LinkedList<ItemStack>();
final SelectedPart sp = selectPart( player, host, mop.hitVec.addVector( -mop.blockX, -mop.blockY, -mop.blockZ ) );

BlockEvent.BreakEvent event = new BlockEvent.BreakEvent( x, y, z, world, block, world.getBlockMetadata( x, y, z ), player );
MinecraftForge.EVENT_BUS.post(event);
if(event.isCanceled()) return true;

if( sp.part != null )
{
is.add( sp.part.getItemStack( PartItemStack.Wrench ) );
Expand Down Expand Up @@ -423,6 +428,16 @@ public static IFacadePart isFacade( final ItemStack held, final ForgeDirection s
return null;
}

private static float getEyeHeight()
{
return eyeHeight;
}

public static void setEyeHeight( final float eyeHeight )
{
PartPlacement.eyeHeight = eyeHeight;
}

@SubscribeEvent
public void playerInteract( final TickEvent.ClientTickEvent event )
{
Expand Down Expand Up @@ -485,16 +500,6 @@ else if( event.action == Action.RIGHT_CLICK_BLOCK && event.entityPlayer.worldObj
}
}

private static float getEyeHeight()
{
return eyeHeight;
}

public static void setEyeHeight( final float eyeHeight )
{
PartPlacement.eyeHeight = eyeHeight;
}

public enum PlaceType
{
PLACE_ITEM, INTERACT_FIRST_PASS, INTERACT_SECOND_PASS
Expand Down

0 comments on commit bc50afa

Please sign in to comment.