Fixes #675 No disabled feature should log spam or crash anymore.

Deprecates the old usage of the AEItemDefinitions via the direct method access of

* blocks()
* parts()
* items()
* materials()

and thus use the new re-direct via definitions().

All definitions are now initialized, no matter what. But SubItems, Items and Blocks are not registered, if by chance are disabled.
This commit is contained in:
thatsIch
2015-01-03 02:53:14 +01:00
parent 3dd81433ac
commit 9986ffc458
385 changed files with 12477 additions and 8292 deletions
+99 -90
View File
@@ -18,6 +18,7 @@
package appeng.parts;
import java.util.LinkedList;
import java.util.List;
@@ -40,8 +41,11 @@ import net.minecraftforge.event.entity.player.PlayerInteractEvent.Action;
import cpw.mods.fml.common.eventhandler.SubscribeEvent;
import cpw.mods.fml.common.gameevent.TickEvent;
import com.google.common.base.Optional;
import appeng.api.AEApi;
import appeng.api.definitions.Items;
import appeng.api.definitions.IBlockDefinition;
import appeng.api.definitions.IItems;
import appeng.api.parts.IFacadePart;
import appeng.api.parts.IPartHost;
import appeng.api.parts.IPartItem;
@@ -61,78 +65,15 @@ import appeng.integration.abstraction.IImmibisMicroblocks;
import appeng.util.LookDirection;
import appeng.util.Platform;
public class PartPlacement
{
public static float eyeHeight = 0.0f;
private final ThreadLocal<Object> placing = new ThreadLocal<Object>();
private boolean wasCanceled = false;
@SubscribeEvent
public void playerInteract(TickEvent.ClientTickEvent event)
{
this.wasCanceled = false;
}
@SubscribeEvent
public void playerInteract(PlayerInteractEvent event)
{
if ( event.action == Action.RIGHT_CLICK_AIR && event.entityPlayer.worldObj.isRemote )
{
// re-check to see if this event was already channeled, cause these two events are really stupid...
MovingObjectPosition mop = Platform.rayTrace( event.entityPlayer, true, false );
Minecraft mc = Minecraft.getMinecraft();
float f = 1.0F;
double d0 = mc.playerController.getBlockReachDistance();
Vec3 vec3 = mc.renderViewEntity.getPosition( f );
if ( mop != null && mop.hitVec.distanceTo( vec3 ) < d0 )
{
World w = event.entity.worldObj;
TileEntity te = w.getTileEntity( mop.blockX, mop.blockY, mop.blockZ );
if ( te instanceof IPartHost && this.wasCanceled )
event.setCanceled( true );
}
else
{
ItemStack held = event.entityPlayer.getHeldItem();
final Items items = AEApi.instance().items();
final boolean sameAsMemoryCard = items.itemMemoryCard != null && items.itemMemoryCard.sameAsStack( held );
final boolean sameAsColorApp = items.itemColorApplicator != null && items.itemColorApplicator.sameAsStack( held );
final boolean supportedItem = sameAsMemoryCard || sameAsColorApp;
if ( event.entityPlayer.isSneaking() && held != null && supportedItem )
{
NetworkHandler.instance.sendToServer( new PacketClick( event.x, event.y, event.z, event.face, 0, 0, 0 ) );
}
}
}
else if ( event.action == Action.RIGHT_CLICK_BLOCK && event.entityPlayer.worldObj.isRemote )
{
if ( this.placing.get() != null )
return;
this.placing.set( event );
ItemStack held = event.entityPlayer.getHeldItem();
if ( place( held, event.x, event.y, event.z, event.face, event.entityPlayer, event.entityPlayer.worldObj, PlaceType.INTERACT_FIRST_PASS, 0 ) )
{
event.setCanceled( true );
this.wasCanceled = true;
}
this.placing.set( null );
}
}
public enum PlaceType
{
PLACE_ITEM, INTERACT_FIRST_PASS, INTERACT_SECOND_PASS
}
public static boolean place(ItemStack held, int x, int y, int z, int face, EntityPlayer player, World world, PlaceType pass, int depth)
public static boolean place( ItemStack held, int x, int y, int z, int face, EntityPlayer player, World world, PlaceType pass, int depth )
{
if ( depth > 3 )
return false;
@@ -244,10 +185,10 @@ public class PartPlacement
}
if ( host == null && tile != null && AppEng.instance.isIntegrationEnabled( IntegrationType.FMP ) )
host = ((IFMP) AppEng.instance.getIntegration( IntegrationType.FMP )).getOrCreateHost( tile );
host = ( (IFMP) AppEng.instance.getIntegration( IntegrationType.FMP ) ).getOrCreateHost( tile );
if ( host == null && tile != null && AppEng.instance.isIntegrationEnabled( IntegrationType.ImmibisMicroblocks ) )
host = ((IImmibisMicroblocks) AppEng.instance.getIntegration( IntegrationType.ImmibisMicroblocks )).getOrCreateHost( player, face, tile );
host = ( (IImmibisMicroblocks) AppEng.instance.getIntegration( IntegrationType.ImmibisMicroblocks ) ).getOrCreateHost( player, face, tile );
// if ( held == null )
{
@@ -271,20 +212,18 @@ public class PartPlacement
}
}
}
}
if ( held == null || !(held.getItem() instanceof IPartItem) )
if ( held == null || !( held.getItem() instanceof IPartItem ) )
return false;
int te_x = x;
int te_y = y;
int te_z = z;
final IBlockDefinition multiPart = AEApi.instance().definitions().blocks().multiPart();
if ( host == null && pass == PlaceType.PLACE_ITEM )
{
ItemStack is = AEApi.instance().blocks().blockMultiPart.stack( 1 );
ItemBlock ib = (ItemBlock) is.getItem();
ForgeDirection offset = ForgeDirection.UNKNOWN;
Block blkID = world.getBlock( x, y, z );
@@ -304,13 +243,20 @@ public class PartPlacement
host = (IPartHost) tile;
if ( host == null && tile != null && AppEng.instance.isIntegrationEnabled( IntegrationType.FMP ) )
host = ((IFMP) AppEng.instance.getIntegration( IntegrationType.FMP )).getOrCreateHost( tile );
host = ( (IFMP) AppEng.instance.getIntegration( IntegrationType.FMP ) ).getOrCreateHost( tile );
if ( host == null && tile != null && AppEng.instance.isIntegrationEnabled( IntegrationType.ImmibisMicroblocks ) )
host = ((IImmibisMicroblocks) AppEng.instance.getIntegration( IntegrationType.ImmibisMicroblocks )).getOrCreateHost( player, face, tile );
host = ( (IImmibisMicroblocks) AppEng.instance.getIntegration( IntegrationType.ImmibisMicroblocks ) ).getOrCreateHost( player, face, tile );
if ( host == null && AEApi.instance().blocks().blockMultiPart.block().canPlaceBlockAt( world, te_x, te_y, te_z )
&& ib.placeBlockAt( is, player, world, te_x, te_y, te_z, side.ordinal(), 0.5f, 0.5f, 0.5f, 0 ) )
final Optional<ItemStack> maybeMultiPartStack = multiPart.maybeStack( 1 );
final Optional<Block> maybeMultiPartBlock = multiPart.maybeBlock();
final Optional<ItemBlock> maybeMultiPartItemBlock = multiPart.maybeItemBlock();
final boolean hostIsNotPresent = host == null;
final boolean multiPartPresent = maybeMultiPartBlock.isPresent() && maybeMultiPartStack.isPresent() && maybeMultiPartItemBlock.isPresent();
final boolean canMultiPartBePlaced = maybeMultiPartBlock.get().canPlaceBlockAt( world, te_x, te_y, te_z );
if ( hostIsNotPresent && multiPartPresent && canMultiPartBePlaced && maybeMultiPartItemBlock.get().placeBlockAt( maybeMultiPartStack.get(), player, world, te_x, te_y, te_z, side.ordinal(), 0.5f, 0.5f, 0.5f, 0 ) )
{
if ( !world.isRemote )
{
@@ -329,7 +275,9 @@ public class PartPlacement
}
}
else if ( host != null && !host.canAddPart( held, side ) )
{
return false;
}
}
if ( host == null )
@@ -347,11 +295,10 @@ public class PartPlacement
tile = world.getTileEntity( te_x, te_y, te_z );
if ( tile != null && AppEng.instance.isIntegrationEnabled( IntegrationType.FMP ) )
host = ((IFMP) AppEng.instance.getIntegration( IntegrationType.FMP )).getOrCreateHost( tile );
host = ( (IFMP) AppEng.instance.getIntegration( IntegrationType.FMP ) ).getOrCreateHost( tile );
if ( (blkID == null || blkID.isReplaceable( world, te_x, te_y, te_z ) || host != null) && side != ForgeDirection.UNKNOWN )
return place( held, te_x, te_y, te_z, side.getOpposite().ordinal(), player, world,
pass == PlaceType.INTERACT_FIRST_PASS ? PlaceType.INTERACT_SECOND_PASS : PlaceType.PLACE_ITEM, depth + 1 );
if ( ( blkID == null || blkID.isReplaceable( world, te_x, te_y, te_z ) || host != null ) && side != ForgeDirection.UNKNOWN )
return place( held, te_x, te_y, te_z, side.getOpposite().ordinal(), player, world, pass == PlaceType.INTERACT_FIRST_PASS ? PlaceType.INTERACT_SECOND_PASS : PlaceType.PLACE_ITEM, depth + 1 );
}
return false;
}
@@ -379,10 +326,12 @@ public class PartPlacement
ForgeDirection mySide = host.addPart( held, side, player );
if ( mySide != null )
{
SoundType ss = AEApi.instance().blocks().blockMultiPart.block().stepSound;
for ( Block multiPartBlock : multiPart.maybeBlock().asSet() )
{
final SoundType ss = multiPartBlock.stepSound;
// ss.getPlaceSound()
world.playSoundEffect( 0.5 + x, 0.5 + y, 0.5 + z, ss.func_150496_b(), (ss.getVolume() + 1.0F) / 2.0F, ss.getPitch() * 0.8F );
world.playSoundEffect( 0.5 + x, 0.5 + y, 0.5 + z, ss.func_150496_b(), ( ss.getVolume() + 1.0F ) / 2.0F, ss.getPitch() * 0.8F );
}
if ( !player.capabilities.isCreativeMode )
{
@@ -403,9 +352,7 @@ public class PartPlacement
return true;
}
public static float eyeHeight = 0.0f;
private static float getEyeOffset(EntityPlayer p)
private static float getEyeOffset( EntityPlayer p )
{
if ( p.worldObj.isRemote )
return Platform.getEyeOffset( p );
@@ -413,7 +360,7 @@ public class PartPlacement
return eyeHeight;
}
private static SelectedPart selectPart(EntityPlayer player, IPartHost host, Vec3 pos)
private static SelectedPart selectPart( EntityPlayer player, IPartHost host, Vec3 pos )
{
CommonHelper.proxy.updateRenderMode( player );
SelectedPart sp = host.selectPart( pos );
@@ -422,10 +369,10 @@ public class PartPlacement
return sp;
}
public static IFacadePart isFacade(ItemStack held, ForgeDirection side)
public static IFacadePart isFacade( ItemStack held, ForgeDirection side )
{
if ( held.getItem() instanceof IFacadeItem )
return ((IFacadeItem) held.getItem()).createPartFromItemStack( held, side );
return ( (IFacadeItem) held.getItem() ).createPartFromItemStack( held, side );
if ( AppEng.instance.isIntegrationEnabled( IntegrationType.BC ) )
{
@@ -437,4 +384,66 @@ public class PartPlacement
return null;
}
@SubscribeEvent
public void playerInteract( TickEvent.ClientTickEvent event )
{
this.wasCanceled = false;
}
@SubscribeEvent
public void playerInteract( PlayerInteractEvent event )
{
if ( event.action == Action.RIGHT_CLICK_AIR && event.entityPlayer.worldObj.isRemote )
{
// re-check to see if this event was already channeled, cause these two events are really stupid...
MovingObjectPosition mop = Platform.rayTrace( event.entityPlayer, true, false );
Minecraft mc = Minecraft.getMinecraft();
float f = 1.0F;
double d0 = mc.playerController.getBlockReachDistance();
Vec3 vec3 = mc.renderViewEntity.getPosition( f );
if ( mop != null && mop.hitVec.distanceTo( vec3 ) < d0 )
{
World w = event.entity.worldObj;
TileEntity te = w.getTileEntity( mop.blockX, mop.blockY, mop.blockZ );
if ( te instanceof IPartHost && this.wasCanceled )
event.setCanceled( true );
}
else
{
ItemStack held = event.entityPlayer.getHeldItem();
final IItems items = AEApi.instance().definitions().items();
boolean supportedItem = items.memoryCard().isSameAs( held );
supportedItem |= items.colorApplicator().isSameAs( held );
if ( event.entityPlayer.isSneaking() && held != null && supportedItem )
{
NetworkHandler.instance.sendToServer( new PacketClick( event.x, event.y, event.z, event.face, 0, 0, 0 ) );
}
}
}
else if ( event.action == Action.RIGHT_CLICK_BLOCK && event.entityPlayer.worldObj.isRemote )
{
if ( this.placing.get() != null )
return;
this.placing.set( event );
ItemStack held = event.entityPlayer.getHeldItem();
if ( place( held, event.x, event.y, event.z, event.face, event.entityPlayer, event.entityPlayer.worldObj, PlaceType.INTERACT_FIRST_PASS, 0 ) )
{
event.setCanceled( true );
this.wasCanceled = true;
}
this.placing.set( null );
}
}
public enum PlaceType
{
PLACE_ITEM, INTERACT_FIRST_PASS, INTERACT_SECOND_PASS
}
}