pick 97420a31d The big reformat of 2020
This commit is contained in:
@@ -18,82 +18,44 @@
|
||||
|
||||
package appeng.hooks;
|
||||
|
||||
|
||||
// TODO Villager Trading!??!?!
|
||||
|
||||
public class AETrading
|
||||
{
|
||||
public class AETrading {
|
||||
|
||||
/*
|
||||
* @Override
|
||||
* public void manipulateTradesForVillager( EntityVillager villager, MerchantRecipeList recipeList, Random random )
|
||||
* {
|
||||
* final IMaterials materials = AEApi.instance().definitions().materials();
|
||||
* this.addMerchant( recipeList, materials.silicon(), 1, random, 2 );
|
||||
* this.addMerchant( recipeList, materials.certusQuartzCrystal(), 2, random, 4 );
|
||||
* this.addMerchant( recipeList, materials.certusQuartzDust(), 1, random, 3 );
|
||||
* this.addTrade( recipeList, materials.certusQuartzDust(), materials.certusQuartzCrystal(), random, 2 );
|
||||
* }
|
||||
* private void addMerchant( MerchantRecipeList list, IItemDefinition item, int emera, Random rand, int greed )
|
||||
* {
|
||||
* for( ItemStack itemStack : item.maybeStack( 1 ).asSet() )
|
||||
* {
|
||||
* // Sell
|
||||
* ItemStack from = itemStack.copy();
|
||||
* ItemStack to = new ItemStack( Items.emerald );
|
||||
* int multiplier = ( Math.abs( rand.nextInt() ) % 6 );
|
||||
* final int emeraldCost = emera + ( Math.abs( rand.nextInt() ) % greed ) - multiplier;
|
||||
* int mood = rand.nextInt() % 2;
|
||||
* from.stackSize = multiplier + mood;
|
||||
* to.stackSize = multiplier * emeraldCost - mood;
|
||||
* if( to.stackSize < 0 )
|
||||
* {
|
||||
* from.stackSize -= to.stackSize;
|
||||
* to.stackSize -= to.stackSize;
|
||||
* }
|
||||
* this.addToList( list, from, to );
|
||||
* // Buy
|
||||
* ItemStack reverseTo = from.copy();
|
||||
* ItemStack reverseFrom = to.copy();
|
||||
* reverseFrom.stackSize *= rand.nextFloat() * 3.0f + 1.0f;
|
||||
* this.addToList( list, reverseFrom, reverseTo );
|
||||
* }
|
||||
* }
|
||||
* private void addTrade( MerchantRecipeList list, IItemDefinition inputDefinition, IItemDefinition
|
||||
* outputDefinition, Random rand, int conversionVariance )
|
||||
* {
|
||||
* final Optional<ItemStack> maybeInputStack = inputDefinition.maybeStack( 1 );
|
||||
* final Optional<ItemStack> maybeOutputStack = outputDefinition.maybeStack( 1 );
|
||||
* if( maybeInputStack.isPresent() && maybeOutputStack.isPresent() )
|
||||
* {
|
||||
* // Sell
|
||||
* ItemStack inputStack = maybeInputStack.get().copy();
|
||||
* ItemStack outputStack = maybeOutputStack.get().copy();
|
||||
* inputStack.stackSize = 1 + ( Math.abs( rand.nextInt() ) % ( 1 + conversionVariance ) );
|
||||
* outputStack.stackSize = 1;
|
||||
* this.addToList( list, inputStack, outputStack );
|
||||
* }
|
||||
* }
|
||||
* 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 ) );
|
||||
* }
|
||||
*/
|
||||
/*
|
||||
* @Override public void manipulateTradesForVillager( EntityVillager villager,
|
||||
* MerchantRecipeList recipeList, Random random ) { final IMaterials materials =
|
||||
* AEApi.instance().definitions().materials(); this.addMerchant( recipeList,
|
||||
* materials.silicon(), 1, random, 2 ); this.addMerchant( recipeList,
|
||||
* materials.certusQuartzCrystal(), 2, random, 4 ); this.addMerchant(
|
||||
* recipeList, materials.certusQuartzDust(), 1, random, 3 ); this.addTrade(
|
||||
* recipeList, materials.certusQuartzDust(), materials.certusQuartzCrystal(),
|
||||
* random, 2 ); } private void addMerchant( MerchantRecipeList list,
|
||||
* IItemDefinition item, int emera, Random rand, int greed ) { for( ItemStack
|
||||
* itemStack : item.maybeStack( 1 ).asSet() ) { // Sell ItemStack from =
|
||||
* itemStack.copy(); ItemStack to = new ItemStack( Items.emerald ); int
|
||||
* multiplier = ( Math.abs( rand.nextInt() ) % 6 ); final int emeraldCost =
|
||||
* emera + ( Math.abs( rand.nextInt() ) % greed ) - multiplier; int mood =
|
||||
* rand.nextInt() % 2; from.stackSize = multiplier + mood; to.stackSize =
|
||||
* multiplier * emeraldCost - mood; if( to.stackSize < 0 ) { from.stackSize -=
|
||||
* to.stackSize; to.stackSize -= to.stackSize; } this.addToList( list, from, to
|
||||
* ); // Buy ItemStack reverseTo = from.copy(); ItemStack reverseFrom =
|
||||
* to.copy(); reverseFrom.stackSize *= rand.nextFloat() * 3.0f + 1.0f;
|
||||
* this.addToList( list, reverseFrom, reverseTo ); } } private void addTrade(
|
||||
* MerchantRecipeList list, IItemDefinition inputDefinition, IItemDefinition
|
||||
* outputDefinition, Random rand, int conversionVariance ) { final
|
||||
* Optional<ItemStack> maybeInputStack = inputDefinition.maybeStack( 1 ); final
|
||||
* Optional<ItemStack> maybeOutputStack = outputDefinition.maybeStack( 1 ); if(
|
||||
* maybeInputStack.isPresent() && maybeOutputStack.isPresent() ) { // Sell
|
||||
* ItemStack inputStack = maybeInputStack.get().copy(); ItemStack outputStack =
|
||||
* maybeOutputStack.get().copy(); inputStack.stackSize = 1 + ( Math.abs(
|
||||
* rand.nextInt() ) % ( 1 + conversionVariance ) ); outputStack.stackSize = 1;
|
||||
* this.addToList( list, inputStack, outputStack ); } } 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 ) ); }
|
||||
*/
|
||||
|
||||
}
|
||||
|
||||
@@ -18,105 +18,88 @@
|
||||
|
||||
package appeng.hooks;
|
||||
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.Iterator;
|
||||
|
||||
import appeng.core.sync.network.NetworkHandler;
|
||||
import appeng.core.sync.packets.PacketCompassRequest;
|
||||
|
||||
public class CompassManager {
|
||||
|
||||
public class CompassManager
|
||||
{
|
||||
public static final CompassManager INSTANCE = new CompassManager();
|
||||
private final HashMap<CompassRequest, CompassResult> requests = new HashMap<>();
|
||||
|
||||
public static final CompassManager INSTANCE = new CompassManager();
|
||||
private final HashMap<CompassRequest, CompassResult> requests = new HashMap<>();
|
||||
public void postResult(final long attunement, final int x, final int y, final int z, final CompassResult result) {
|
||||
final CompassRequest r = new CompassRequest(attunement, x, y, z);
|
||||
this.requests.put(r, result);
|
||||
}
|
||||
|
||||
public void postResult( final long attunement, final int x, final int y, final int z, final CompassResult result )
|
||||
{
|
||||
final CompassRequest r = new CompassRequest( attunement, x, y, z );
|
||||
this.requests.put( r, result );
|
||||
}
|
||||
public CompassResult getCompassDirection(final long attunement, final int x, final int y, final int z) {
|
||||
final long now = System.currentTimeMillis();
|
||||
|
||||
public CompassResult getCompassDirection( final long attunement, final int x, final int y, final int z )
|
||||
{
|
||||
final long now = System.currentTimeMillis();
|
||||
final Iterator<CompassResult> i = this.requests.values().iterator();
|
||||
while (i.hasNext()) {
|
||||
final CompassResult res = i.next();
|
||||
final long diff = now - res.getTime();
|
||||
if (diff > 20000) {
|
||||
i.remove();
|
||||
}
|
||||
}
|
||||
|
||||
final Iterator<CompassResult> i = this.requests.values().iterator();
|
||||
while( i.hasNext() )
|
||||
{
|
||||
final CompassResult res = i.next();
|
||||
final long diff = now - res.getTime();
|
||||
if( diff > 20000 )
|
||||
{
|
||||
i.remove();
|
||||
}
|
||||
}
|
||||
final CompassRequest r = new CompassRequest(attunement, x, y, z);
|
||||
CompassResult res = this.requests.get(r);
|
||||
|
||||
final CompassRequest r = new CompassRequest( attunement, x, y, z );
|
||||
CompassResult res = this.requests.get( r );
|
||||
if (res == null) {
|
||||
res = new CompassResult(false, true, 0);
|
||||
this.requests.put(r, res);
|
||||
this.requestUpdate(r);
|
||||
} else if (now - res.getTime() > 1000 * 3) {
|
||||
if (!res.isRequested()) {
|
||||
res.setRequested(true);
|
||||
this.requestUpdate(r);
|
||||
}
|
||||
}
|
||||
|
||||
if( res == null )
|
||||
{
|
||||
res = new CompassResult( false, true, 0 );
|
||||
this.requests.put( r, res );
|
||||
this.requestUpdate( r );
|
||||
}
|
||||
else if( now - res.getTime() > 1000 * 3 )
|
||||
{
|
||||
if( !res.isRequested() )
|
||||
{
|
||||
res.setRequested( true );
|
||||
this.requestUpdate( r );
|
||||
}
|
||||
}
|
||||
return res;
|
||||
}
|
||||
|
||||
return res;
|
||||
}
|
||||
private void requestUpdate(final CompassRequest r) {
|
||||
NetworkHandler.instance().sendToServer(new PacketCompassRequest(r.attunement, r.cx, r.cz, r.cdy));
|
||||
}
|
||||
|
||||
private void requestUpdate( final CompassRequest r )
|
||||
{
|
||||
NetworkHandler.instance().sendToServer( new PacketCompassRequest( r.attunement, r.cx, r.cz, r.cdy ) );
|
||||
}
|
||||
private static class CompassRequest {
|
||||
|
||||
private static class CompassRequest
|
||||
{
|
||||
private final int hash;
|
||||
private final long attunement;
|
||||
private final int cx;
|
||||
private final int cdy;
|
||||
private final int cz;
|
||||
|
||||
private final int hash;
|
||||
private final long attunement;
|
||||
private final int cx;
|
||||
private final int cdy;
|
||||
private final int cz;
|
||||
public CompassRequest(final long attunement, final int x, final int y, final int z) {
|
||||
this.attunement = attunement;
|
||||
this.cx = x >> 4;
|
||||
this.cdy = y >> 5;
|
||||
this.cz = z >> 4;
|
||||
this.hash = ((Integer) this.cx).hashCode() ^ ((Integer) this.cdy).hashCode()
|
||||
^ ((Integer) this.cz).hashCode() ^ ((Long) attunement).hashCode();
|
||||
}
|
||||
|
||||
public CompassRequest( final long attunement, final int x, final int y, final int z )
|
||||
{
|
||||
this.attunement = attunement;
|
||||
this.cx = x >> 4;
|
||||
this.cdy = y >> 5;
|
||||
this.cz = z >> 4;
|
||||
this.hash = ( (Integer) this.cx ).hashCode() ^ ( (Integer) this.cdy ).hashCode() ^ ( (Integer) this.cz ).hashCode() ^ ( (Long) attunement )
|
||||
.hashCode();
|
||||
}
|
||||
@Override
|
||||
public int hashCode() {
|
||||
return this.hash;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int hashCode()
|
||||
{
|
||||
return this.hash;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean equals( final Object obj )
|
||||
{
|
||||
if( obj == null )
|
||||
{
|
||||
return false;
|
||||
}
|
||||
if( this.getClass() != obj.getClass() )
|
||||
{
|
||||
return false;
|
||||
}
|
||||
final CompassRequest other = (CompassRequest) obj;
|
||||
return this.attunement == other.attunement && this.cx == other.cx && this.cdy == other.cdy && this.cz == other.cz;
|
||||
}
|
||||
}
|
||||
@Override
|
||||
public boolean equals(final Object obj) {
|
||||
if (obj == null) {
|
||||
return false;
|
||||
}
|
||||
if (this.getClass() != obj.getClass()) {
|
||||
return false;
|
||||
}
|
||||
final CompassRequest other = (CompassRequest) obj;
|
||||
return this.attunement == other.attunement && this.cx == other.cx && this.cdy == other.cdy
|
||||
&& this.cz == other.cz;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -18,51 +18,42 @@
|
||||
|
||||
package appeng.hooks;
|
||||
|
||||
public class CompassResult {
|
||||
|
||||
public class CompassResult
|
||||
{
|
||||
private final boolean hasResult;
|
||||
private final boolean spin;
|
||||
private final double rad;
|
||||
private final long time;
|
||||
private boolean requested = false;
|
||||
|
||||
private final boolean hasResult;
|
||||
private final boolean spin;
|
||||
private final double rad;
|
||||
private final long time;
|
||||
private boolean requested = false;
|
||||
public CompassResult(final boolean hasResult, final boolean spin, final double rad) {
|
||||
this.hasResult = hasResult;
|
||||
this.spin = spin;
|
||||
this.rad = rad;
|
||||
this.time = System.currentTimeMillis();
|
||||
}
|
||||
|
||||
public CompassResult( final boolean hasResult, final boolean spin, final double rad )
|
||||
{
|
||||
this.hasResult = hasResult;
|
||||
this.spin = spin;
|
||||
this.rad = rad;
|
||||
this.time = System.currentTimeMillis();
|
||||
}
|
||||
public boolean isValidResult() {
|
||||
return this.hasResult;
|
||||
}
|
||||
|
||||
public boolean isValidResult()
|
||||
{
|
||||
return this.hasResult;
|
||||
}
|
||||
public boolean isSpin() {
|
||||
return this.spin;
|
||||
}
|
||||
|
||||
public boolean isSpin()
|
||||
{
|
||||
return this.spin;
|
||||
}
|
||||
public double getRad() {
|
||||
return this.rad;
|
||||
}
|
||||
|
||||
public double getRad()
|
||||
{
|
||||
return this.rad;
|
||||
}
|
||||
boolean isRequested() {
|
||||
return this.requested;
|
||||
}
|
||||
|
||||
boolean isRequested()
|
||||
{
|
||||
return this.requested;
|
||||
}
|
||||
void setRequested(final boolean requested) {
|
||||
this.requested = requested;
|
||||
}
|
||||
|
||||
void setRequested( final boolean requested )
|
||||
{
|
||||
this.requested = requested;
|
||||
}
|
||||
|
||||
long getTime()
|
||||
{
|
||||
return this.time;
|
||||
}
|
||||
long getTime() {
|
||||
return this.time;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -18,7 +18,6 @@
|
||||
|
||||
package appeng.hooks;
|
||||
|
||||
|
||||
import net.minecraft.block.DispenserBlock;
|
||||
import net.minecraft.dispenser.DefaultDispenseItemBehavior;
|
||||
import net.minecraft.dispenser.IBlockSource;
|
||||
@@ -28,21 +27,19 @@ import net.minecraft.world.World;
|
||||
|
||||
import appeng.entity.EntityTinyTNTPrimed;
|
||||
|
||||
public final class DispenserBehaviorTinyTNT extends DefaultDispenseItemBehavior {
|
||||
|
||||
public final class DispenserBehaviorTinyTNT extends DefaultDispenseItemBehavior
|
||||
{
|
||||
|
||||
@Override
|
||||
protected ItemStack dispenseStack( final IBlockSource dispenser, final ItemStack dispensedItem )
|
||||
{
|
||||
final Direction Direction = dispenser.getBlockState().get( DispenserBlock.FACING );
|
||||
final World world = dispenser.getWorld();
|
||||
final int i = dispenser.getBlockPos().getX() + Direction.getXOffset();
|
||||
final int j = dispenser.getBlockPos().getY() + Direction.getYOffset();
|
||||
final int k = dispenser.getBlockPos().getZ() + Direction.getZOffset();
|
||||
final EntityTinyTNTPrimed primedTinyTNTEntity = new EntityTinyTNTPrimed( world, i + 0.5F, j + 0.5F, k + 0.5F, null );
|
||||
world.addEntity( primedTinyTNTEntity );
|
||||
dispensedItem.setCount( dispensedItem.getCount() - 1 );
|
||||
return dispensedItem;
|
||||
}
|
||||
@Override
|
||||
protected ItemStack dispenseStack(final IBlockSource dispenser, final ItemStack dispensedItem) {
|
||||
final Direction Direction = dispenser.getBlockState().get(DispenserBlock.FACING);
|
||||
final World world = dispenser.getWorld();
|
||||
final int i = dispenser.getBlockPos().getX() + Direction.getXOffset();
|
||||
final int j = dispenser.getBlockPos().getY() + Direction.getYOffset();
|
||||
final int k = dispenser.getBlockPos().getZ() + Direction.getZOffset();
|
||||
final EntityTinyTNTPrimed primedTinyTNTEntity = new EntityTinyTNTPrimed(world, i + 0.5F, j + 0.5F, k + 0.5F,
|
||||
null);
|
||||
world.addEntity(primedTinyTNTEntity);
|
||||
dispensedItem.setCount(dispensedItem.getCount() - 1);
|
||||
return dispensedItem;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -18,7 +18,6 @@
|
||||
|
||||
package appeng.hooks;
|
||||
|
||||
|
||||
import net.minecraft.block.DispenserBlock;
|
||||
import net.minecraft.dispenser.DefaultDispenseItemBehavior;
|
||||
import net.minecraft.dispenser.IBlockSource;
|
||||
@@ -31,26 +30,21 @@ import net.minecraft.world.server.ServerWorld;
|
||||
|
||||
import appeng.util.Platform;
|
||||
|
||||
public final class DispenserBlockTool extends DefaultDispenseItemBehavior {
|
||||
|
||||
public final class DispenserBlockTool extends DefaultDispenseItemBehavior
|
||||
{
|
||||
@Override
|
||||
protected ItemStack dispenseStack(final IBlockSource dispenser, final ItemStack dispensedItem) {
|
||||
final Item i = dispensedItem.getItem();
|
||||
if (i instanceof IBlockTool) {
|
||||
final Direction Direction = dispenser.getBlockState().get(DispenserBlock.FACING);
|
||||
final IBlockTool tm = (IBlockTool) i;
|
||||
|
||||
@Override
|
||||
protected ItemStack dispenseStack( final IBlockSource dispenser, final ItemStack dispensedItem )
|
||||
{
|
||||
final Item i = dispensedItem.getItem();
|
||||
if( i instanceof IBlockTool )
|
||||
{
|
||||
final Direction Direction = dispenser.getBlockState().get( DispenserBlock.FACING );
|
||||
final IBlockTool tm = (IBlockTool) i;
|
||||
|
||||
final World w = dispenser.getWorld();
|
||||
if( w instanceof ServerWorld )
|
||||
{
|
||||
tm.onItemUse( dispensedItem, Platform.getPlayer( (ServerWorld) w ), w, dispenser.getBlockPos().offset( Direction ), Hand.MAIN_HAND,
|
||||
Direction, 0.5f, 0.5f, 0.5f );
|
||||
}
|
||||
}
|
||||
return dispensedItem;
|
||||
}
|
||||
final World w = dispenser.getWorld();
|
||||
if (w instanceof ServerWorld) {
|
||||
tm.onItemUse(dispensedItem, Platform.getPlayer((ServerWorld) w), w,
|
||||
dispenser.getBlockPos().offset(Direction), Hand.MAIN_HAND, Direction, 0.5f, 0.5f, 0.5f);
|
||||
}
|
||||
}
|
||||
return dispensedItem;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -18,7 +18,6 @@
|
||||
|
||||
package appeng.hooks;
|
||||
|
||||
|
||||
import net.minecraft.block.DispenserBlock;
|
||||
import net.minecraft.dispenser.DefaultDispenseItemBehavior;
|
||||
import net.minecraft.dispenser.IBlockSource;
|
||||
@@ -33,39 +32,33 @@ import appeng.api.util.AEPartLocation;
|
||||
import appeng.items.tools.powered.ToolMatterCannon;
|
||||
import appeng.util.Platform;
|
||||
|
||||
public final class DispenserMatterCannon extends DefaultDispenseItemBehavior {
|
||||
|
||||
public final class DispenserMatterCannon extends DefaultDispenseItemBehavior
|
||||
{
|
||||
@Override
|
||||
protected ItemStack dispenseStack(final IBlockSource dispenser, ItemStack dispensedItem) {
|
||||
final Item i = dispensedItem.getItem();
|
||||
if (i instanceof ToolMatterCannon) {
|
||||
final Direction Direction = dispenser.getBlockState().get(DispenserBlock.FACING);
|
||||
AEPartLocation dir = AEPartLocation.INTERNAL;
|
||||
for (final AEPartLocation d : AEPartLocation.SIDE_LOCATIONS) {
|
||||
if (Direction.getXOffset() == d.xOffset && Direction.getYOffset() == d.yOffset
|
||||
&& Direction.getZOffset() == d.zOffset) {
|
||||
dir = d;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
protected ItemStack dispenseStack( final IBlockSource dispenser, ItemStack dispensedItem )
|
||||
{
|
||||
final Item i = dispensedItem.getItem();
|
||||
if( i instanceof ToolMatterCannon )
|
||||
{
|
||||
final Direction Direction = dispenser.getBlockState().get( DispenserBlock.FACING );
|
||||
AEPartLocation dir = AEPartLocation.INTERNAL;
|
||||
for( final AEPartLocation d : AEPartLocation.SIDE_LOCATIONS )
|
||||
{
|
||||
if( Direction.getXOffset() == d.xOffset && Direction.getYOffset() == d.yOffset && Direction.getZOffset() == d.zOffset )
|
||||
{
|
||||
dir = d;
|
||||
}
|
||||
}
|
||||
final ToolMatterCannon tm = (ToolMatterCannon) i;
|
||||
|
||||
final ToolMatterCannon tm = (ToolMatterCannon) i;
|
||||
final World w = dispenser.getWorld();
|
||||
if (w instanceof ServerWorld) {
|
||||
final PlayerEntity p = Platform.getPlayer((ServerWorld) w);
|
||||
Platform.configurePlayer(p, dir, dispenser.getBlockTileEntity());
|
||||
|
||||
final World w = dispenser.getWorld();
|
||||
if( w instanceof ServerWorld )
|
||||
{
|
||||
final PlayerEntity p = Platform.getPlayer( (ServerWorld) w );
|
||||
Platform.configurePlayer( p, dir, dispenser.getBlockTileEntity() );
|
||||
p.setPosition(p.getPosX() + dir.xOffset, p.getPosY() + dir.yOffset, p.getPosZ() + dir.zOffset);
|
||||
|
||||
p.setPosition( p.getPosX() + dir.xOffset, p.getPosY() + dir.yOffset, p.getPosZ() + dir.zOffset );
|
||||
|
||||
dispensedItem = tm.onItemRightClick( w, p, null ).getResult();
|
||||
}
|
||||
}
|
||||
return dispensedItem;
|
||||
}
|
||||
dispensedItem = tm.onItemRightClick(w, p, null).getResult();
|
||||
}
|
||||
}
|
||||
return dispensedItem;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -18,7 +18,6 @@
|
||||
|
||||
package appeng.hooks;
|
||||
|
||||
|
||||
import net.minecraft.entity.player.PlayerEntity;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.util.ActionResultType;
|
||||
@@ -27,13 +26,13 @@ import net.minecraft.util.Hand;
|
||||
import net.minecraft.util.math.BlockPos;
|
||||
import net.minecraft.world.World;
|
||||
|
||||
public interface IBlockTool {
|
||||
// Workaround for dispenser logic.
|
||||
// TODO ItemUseContext
|
||||
ActionResultType onItemUse(ItemStack is, PlayerEntity p, World w, BlockPos pos, Hand hand, Direction side,
|
||||
float hitX, float hitY, float hitZ);
|
||||
|
||||
public interface IBlockTool
|
||||
{
|
||||
// Workaround for dispenser logic.
|
||||
//TODO ItemUseContext
|
||||
ActionResultType onItemUse( ItemStack is, PlayerEntity p, World w, BlockPos pos, Hand hand, Direction side, float hitX, float hitY, float hitZ );
|
||||
|
||||
ActionResultType onItemUse( PlayerEntity p, World w, BlockPos pos, Hand hand, Direction side, float hitX, float hitY, float hitZ );
|
||||
ActionResultType onItemUse(PlayerEntity p, World w, BlockPos pos, Hand hand, Direction side, float hitX, float hitY,
|
||||
float hitZ);
|
||||
|
||||
}
|
||||
|
||||
@@ -18,7 +18,6 @@
|
||||
|
||||
package appeng.hooks;
|
||||
|
||||
|
||||
import java.util.ArrayDeque;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collection;
|
||||
@@ -58,297 +57,244 @@ import appeng.tile.AEBaseTile;
|
||||
import appeng.util.IWorldCallable;
|
||||
import appeng.util.Platform;
|
||||
|
||||
public class TickHandler {
|
||||
|
||||
public class TickHandler
|
||||
{
|
||||
public static final TickHandler INSTANCE = new TickHandler();
|
||||
private final Queue<IWorldCallable<?>> serverQueue = new ArrayDeque<>();
|
||||
private final Multimap<World, CraftingJob> craftingJobs = LinkedListMultimap.create();
|
||||
private final WeakHashMap<IWorld, Queue<IWorldCallable<?>>> callQueue = new WeakHashMap<>();
|
||||
private final HandlerRep server = new HandlerRep();
|
||||
private final HandlerRep client = new HandlerRep();
|
||||
private final HashMap<Integer, PlayerColor> cliPlayerColors = new HashMap<>();
|
||||
private final HashMap<Integer, PlayerColor> srvPlayerColors = new HashMap<>();
|
||||
private CableRenderMode crm = CableRenderMode.STANDARD;
|
||||
|
||||
public static final TickHandler INSTANCE = new TickHandler();
|
||||
private final Queue<IWorldCallable<?>> serverQueue = new ArrayDeque<>();
|
||||
private final Multimap<World, CraftingJob> craftingJobs = LinkedListMultimap.create();
|
||||
private final WeakHashMap<IWorld, Queue<IWorldCallable<?>>> callQueue = new WeakHashMap<>();
|
||||
private final HandlerRep server = new HandlerRep();
|
||||
private final HandlerRep client = new HandlerRep();
|
||||
private final HashMap<Integer, PlayerColor> cliPlayerColors = new HashMap<>();
|
||||
private final HashMap<Integer, PlayerColor> srvPlayerColors = new HashMap<>();
|
||||
private CableRenderMode crm = CableRenderMode.STANDARD;
|
||||
public HashMap<Integer, PlayerColor> getPlayerColors() {
|
||||
if (Platform.isServer()) {
|
||||
return this.srvPlayerColors;
|
||||
}
|
||||
return this.cliPlayerColors;
|
||||
}
|
||||
|
||||
public HashMap<Integer, PlayerColor> getPlayerColors()
|
||||
{
|
||||
if( Platform.isServer() )
|
||||
{
|
||||
return this.srvPlayerColors;
|
||||
}
|
||||
return this.cliPlayerColors;
|
||||
}
|
||||
public void addCallable(final IWorld w, final IWorldCallable<?> c) {
|
||||
if (w == null) {
|
||||
this.serverQueue.add(c);
|
||||
} else {
|
||||
Queue<IWorldCallable<?>> queue = this.callQueue.get(w);
|
||||
|
||||
public void addCallable( final IWorld w, final IWorldCallable<?> c )
|
||||
{
|
||||
if( w == null )
|
||||
{
|
||||
this.serverQueue.add( c );
|
||||
}
|
||||
else
|
||||
{
|
||||
Queue<IWorldCallable<?>> queue = this.callQueue.get( w );
|
||||
if (queue == null) {
|
||||
queue = new ArrayDeque<>();
|
||||
this.callQueue.put(w, queue);
|
||||
}
|
||||
|
||||
if( queue == null )
|
||||
{
|
||||
queue = new ArrayDeque<>();
|
||||
this.callQueue.put( w, queue );
|
||||
}
|
||||
queue.add(c);
|
||||
}
|
||||
}
|
||||
|
||||
queue.add( c );
|
||||
}
|
||||
}
|
||||
public void addInit(final AEBaseTile tile) {
|
||||
if (Platform.isServer()) // for no there is no reason to care about this on the client...
|
||||
{
|
||||
this.getRepo().tiles.add(tile);
|
||||
}
|
||||
}
|
||||
|
||||
public void addInit( final AEBaseTile tile )
|
||||
{
|
||||
if( Platform.isServer() ) // for no there is no reason to care about this on the client...
|
||||
{
|
||||
this.getRepo().tiles.add( tile );
|
||||
}
|
||||
}
|
||||
private HandlerRep getRepo() {
|
||||
if (Platform.isServer()) {
|
||||
return this.server;
|
||||
}
|
||||
return this.client;
|
||||
}
|
||||
|
||||
private HandlerRep getRepo()
|
||||
{
|
||||
if( Platform.isServer() )
|
||||
{
|
||||
return this.server;
|
||||
}
|
||||
return this.client;
|
||||
}
|
||||
public void addNetwork(final Grid grid) {
|
||||
if (Platform.isServer()) // for no there is no reason to care about this on the client...
|
||||
{
|
||||
this.getRepo().addNetwork(grid);
|
||||
}
|
||||
}
|
||||
|
||||
public void addNetwork( final Grid grid )
|
||||
{
|
||||
if( Platform.isServer() ) // for no there is no reason to care about this on the client...
|
||||
{
|
||||
this.getRepo().addNetwork( grid );
|
||||
}
|
||||
}
|
||||
public void removeNetwork(final Grid grid) {
|
||||
if (Platform.isServer()) // for no there is no reason to care about this on the client...
|
||||
{
|
||||
this.getRepo().removeNetwork(grid);
|
||||
}
|
||||
}
|
||||
|
||||
public void removeNetwork( final Grid grid )
|
||||
{
|
||||
if( Platform.isServer() ) // for no there is no reason to care about this on the client...
|
||||
{
|
||||
this.getRepo().removeNetwork( grid );
|
||||
}
|
||||
}
|
||||
public Iterable<Grid> getGridList() {
|
||||
return this.getRepo().networks;
|
||||
}
|
||||
|
||||
public Iterable<Grid> getGridList()
|
||||
{
|
||||
return this.getRepo().networks;
|
||||
}
|
||||
public void shutdown() {
|
||||
this.getRepo().clear();
|
||||
}
|
||||
|
||||
public void shutdown()
|
||||
{
|
||||
this.getRepo().clear();
|
||||
}
|
||||
public void unloadWorld(final WorldEvent.Unload ev) {
|
||||
if (Platform.isServer()) // for no there is no reason to care about this on the client...
|
||||
{
|
||||
final List<IGridNode> toDestroy = new ArrayList<>();
|
||||
|
||||
public void unloadWorld( final WorldEvent.Unload ev )
|
||||
{
|
||||
if( Platform.isServer() ) // for no there is no reason to care about this on the client...
|
||||
{
|
||||
final List<IGridNode> toDestroy = new ArrayList<>();
|
||||
this.getRepo().updateNetworks();
|
||||
for (final Grid g : this.getRepo().networks) {
|
||||
for (final IGridNode n : g.getNodes()) {
|
||||
if (n.getWorld() == ev.getWorld()) {
|
||||
toDestroy.add(n);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
this.getRepo().updateNetworks();
|
||||
for( final Grid g : this.getRepo().networks )
|
||||
{
|
||||
for( final IGridNode n : g.getNodes() )
|
||||
{
|
||||
if( n.getWorld() == ev.getWorld() )
|
||||
{
|
||||
toDestroy.add( n );
|
||||
}
|
||||
}
|
||||
}
|
||||
for (final IGridNode n : toDestroy) {
|
||||
n.destroy();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
for( final IGridNode n : toDestroy )
|
||||
{
|
||||
n.destroy();
|
||||
}
|
||||
}
|
||||
}
|
||||
public void onTick(final TickEvent ev) {
|
||||
|
||||
public void onTick( final TickEvent ev )
|
||||
{
|
||||
if (ev.type == Type.CLIENT && ev.phase == Phase.START) {
|
||||
this.tickColors(this.cliPlayerColors);
|
||||
final CableRenderMode currentMode = AEApi.instance().partHelper().getCableRenderMode();
|
||||
if (currentMode != this.crm) {
|
||||
this.crm = currentMode;
|
||||
AppEng.proxy.triggerUpdates();
|
||||
}
|
||||
}
|
||||
|
||||
if( ev.type == Type.CLIENT && ev.phase == Phase.START )
|
||||
{
|
||||
this.tickColors( this.cliPlayerColors );
|
||||
final CableRenderMode currentMode = AEApi.instance().partHelper().getCableRenderMode();
|
||||
if( currentMode != this.crm )
|
||||
{
|
||||
this.crm = currentMode;
|
||||
AppEng.proxy.triggerUpdates();
|
||||
}
|
||||
}
|
||||
if (ev.type == Type.WORLD && ev.phase == Phase.END) {
|
||||
final WorldTickEvent wte = (WorldTickEvent) ev;
|
||||
synchronized (this.craftingJobs) {
|
||||
final Collection<CraftingJob> jobSet = this.craftingJobs.get(wte.world);
|
||||
if (!jobSet.isEmpty()) {
|
||||
final int simTime = Math.max(1,
|
||||
AEConfig.instance().getCraftingCalculationTimePerTick() / jobSet.size());
|
||||
final Iterator<CraftingJob> i = jobSet.iterator();
|
||||
while (i.hasNext()) {
|
||||
final CraftingJob cj = i.next();
|
||||
if (!cj.simulateFor(simTime)) {
|
||||
i.remove();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if( ev.type == Type.WORLD && ev.phase == Phase.END )
|
||||
{
|
||||
final WorldTickEvent wte = (WorldTickEvent) ev;
|
||||
synchronized( this.craftingJobs )
|
||||
{
|
||||
final Collection<CraftingJob> jobSet = this.craftingJobs.get( wte.world );
|
||||
if( !jobSet.isEmpty() )
|
||||
{
|
||||
final int simTime = Math.max( 1, AEConfig.instance().getCraftingCalculationTimePerTick() / jobSet.size() );
|
||||
final Iterator<CraftingJob> i = jobSet.iterator();
|
||||
while( i.hasNext() )
|
||||
{
|
||||
final CraftingJob cj = i.next();
|
||||
if( !cj.simulateFor( simTime ) )
|
||||
{
|
||||
i.remove();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
// for no there is no reason to care about this on the client...
|
||||
else if (ev.type == Type.SERVER && ev.phase == Phase.END) {
|
||||
this.tickColors(this.srvPlayerColors);
|
||||
// ready tiles.
|
||||
final HandlerRep repo = this.getRepo();
|
||||
while (!repo.tiles.isEmpty()) {
|
||||
final AEBaseTile bt = repo.tiles.poll();
|
||||
if (!bt.isRemoved()) {
|
||||
bt.onReady();
|
||||
}
|
||||
}
|
||||
|
||||
// for no there is no reason to care about this on the client...
|
||||
else if( ev.type == Type.SERVER && ev.phase == Phase.END )
|
||||
{
|
||||
this.tickColors( this.srvPlayerColors );
|
||||
// ready tiles.
|
||||
final HandlerRep repo = this.getRepo();
|
||||
while( !repo.tiles.isEmpty() )
|
||||
{
|
||||
final AEBaseTile bt = repo.tiles.poll();
|
||||
if( !bt.isRemoved() )
|
||||
{
|
||||
bt.onReady();
|
||||
}
|
||||
}
|
||||
// tick networks.
|
||||
this.getRepo().updateNetworks();
|
||||
for (final Grid g : this.getRepo().networks) {
|
||||
g.update();
|
||||
}
|
||||
|
||||
// tick networks.
|
||||
this.getRepo().updateNetworks();
|
||||
for( final Grid g : this.getRepo().networks )
|
||||
{
|
||||
g.update();
|
||||
}
|
||||
// cross world queue.
|
||||
this.processQueue(this.serverQueue, null);
|
||||
}
|
||||
|
||||
// cross world queue.
|
||||
this.processQueue( this.serverQueue, null );
|
||||
}
|
||||
// world synced queue(s)
|
||||
if (ev.type == Type.WORLD && ev.phase == Phase.START) {
|
||||
final World world = ((WorldTickEvent) ev).world;
|
||||
final Queue<IWorldCallable<?>> queue = this.callQueue.get(world);
|
||||
this.processQueue(queue, world);
|
||||
}
|
||||
}
|
||||
|
||||
// world synced queue(s)
|
||||
if( ev.type == Type.WORLD && ev.phase == Phase.START )
|
||||
{
|
||||
final World world = ( (WorldTickEvent) ev ).world;
|
||||
final Queue<IWorldCallable<?>> queue = this.callQueue.get( world );
|
||||
this.processQueue( queue, world );
|
||||
}
|
||||
}
|
||||
private void tickColors(final HashMap<Integer, PlayerColor> playerSet) {
|
||||
final Iterator<PlayerColor> i = playerSet.values().iterator();
|
||||
while (i.hasNext()) {
|
||||
final PlayerColor pc = i.next();
|
||||
if (pc.ticksLeft <= 0) {
|
||||
i.remove();
|
||||
}
|
||||
pc.ticksLeft--;
|
||||
}
|
||||
}
|
||||
|
||||
private void tickColors( final HashMap<Integer, PlayerColor> playerSet )
|
||||
{
|
||||
final Iterator<PlayerColor> i = playerSet.values().iterator();
|
||||
while( i.hasNext() )
|
||||
{
|
||||
final PlayerColor pc = i.next();
|
||||
if( pc.ticksLeft <= 0 )
|
||||
{
|
||||
i.remove();
|
||||
}
|
||||
pc.ticksLeft--;
|
||||
}
|
||||
}
|
||||
private void processQueue(final Queue<IWorldCallable<?>> queue, final World world) {
|
||||
if (queue == null) {
|
||||
return;
|
||||
}
|
||||
|
||||
private void processQueue( final Queue<IWorldCallable<?>> queue, final World world )
|
||||
{
|
||||
if( queue == null )
|
||||
{
|
||||
return;
|
||||
}
|
||||
final Stopwatch sw = Stopwatch.createStarted();
|
||||
|
||||
final Stopwatch sw = Stopwatch.createStarted();
|
||||
IWorldCallable<?> c = null;
|
||||
while ((c = queue.poll()) != null) {
|
||||
try {
|
||||
c.call(world);
|
||||
|
||||
IWorldCallable<?> c = null;
|
||||
while( ( c = queue.poll() ) != null )
|
||||
{
|
||||
try
|
||||
{
|
||||
c.call( world );
|
||||
if (sw.elapsed(TimeUnit.MILLISECONDS) > 50) {
|
||||
break;
|
||||
}
|
||||
} catch (final Exception e) {
|
||||
AELog.debug(e);
|
||||
}
|
||||
}
|
||||
|
||||
if( sw.elapsed( TimeUnit.MILLISECONDS ) > 50 )
|
||||
{
|
||||
break;
|
||||
}
|
||||
}
|
||||
catch( final Exception e )
|
||||
{
|
||||
AELog.debug( e );
|
||||
}
|
||||
}
|
||||
// long time = sw.elapsed( TimeUnit.MILLISECONDS );
|
||||
// if ( time > 0 )
|
||||
// AELog.info( "processQueue Time: " + time + "ms" );
|
||||
}
|
||||
|
||||
// long time = sw.elapsed( TimeUnit.MILLISECONDS );
|
||||
// if ( time > 0 )
|
||||
// AELog.info( "processQueue Time: " + time + "ms" );
|
||||
}
|
||||
public void registerCraftingSimulation(final World world, final CraftingJob craftingJob) {
|
||||
synchronized (this.craftingJobs) {
|
||||
this.craftingJobs.put(world, craftingJob);
|
||||
}
|
||||
}
|
||||
|
||||
public void registerCraftingSimulation( final World world, final CraftingJob craftingJob )
|
||||
{
|
||||
synchronized( this.craftingJobs )
|
||||
{
|
||||
this.craftingJobs.put( world, craftingJob );
|
||||
}
|
||||
}
|
||||
private static class HandlerRep {
|
||||
|
||||
private static class HandlerRep
|
||||
{
|
||||
private Queue<AEBaseTile> tiles = new ArrayDeque<>();
|
||||
private Set<Grid> networks = new HashSet<>();
|
||||
private Set<Grid> toAdd = new HashSet<>();
|
||||
private Set<Grid> toRemove = new HashSet<>();
|
||||
|
||||
private Queue<AEBaseTile> tiles = new ArrayDeque<>();
|
||||
private Set<Grid> networks = new HashSet<>();
|
||||
private Set<Grid> toAdd = new HashSet<>();
|
||||
private Set<Grid> toRemove = new HashSet<>();
|
||||
private void clear() {
|
||||
this.tiles = new ArrayDeque<>();
|
||||
this.networks = new HashSet<>();
|
||||
this.toAdd = new HashSet<>();
|
||||
this.toRemove = new HashSet<>();
|
||||
}
|
||||
|
||||
private void clear()
|
||||
{
|
||||
this.tiles = new ArrayDeque<>();
|
||||
this.networks = new HashSet<>();
|
||||
this.toAdd = new HashSet<>();
|
||||
this.toRemove = new HashSet<>();
|
||||
}
|
||||
private synchronized void addNetwork(Grid g) {
|
||||
this.toAdd.add(g);
|
||||
this.toRemove.remove(g);
|
||||
}
|
||||
|
||||
private synchronized void addNetwork( Grid g )
|
||||
{
|
||||
this.toAdd.add( g );
|
||||
this.toRemove.remove( g );
|
||||
}
|
||||
private synchronized void removeNetwork(Grid g) {
|
||||
this.toRemove.add(g);
|
||||
this.toAdd.remove(g);
|
||||
}
|
||||
|
||||
private synchronized void removeNetwork( Grid g )
|
||||
{
|
||||
this.toRemove.add( g );
|
||||
this.toAdd.remove( g );
|
||||
}
|
||||
private synchronized void updateNetworks() {
|
||||
this.networks.removeAll(this.toRemove);
|
||||
this.toRemove.clear();
|
||||
|
||||
private synchronized void updateNetworks()
|
||||
{
|
||||
this.networks.removeAll( this.toRemove );
|
||||
this.toRemove.clear();
|
||||
this.networks.addAll(this.toAdd);
|
||||
this.toAdd.clear();
|
||||
}
|
||||
}
|
||||
|
||||
this.networks.addAll( this.toAdd );
|
||||
this.toAdd.clear();
|
||||
}
|
||||
}
|
||||
public static class PlayerColor {
|
||||
|
||||
public static class PlayerColor
|
||||
{
|
||||
public final AEColor myColor;
|
||||
private final int myEntity;
|
||||
private int ticksLeft;
|
||||
|
||||
public final AEColor myColor;
|
||||
private final int myEntity;
|
||||
private int ticksLeft;
|
||||
public PlayerColor(final int id, final AEColor col, final int ticks) {
|
||||
this.myEntity = id;
|
||||
this.myColor = col;
|
||||
this.ticksLeft = ticks;
|
||||
}
|
||||
|
||||
public PlayerColor( final int id, final AEColor col, final int ticks )
|
||||
{
|
||||
this.myEntity = id;
|
||||
this.myColor = col;
|
||||
this.ticksLeft = ticks;
|
||||
}
|
||||
|
||||
public PacketPaintedEntity getPacket()
|
||||
{
|
||||
return new PacketPaintedEntity( this.myEntity, this.myColor, this.ticksLeft );
|
||||
}
|
||||
}
|
||||
public PacketPaintedEntity getPacket() {
|
||||
return new PacketPaintedEntity(this.myEntity, this.myColor, this.ticksLeft);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user