AE2 First Commit, the dawn of 1.7 hast arrived.
This commit is contained in:
@@ -0,0 +1,9 @@
|
||||
package appeng.helpers;
|
||||
|
||||
import appeng.api.networking.IGridHost;
|
||||
import appeng.api.parts.IPartHost;
|
||||
|
||||
public interface AEMultiTile extends IGridHost, IPartHost
|
||||
{
|
||||
|
||||
}
|
||||
@@ -0,0 +1,8 @@
|
||||
package appeng.helpers;
|
||||
|
||||
public class AENoHandler extends Exception
|
||||
{
|
||||
|
||||
private static final long serialVersionUID = 7995805326136526631L;
|
||||
|
||||
}
|
||||
@@ -0,0 +1,85 @@
|
||||
package appeng.helpers;
|
||||
|
||||
import java.util.Random;
|
||||
|
||||
import net.minecraft.entity.passive.EntityVillager;
|
||||
import net.minecraft.item.Item;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.village.MerchantRecipe;
|
||||
import net.minecraft.village.MerchantRecipeList;
|
||||
import appeng.api.AEApi;
|
||||
import cpw.mods.fml.common.registry.VillagerRegistry.IVillageTradeHandler;
|
||||
|
||||
public class AETrading implements IVillageTradeHandler
|
||||
{
|
||||
|
||||
private void addToList(MerchantRecipeList l, ItemStack a, ItemStack b)
|
||||
{
|
||||
if ( a.stackSize < 1 )
|
||||
a.stackSize = 1;
|
||||
if ( b.stackSize < 1 )
|
||||
b.stackSize = 1;
|
||||
|
||||
if ( a.stackSize > a.getMaxStackSize() )
|
||||
a.stackSize = a.getMaxStackSize();
|
||||
if ( b.stackSize > b.getMaxStackSize() )
|
||||
b.stackSize = b.getMaxStackSize();
|
||||
|
||||
l.add( new MerchantRecipe( a, b ) );
|
||||
}
|
||||
|
||||
private void addTrade(MerchantRecipeList list, ItemStack a, ItemStack b, Random rand, int convertion_Variance)
|
||||
{
|
||||
// Sell
|
||||
ItemStack From = a.copy();
|
||||
ItemStack To = b.copy();
|
||||
|
||||
From.stackSize = 1 + (Math.abs( rand.nextInt() ) % (1 + convertion_Variance));
|
||||
To.stackSize = 1;
|
||||
|
||||
addToList( list, From, To );
|
||||
}
|
||||
|
||||
private void addMerchent(MerchantRecipeList list, ItemStack item, int emera, Random rand, int greed)
|
||||
{
|
||||
// Sell
|
||||
ItemStack From = item.copy();
|
||||
ItemStack To = new ItemStack( Item.emerald );
|
||||
|
||||
int multiplier = (Math.abs( rand.nextInt() ) % 6);
|
||||
emera += (Math.abs( rand.nextInt() ) % greed) - multiplier;
|
||||
int mood = rand.nextInt() % 2;
|
||||
|
||||
From.stackSize = multiplier + mood;
|
||||
To.stackSize = multiplier * emera - mood;
|
||||
|
||||
if ( To.stackSize < 0 )
|
||||
{
|
||||
From.stackSize -= To.stackSize;
|
||||
To.stackSize -= To.stackSize;
|
||||
}
|
||||
|
||||
addToList( list, From, To );
|
||||
|
||||
// Buy
|
||||
ItemStack reverseTo = From.copy();
|
||||
ItemStack reverseFrom = To.copy();
|
||||
|
||||
reverseFrom.stackSize = (int) (reverseFrom.stackSize * (rand.nextFloat() * 3.0f + 1.0f));
|
||||
reverseTo.stackSize = reverseTo.stackSize;
|
||||
|
||||
addToList( list, reverseFrom, reverseTo );
|
||||
}
|
||||
|
||||
@Override
|
||||
public void manipulateTradesForVillager(EntityVillager villager, MerchantRecipeList recipeList, Random random)
|
||||
{
|
||||
addMerchent( recipeList, AEApi.instance().materials().materialSilicon.stack( 1 ), 1, random, 1 );
|
||||
addMerchent( recipeList, AEApi.instance().materials().materialCertusQuartzCrystal.stack( 1 ), 2, random, 3 );
|
||||
addMerchent( recipeList, AEApi.instance().materials().materialCertusQuartzDust.stack( 1 ), 1, random, 2 );
|
||||
|
||||
addTrade( recipeList, AEApi.instance().materials().materialCertusQuartzDust.stack( 1 ),
|
||||
AEApi.instance().materials().materialCertusQuartzCrystal.stack( 1 ), random, 1 );
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,56 @@
|
||||
package appeng.helpers;
|
||||
|
||||
import java.util.Iterator;
|
||||
|
||||
import net.minecraftforge.common.ForgeDirection;
|
||||
import appeng.api.parts.IPart;
|
||||
import appeng.parts.CableBusContainer;
|
||||
|
||||
public class CBIterator implements Iterator<IPart>
|
||||
{
|
||||
|
||||
int side = 0;
|
||||
CableBusContainer container;
|
||||
|
||||
public CBIterator(CableBusContainer cableBusContainer) {
|
||||
container = cableBusContainer;
|
||||
}
|
||||
|
||||
private void scan()
|
||||
{
|
||||
while (container.getPart( ForgeDirection.getOrientation( side ) ) == null)
|
||||
{
|
||||
side++;
|
||||
if ( side > 6 )
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean hasNext()
|
||||
{
|
||||
scan();
|
||||
if ( side <= 6 )
|
||||
return true;
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public IPart next()
|
||||
{
|
||||
scan();
|
||||
if ( side <= 6 )
|
||||
{
|
||||
side++;
|
||||
return container.getPart( ForgeDirection.getOrientation( side ) );
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void remove()
|
||||
{
|
||||
container.removePart( ForgeDirection.getOrientation( side ) );
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,30 @@
|
||||
package appeng.helpers;
|
||||
|
||||
import net.minecraft.block.BlockDispenser;
|
||||
import net.minecraft.dispenser.BehaviorDefaultDispenseItem;
|
||||
import net.minecraft.dispenser.IBlockSource;
|
||||
import net.minecraft.entity.EntityLiving;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.util.EnumFacing;
|
||||
import net.minecraft.world.World;
|
||||
import appeng.entity.EntityTinyTNTPrimed;
|
||||
|
||||
final public class DispenserBehaviorTinyTNT extends BehaviorDefaultDispenseItem
|
||||
{
|
||||
|
||||
@Override
|
||||
protected ItemStack dispenseStack(IBlockSource dispenser, ItemStack dispensedItem)
|
||||
{
|
||||
EnumFacing enumfacing = BlockDispenser.getFacing( dispenser.getBlockMetadata() );
|
||||
World world = dispenser.getWorld();
|
||||
int i = dispenser.getXInt() + enumfacing.getFrontOffsetX();
|
||||
int j = dispenser.getYInt() + enumfacing.getFrontOffsetY();
|
||||
int k = dispenser.getZInt() + enumfacing.getFrontOffsetZ();
|
||||
EntityTinyTNTPrimed entitytntprimed = new EntityTinyTNTPrimed( world, (double) ((float) i + 0.5F), (double) ((float) j + 0.5F),
|
||||
(double) ((float) k + 0.5F), (EntityLiving) null );
|
||||
world.spawnEntityInWorld( entitytntprimed );
|
||||
--dispensedItem.stackSize;
|
||||
return dispensedItem;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,16 @@
|
||||
package appeng.helpers;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import net.minecraft.entity.Entity;
|
||||
import net.minecraft.util.AxisAlignedBB;
|
||||
import net.minecraft.world.World;
|
||||
|
||||
public interface ICustomCollision
|
||||
{
|
||||
|
||||
Iterable<AxisAlignedBB> getSelectedBoundingBoxsFromPool(World w, int x, int y, int z);
|
||||
|
||||
void addCollidingBlockToList(World w, int x, int y, int z, AxisAlignedBB bb, List out, Entity e);
|
||||
|
||||
}
|
||||
@@ -0,0 +1,23 @@
|
||||
package appeng.helpers;
|
||||
|
||||
import net.minecraft.item.ItemStack;
|
||||
import appeng.api.storage.data.IAEItemStack;
|
||||
import appeng.util.item.AEItemStack;
|
||||
|
||||
public interface ISharedTagCompoundCache
|
||||
{
|
||||
|
||||
final class CacheIAEItemStack
|
||||
{
|
||||
|
||||
ItemStack src;
|
||||
AEItemStack stack;
|
||||
};
|
||||
|
||||
CacheIAEItemStack[] itemStackCache = new CacheIAEItemStack[0];
|
||||
|
||||
void checkCacheSetup(int size);
|
||||
|
||||
IAEItemStack getItem(int x, ItemStack is);
|
||||
|
||||
}
|
||||
@@ -0,0 +1,10 @@
|
||||
package appeng.helpers;
|
||||
|
||||
public enum InventoryAction
|
||||
{
|
||||
// standard vanilla mechanics.
|
||||
PICKUP_OR_SETDOWN, SPLIT_OR_PLACESINGLE, CREATIVE_DUPLICATE, SHIFT_CLICK,
|
||||
|
||||
// extra...
|
||||
MOVE_REGION
|
||||
}
|
||||
@@ -0,0 +1,48 @@
|
||||
package appeng.helpers;
|
||||
|
||||
import net.minecraft.world.IBlockAccess;
|
||||
import net.minecraftforge.common.ForgeDirection;
|
||||
import appeng.api.util.IOrientable;
|
||||
|
||||
public class LocationRotation implements IOrientable
|
||||
{
|
||||
|
||||
final IBlockAccess w;
|
||||
final int x;
|
||||
final int y;
|
||||
final int z;
|
||||
|
||||
public LocationRotation(IBlockAccess world, int x, int y, int z) {
|
||||
w = world;
|
||||
this.x = x;
|
||||
this.y = y;
|
||||
this.z = z;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setOrientation(ForgeDirection Forward, ForgeDirection Up)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public ForgeDirection getUp()
|
||||
{
|
||||
int num = Math.abs( x + y + z ) % 6;
|
||||
return ForgeDirection.getOrientation( num );
|
||||
}
|
||||
|
||||
@Override
|
||||
public ForgeDirection getForward()
|
||||
{
|
||||
if ( getUp().offsetY == 0 )
|
||||
return ForgeDirection.UP;
|
||||
return ForgeDirection.SOUTH;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean canBeRotated()
|
||||
{
|
||||
return true;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,51 @@
|
||||
package appeng.helpers;
|
||||
|
||||
import net.minecraft.world.IBlockAccess;
|
||||
import net.minecraft.world.World;
|
||||
import net.minecraftforge.common.ForgeDirection;
|
||||
import appeng.api.util.IOrientable;
|
||||
|
||||
public class MetaRotation implements IOrientable
|
||||
{
|
||||
|
||||
final IBlockAccess w;
|
||||
final int x;
|
||||
final int y;
|
||||
final int z;
|
||||
|
||||
public MetaRotation(IBlockAccess world, int x, int y, int z) {
|
||||
w = world;
|
||||
this.x = x;
|
||||
this.y = y;
|
||||
this.z = z;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setOrientation(ForgeDirection Forward, ForgeDirection Up)
|
||||
{
|
||||
if ( w instanceof World )
|
||||
((World) w).setBlockMetadataWithNotify( x, y, z, Up.ordinal(), 1 + 2 );
|
||||
else
|
||||
throw new RuntimeException( w.getClass().getName() + " recieved, exptected World" );
|
||||
}
|
||||
|
||||
@Override
|
||||
public ForgeDirection getUp()
|
||||
{
|
||||
return ForgeDirection.getOrientation( w.getBlockMetadata( x, y, z ) );
|
||||
}
|
||||
|
||||
@Override
|
||||
public ForgeDirection getForward()
|
||||
{
|
||||
if ( getUp().offsetY == 0 )
|
||||
return ForgeDirection.UP;
|
||||
return ForgeDirection.SOUTH;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean canBeRotated()
|
||||
{
|
||||
return true;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,311 @@
|
||||
package appeng.helpers;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.util.LinkedList;
|
||||
import java.util.List;
|
||||
|
||||
import net.minecraft.block.Block;
|
||||
import net.minecraft.block.StepSound;
|
||||
import net.minecraft.entity.player.EntityPlayer;
|
||||
import net.minecraft.item.ItemBlock;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.tileentity.TileEntity;
|
||||
import net.minecraft.util.MovingObjectPosition;
|
||||
import net.minecraft.world.World;
|
||||
import net.minecraftforge.common.ForgeDirection;
|
||||
import net.minecraftforge.common.MinecraftForge;
|
||||
import net.minecraftforge.event.ForgeSubscribe;
|
||||
import net.minecraftforge.event.entity.player.PlayerDestroyItemEvent;
|
||||
import net.minecraftforge.event.entity.player.PlayerInteractEvent;
|
||||
import net.minecraftforge.event.entity.player.PlayerInteractEvent.Action;
|
||||
import appeng.api.AEApi;
|
||||
import appeng.api.parts.IFacadePart;
|
||||
import appeng.api.parts.IPartHost;
|
||||
import appeng.api.parts.IPartItem;
|
||||
import appeng.api.parts.SelectedPart;
|
||||
import appeng.core.AppEng;
|
||||
import appeng.core.sync.packets.PacketPartPlacement;
|
||||
import appeng.facade.IFacadeItem;
|
||||
import appeng.integration.abstraction.IBC;
|
||||
import appeng.integration.abstraction.IFMP;
|
||||
import appeng.util.LookDirection;
|
||||
import appeng.util.Platform;
|
||||
import cpw.mods.fml.common.network.PacketDispatcher;
|
||||
|
||||
public class PartPlacement
|
||||
{
|
||||
|
||||
private ThreadLocal<Object> placing = new ThreadLocal<Object>();
|
||||
|
||||
@ForgeSubscribe
|
||||
public void playerInteract(PlayerInteractEvent event)
|
||||
{
|
||||
if ( event.action == Action.RIGHT_CLICK_BLOCK && event.entityPlayer.worldObj.isRemote )
|
||||
{
|
||||
if ( placing.get() != null )
|
||||
return;
|
||||
|
||||
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 );
|
||||
|
||||
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)
|
||||
{
|
||||
if ( depth > 3 )
|
||||
return false;
|
||||
|
||||
ForgeDirection side = ForgeDirection.getOrientation( face );
|
||||
|
||||
if ( held == null )
|
||||
return false;
|
||||
|
||||
if ( Platform.isWrench( player, held, x, y, z ) )
|
||||
{
|
||||
int block = world.getBlockId( x, y, z );
|
||||
TileEntity tile = world.getBlockTileEntity( x, y, z );
|
||||
IPartHost host = null;
|
||||
|
||||
if ( tile instanceof IPartHost )
|
||||
host = (IPartHost) tile;
|
||||
|
||||
if ( host != null )
|
||||
{
|
||||
if ( !world.isRemote )
|
||||
{
|
||||
LookDirection dir = Platform.getPlayerRay( player );
|
||||
MovingObjectPosition mop = Block.blocksList[block].collisionRayTrace( world, x, y, z, dir.a, dir.b );
|
||||
if ( mop != null )
|
||||
{
|
||||
List<ItemStack> is = new LinkedList();
|
||||
SelectedPart sp = host.selectPart( mop.hitVec.addVector( -mop.blockX, -mop.blockY, -mop.blockZ ) );
|
||||
|
||||
if ( sp.part != null )
|
||||
{
|
||||
is.add( sp.part.getItemStack( true ) );
|
||||
sp.part.getDrops( is, true );
|
||||
host.removePart( sp.side );
|
||||
}
|
||||
|
||||
if ( sp.facade != null )
|
||||
{
|
||||
is.add( sp.facade.getItemStack() );
|
||||
host.getFacadeContainer().removeFacade( host, sp.side );
|
||||
}
|
||||
|
||||
if ( is != null && !is.isEmpty() )
|
||||
{
|
||||
Platform.spawnDrops( world, x, y, z, is );
|
||||
}
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
player.swingItem();
|
||||
try
|
||||
{
|
||||
PacketDispatcher.sendPacketToServer( (new PacketPartPlacement( x, y, z, face )).getPacket() );
|
||||
}
|
||||
catch (IOException e)
|
||||
{
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
TileEntity tile = world.getBlockTileEntity( x, y, z );
|
||||
IPartHost host = null;
|
||||
|
||||
if ( tile instanceof IPartHost )
|
||||
host = (IPartHost) tile;
|
||||
|
||||
IFacadePart fp = isFacade( held, side );
|
||||
if ( fp != null )
|
||||
{
|
||||
if ( host != null )
|
||||
{
|
||||
if ( !world.isRemote )
|
||||
{
|
||||
if ( host.getPart( ForgeDirection.UNKNOWN ) == null )
|
||||
return false;
|
||||
|
||||
if ( host.getFacadeContainer().addFacade( fp ) )
|
||||
{
|
||||
host.markForUpdate();
|
||||
if ( !player.capabilities.isCreativeMode )
|
||||
{
|
||||
held.stackSize--;
|
||||
if ( held.stackSize == 0 )
|
||||
{
|
||||
player.inventory.mainInventory[player.inventory.currentItem] = null;
|
||||
MinecraftForge.EVENT_BUS.post( new PlayerDestroyItemEvent( player, held ) );
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
player.swingItem();
|
||||
try
|
||||
{
|
||||
PacketDispatcher.sendPacketToServer( (new PacketPartPlacement( x, y, z, face )).getPacket() );
|
||||
}
|
||||
catch (IOException e)
|
||||
{
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
if ( host == null && tile != null && AppEng.instance.isIntegrationEnabled( "FMP" ) )
|
||||
host = ((IFMP) AppEng.instance.getIntegration( "FMP" )).getOrCreateHost( tile );
|
||||
|
||||
if ( !(held.getItem() instanceof IPartItem) )
|
||||
return false;
|
||||
|
||||
int te_x = x;
|
||||
int te_y = y;
|
||||
int te_z = z;
|
||||
|
||||
if ( host == null && pass == PlaceType.PLACE_ITEM )
|
||||
{
|
||||
ItemStack is = AEApi.instance().blocks().blockMultiPart.stack( 1 );
|
||||
ItemBlock ib = (ItemBlock) is.getItem();
|
||||
ForgeDirection offset = ForgeDirection.UNKNOWN;
|
||||
|
||||
int blkID = world.getBlockId( x, y, z );
|
||||
if ( blkID != 0 && !Block.blocksList[blkID].isBlockReplaceable( world, x, y, z ) )
|
||||
{
|
||||
offset = side;
|
||||
if ( Platform.isServer() )
|
||||
side = side.getOpposite();
|
||||
}
|
||||
|
||||
te_x = x + offset.offsetX;
|
||||
te_y = y + offset.offsetY;
|
||||
te_z = z + offset.offsetZ;
|
||||
|
||||
tile = world.getBlockTileEntity( te_x, te_y, te_z );
|
||||
if ( tile instanceof IPartHost )
|
||||
host = (IPartHost) tile;
|
||||
|
||||
if ( host == null && tile != null && AppEng.instance.isIntegrationEnabled( "FMP" ) )
|
||||
host = ((IFMP) AppEng.instance.getIntegration( "FMP" )).getOrCreateHost( 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 ) )
|
||||
{
|
||||
if ( !world.isRemote )
|
||||
{
|
||||
tile = world.getBlockTileEntity( te_x, te_y, te_z );
|
||||
|
||||
if ( tile instanceof IPartHost )
|
||||
host = (IPartHost) tile;
|
||||
|
||||
pass = PlaceType.INTERACT_SECOND_PASS;
|
||||
}
|
||||
else
|
||||
{
|
||||
player.swingItem();
|
||||
try
|
||||
{
|
||||
PacketDispatcher.sendPacketToServer( (new PacketPartPlacement( x, y, z, face )).getPacket() );
|
||||
}
|
||||
catch (IOException e)
|
||||
{
|
||||
e.printStackTrace();
|
||||
}
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if ( host == null )
|
||||
return false;
|
||||
|
||||
if ( !host.canAddPart( held, side ) )
|
||||
{
|
||||
if ( pass == PlaceType.INTERACT_FIRST_PASS || pass == PlaceType.PLACE_ITEM )
|
||||
{
|
||||
ForgeDirection offset = side;
|
||||
|
||||
te_x = x + offset.offsetX;
|
||||
te_y = y + offset.offsetY;
|
||||
te_z = z + offset.offsetZ;
|
||||
|
||||
int blkID = world.getBlockId( te_x, te_y, te_z );
|
||||
tile = world.getBlockTileEntity( te_x, te_y, te_z );
|
||||
|
||||
if ( tile != null && AppEng.instance.isIntegrationEnabled( "FMP" ) )
|
||||
host = ((IFMP) AppEng.instance.getIntegration( "FMP" )).getOrCreateHost( tile );
|
||||
|
||||
if ( (blkID == 0 || Block.blocksList[blkID].isBlockReplaceable( world, te_x, te_y, te_z ) || host != null) && offset != 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;
|
||||
}
|
||||
|
||||
if ( !world.isRemote )
|
||||
{
|
||||
if ( host.addPart( held, side ) != null )
|
||||
{
|
||||
StepSound ss = AEApi.instance().blocks().blockMultiPart.block().stepSound;
|
||||
world.playSoundEffect( 0.5 + x, 0.5 + y, 0.5 + z, ss.getPlaceSound(), (ss.getVolume() + 1.0F) / 2.0F, ss.getPitch() * 0.8F );
|
||||
|
||||
if ( !player.capabilities.isCreativeMode )
|
||||
{
|
||||
held.stackSize--;
|
||||
if ( held.stackSize == 0 )
|
||||
{
|
||||
player.inventory.mainInventory[player.inventory.currentItem] = null;
|
||||
MinecraftForge.EVENT_BUS.post( new PlayerDestroyItemEvent( player, held ) );
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
player.swingItem();
|
||||
try
|
||||
{
|
||||
PacketDispatcher.sendPacketToServer( (new PacketPartPlacement( x, y, z, face )).getPacket() );
|
||||
}
|
||||
catch (IOException e)
|
||||
{
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
private static IFacadePart isFacade(ItemStack held, ForgeDirection side)
|
||||
{
|
||||
if ( held.getItem() instanceof IFacadeItem )
|
||||
return ((IFacadeItem) held.getItem()).createPartFromItemStack( held, side );
|
||||
if ( AppEng.instance.isIntegrationEnabled( "BC" ) )
|
||||
{
|
||||
IBC bc = (IBC) AppEng.instance.getIntegration( "BC" );
|
||||
if ( bc.isFacade( held ) )
|
||||
return bc.createFacadePart( held, side );
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,54 @@
|
||||
package appeng.helpers;
|
||||
|
||||
import java.util.Random;
|
||||
|
||||
import net.minecraft.block.Block;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.world.World;
|
||||
import net.minecraft.world.chunk.IChunkProvider;
|
||||
import net.minecraft.world.gen.feature.WorldGenMinable;
|
||||
import appeng.api.AEApi;
|
||||
import appeng.core.Configuration;
|
||||
import cpw.mods.fml.common.IWorldGenerator;
|
||||
|
||||
final public class QuartzWorldGen implements IWorldGenerator
|
||||
{
|
||||
|
||||
final WorldGenMinable oreNormal;
|
||||
final WorldGenMinable oreCharged;
|
||||
|
||||
public QuartzWorldGen() {
|
||||
ItemStack normal = AEApi.instance().blocks().blockQuartzOre.stack( 1 );
|
||||
ItemStack charged = AEApi.instance().blocks().blockQuartzOreCharged.stack( 1 );
|
||||
|
||||
if ( normal == null || charged == null )
|
||||
{
|
||||
oreNormal = new WorldGenMinable( normal.itemID, normal.getItemDamage(), Configuration.instance.oresPerCluster, Block.stone.blockID );
|
||||
oreCharged = new WorldGenMinable( normal.itemID, normal.getItemDamage(), Configuration.instance.oresPerCluster, Block.stone.blockID );
|
||||
}
|
||||
else
|
||||
oreNormal = oreCharged = null;
|
||||
};
|
||||
|
||||
@Override
|
||||
public void generate(Random r, int chunkX, int chunkZ, World w, IChunkProvider chunkGenerator, IChunkProvider chunkProvider)
|
||||
{
|
||||
int sealevel = w.provider.getAverageGroundLevel() + 1;
|
||||
|
||||
if ( oreNormal == null || oreCharged == null )
|
||||
return;
|
||||
|
||||
double oreDepthMultiplier = 15 * sealevel / 64;
|
||||
int scale = (int) Math.round( r.nextGaussian() * Math.sqrt( oreDepthMultiplier ) + oreDepthMultiplier );
|
||||
|
||||
for (int x = 0; x < (r.nextBoolean() ? scale * 2 : scale) / 2; ++x)
|
||||
{
|
||||
WorldGenMinable whichOre = r.nextFloat() > 0.92 ? oreCharged : oreNormal;
|
||||
int a = chunkX * 16 + r.nextInt( 22 );
|
||||
int b = r.nextInt( 40 * sealevel / 64 ) + r.nextInt( 22 * sealevel / 64 ) + 12 * sealevel / 64;
|
||||
int c = chunkZ * 16 + r.nextInt( 22 );
|
||||
whichOre.generate( w, r, a, b, c );
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,123 @@
|
||||
package appeng.helpers;
|
||||
|
||||
import java.util.EnumSet;
|
||||
import java.util.LinkedList;
|
||||
import java.util.List;
|
||||
import java.util.Queue;
|
||||
|
||||
import net.minecraftforge.event.ForgeSubscribe;
|
||||
import net.minecraftforge.event.world.WorldEvent;
|
||||
import appeng.api.networking.IGridNode;
|
||||
import appeng.me.Grid;
|
||||
import appeng.tile.AEBaseTile;
|
||||
import appeng.util.Platform;
|
||||
import cpw.mods.fml.common.ITickHandler;
|
||||
import cpw.mods.fml.common.TickType;
|
||||
|
||||
public class TickHandler implements ITickHandler
|
||||
{
|
||||
|
||||
class HandlerRep
|
||||
{
|
||||
|
||||
public Queue<AEBaseTile> tiles = new LinkedList();
|
||||
|
||||
public List<Grid> networks = new LinkedList();
|
||||
|
||||
public void clear()
|
||||
{
|
||||
tiles = new LinkedList();
|
||||
networks = new LinkedList();
|
||||
}
|
||||
|
||||
};
|
||||
|
||||
final public static TickHandler instance = new TickHandler();
|
||||
|
||||
final private HandlerRep server = new HandlerRep();
|
||||
final private HandlerRep client = new HandlerRep();
|
||||
|
||||
HandlerRep getRepo()
|
||||
{
|
||||
if ( Platform.isServer() )
|
||||
return server;
|
||||
return client;
|
||||
}
|
||||
|
||||
public void addInit(AEBaseTile tile)
|
||||
{
|
||||
getRepo().tiles.add( tile );
|
||||
}
|
||||
|
||||
public void addNetwork(Grid grid)
|
||||
{
|
||||
if ( Platform.isServer() )
|
||||
getRepo().networks.add( grid );
|
||||
}
|
||||
|
||||
public void removeNetwork(Grid grid)
|
||||
{
|
||||
if ( Platform.isServer() )
|
||||
getRepo().networks.remove( grid );
|
||||
}
|
||||
|
||||
public Iterable<Grid> getGridList()
|
||||
{
|
||||
return getRepo().networks;
|
||||
}
|
||||
|
||||
public void shutdown()
|
||||
{
|
||||
getRepo().clear();
|
||||
}
|
||||
|
||||
@ForgeSubscribe
|
||||
public void unloadWorld(WorldEvent.Unload ev)
|
||||
{
|
||||
if ( Platform.isServer() )
|
||||
{
|
||||
for (Grid g : getRepo().networks)
|
||||
{
|
||||
for (IGridNode n : g.getNodes())
|
||||
{
|
||||
if ( n.getWorld() == ev.world )
|
||||
n.destroy();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void tickStart(EnumSet<TickType> type, Object... tickData)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void tickEnd(EnumSet<TickType> type, Object... tickData)
|
||||
{
|
||||
HandlerRep repo = getRepo();
|
||||
while (!repo.tiles.isEmpty())
|
||||
{
|
||||
AEBaseTile bt = repo.tiles.poll();
|
||||
bt.onReady();
|
||||
}
|
||||
|
||||
for (Grid g : getRepo().networks)
|
||||
{
|
||||
g.update();
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public EnumSet<TickType> ticks()
|
||||
{
|
||||
return EnumSet.of( TickType.WORLD );
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getLabel()
|
||||
{
|
||||
return "AE-TickHandler";
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user