Lots more moved

This commit is contained in:
Sebastian Hartte
2020-07-04 21:03:30 +02:00
parent 5982f094ec
commit 1478e4c378
444 changed files with 4693 additions and 5235 deletions
@@ -0,0 +1,201 @@
/*
* This file is part of Applied Energistics 2.
* Copyright (c) 2013 - 2014, AlgorithmX2, All rights reserved.
*
* Applied Energistics 2 is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* Applied Energistics 2 is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with Applied Energistics 2. If not, see <http://www.gnu.org/licenses/lgpl>.
*/
package appeng.debug;
import java.util.HashSet;
import java.util.Set;
import appeng.hooks.AEToolItem;
import appeng.tile.networking.ControllerBlockEntity;
import net.minecraft.entity.Entity;
import net.minecraft.entity.player.PlayerEntity;
import net.minecraft.item.ItemStack;
import net.minecraft.item.ItemUsageContext;
import net.minecraft.block.entity.BlockEntity;
import net.minecraft.text.LiteralText;
import net.minecraft.util.ActionResult;
import net.minecraft.util.Util;
import net.minecraft.util.math.Direction;
import net.minecraft.util.math.BlockPos;
import net.minecraft.world.World;
import appeng.api.networking.IGridConnection;
import appeng.api.networking.IGridHost;
import appeng.api.networking.IGridNode;
import appeng.api.networking.energy.IAEPowerStorage;
import appeng.api.networking.energy.IEnergyGrid;
import appeng.api.networking.pathing.ControllerState;
import appeng.api.networking.pathing.IPathingGrid;
import appeng.api.networking.ticking.ITickManager;
import appeng.api.parts.IPart;
import appeng.api.parts.IPartHost;
import appeng.api.util.AEPartLocation;
import appeng.hooks.TickHandler;
import appeng.items.AEBaseItem;
import appeng.me.Grid;
import appeng.me.GridNode;
import appeng.me.cache.TickManagerCache;
import appeng.parts.p2p.P2PTunnelPart;
public class DebugCardItem extends AEBaseItem implements AEToolItem {
public DebugCardItem(Settings properties) {
super(properties);
}
@Override
public ActionResult onItemUseFirst(ItemStack stack, ItemUsageContext context) {
if (context.getWorld().isClient()) {
return ActionResult.PASS;
}
PlayerEntity player = context.getPlayer();
World world = context.getWorld();
BlockPos pos = context.getBlockPos();
Direction side = context.getSide();
if (player == null) {
return ActionResult.PASS;
}
if (player.isInSneakingPose()) {
int grids = 0;
int totalNodes = 0;
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 BlockEntity te = world.getBlockEntity(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());
final IPathingGrid pg = g.getCache(IPathingGrid.class);
if (pg.getControllerState() == ControllerState.CONTROLLER_ONLINE) {
Set<IGridNode> next = new HashSet<>();
next.add(node);
final int maxLength = 10000;
int length = 0;
outer: while (!next.isEmpty()) {
final Iterable<IGridNode> current = next;
next = new HashSet<>();
for (final IGridNode n : current) {
if (n.getMachine() instanceof ControllerBlockEntity) {
break outer;
}
for (final IGridConnection c : n.getConnections()) {
next.add(c.getOtherSide(n));
}
}
length++;
if (length > maxLength) {
break;
}
}
this.outputMsg(player, "Cable Distance: " + length);
}
if (center.getMachine() instanceof P2PTunnelPart) {
this.outputMsg(player, "Freq: " + ((P2PTunnelPart<?>) 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);
}
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 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 ActionResult.SUCCESS;
}
private void outputMsg(final Entity player, final String string) {
player.sendSystemMessage(new LiteralText(string), Util.NIL_UUID);
}
private String timeMeasurement(final long nanos) {
final long ms = nanos / 100000;
if (nanos <= 100000) {
return nanos + "ns";
}
return (ms / 10.0f) + "ms";
}
}
@@ -0,0 +1,109 @@
package appeng.debug;
import java.util.Arrays;
import appeng.hooks.AEToolItem;
import net.minecraft.block.entity.BlockEntity;
import net.minecraft.entity.player.PlayerEntity;
import net.minecraft.item.Item;
import net.minecraft.item.ItemStack;
import net.minecraft.item.ItemUsageContext;
import net.minecraft.text.LiteralText;
import net.minecraft.util.ActionResult;
import net.minecraft.util.Util;
import net.minecraft.util.math.Direction;
import net.minecraft.util.math.BlockPos;
import net.minecraft.util.math.Vec3i;
import net.minecraft.util.registry.Registry;
import net.minecraft.world.World;
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.PartItem;
/**
* This tool will try to place anything that is registered as a {@link PartItem}
* (and not a colored one) onto an existing cable to quickly test parts and
* their rendering.
*/
public class DebugPartPlacerItem extends AEBaseItem implements AEToolItem {
public DebugPartPlacerItem(Settings properties) {
super(properties);
}
@Override
public ActionResult onItemUseFirst(ItemStack stack, ItemUsageContext context) {
World world = context.getWorld();
if (world.isClient()) {
return ActionResult.PASS;
}
PlayerEntity player = context.getPlayer();
BlockPos pos = context.getBlockPos();
if (player == null) {
return ActionResult.PASS;
}
if (!player.isCreative()) {
player.sendSystemMessage(new LiteralText("Only usable in creative mode"), Util.NIL_UUID);
return ActionResult.FAIL;
}
BlockEntity te = world.getBlockEntity(pos);
if (!(te instanceof IPartHost)) {
player.sendSystemMessage(new LiteralText("Right-click something that will accept parts"), Util.NIL_UUID);
return ActionResult.FAIL;
}
IPartHost center = (IPartHost) te;
IPart cable = center.getPart(AEPartLocation.INTERNAL);
if (cable == null) {
player.sendSystemMessage(new LiteralText("Clicked part host must have an INSIDE part"), Util.NIL_UUID);
return ActionResult.FAIL;
}
Direction face = context.getSide();
Vec3i offset = face.getVector();
Direction[] perpendicularFaces = Arrays.stream(Direction.values()).filter(d -> d.getAxis() != face.getAxis())
.toArray(Direction[]::new);
BlockPos nextPos = pos;
for (Item item : Registry.ITEM) {
if (!(item instanceof PartItem)) {
continue;
}
if (item instanceof ColoredPartItem) {
continue; // Cables and such
}
nextPos = nextPos.add(offset);
if (!world.setBlockState(nextPos, te.getCachedState())) {
continue;
}
BlockEntity t = world.getBlockEntity(nextPos);
if (!(t instanceof IPartHost)) {
continue;
}
IPartHost partHost = (IPartHost) t;
if (partHost.addPart(cable.getItemStack(PartItemStack.PICK), AEPartLocation.INTERNAL, player,
null) == null) {
continue;
}
for (Direction dir : perpendicularFaces) {
ItemStack itemStack = new ItemStack(item, 1);
partHost.addPart(itemStack, AEPartLocation.fromFacing(dir), player, null);
}
}
return ActionResult.SUCCESS;
}
}
+152
View File
@@ -0,0 +1,152 @@
/*
* This file is part of Applied Energistics 2.
* Copyright (c) 2013 - 2014, AlgorithmX2, All rights reserved.
*
* Applied Energistics 2 is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* Applied Energistics 2 is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with Applied Energistics 2. If not, see <http://www.gnu.org/licenses/lgpl>.
*/
package appeng.debug;
import java.util.ArrayDeque;
import java.util.HashSet;
import java.util.Queue;
import java.util.Set;
import appeng.hooks.AEToolItem;
import net.minecraft.block.Block;
import net.minecraft.block.Blocks;
import net.minecraft.entity.player.PlayerEntity;
import net.minecraft.item.ItemStack;
import net.minecraft.item.ItemUsageContext;
import net.minecraft.tag.BlockTags;
import net.minecraft.util.ActionResult;
import net.minecraft.util.math.BlockPos;
import net.minecraft.world.World;
import appeng.core.AELog;
import appeng.items.AEBaseItem;
public class EraserItem extends AEBaseItem implements AEToolItem {
private static final int BOX_SIZE = 48;
private static final int BLOCK_ERASE_LIMIT = BOX_SIZE * BOX_SIZE * BOX_SIZE;
final static Set<Block> COMMON_BLOCKS = new HashSet<>();
public EraserItem(Settings properties) {
super(properties);
}
@Override
public ActionResult onItemUseFirst(ItemStack stack, ItemUsageContext context) {
if (context.getWorld().isClient()) {
return ActionResult.PASS;
}
final PlayerEntity player = context.getPlayer();
final World world = context.getWorld();
final BlockPos pos = context.getBlockPos();
if (player == null) {
return ActionResult.PASS;
}
final Block state = world.getBlockState(pos).getBlock();
final boolean bulk = player.isSneaking();
final Queue<BlockPos> next = new ArrayDeque<>();
final Set<BlockPos> closed = new HashSet<>();
final Set<Block> commonBlocks = this.getCommonBlocks();
next.add(pos);
int blocks = 0;
while (blocks < BLOCK_ERASE_LIMIT && next.peek() != null) {
final BlockPos wc = next.poll();
final Block c_state = world.getBlockState(wc).getBlock();
final boolean contains = state == c_state || (bulk && (commonBlocks.contains(c_state)));
closed.add(wc);
if (contains) {
blocks++;
world.setBlockState(wc, Blocks.AIR.getDefaultState(), 2);
world.breakBlock(wc, false);
if (isInsideBox(wc, pos)) {
for (int x = -1; x <= 1; x++) {
for (int y = -1; y <= 1; y++) {
for (int z = -1; z <= 1; z++) {
if (0 == x && 0 == y && 0 == z) {
continue;
}
final BlockPos nextPos = wc.add(x, y, z);
if (!closed.contains(nextPos)) {
next.add(nextPos);
}
}
}
}
}
}
}
AELog.info("Delete " + blocks + " blocks");
return ActionResult.SUCCESS;
}
private boolean isInsideBox(BlockPos pos, BlockPos origin) {
boolean ret = true;
if (pos.getX() > origin.getX() + BOX_SIZE || pos.getX() < origin.getX() - BOX_SIZE) {
ret = false;
}
if (pos.getY() > origin.getY() + BOX_SIZE || pos.getY() < origin.getY() - BOX_SIZE) {
ret = false;
}
if (pos.getZ() > origin.getZ() + BOX_SIZE || pos.getZ() < origin.getZ() - BOX_SIZE) {
ret = false;
}
return ret;
}
/**
* Filling needs to be deferred as the tags might not be populated at
* construction time.
*
* @return
*/
private Set<Block> getCommonBlocks() {
if (COMMON_BLOCKS.isEmpty()) {
COMMON_BLOCKS.add(Blocks.STONE);
COMMON_BLOCKS.add(Blocks.DIRT);
COMMON_BLOCKS.add(Blocks.GRASS_BLOCK);
COMMON_BLOCKS.add(Blocks.COBBLESTONE);
COMMON_BLOCKS.add(Blocks.ANDESITE);
COMMON_BLOCKS.add(Blocks.GRANITE);
COMMON_BLOCKS.add(Blocks.DIORITE);
COMMON_BLOCKS.add(Blocks.GRAVEL);
COMMON_BLOCKS.add(Blocks.SANDSTONE);
COMMON_BLOCKS.add(Blocks.NETHERRACK);
COMMON_BLOCKS.add(Blocks.WATER);
COMMON_BLOCKS.add(Blocks.LAVA);
COMMON_BLOCKS.addAll(BlockTags.LEAVES.values());
COMMON_BLOCKS.addAll(BlockTags.SAND.values());
COMMON_BLOCKS.addAll(BlockTags.LOGS.values());
}
return COMMON_BLOCKS;
}
}
@@ -0,0 +1,176 @@
/*
* This file is part of Applied Energistics 2.
* Copyright (c) 2013 - 2014, AlgorithmX2, All rights reserved.
*
* Applied Energistics 2 is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* Applied Energistics 2 is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with Applied Energistics 2. If not, see <http://www.gnu.org/licenses/lgpl>.
*/
package appeng.debug;
import appeng.hooks.AEToolItem;
import net.minecraft.block.Block;
import net.minecraft.block.BlockEntityProvider;
import net.minecraft.block.BlockState;
import net.minecraft.entity.Entity;
import net.minecraft.entity.player.PlayerEntity;
import net.minecraft.item.ItemStack;
import net.minecraft.item.ItemUsageContext;
import net.minecraft.nbt.CompoundTag;
import net.minecraft.block.entity.BlockEntity;
import net.minecraft.server.MinecraftServer;
import net.minecraft.server.world.ServerWorld;
import net.minecraft.util.ActionResult;
import net.minecraft.util.Identifier;
import net.minecraft.util.Util;
import net.minecraft.util.math.Direction;
import net.minecraft.util.Hand;
import net.minecraft.util.math.BlockPos;
import net.minecraft.text.LiteralText;
import net.minecraft.util.registry.Registry;
import net.minecraft.util.registry.RegistryKey;
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;
public class ReplicatorCardItem extends AEBaseItem implements AEToolItem {
public ReplicatorCardItem(Settings properties) {
super(properties);
}
@Override
public ActionResult onItemUseFirst(ItemStack stack, ItemUsageContext context) {
if (context.getWorld().isClient()) {
return ActionResult.PASS;
}
PlayerEntity player = context.getPlayer();
World world = context.getWorld();
BlockPos pos = context.getBlockPos();
Direction side = context.getSide();
Hand hand = context.getHand();
if (player == null) {
return ActionResult.PASS;
}
int x = pos.getX();
int y = pos.getY();
int z = pos.getZ();
if (player.isInSneakingPose()) {
if (world.getBlockEntity(pos) instanceof IGridHost) {
final CompoundTag tag = new CompoundTag();
tag.putInt("x", x);
tag.putInt("y", y);
tag.putInt("z", z);
tag.putInt("side", side.ordinal());
tag.putString("w", world.getRegistryKey().getValue().toString());
player.getStackInHand(hand).setTag(tag);
} else {
this.outputMsg(player, "This is not a Grid Tile.");
}
} else {
final CompoundTag ish = player.getStackInHand(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 String worldId = ish.getString("w");
final World src_w = world.getServer().getWorld(RegistryKey.of(Registry.DIMENSION, new Identifier(worldId)));
final BlockEntity te = src_w.getBlockEntity(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.getOffsetX();
y += currentSideOff.getOffsetY();
z += currentSideOff.getOffsetZ();
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 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);
world.setBlockState(d, state);
if (blk instanceof BlockEntityProvider) {
BlockEntityProvider blkEntityProvider = (BlockEntityProvider)blk;
final BlockEntity ote = src_w.getBlockEntity(p);
final BlockEntity nte = blkEntityProvider.createBlockEntity(world);
final CompoundTag data = new CompoundTag();
ote.toTag(data);
nte.fromTag(state, data.copy());
world.setBlockEntity(d, nte);
}
world.updateListeners(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 ActionResult.SUCCESS;
}
private void outputMsg(final Entity player, final String string) {
player.sendSystemMessage(new LiteralText(string), Util.NIL_UUID);
}
}