pick 97420a31d The big reformat of 2020

This commit is contained in:
yueh
2020-06-16 21:41:28 +02:00
parent 5304b3febe
commit 5225ea426b
2252 changed files with 95466 additions and 118582 deletions
@@ -18,11 +18,10 @@
package appeng.debug;
import appeng.block.AEBaseTileBlock;
import net.minecraft.block.Block;
import net.minecraft.block.material.Material;
import appeng.block.AEBaseTileBlock;
public class BlockChunkloader extends AEBaseTileBlock<TileChunkLoader> {
@@ -18,7 +18,6 @@
package appeng.debug;
import javax.annotation.Nullable;
import net.minecraft.block.Block;
@@ -33,25 +32,21 @@ import net.minecraft.world.World;
import appeng.block.AEBaseTileBlock;
public class BlockCubeGenerator extends AEBaseTileBlock<TileCubeGenerator> {
public class BlockCubeGenerator extends AEBaseTileBlock<TileCubeGenerator>
{
public BlockCubeGenerator() {
super(defaultProps(Material.IRON));
}
public BlockCubeGenerator()
{
super(defaultProps(Material.IRON) );
}
@Override
public ActionResultType onActivated(final World w, final BlockPos pos, final PlayerEntity player, final Hand hand,
final @Nullable ItemStack heldItem, final BlockRayTraceResult hit) {
final TileCubeGenerator tcg = this.getTileEntity(w, pos);
if (tcg != null) {
tcg.click(player);
}
@Override
public ActionResultType onActivated(final World w, final BlockPos pos, final PlayerEntity player, final Hand hand, final @Nullable ItemStack heldItem, final BlockRayTraceResult hit)
{
final TileCubeGenerator tcg = this.getTileEntity( w, pos );
if( tcg != null )
{
tcg.click( player );
}
return ActionResultType.SUCCESS;
}
return ActionResultType.SUCCESS;
}
}
@@ -18,19 +18,15 @@
package appeng.debug;
import net.minecraft.block.Block;
import net.minecraft.block.material.Material;
import appeng.block.AEBaseTileBlock;
public class BlockEnergyGenerator extends AEBaseTileBlock<TileEnergyGenerator> {
public class BlockEnergyGenerator extends AEBaseTileBlock<TileEnergyGenerator>
{
public BlockEnergyGenerator()
{
super( defaultProps(Material.IRON) );
}
public BlockEnergyGenerator() {
super(defaultProps(Material.IRON));
}
}
+4 -8
View File
@@ -18,19 +18,15 @@
package appeng.debug;
import net.minecraft.block.Block;
import net.minecraft.block.material.Material;
import appeng.block.AEBaseTileBlock;
public class BlockItemGen extends AEBaseTileBlock<TileItemGen> {
public class BlockItemGen extends AEBaseTileBlock<TileItemGen>
{
public BlockItemGen()
{
super( defaultProps(Material.IRON) );
}
public BlockItemGen() {
super(defaultProps(Material.IRON));
}
}
@@ -18,7 +18,6 @@
package appeng.debug;
import javax.annotation.Nullable;
import net.minecraft.block.Block;
@@ -33,21 +32,18 @@ import net.minecraft.world.World;
import appeng.block.AEBaseTileBlock;
public class BlockPhantomNode extends AEBaseTileBlock<TilePhantomNode> {
public class BlockPhantomNode extends AEBaseTileBlock<TilePhantomNode>
{
public BlockPhantomNode() {
super(defaultProps(Material.IRON));
}
public BlockPhantomNode()
{
super( defaultProps(Material.IRON) );
}
@Override
public ActionResultType onActivated(final World w, final BlockPos pos, final PlayerEntity player, final Hand hand, final @Nullable ItemStack heldItem, final BlockRayTraceResult hit)
{
final TilePhantomNode tpn = this.getTileEntity( w, pos );
tpn.triggerCrashMode();
return ActionResultType.SUCCESS;
}
@Override
public ActionResultType onActivated(final World w, final BlockPos pos, final PlayerEntity player, final Hand hand,
final @Nullable ItemStack heldItem, final BlockRayTraceResult hit) {
final TilePhantomNode tpn = this.getTileEntity(w, pos);
tpn.triggerCrashMode();
return ActionResultType.SUCCESS;
}
}
@@ -18,15 +18,14 @@
package appeng.debug;
import appeng.core.AELog;
import appeng.tile.AEBaseTile;
import net.minecraft.tileentity.ITickableTileEntity;
import net.minecraft.tileentity.TileEntityType;
import net.minecraft.util.math.ChunkPos;
import net.minecraft.world.World;
import net.minecraft.world.server.ServerWorld;
import appeng.core.AELog;
import appeng.tile.AEBaseTile;
public class TileChunkLoader extends AEBaseTile implements ITickableTileEntity {
@@ -63,7 +62,8 @@ public class TileChunkLoader extends AEBaseTile implements ITickableTileEntity {
ServerWorld serverWorld = (ServerWorld) world;
if (!serverWorld.getForcedChunks().contains(chunkPos.asLong())) {
AELog.debug("Force-loading chunk @ %d,%d in %s", chunkPos.x, chunkPos.z, serverWorld.dimension.getType().getRegistryName());
AELog.debug("Force-loading chunk @ %d,%d in %s", chunkPos.x, chunkPos.z,
serverWorld.dimension.getType().getRegistryName());
serverWorld.forceChunk(chunkPos.x, chunkPos.z, false);
}
}
@@ -18,10 +18,6 @@
package appeng.debug;
import appeng.core.AppEng;
import appeng.tile.AEBaseTile;
import appeng.util.Platform;
import net.minecraft.entity.player.PlayerEntity;
import net.minecraft.item.DirectionalPlaceContext;
import net.minecraft.item.Item;
@@ -33,102 +29,84 @@ import net.minecraft.util.Direction;
import net.minecraft.util.math.BlockPos;
import net.minecraft.util.text.StringTextComponent;
import appeng.core.AppEng;
import appeng.tile.AEBaseTile;
import appeng.util.Platform;
public class TileCubeGenerator extends AEBaseTile implements ITickableTileEntity
{
public class TileCubeGenerator extends AEBaseTile implements ITickableTileEntity {
private int size = 3;
private ItemStack is = ItemStack.EMPTY;
private int countdown = 20 * 10;
private PlayerEntity who = null;
private int size = 3;
private ItemStack is = ItemStack.EMPTY;
private int countdown = 20 * 10;
private PlayerEntity who = null;
public TileCubeGenerator(TileEntityType<?> tileEntityTypeIn) {
super(tileEntityTypeIn);
}
public TileCubeGenerator(TileEntityType<?> tileEntityTypeIn) {
super(tileEntityTypeIn);
}
@Override
public void tick()
{
if( !this.is.isEmpty() && Platform.isServer() )
{
this.countdown--;
@Override
public void tick() {
if (!this.is.isEmpty() && Platform.isServer()) {
this.countdown--;
if( this.countdown % 20 == 0 )
{
for( final PlayerEntity e : AppEng.proxy.getPlayers() )
{
e.sendMessage( new StringTextComponent( "Spawning in... " + ( this.countdown / 20 ) ) );
}
}
if (this.countdown % 20 == 0) {
for (final PlayerEntity e : AppEng.proxy.getPlayers()) {
e.sendMessage(new StringTextComponent("Spawning in... " + (this.countdown / 20)));
}
}
if( this.countdown <= 0 )
{
this.spawn();
}
}
}
if (this.countdown <= 0) {
this.spawn();
}
}
}
private void spawn()
{
this.world.removeBlock(this.pos, false);
private void spawn() {
this.world.removeBlock(this.pos, false);
final Item i = this.is.getItem();
final Direction side = Direction.UP;
final Item i = this.is.getItem();
final Direction side = Direction.UP;
final int half = (int) Math.floor( this.size / 2 );
final int half = (int) Math.floor(this.size / 2);
for( int y = 0; y < this.size; y++ )
{
for( int x = -half; x < half; x++ )
{
for( int z = -half; z < half; z++ )
{
final BlockPos p = this.pos.add( x, y - 1, z );
ItemUseContext useContext = new DirectionalPlaceContext(
this.world, p, side, this.is, side.getOpposite()
);
i.onItemUse(useContext);
}
}
}
}
for (int y = 0; y < this.size; y++) {
for (int x = -half; x < half; x++) {
for (int z = -half; z < half; z++) {
final BlockPos p = this.pos.add(x, y - 1, z);
ItemUseContext useContext = new DirectionalPlaceContext(this.world, p, side, this.is,
side.getOpposite());
i.onItemUse(useContext);
}
}
}
}
void click( final PlayerEntity player )
{
if( Platform.isServer() )
{
final ItemStack hand = player.inventory.getCurrentItem();
this.who = player;
void click(final PlayerEntity player) {
if (Platform.isServer()) {
final ItemStack hand = player.inventory.getCurrentItem();
this.who = player;
if( hand.isEmpty() )
{
this.is = ItemStack.EMPTY;
if (hand.isEmpty()) {
this.is = ItemStack.EMPTY;
if( player.isCrouching() )
{
this.size--;
}
else
{
this.size++;
}
if (player.isCrouching()) {
this.size--;
} else {
this.size++;
}
if( this.size < 3 )
{
this.size = 3;
}
if( this.size > 64 )
{
this.size = 64;
}
if (this.size < 3) {
this.size = 3;
}
if (this.size > 64) {
this.size = 64;
}
player.sendMessage( new StringTextComponent( "Size: " + this.size ) );
}
else
{
this.countdown = 20 * 10;
this.is = hand;
}
}
}
player.sendMessage(new StringTextComponent("Size: " + this.size));
} else {
this.countdown = 20 * 10;
this.is = hand;
}
}
}
}
@@ -18,7 +18,6 @@
package appeng.debug;
import java.util.EnumSet;
import javax.annotation.Nullable;
@@ -38,98 +37,84 @@ import net.minecraftforge.energy.IEnergyStorage;
import appeng.tile.AEBaseTile;
public class TileEnergyGenerator extends AEBaseTile implements ITickableTileEntity, IEnergyStorage {
/**
* The base energy injected each tick. Adjacent TileEnergyGenerators will
* increase it to pow(base, #generators).
*/
private static final int BASE_ENERGY = 8;
public class TileEnergyGenerator extends AEBaseTile implements ITickableTileEntity, IEnergyStorage
{
/**
* The base energy injected each tick.
* Adjacent TileEnergyGenerators will increase it to pow(base, #generators).
*/
private static final int BASE_ENERGY = 8;
public TileEnergyGenerator(TileEntityType<?> tileEntityTypeIn) {
super(tileEntityTypeIn);
}
public TileEnergyGenerator(TileEntityType<?> tileEntityTypeIn) {
super(tileEntityTypeIn);
}
@Override
public void tick() {
World world = this.getWorld();
if (world == null) {
return;
}
@Override
public void tick()
{
World world = this.getWorld();
if (world == null) {
return;
}
int tier = 1;
for (Direction facing : Direction.values()) {
final TileEntity te = world.getTileEntity(this.getPos().offset(facing));
int tier = 1;
for( Direction facing : Direction.values() )
{
final TileEntity te = world.getTileEntity( this.getPos().offset( facing ) );
if (te instanceof TileEnergyGenerator) {
tier++;
}
}
if( te instanceof TileEnergyGenerator )
{
tier++;
}
}
final int energyToInsert = IntMath.pow(BASE_ENERGY, tier);
final int energyToInsert = IntMath.pow( BASE_ENERGY, tier );
for (Direction facing : Direction.values()) {
final TileEntity te = this.getWorld().getTileEntity(this.getPos().offset(facing));
final LazyOptional<IEnergyStorage> cap = te.getCapability(CapabilityEnergy.ENERGY, facing.getOpposite());
for( Direction facing : Direction.values() )
{
final TileEntity te = this.getWorld().getTileEntity( this.getPos().offset( facing ) );
final LazyOptional<IEnergyStorage> cap = te.getCapability( CapabilityEnergy.ENERGY, facing.getOpposite() );
cap.ifPresent(consumer -> {
if (consumer.canReceive()) {
consumer.receiveEnergy(energyToInsert, false);
}
});
}
}
cap.ifPresent(consumer -> {
if (consumer.canReceive()) {
consumer.receiveEnergy( energyToInsert, false );
}
});
}
}
@SuppressWarnings("unchecked")
@Override
@Nullable
public <T> LazyOptional<T> getCapability(Capability<T> capability, @Nullable Direction facing) {
if (capability == CapabilityEnergy.ENERGY) {
return (LazyOptional<T>) LazyOptional.of(() -> this);
}
return super.getCapability(capability, facing);
}
@SuppressWarnings("unchecked")
@Override
@Nullable
public <T> LazyOptional<T> getCapability(Capability<T> capability, @Nullable Direction facing )
{
if( capability == CapabilityEnergy.ENERGY )
{
return (LazyOptional<T>) LazyOptional.of(() ->this);
}
return super.getCapability( capability, facing );
}
@Override
public int receiveEnergy(int maxReceive, boolean simulate) {
return 0;
}
@Override
public int receiveEnergy( int maxReceive, boolean simulate )
{
return 0;
}
@Override
public int extractEnergy(int maxExtract, boolean simulate) {
return maxExtract;
}
@Override
public int extractEnergy( int maxExtract, boolean simulate )
{
return maxExtract;
}
@Override
public int getEnergyStored() {
return Integer.MAX_VALUE;
}
@Override
public int getEnergyStored()
{
return Integer.MAX_VALUE;
}
@Override
public int getMaxEnergyStored() {
return Integer.MAX_VALUE;
}
@Override
public int getMaxEnergyStored()
{
return Integer.MAX_VALUE;
}
@Override
public boolean canExtract() {
return true;
}
@Override
public boolean canExtract()
{
return true;
}
@Override
public boolean canReceive()
{
return false;
}
@Override
public boolean canReceive() {
return false;
}
}
+76 -96
View File
@@ -18,16 +18,15 @@
package appeng.debug;
import java.util.ArrayDeque;
import java.util.Queue;
import javax.annotation.Nonnull;
import javax.annotation.Nullable;
import net.minecraft.item.Items;
import net.minecraft.item.Item;
import net.minecraft.item.ItemStack;
import net.minecraft.item.Items;
import net.minecraft.tileentity.TileEntityType;
import net.minecraft.util.Direction;
import net.minecraft.util.NonNullList;
@@ -36,117 +35,98 @@ import net.minecraftforge.common.capabilities.Capability;
import net.minecraftforge.common.util.LazyOptional;
import net.minecraftforge.items.CapabilityItemHandler;
import net.minecraftforge.items.IItemHandler;
import appeng.tile.AEBaseTile;
import net.minecraftforge.registries.ForgeRegistries;
import appeng.tile.AEBaseTile;
public class TileItemGen extends AEBaseTile
{
public class TileItemGen extends AEBaseTile {
private static final Queue<ItemStack> POSSIBLE_ITEMS = new ArrayDeque<>();
private static final Queue<ItemStack> POSSIBLE_ITEMS = new ArrayDeque<>();
private final IItemHandler handler = new QueuedItemHandler();
private final IItemHandler handler = new QueuedItemHandler();
public TileItemGen(TileEntityType<?> tileEntityTypeIn) {
super(tileEntityTypeIn);
if( POSSIBLE_ITEMS.isEmpty() )
{
for( final Item mi : ForgeRegistries.ITEMS)
{
if( mi != null && mi != Items.AIR )
{
if( mi.isDamageable() )
{
// FIXME: Rethink if this branch is necessary
for( int dmg = 0; dmg < mi.getMaxDamage(); dmg++ )
{
ItemStack item = new ItemStack(mi, 1);
item.setDamage(dmg);
POSSIBLE_ITEMS.add(item);
}
}
else
{
if (mi.getGroup() == null) {
continue;
}
public TileItemGen(TileEntityType<?> tileEntityTypeIn) {
super(tileEntityTypeIn);
if (POSSIBLE_ITEMS.isEmpty()) {
for (final Item mi : ForgeRegistries.ITEMS) {
if (mi != null && mi != Items.AIR) {
if (mi.isDamageable()) {
// FIXME: Rethink if this branch is necessary
for (int dmg = 0; dmg < mi.getMaxDamage(); dmg++) {
ItemStack item = new ItemStack(mi, 1);
item.setDamage(dmg);
POSSIBLE_ITEMS.add(item);
}
} else {
if (mi.getGroup() == null) {
continue;
}
final NonNullList<ItemStack> list = NonNullList.create();
mi.fillItemGroup( mi.getGroup(), list );
POSSIBLE_ITEMS.addAll( list );
}
}
}
}
}
final NonNullList<ItemStack> list = NonNullList.create();
mi.fillItemGroup(mi.getGroup(), list);
POSSIBLE_ITEMS.addAll(list);
}
}
}
}
}
@SuppressWarnings("unchecked")
@Override
@Nullable
public <T> LazyOptional<T> getCapability(Capability<T> capability, @Nullable Direction facing )
{
if( CapabilityItemHandler.ITEM_HANDLER_CAPABILITY == capability )
{
return (LazyOptional<T>) LazyOptional.of(() ->this.handler);
}
return super.getCapability( capability, facing );
}
@SuppressWarnings("unchecked")
@Override
@Nullable
public <T> LazyOptional<T> getCapability(Capability<T> capability, @Nullable Direction facing) {
if (CapabilityItemHandler.ITEM_HANDLER_CAPABILITY == capability) {
return (LazyOptional<T>) LazyOptional.of(() -> this.handler);
}
return super.getCapability(capability, facing);
}
class QueuedItemHandler implements IItemHandler
{
class QueuedItemHandler implements IItemHandler {
@Override
@Nonnull
public ItemStack insertItem( int slot, @Nonnull ItemStack stack, boolean simulate )
{
return stack;
}
@Override
@Nonnull
public ItemStack insertItem(int slot, @Nonnull ItemStack stack, boolean simulate) {
return stack;
}
@Override
@Nonnull
public ItemStack getStackInSlot( int slot )
{
return POSSIBLE_ITEMS.peek() != null ? POSSIBLE_ITEMS.peek().copy() : ItemStack.EMPTY;
}
@Override
@Nonnull
public ItemStack getStackInSlot(int slot) {
return POSSIBLE_ITEMS.peek() != null ? POSSIBLE_ITEMS.peek().copy() : ItemStack.EMPTY;
}
@Override
public boolean isItemValid(int slot, @Nonnull ItemStack stack) {
return false;
}
@Override
public boolean isItemValid(int slot, @Nonnull ItemStack stack) {
return false;
}
@Override
public int getSlots()
{
return 1;
}
@Override
public int getSlots() {
return 1;
}
@Override
public int getSlotLimit( int slot )
{
return 1;
}
@Override
public int getSlotLimit(int slot) {
return 1;
}
@Override
@Nonnull
public ItemStack extractItem( int slot, int amount, boolean simulate )
{
final ItemStack is = POSSIBLE_ITEMS.peek();
@Override
@Nonnull
public ItemStack extractItem(int slot, int amount, boolean simulate) {
final ItemStack is = POSSIBLE_ITEMS.peek();
if( is == null )
{
return ItemStack.EMPTY;
}
if (is == null) {
return ItemStack.EMPTY;
}
return simulate ? is.copy() : this.getNextItem();
}
return simulate ? is.copy() : this.getNextItem();
}
private ItemStack getNextItem()
{
final ItemStack is = POSSIBLE_ITEMS.poll();
private ItemStack getNextItem() {
final ItemStack is = POSSIBLE_ITEMS.poll();
POSSIBLE_ITEMS.add( is );
return is.copy();
}
};
POSSIBLE_ITEMS.add(is);
return is.copy();
}
};
}
+26 -34
View File
@@ -18,7 +18,6 @@
package appeng.debug;
import java.util.EnumSet;
import net.minecraft.tileentity.TileEntityType;
@@ -29,43 +28,36 @@ import appeng.api.util.AEPartLocation;
import appeng.me.helpers.AENetworkProxy;
import appeng.tile.grid.AENetworkTile;
public class TilePhantomNode extends AENetworkTile {
public class TilePhantomNode extends AENetworkTile
{
private AENetworkProxy proxy = null;
private boolean crashMode = false;
private AENetworkProxy proxy = null;
private boolean crashMode = false;
public TilePhantomNode(TileEntityType<?> tileEntityTypeIn) {
super(tileEntityTypeIn);
}
public TilePhantomNode(TileEntityType<?> tileEntityTypeIn) {
super(tileEntityTypeIn);
}
@Override
public IGridNode getGridNode(final AEPartLocation dir) {
if (!this.crashMode) {
return super.getGridNode(dir);
}
@Override
public IGridNode getGridNode( final AEPartLocation dir )
{
if( !this.crashMode )
{
return super.getGridNode( dir );
}
return this.proxy.getNode();
}
return this.proxy.getNode();
}
@Override
public void onReady() {
super.onReady();
this.proxy = this.createProxy();
this.proxy.onReady();
this.crashMode = true;
}
@Override
public void onReady()
{
super.onReady();
this.proxy = this.createProxy();
this.proxy.onReady();
this.crashMode = true;
}
void triggerCrashMode()
{
if( this.proxy != null )
{
this.crashMode = true;
this.proxy.setValidSides( EnumSet.allOf( Direction.class ) );
}
}
void triggerCrashMode() {
if (this.proxy != null) {
this.crashMode = true;
this.proxy.setValidSides(EnumSet.allOf(Direction.class));
}
}
}
+133 -168
View File
@@ -18,6 +18,19 @@
package appeng.debug;
import java.util.HashSet;
import java.util.Set;
import net.minecraft.entity.Entity;
import net.minecraft.entity.player.PlayerEntity;
import net.minecraft.item.ItemStack;
import net.minecraft.item.ItemUseContext;
import net.minecraft.tileentity.TileEntity;
import net.minecraft.util.ActionResultType;
import net.minecraft.util.Direction;
import net.minecraft.util.math.BlockPos;
import net.minecraft.util.text.StringTextComponent;
import net.minecraft.world.World;
import appeng.api.networking.IGridConnection;
import appeng.api.networking.IGridHost;
@@ -38,198 +51,150 @@ import appeng.me.cache.TickManagerCache;
import appeng.parts.p2p.PartP2PTunnel;
import appeng.tile.networking.TileController;
import appeng.util.Platform;
import net.minecraft.entity.Entity;
import net.minecraft.entity.player.PlayerEntity;
import net.minecraft.item.ItemStack;
import net.minecraft.item.ItemUseContext;
import net.minecraft.tileentity.TileEntity;
import net.minecraft.util.ActionResultType;
import net.minecraft.util.Direction;
import net.minecraft.util.math.BlockPos;
import net.minecraft.util.text.StringTextComponent;
import net.minecraft.world.World;
import java.util.HashSet;
import java.util.Set;
public class ToolDebugCard extends AEBaseItem {
public ToolDebugCard(Properties properties) {
super(properties);
}
public class ToolDebugCard extends AEBaseItem
{
@Override
public ActionResultType onItemUseFirst(ItemStack stack, ItemUseContext context) {
if (context.getWorld().isRemote()) {
return ActionResultType.PASS;
}
public ToolDebugCard(Properties properties) {
super(properties);
}
PlayerEntity player = context.getPlayer();
World world = context.getWorld();
BlockPos pos = context.getPos();
Direction side = context.getFace();
@Override
public ActionResultType onItemUseFirst(ItemStack stack, ItemUseContext context) {
if( context.getWorld().isRemote() )
{
return ActionResultType.PASS;
}
if (player == null) {
return ActionResultType.PASS;
}
PlayerEntity player = context.getPlayer();
World world = context.getWorld();
BlockPos pos = context.getPos();
Direction side = context.getFace();
if (player.isCrouching()) {
int grids = 0;
int totalNodes = 0;
if (player == null) {
return ActionResultType.PASS;
}
if( player.isCrouching() )
{
int grids = 0;
int totalNodes = 0;
for (final Grid g : TickHandler.INSTANCE.getGridList()) {
grids++;
totalNodes += g.getNodes().size();
}
for( final Grid g : TickHandler.INSTANCE.getGridList() )
{
grids++;
totalNodes += g.getNodes().size();
}
this.outputMsg(player, "Grids: " + grids);
this.outputMsg(player, "Total Nodes: " + totalNodes);
} else {
final TileEntity te = world.getTileEntity(pos);
this.outputMsg( player, "Grids: " + grids );
this.outputMsg( player, "Total Nodes: " + totalNodes );
}
else
{
final TileEntity te = world.getTileEntity( pos );
if (te instanceof IGridHost) {
final GridNode node = (GridNode) ((IGridHost) te).getGridNode(AEPartLocation.fromFacing(side));
if (node != null) {
final Grid g = node.getInternalGrid();
final IGridNode center = g.getPivot();
this.outputMsg(player, "This Node: " + node.toString());
this.outputMsg(player, "Center Node: " + center.toString());
if( te instanceof IGridHost )
{
final GridNode node = (GridNode) ( (IGridHost) te ).getGridNode( AEPartLocation.fromFacing( side ) );
if( node != null )
{
final Grid g = node.getInternalGrid();
final IGridNode center = g.getPivot();
this.outputMsg( player, "This Node: " + node.toString() );
this.outputMsg( player, "Center Node: " + center.toString() );
final IPathingGrid pg = g.getCache(IPathingGrid.class);
if (pg.getControllerState() == ControllerState.CONTROLLER_ONLINE) {
final IPathingGrid pg = g.getCache( IPathingGrid.class );
if( pg.getControllerState() == ControllerState.CONTROLLER_ONLINE )
{
Set<IGridNode> next = new HashSet<>();
next.add(node);
Set<IGridNode> next = new HashSet<>();
next.add( node );
final int maxLength = 10000;
final int maxLength = 10000;
int length = 0;
outer: while (!next.isEmpty()) {
final Iterable<IGridNode> current = next;
next = new HashSet<>();
int length = 0;
outer:
while( !next.isEmpty() )
{
final Iterable<IGridNode> current = next;
next = new HashSet<>();
for (final IGridNode n : current) {
if (n.getMachine() instanceof TileController) {
break outer;
}
for( final IGridNode n : current )
{
if( n.getMachine() instanceof TileController )
{
break outer;
}
for (final IGridConnection c : n.getConnections()) {
next.add(c.getOtherSide(n));
}
}
for( final IGridConnection c : n.getConnections() )
{
next.add( c.getOtherSide( n ) );
}
}
length++;
length++;
if (length > maxLength) {
break;
}
}
if( length > maxLength )
{
break;
}
}
this.outputMsg(player, "Cable Distance: " + length);
}
this.outputMsg( player, "Cable Distance: " + length );
}
if (center.getMachine() instanceof PartP2PTunnel) {
this.outputMsg(player, "Freq: " + ((PartP2PTunnel<?>) center.getMachine()).getFrequency());
}
if( center.getMachine() instanceof PartP2PTunnel )
{
this.outputMsg( player, "Freq: " + ( (PartP2PTunnel<?>) center.getMachine() ).getFrequency() );
}
final TickManagerCache tmc = g.getCache(ITickManager.class);
for (final Class<? extends IGridHost> c : g.getMachineClasses()) {
int o = 0;
long nanos = 0;
for (final IGridNode oj : g.getMachines(c)) {
o++;
nanos += tmc.getAvgNanoTime(oj);
}
final TickManagerCache tmc = g.getCache( ITickManager.class );
for( final Class<? extends IGridHost> c : g.getMachineClasses() )
{
int o = 0;
long nanos = 0;
for( final IGridNode oj : g.getMachines( c ) )
{
o++;
nanos += tmc.getAvgNanoTime( oj );
}
if (nanos < 0) {
this.outputMsg(player, c.getSimpleName() + " - " + o);
} else {
this.outputMsg(player, c.getSimpleName() + " - " + o + "; " + this.timeMeasurement(nanos));
}
}
} else {
this.outputMsg(player, "No Node Available.");
}
} else {
this.outputMsg(player, "Not Networked Block");
}
if( nanos < 0 )
{
this.outputMsg( player, c.getSimpleName() + " - " + o );
}
else
{
this.outputMsg( player, c.getSimpleName() + " - " + o + "; " + this.timeMeasurement( nanos ) );
}
}
}
else
{
this.outputMsg( player, "No Node Available." );
}
}
else
{
this.outputMsg( player, "Not Networked Block" );
}
if (te instanceof IPartHost) {
final IPart center = ((IPartHost) te).getPart(AEPartLocation.INTERNAL);
((IPartHost) te).markForUpdate();
if (center != null) {
final GridNode n = (GridNode) center.getGridNode();
this.outputMsg(player, "Node Channels: " + n.usedChannels());
for (final IGridConnection gc : n.getConnections()) {
final AEPartLocation fd = gc.getDirection(n);
if (fd != AEPartLocation.INTERNAL) {
this.outputMsg(player, fd.toString() + ": " + gc.getUsedChannels());
}
}
}
}
if( te instanceof IPartHost )
{
final IPart center = ( (IPartHost) te ).getPart( AEPartLocation.INTERNAL );
( (IPartHost) te ).markForUpdate();
if( center != null )
{
final GridNode n = (GridNode) center.getGridNode();
this.outputMsg( player, "Node Channels: " + n.usedChannels() );
for( final IGridConnection gc : n.getConnections() )
{
final AEPartLocation fd = gc.getDirection( n );
if( fd != AEPartLocation.INTERNAL )
{
this.outputMsg( player, fd.toString() + ": " + gc.getUsedChannels() );
}
}
}
}
if (te instanceof IAEPowerStorage) {
final IAEPowerStorage ps = (IAEPowerStorage) te;
this.outputMsg(player, "Energy: " + ps.getAECurrentPower() + " / " + ps.getAEMaxPower());
if( te instanceof IAEPowerStorage )
{
final IAEPowerStorage ps = (IAEPowerStorage) te;
this.outputMsg( player, "Energy: " + ps.getAECurrentPower() + " / " + ps.getAEMaxPower() );
if (te instanceof IGridHost) {
final IGridNode node = ((IGridHost) te).getGridNode(AEPartLocation.fromFacing(side));
if (node != null && node.getGrid() != null) {
final IEnergyGrid eg = node.getGrid().getCache(IEnergyGrid.class);
this.outputMsg(player,
"GridEnergy: " + eg.getStoredPower() + " : " + eg.getEnergyDemand(Double.MAX_VALUE));
}
}
}
}
return ActionResultType.SUCCESS;
}
if( te instanceof IGridHost )
{
final IGridNode node = ( (IGridHost) te ).getGridNode( AEPartLocation.fromFacing( side ) );
if( node != null && node.getGrid() != null )
{
final IEnergyGrid eg = node.getGrid().getCache( IEnergyGrid.class );
this.outputMsg( player, "GridEnergy: " + eg.getStoredPower() + " : " + eg.getEnergyDemand( Double.MAX_VALUE ) );
}
}
}
}
return ActionResultType.SUCCESS;
}
private void outputMsg(final Entity player, final String string) {
player.sendMessage(new StringTextComponent(string));
}
private void outputMsg(final Entity player, final String string )
{
player.sendMessage( new StringTextComponent( string ) );
}
private String timeMeasurement( final long nanos )
{
final long ms = nanos / 100000;
if( nanos <= 100000 )
{
return nanos + "ns";
}
return ( ms / 10.0f ) + "ms";
}
private String timeMeasurement(final long nanos) {
final long ms = nanos / 100000;
if (nanos <= 100000) {
return nanos + "ns";
}
return (ms / 10.0f) + "ms";
}
}
@@ -1,12 +1,7 @@
package appeng.debug;
import appeng.api.parts.IPart;
import appeng.api.parts.IPartHost;
import appeng.api.parts.PartItemStack;
import appeng.api.util.AEPartLocation;
import appeng.items.AEBaseItem;
import appeng.items.parts.ColoredPartItem;
import appeng.items.parts.ItemPart;
import java.util.Arrays;
import net.minecraft.entity.player.PlayerEntity;
import net.minecraft.item.Item;
import net.minecraft.item.ItemStack;
@@ -20,11 +15,18 @@ import net.minecraft.util.text.StringTextComponent;
import net.minecraft.world.World;
import net.minecraftforge.registries.ForgeRegistries;
import java.util.Arrays;
import appeng.api.parts.IPart;
import appeng.api.parts.IPartHost;
import appeng.api.parts.PartItemStack;
import appeng.api.util.AEPartLocation;
import appeng.items.AEBaseItem;
import appeng.items.parts.ColoredPartItem;
import appeng.items.parts.ItemPart;
/**
* This tool will try to place anything that is registered as a {@link ItemPart} (and not a colored one)
* onto an existing cable to quickly test parts and their rendering.
* This tool will try to place anything that is registered as a {@link ItemPart}
* (and not a colored one) onto an existing cable to quickly test parts and
* their rendering.
*/
public class ToolDebugPartPlacer extends AEBaseItem {
@@ -89,7 +91,8 @@ public class ToolDebugPartPlacer extends AEBaseItem {
}
IPartHost partHost = (IPartHost) t;
if (partHost.addPart(cable.getItemStack(PartItemStack.PICK), AEPartLocation.INTERNAL, player, null) == null) {
if (partHost.addPart(cable.getItemStack(PartItemStack.PICK), AEPartLocation.INTERNAL, player,
null) == null) {
continue;
}
for (Direction dir : perpendicularFaces) {
+45 -51
View File
@@ -18,10 +18,9 @@
package appeng.debug;
import java.util.ArrayList;
import java.util.List;
import appeng.core.AELog;
import appeng.items.AEBaseItem;
import appeng.util.Platform;
import net.minecraft.block.BlockState;
import net.minecraft.entity.player.PlayerEntity;
import net.minecraft.item.ItemStack;
@@ -30,66 +29,61 @@ import net.minecraft.util.ActionResultType;
import net.minecraft.util.math.BlockPos;
import net.minecraft.world.World;
import java.util.ArrayList;
import java.util.List;
import appeng.core.AELog;
import appeng.items.AEBaseItem;
import appeng.util.Platform;
public class ToolEraser extends AEBaseItem {
public class ToolEraser extends AEBaseItem
{
private static final int BLOCK_ERASE_LIMIT = 90000;
private static final int BLOCK_ERASE_LIMIT = 90000;
public ToolEraser(Properties properties) {
super(properties);
}
public ToolEraser(Properties properties) {
super(properties);
}
@Override
public ActionResultType onItemUseFirst(ItemStack stack, ItemUseContext context) {
if (context.getWorld().isRemote()) {
return ActionResultType.PASS;
}
@Override
public ActionResultType onItemUseFirst(ItemStack stack, ItemUseContext context) {
if( context.getWorld().isRemote() )
{
return ActionResultType.PASS;
}
PlayerEntity player = context.getPlayer();
World world = context.getWorld();
BlockPos pos = context.getPos();
PlayerEntity player = context.getPlayer();
World world = context.getWorld();
BlockPos pos = context.getPos();
if (player == null) {
return ActionResultType.PASS;
}
if (player == null) {
return ActionResultType.PASS;
}
final BlockState state = world.getBlockState(pos);
final BlockState state = world.getBlockState( pos );
List<BlockPos> next = new ArrayList<>();
next.add(pos);
List<BlockPos> next = new ArrayList<>();
next.add( pos );
int blocks = 0;
while (blocks < BLOCK_ERASE_LIMIT && !next.isEmpty()) {
final List<BlockPos> c = next;
next = new ArrayList<>();
int blocks = 0;
while( blocks < BLOCK_ERASE_LIMIT && !next.isEmpty() )
{
final List<BlockPos> c = next;
next = new ArrayList<>();
for (final BlockPos wc : c) {
final BlockState c_state = world.getBlockState(wc);
for( final BlockPos wc : c )
{
final BlockState c_state = world.getBlockState( wc );
if (state == c_state) {
blocks++;
world.removeBlock(wc, false);
if( state == c_state )
{
blocks++;
world.removeBlock(wc, false);
next.add(wc.add(1, 0, 0));
next.add(wc.add(-1, 0, 0));
next.add(wc.add(0, 1, 0));
next.add(wc.add(0, -1, 0));
next.add(wc.add(0, 0, 1));
next.add(wc.add(0, 0, -1));
}
}
}
next.add( wc.add( 1, 0, 0 ) );
next.add( wc.add( -1, 0, 0 ) );
next.add( wc.add( 0, 1, 0 ) );
next.add( wc.add( 0, -1, 0 ) );
next.add( wc.add( 0, 0, 1 ) );
next.add( wc.add( 0, 0, -1 ) );
}
}
}
AELog.info("Delete " + blocks + " blocks");
AELog.info( "Delete " + blocks + " blocks" );
return ActionResultType.SUCCESS;
}
return ActionResultType.SUCCESS;
}
}
@@ -18,11 +18,6 @@
package appeng.debug;
import appeng.worldgen.MeteoritePlacer;
import appeng.worldgen.MeteoriteSpawner;
import appeng.worldgen.PlacedMeteoriteSettings;
import appeng.worldgen.meteorite.StandardWorld;
import net.minecraft.entity.player.PlayerEntity;
import net.minecraft.entity.player.ServerPlayerEntity;
import net.minecraft.item.ItemStack;
@@ -33,55 +28,55 @@ import net.minecraft.util.math.BlockPos;
import net.minecraft.util.math.ChunkPos;
import net.minecraft.util.text.StringTextComponent;
import net.minecraft.world.World;
import appeng.items.AEBaseItem;
import net.minecraft.world.chunk.Chunk;
import net.minecraft.world.chunk.ChunkSection;
import net.minecraft.world.server.ServerWorld;
import appeng.items.AEBaseItem;
import appeng.worldgen.MeteoritePlacer;
import appeng.worldgen.MeteoriteSpawner;
import appeng.worldgen.PlacedMeteoriteSettings;
import appeng.worldgen.meteorite.StandardWorld;
public class ToolMeteoritePlacer extends AEBaseItem
{
public class ToolMeteoritePlacer extends AEBaseItem {
public ToolMeteoritePlacer(Properties properties) {
super(properties);
}
public ToolMeteoritePlacer(Properties properties) {
super(properties);
}
@Override
public ActionResultType onItemUseFirst(ItemStack stack, ItemUseContext context) {
if( context.getWorld().isRemote() )
{
return ActionResultType.PASS;
}
@Override
public ActionResultType onItemUseFirst(ItemStack stack, ItemUseContext context) {
if (context.getWorld().isRemote()) {
return ActionResultType.PASS;
}
ServerPlayerEntity player = (ServerPlayerEntity) context.getPlayer();
ServerWorld world = (ServerWorld) context.getWorld();
BlockPos pos = context.getPos();
ServerPlayerEntity player = (ServerPlayerEntity) context.getPlayer();
ServerWorld world = (ServerWorld) context.getWorld();
BlockPos pos = context.getPos();
if (player == null) {
return ActionResultType.PASS;
}
if (player == null) {
return ActionResultType.PASS;
}
final MeteoriteSpawner ms = new MeteoriteSpawner();
PlacedMeteoriteSettings spawned = ms.trySpawnMeteorite(world, pos);
final MeteoriteSpawner ms = new MeteoriteSpawner();
PlacedMeteoriteSettings spawned = ms.trySpawnMeteorite(world, pos);
if( spawned == null )
{
player.sendMessage( new StringTextComponent( "Un-suitable Location." ) );
return ActionResultType.FAIL;
}
if (spawned == null) {
player.sendMessage(new StringTextComponent("Un-suitable Location."));
return ActionResultType.FAIL;
}
final MeteoritePlacer placer = new MeteoritePlacer(world, spawned);
placer.place();
final MeteoritePlacer placer = new MeteoritePlacer(world, spawned);
placer.place();
// The placer will not send chunks to the player since it's used as part
// of world-gen normally, so we'll have to do it ourselves. Since this
// is a debug tool, we'll not care about being terribly efficient here
ChunkPos.getAllInBox(new ChunkPos(spawned.getPos()), 1).forEach(cp -> {
Chunk c = world.getChunk(cp.x, cp.z);
player.connection.sendPacket(new SChunkDataPacket(c, 65535)); // 65535 == full chunk
});
// The placer will not send chunks to the player since it's used as part
// of world-gen normally, so we'll have to do it ourselves. Since this
// is a debug tool, we'll not care about being terribly efficient here
ChunkPos.getAllInBox(new ChunkPos(spawned.getPos()), 1).forEach(cp -> {
Chunk c = world.getChunk(cp.x, cp.z);
player.connection.sendPacket(new SChunkDataPacket(c, 65535)); // 65535 == full chunk
});
return ActionResultType.SUCCESS;
}
return ActionResultType.SUCCESS;
}
}
+116 -145
View File
@@ -18,15 +18,6 @@
package appeng.debug;
import appeng.api.networking.IGrid;
import appeng.api.networking.IGridHost;
import appeng.api.networking.IGridNode;
import appeng.api.networking.spatial.ISpatialCache;
import appeng.api.util.AEPartLocation;
import appeng.api.util.DimensionalCoord;
import appeng.items.AEBaseItem;
import appeng.util.Platform;
import net.minecraft.block.Block;
import net.minecraft.block.BlockState;
import net.minecraft.entity.Entity;
@@ -43,155 +34,135 @@ import net.minecraft.util.text.StringTextComponent;
import net.minecraft.world.World;
import net.minecraft.world.dimension.DimensionType;
import appeng.api.networking.IGrid;
import appeng.api.networking.IGridHost;
import appeng.api.networking.IGridNode;
import appeng.api.networking.spatial.ISpatialCache;
import appeng.api.util.AEPartLocation;
import appeng.api.util.DimensionalCoord;
import appeng.items.AEBaseItem;
import appeng.util.Platform;
public class ToolReplicatorCard extends AEBaseItem
{
public class ToolReplicatorCard extends AEBaseItem {
public ToolReplicatorCard(Properties properties) {
super(properties);
}
public ToolReplicatorCard(Properties properties) {
super(properties);
}
@Override
public ActionResultType onItemUseFirst(ItemStack stack, ItemUseContext context) {
if( context.getWorld().isRemote() )
{
return ActionResultType.PASS;
}
@Override
public ActionResultType onItemUseFirst(ItemStack stack, ItemUseContext context) {
if (context.getWorld().isRemote()) {
return ActionResultType.PASS;
}
PlayerEntity player = context.getPlayer();
World world = context.getWorld();
BlockPos pos = context.getPos();
Direction side = context.getFace();
Hand hand = context.getHand();
PlayerEntity player = context.getPlayer();
World world = context.getWorld();
BlockPos pos = context.getPos();
Direction side = context.getFace();
Hand hand = context.getHand();
if (player == null) {
return ActionResultType.PASS;
}
if (player == null) {
return ActionResultType.PASS;
}
int x = pos.getX();
int y = pos.getY();
int z = pos.getZ();
int x = pos.getX();
int y = pos.getY();
int z = pos.getZ();
if( player.isCrouching() )
{
if( world.getTileEntity( pos ) instanceof IGridHost )
{
final CompoundNBT tag = new CompoundNBT();
tag.putInt( "x", x );
tag.putInt( "y", y );
tag.putInt( "z", z );
tag.putInt( "side", side.ordinal() );
tag.putInt( "dimid", world.getDimension().getType().getId() );
player.getHeldItem( hand ).setTag( tag );
}
else
{
this.outputMsg( player, "This is not a Grid Tile." );
}
}
else
{
final CompoundNBT ish = player.getHeldItem( hand ).getTag();
if( ish != null )
{
final int src_x = ish.getInt( "x" );
final int src_y = ish.getInt( "y" );
final int src_z = ish.getInt( "z" );
final int src_side = ish.getInt( "side" );
final int dimid = ish.getInt( "dimid" );
final World src_w = world.getServer().getWorld(DimensionType.getById(dimid));
if (player.isCrouching()) {
if (world.getTileEntity(pos) instanceof IGridHost) {
final CompoundNBT tag = new CompoundNBT();
tag.putInt("x", x);
tag.putInt("y", y);
tag.putInt("z", z);
tag.putInt("side", side.ordinal());
tag.putInt("dimid", world.getDimension().getType().getId());
player.getHeldItem(hand).setTag(tag);
} else {
this.outputMsg(player, "This is not a Grid Tile.");
}
} else {
final CompoundNBT ish = player.getHeldItem(hand).getTag();
if (ish != null) {
final int src_x = ish.getInt("x");
final int src_y = ish.getInt("y");
final int src_z = ish.getInt("z");
final int src_side = ish.getInt("side");
final int dimid = ish.getInt("dimid");
final World src_w = world.getServer().getWorld(DimensionType.getById(dimid));
final TileEntity te = src_w.getTileEntity( new BlockPos( src_x, src_y, src_z ) );
if( te instanceof IGridHost )
{
final IGridHost gh = (IGridHost) te;
final Direction sideOff = Direction.values()[src_side];
final Direction currentSideOff = side;
final IGridNode n = gh.getGridNode( AEPartLocation.fromFacing( sideOff ) );
if( n != null )
{
final IGrid g = n.getGrid();
if( g != null )
{
final ISpatialCache sc = g.getCache( ISpatialCache.class );
if( sc.isValidRegion() )
{
final DimensionalCoord min = sc.getMin();
final DimensionalCoord max = sc.getMax();
final TileEntity te = src_w.getTileEntity(new BlockPos(src_x, src_y, src_z));
if (te instanceof IGridHost) {
final IGridHost gh = (IGridHost) te;
final Direction sideOff = Direction.values()[src_side];
final Direction currentSideOff = side;
final IGridNode n = gh.getGridNode(AEPartLocation.fromFacing(sideOff));
if (n != null) {
final IGrid g = n.getGrid();
if (g != null) {
final ISpatialCache sc = g.getCache(ISpatialCache.class);
if (sc.isValidRegion()) {
final DimensionalCoord min = sc.getMin();
final DimensionalCoord max = sc.getMax();
x += currentSideOff.getXOffset();
y += currentSideOff.getYOffset();
z += currentSideOff.getZOffset();
x += currentSideOff.getXOffset();
y += currentSideOff.getYOffset();
z += currentSideOff.getZOffset();
final int min_x = min.x;
final int min_y = min.y;
final int min_z = min.z;
final int min_x = min.x;
final int min_y = min.y;
final int min_z = min.z;
final int rel_x = min.x - src_x + x;
final int rel_y = min.y - src_y + y;
final int rel_z = min.z - src_z + z;
final int rel_x = min.x - src_x + x;
final int rel_y = min.y - src_y + y;
final int rel_z = min.z - src_z + z;
final int scale_x = max.x - min.x;
final int scale_y = max.y - min.y;
final int scale_z = max.z - min.z;
final int scale_x = max.x - min.x;
final int scale_y = max.y - min.y;
final int scale_z = max.z - min.z;
for( int i = 1; i < scale_x; i++ )
{
for( int j = 1; j < scale_y; j++ )
{
for( int k = 1; k < scale_z; k++ )
{
final BlockPos p = new BlockPos( min_x + i, min_y + j, min_z + k );
final BlockPos d = new BlockPos( i + rel_x, j + rel_y, k + rel_z );
final BlockState state = src_w.getBlockState( p );
final Block blk = state.getBlock();
final BlockState prev = world.getBlockState( d );
for (int i = 1; i < scale_x; i++) {
for (int j = 1; j < scale_y; j++) {
for (int k = 1; k < scale_z; k++) {
final BlockPos p = new BlockPos(min_x + i, min_y + j, min_z + k);
final BlockPos d = new BlockPos(i + rel_x, j + rel_y, k + rel_z);
final BlockState state = src_w.getBlockState(p);
final Block blk = state.getBlock();
final BlockState prev = world.getBlockState(d);
world.setBlockState( d, state );
if( blk != null && blk.hasTileEntity( state ) )
{
final TileEntity ote = src_w.getTileEntity( p );
final TileEntity nte = blk.createTileEntity( state, world );
final CompoundNBT data = new CompoundNBT();
ote.write( data );
nte.read( data.copy() );
world.setTileEntity( d, nte );
}
world.notifyBlockUpdate( d, prev, state, 3 );
}
}
}
}
else
{
this.outputMsg( player, "requires valid spatial pylon setup." );
}
}
else
{
this.outputMsg( player, "no grid?" );
}
}
else
{
this.outputMsg( player, "No grid node?" );
}
}
else
{
this.outputMsg( player, "Src is no longer a grid block?" );
}
}
else
{
this.outputMsg( player, "No Source Defined" );
}
}
return ActionResultType.SUCCESS;
}
world.setBlockState(d, state);
if (blk != null && blk.hasTileEntity(state)) {
final TileEntity ote = src_w.getTileEntity(p);
final TileEntity nte = blk.createTileEntity(state, world);
final CompoundNBT data = new CompoundNBT();
ote.write(data);
nte.read(data.copy());
world.setTileEntity(d, nte);
}
world.notifyBlockUpdate(d, prev, state, 3);
}
}
}
} else {
this.outputMsg(player, "requires valid spatial pylon setup.");
}
} else {
this.outputMsg(player, "no grid?");
}
} else {
this.outputMsg(player, "No grid node?");
}
} else {
this.outputMsg(player, "Src is no longer a grid block?");
}
} else {
this.outputMsg(player, "No Source Defined");
}
}
return ActionResultType.SUCCESS;
}
private void outputMsg(final Entity player, final String string )
{
player.sendMessage( new StringTextComponent( string ) );
}
private void outputMsg(final Entity player, final String string) {
player.sendMessage(new StringTextComponent(string));
}
}