Added Sky Stone Tracking.
Added Meteorite Compass Block / Item. Added Meteorite Spawner Debug Item. Some Refactoring.
This commit is contained in:
@@ -0,0 +1,85 @@
|
||||
package appeng.hooks;
|
||||
|
||||
import java.util.Random;
|
||||
|
||||
import net.minecraft.entity.passive.EntityVillager;
|
||||
import net.minecraft.init.Items;
|
||||
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( Items.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, 2 );
|
||||
addMerchent( recipeList, AEApi.instance().materials().materialCertusQuartzCrystal.stack( 1 ), 2, random, 4 );
|
||||
addMerchent( recipeList, AEApi.instance().materials().materialCertusQuartzDust.stack( 1 ), 1, random, 3 );
|
||||
|
||||
addTrade( recipeList, AEApi.instance().materials().materialCertusQuartzDust.stack( 1 ),
|
||||
AEApi.instance().materials().materialCertusQuartzCrystal.stack( 1 ), random, 2 );
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,104 @@
|
||||
package appeng.hooks;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.util.HashMap;
|
||||
import java.util.Iterator;
|
||||
|
||||
import appeng.core.AELog;
|
||||
import appeng.core.sync.network.NetworkHandler;
|
||||
import appeng.core.sync.packets.PacketCompassRequest;
|
||||
|
||||
public class CompassManager
|
||||
{
|
||||
|
||||
public static CompassManager instance = new CompassManager();
|
||||
|
||||
class CompassReq
|
||||
{
|
||||
|
||||
final int hash;
|
||||
|
||||
final long attunement;
|
||||
final int cx, cdy, cz;
|
||||
|
||||
public CompassReq(long attunement, int x, int y, int z) {
|
||||
this.attunement = attunement;
|
||||
cx = x >> 4;
|
||||
cdy = y >> 5;
|
||||
cz = z >> 4;
|
||||
hash = ((Integer) cx).hashCode() ^ ((Integer) cdy).hashCode() ^ ((Integer) cz).hashCode() ^ ((Long) attunement).hashCode();
|
||||
}
|
||||
|
||||
@Override
|
||||
public int hashCode()
|
||||
{
|
||||
return hash;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean equals(Object obj)
|
||||
{
|
||||
CompassReq b = (CompassReq) obj;
|
||||
return attunement == b.attunement && cx == b.cx && cdy == b.cdy && cz == b.cz;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
HashMap<CompassReq, CompassResult> reqs = new HashMap();
|
||||
|
||||
public void postResult(long attunement, int x, int y, int z, CompassResult res)
|
||||
{
|
||||
AELog.info( "CompassManager.postResult" );
|
||||
CompassReq r = new CompassReq( attunement, x, y, z );
|
||||
reqs.put( r, res );
|
||||
}
|
||||
|
||||
public CompassResult getCompassDirection(long attunement, int x, int y, int z)
|
||||
{
|
||||
long now = System.currentTimeMillis();
|
||||
|
||||
Iterator<CompassResult> i = reqs.values().iterator();
|
||||
while (i.hasNext())
|
||||
{
|
||||
CompassResult res = i.next();
|
||||
long diff = now - res.time;
|
||||
if ( diff > 20000 )
|
||||
i.remove();
|
||||
}
|
||||
|
||||
CompassReq r = new CompassReq( attunement, x, y, z );
|
||||
CompassResult res = reqs.get( r );
|
||||
|
||||
if ( res == null )
|
||||
{
|
||||
res = new CompassResult( false, true, 0 );
|
||||
reqs.put( r, res );
|
||||
requestUpdate( r );
|
||||
}
|
||||
else if ( now - res.time > 1000 * 3 )
|
||||
{
|
||||
if ( !res.requested )
|
||||
{
|
||||
res.requested = true;
|
||||
requestUpdate( r );
|
||||
}
|
||||
}
|
||||
|
||||
return res;
|
||||
}
|
||||
|
||||
private void requestUpdate(CompassReq r)
|
||||
{
|
||||
AELog.info( "CompassManager.requestUpdate" );
|
||||
|
||||
try
|
||||
{
|
||||
NetworkHandler.instance.sendToServer( new PacketCompassRequest( r.attunement, r.cx, r.cz, r.cdy ) );
|
||||
}
|
||||
catch (IOException e)
|
||||
{
|
||||
AELog.error( e );
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,20 @@
|
||||
package appeng.hooks;
|
||||
|
||||
public class CompassResult
|
||||
{
|
||||
|
||||
public final boolean hasResult;
|
||||
public final boolean spin;
|
||||
public final double rad;
|
||||
public final long time;
|
||||
|
||||
public boolean requested = false;
|
||||
|
||||
public CompassResult(boolean hasResult, boolean spin, double rad) {
|
||||
this.hasResult = hasResult;
|
||||
this.spin = spin;
|
||||
this.rad = rad;
|
||||
this.time = System.currentTimeMillis();
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,30 @@
|
||||
package appeng.hooks;
|
||||
|
||||
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.func_149937_b( 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,38 @@
|
||||
package appeng.hooks;
|
||||
|
||||
import net.minecraft.block.BlockDispenser;
|
||||
import net.minecraft.dispenser.BehaviorDefaultDispenseItem;
|
||||
import net.minecraft.dispenser.IBlockSource;
|
||||
import net.minecraft.item.Item;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.util.EnumFacing;
|
||||
import net.minecraft.world.World;
|
||||
import net.minecraft.world.WorldServer;
|
||||
import appeng.items.tools.powered.ToolEntropyManipulator;
|
||||
import appeng.util.Platform;
|
||||
|
||||
final public class DispenserEntropyManipulator extends BehaviorDefaultDispenseItem
|
||||
{
|
||||
|
||||
@Override
|
||||
protected ItemStack dispenseStack(IBlockSource dispenser, ItemStack dispensedItem)
|
||||
{
|
||||
Item i = dispensedItem.getItem();
|
||||
if ( i instanceof ToolEntropyManipulator )
|
||||
{
|
||||
EnumFacing enumfacing = BlockDispenser.func_149937_b( dispenser.getBlockMetadata() );
|
||||
ToolEntropyManipulator tm = (ToolEntropyManipulator) i;
|
||||
|
||||
World w = dispenser.getWorld();
|
||||
if ( w instanceof WorldServer )
|
||||
{
|
||||
int x = dispenser.getXInt() + enumfacing.getFrontOffsetX();
|
||||
int y = dispenser.getYInt() + enumfacing.getFrontOffsetY();
|
||||
int z = dispenser.getZInt() + enumfacing.getFrontOffsetZ();
|
||||
|
||||
tm.onItemUse( dispensedItem, Platform.getPlayer( (WorldServer) w ), w, x, y, z, enumfacing.ordinal(), 0.5f, 0.5f, 0.5f );
|
||||
}
|
||||
}
|
||||
return dispensedItem;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,50 @@
|
||||
package appeng.hooks;
|
||||
|
||||
import net.minecraft.block.BlockDispenser;
|
||||
import net.minecraft.dispenser.BehaviorDefaultDispenseItem;
|
||||
import net.minecraft.dispenser.IBlockSource;
|
||||
import net.minecraft.entity.player.EntityPlayer;
|
||||
import net.minecraft.item.Item;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.util.EnumFacing;
|
||||
import net.minecraft.world.World;
|
||||
import net.minecraft.world.WorldServer;
|
||||
import net.minecraftforge.common.util.ForgeDirection;
|
||||
import appeng.items.tools.powered.ToolMassCannon;
|
||||
import appeng.util.Platform;
|
||||
|
||||
final public class DispenserMatterCannon extends BehaviorDefaultDispenseItem
|
||||
{
|
||||
|
||||
@Override
|
||||
protected ItemStack dispenseStack(IBlockSource dispenser, ItemStack dispensedItem)
|
||||
{
|
||||
Item i = dispensedItem.getItem();
|
||||
if ( i instanceof ToolMassCannon )
|
||||
{
|
||||
EnumFacing enumfacing = BlockDispenser.func_149937_b( dispenser.getBlockMetadata() );
|
||||
ForgeDirection dir = ForgeDirection.UNKNOWN;
|
||||
for (ForgeDirection d : ForgeDirection.VALID_DIRECTIONS)
|
||||
{
|
||||
if ( enumfacing.getFrontOffsetX() == d.offsetX && enumfacing.getFrontOffsetY() == d.offsetY && enumfacing.getFrontOffsetZ() == d.offsetZ )
|
||||
dir = d;
|
||||
}
|
||||
|
||||
ToolMassCannon tm = (ToolMassCannon) i;
|
||||
|
||||
World w = dispenser.getWorld();
|
||||
if ( w instanceof WorldServer )
|
||||
{
|
||||
EntityPlayer p = Platform.getPlayer( (WorldServer) w );
|
||||
Platform.configurePlayer( p, dir, dispenser.getBlockTileEntity() );
|
||||
|
||||
p.posX += dir.offsetX;
|
||||
p.posY += dir.offsetY;
|
||||
p.posZ += dir.offsetZ;
|
||||
|
||||
dispensedItem = tm.onItemRightClick( dispensedItem, w, p );
|
||||
}
|
||||
}
|
||||
return dispensedItem;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,54 @@
|
||||
package appeng.hooks;
|
||||
|
||||
import java.util.Random;
|
||||
|
||||
import net.minecraft.block.Block;
|
||||
import net.minecraft.init.Blocks;
|
||||
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.AEConfig;
|
||||
import cpw.mods.fml.common.IWorldGenerator;
|
||||
|
||||
final public class QuartzWorldGen implements IWorldGenerator
|
||||
{
|
||||
|
||||
final WorldGenMinable oreNormal;
|
||||
final WorldGenMinable oreCharged;
|
||||
|
||||
public QuartzWorldGen() {
|
||||
Block normal = AEApi.instance().blocks().blockQuartzOre.block();
|
||||
Block charged = AEApi.instance().blocks().blockQuartzOreCharged.block();
|
||||
|
||||
if ( normal != null && charged != null )
|
||||
{
|
||||
oreNormal = new WorldGenMinable( normal, 0, AEConfig.instance.oresPerCluster, Blocks.stone );
|
||||
oreCharged = new WorldGenMinable( charged, 0, AEConfig.instance.oresPerCluster, Blocks.stone );
|
||||
}
|
||||
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,136 @@
|
||||
package appeng.hooks;
|
||||
|
||||
import java.util.Collection;
|
||||
import java.util.LinkedList;
|
||||
import java.util.Queue;
|
||||
import java.util.concurrent.Callable;
|
||||
|
||||
import net.minecraftforge.event.world.WorldEvent;
|
||||
import appeng.api.networking.IGridNode;
|
||||
import appeng.core.AELog;
|
||||
import appeng.me.Grid;
|
||||
import appeng.me.NetworkList;
|
||||
import appeng.tile.AEBaseTile;
|
||||
import appeng.util.Platform;
|
||||
import cpw.mods.fml.common.eventhandler.SubscribeEvent;
|
||||
import cpw.mods.fml.common.gameevent.TickEvent;
|
||||
import cpw.mods.fml.common.gameevent.TickEvent.Type;
|
||||
|
||||
public class TickHandler
|
||||
{
|
||||
|
||||
class HandlerRep
|
||||
{
|
||||
|
||||
public Queue<AEBaseTile> tiles = new LinkedList();
|
||||
|
||||
public Collection<Grid> networks = new NetworkList();
|
||||
|
||||
public void clear()
|
||||
{
|
||||
tiles = new LinkedList();
|
||||
networks = new NetworkList();
|
||||
}
|
||||
|
||||
};
|
||||
|
||||
final public static TickHandler instance = new TickHandler();
|
||||
|
||||
final private Queue<Callable> callQueue = new LinkedList();
|
||||
|
||||
final private HandlerRep server = new HandlerRep();
|
||||
final private HandlerRep client = new HandlerRep();
|
||||
|
||||
HandlerRep getRepo()
|
||||
{
|
||||
if ( Platform.isServer() )
|
||||
return server;
|
||||
return client;
|
||||
}
|
||||
|
||||
public void addCallable(Callable c)
|
||||
{
|
||||
callQueue.add( c );
|
||||
}
|
||||
|
||||
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();
|
||||
}
|
||||
|
||||
@SubscribeEvent
|
||||
public void unloadWorld(WorldEvent.Unload ev)
|
||||
{
|
||||
if ( Platform.isServer() )
|
||||
{
|
||||
LinkedList<IGridNode> toDestroy = new LinkedList();
|
||||
|
||||
for (Grid g : getRepo().networks)
|
||||
{
|
||||
for (IGridNode n : g.getNodes())
|
||||
{
|
||||
if ( n.getWorld() == ev.world )
|
||||
toDestroy.add( n );
|
||||
}
|
||||
}
|
||||
|
||||
for (IGridNode n : toDestroy)
|
||||
n.destroy();
|
||||
}
|
||||
}
|
||||
|
||||
@SubscribeEvent
|
||||
public void onTick(TickEvent ev)
|
||||
{
|
||||
if ( ev.type == Type.SERVER )
|
||||
{
|
||||
HandlerRep repo = getRepo();
|
||||
while (!repo.tiles.isEmpty())
|
||||
{
|
||||
AEBaseTile bt = repo.tiles.poll();
|
||||
bt.onReady();
|
||||
}
|
||||
|
||||
for (Grid g : getRepo().networks)
|
||||
{
|
||||
g.update();
|
||||
}
|
||||
|
||||
Callable c = null;
|
||||
while ((c = callQueue.poll()) != null)
|
||||
{
|
||||
try
|
||||
{
|
||||
c.call();
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
AELog.error( e );
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user