Moving to source sets
This commit is contained in:
@@ -1,31 +0,0 @@
|
||||
/*
|
||||
* This file is part of Applied Energistics 2.
|
||||
* Copyright (c) 2013 - 2015, 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 net.minecraft.block.Material;
|
||||
|
||||
import appeng.block.AEBaseTileBlock;
|
||||
|
||||
public class ChunkLoaderBlock extends AEBaseTileBlock<ChunkLoaderBlockEntity> {
|
||||
|
||||
public ChunkLoaderBlock() {
|
||||
super(defaultProps(Material.METAL));
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,71 +0,0 @@
|
||||
/*
|
||||
* This file is part of Applied Energistics 2.
|
||||
* Copyright (c) 2013 - 2015, 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 net.minecraft.util.Tickable;
|
||||
import net.minecraft.block.entity.BlockEntityType;
|
||||
import net.minecraft.util.math.ChunkPos;
|
||||
import net.minecraft.world.World;
|
||||
import net.minecraft.server.world.ServerWorld;
|
||||
|
||||
import appeng.core.AELog;
|
||||
import appeng.tile.AEBaseBlockEntity;
|
||||
|
||||
public class ChunkLoaderBlockEntity extends AEBaseBlockEntity implements Tickable {
|
||||
|
||||
public ChunkLoaderBlockEntity(BlockEntityType<?> tileEntityTypeIn) {
|
||||
super(tileEntityTypeIn);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onLoad() {
|
||||
super.onLoad();
|
||||
|
||||
World world = getWorld();
|
||||
if (world instanceof ServerWorld) {
|
||||
ChunkPos chunkPos = new ChunkPos(getPos());
|
||||
((ServerWorld) world).forceChunk(chunkPos.x, chunkPos.z, true);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void remove() {
|
||||
World world = getWorld();
|
||||
if (world instanceof ServerWorld) {
|
||||
ChunkPos chunkPos = new ChunkPos(getPos());
|
||||
((ServerWorld) world).forceChunk(chunkPos.x, chunkPos.z, false);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void tick() {
|
||||
// Validate the force-status
|
||||
World world = getWorld();
|
||||
if (world instanceof ServerWorld) {
|
||||
ChunkPos chunkPos = new ChunkPos(getPos());
|
||||
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());
|
||||
serverWorld.forceChunk(chunkPos.x, chunkPos.z, false);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,51 +0,0 @@
|
||||
/*
|
||||
* 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 javax.annotation.Nullable;
|
||||
|
||||
import net.minecraft.block.Material;
|
||||
import net.minecraft.entity.player.PlayerEntity;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.util.ActionResult;
|
||||
import net.minecraft.util.Hand;
|
||||
import net.minecraft.util.hit.BlockHitResult;
|
||||
import net.minecraft.util.math.BlockPos;
|
||||
import net.minecraft.world.World;
|
||||
|
||||
import appeng.block.AEBaseTileBlock;
|
||||
|
||||
public class CubeGeneratorBlock extends AEBaseTileBlock<CubeGeneratorBlockEntity> {
|
||||
|
||||
public CubeGeneratorBlock() {
|
||||
super(defaultProps(Material.METAL));
|
||||
}
|
||||
|
||||
@Override
|
||||
public ActionResult onActivated(final World w, final BlockPos pos, final PlayerEntity player, final Hand hand,
|
||||
final @Nullable ItemStack heldItem, final BlockHitResult hit) {
|
||||
final CubeGeneratorBlockEntity tcg = this.getBlockEntity(w, pos);
|
||||
if (tcg != null) {
|
||||
tcg.click(player);
|
||||
}
|
||||
|
||||
return ActionResult.SUCCESS;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,112 +0,0 @@
|
||||
/*
|
||||
* This file is part of Applied Energistics 2.
|
||||
* Copyright (c) 2013 - 2015, 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 net.minecraft.entity.player.PlayerEntity;
|
||||
import net.minecraft.item.AutomaticItemPlacementContext;
|
||||
import net.minecraft.item.Item;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.item.ItemUsageContext;
|
||||
import net.minecraft.util.Tickable;
|
||||
import net.minecraft.block.entity.BlockEntityType;
|
||||
import net.minecraft.util.math.Direction;
|
||||
import net.minecraft.util.math.BlockPos;
|
||||
import net.minecraft.text.LiteralText;
|
||||
|
||||
import appeng.core.AppEng;
|
||||
import appeng.tile.AEBaseBlockEntity;
|
||||
import appeng.util.Platform;
|
||||
|
||||
public class CubeGeneratorBlockEntity extends AEBaseBlockEntity implements Tickable {
|
||||
|
||||
private int size = 3;
|
||||
private ItemStack is = ItemStack.EMPTY;
|
||||
private int countdown = 20 * 10;
|
||||
private PlayerEntity who = null;
|
||||
|
||||
public CubeGeneratorBlockEntity(BlockEntityType<?> tileEntityTypeIn) {
|
||||
super(tileEntityTypeIn);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void tick() {
|
||||
if (!this.is.isEmpty() && Platform.isServer()) {
|
||||
this.countdown--;
|
||||
|
||||
if (this.countdown % 20 == 0) {
|
||||
for (final PlayerEntity e : AppEng.instance().getPlayers()) {
|
||||
e.sendSystemMessage(new LiteralText("Spawning in... " + (this.countdown / 20)), Util.NIL_UUID);
|
||||
}
|
||||
}
|
||||
|
||||
if (this.countdown <= 0) {
|
||||
this.spawn();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private void spawn() {
|
||||
this.world.removeBlock(this.pos, false);
|
||||
|
||||
final Item i = this.is.getItem();
|
||||
final Direction side = Direction.UP;
|
||||
|
||||
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);
|
||||
ItemUsageContext useContext = new AutomaticItemPlacementContext(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;
|
||||
|
||||
if (hand.isEmpty()) {
|
||||
this.is = ItemStack.EMPTY;
|
||||
|
||||
if (player.isInSneakingPose()) {
|
||||
this.size--;
|
||||
} else {
|
||||
this.size++;
|
||||
}
|
||||
|
||||
if (this.size < 3) {
|
||||
this.size = 3;
|
||||
}
|
||||
if (this.size > 64) {
|
||||
this.size = 64;
|
||||
}
|
||||
|
||||
player.sendSystemMessage(new LiteralText("Size: " + this.size), Util.NIL_UUID);
|
||||
} else {
|
||||
this.countdown = 20 * 10;
|
||||
this.is = hand;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,199 +0,0 @@
|
||||
/*
|
||||
* 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 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.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;
|
||||
import appeng.tile.networking.ControllerBlockEntity;
|
||||
|
||||
public class DebugCardItem extends AEBaseItem {
|
||||
|
||||
public DebugCardItem(Properties 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.sendMessage(new LiteralText(string));
|
||||
}
|
||||
|
||||
private String timeMeasurement(final long nanos) {
|
||||
final long ms = nanos / 100000;
|
||||
if (nanos <= 100000) {
|
||||
return nanos + "ns";
|
||||
}
|
||||
return (ms / 10.0f) + "ms";
|
||||
}
|
||||
}
|
||||
@@ -1,107 +0,0 @@
|
||||
package appeng.debug;
|
||||
|
||||
import java.util.Arrays;
|
||||
|
||||
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.math.Direction;
|
||||
import net.minecraft.util.math.BlockPos;
|
||||
import net.minecraft.util.math.Vec3i;
|
||||
import net.minecraft.world.World;
|
||||
import net.minecraftforge.registries.ForgeRegistries;
|
||||
|
||||
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 {
|
||||
|
||||
public DebugPartPlacerItem(Properties 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.abilities.isCreativeMode) {
|
||||
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.getBlockState())) {
|
||||
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;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,31 +0,0 @@
|
||||
/*
|
||||
* 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 net.minecraft.block.Material;
|
||||
|
||||
import appeng.block.AEBaseTileBlock;
|
||||
|
||||
public class EnergyGeneratorBlock extends AEBaseTileBlock<EnergyGeneratorBlockEntity> {
|
||||
|
||||
public EnergyGeneratorBlock() {
|
||||
super(defaultProps(Material.METAL));
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,120 +0,0 @@
|
||||
/*
|
||||
* This file is part of Applied Energistics 2.
|
||||
* Copyright (c) 2013 - 2015, 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 javax.annotation.Nullable;
|
||||
|
||||
import com.google.common.math.IntMath;
|
||||
|
||||
import net.minecraft.block.entity.BlockEntity;
|
||||
import net.minecraft.block.entity.BlockEntityType;
|
||||
import net.minecraft.util.Tickable;
|
||||
import net.minecraft.util.math.Direction;
|
||||
import net.minecraft.world.World;
|
||||
import net.minecraftforge.common.capabilities.Capability;
|
||||
import net.minecraftforge.common.util.LazyOptional;
|
||||
import net.minecraftforge.energy.CapabilityEnergy;
|
||||
import net.minecraftforge.energy.IEnergyStorage;
|
||||
|
||||
import appeng.tile.AEBaseBlockEntity;
|
||||
|
||||
public class EnergyGeneratorBlockEntity extends AEBaseBlockEntity implements Tickable, IEnergyStorage {
|
||||
/**
|
||||
* The base energy injected each tick. Adjacent TileEnergyGenerators will
|
||||
* increase it to pow(base, #generators).
|
||||
*/
|
||||
private static final int BASE_ENERGY = 8;
|
||||
|
||||
public EnergyGeneratorBlockEntity(BlockEntityType<?> tileEntityTypeIn) {
|
||||
super(tileEntityTypeIn);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void tick() {
|
||||
World world = this.getWorld();
|
||||
if (world == null) {
|
||||
return;
|
||||
}
|
||||
|
||||
int tier = 1;
|
||||
for (Direction facing : Direction.values()) {
|
||||
final BlockEntity te = world.getBlockEntity(this.getPos().offset(facing));
|
||||
|
||||
if (te instanceof EnergyGeneratorBlockEntity) {
|
||||
tier++;
|
||||
}
|
||||
}
|
||||
|
||||
final int energyToInsert = IntMath.pow(BASE_ENERGY, tier);
|
||||
|
||||
for (Direction facing : Direction.values()) {
|
||||
final BlockEntity te = this.getWorld().getBlockEntity(this.getPos().offset(facing));
|
||||
if (te == null) {
|
||||
continue;
|
||||
}
|
||||
final LazyOptional<IEnergyStorage> cap = te.getCapability(CapabilityEnergy.ENERGY, facing.getOpposite());
|
||||
|
||||
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);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int receiveEnergy(int maxReceive, boolean simulate) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int extractEnergy(int maxExtract, boolean simulate) {
|
||||
return maxExtract;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getEnergyStored() {
|
||||
return Integer.MAX_VALUE;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getMaxEnergyStored() {
|
||||
return Integer.MAX_VALUE;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean canExtract() {
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean canReceive() {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
@@ -1,151 +0,0 @@
|
||||
/*
|
||||
* 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 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 {
|
||||
|
||||
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(Properties 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.getAllElements());
|
||||
COMMON_BLOCKS.addAll(BlockTags.SAND.getAllElements());
|
||||
COMMON_BLOCKS.addAll(BlockTags.LOGS.getAllElements());
|
||||
}
|
||||
|
||||
return COMMON_BLOCKS;
|
||||
}
|
||||
}
|
||||
@@ -1,31 +0,0 @@
|
||||
/*
|
||||
* 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 net.minecraft.block.Material;
|
||||
|
||||
import appeng.block.AEBaseTileBlock;
|
||||
|
||||
public class ItemGenBlock extends AEBaseTileBlock<ItemGenBlockEntity> {
|
||||
|
||||
public ItemGenBlock() {
|
||||
super(defaultProps(Material.METAL));
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,132 +0,0 @@
|
||||
/*
|
||||
* 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.Queue;
|
||||
|
||||
import javax.annotation.Nonnull;
|
||||
import javax.annotation.Nullable;
|
||||
|
||||
import alexiil.mc.lib.attributes.item.FixedItemInv;
|
||||
import net.minecraft.block.entity.BlockEntityType;
|
||||
import net.minecraft.item.Item;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.item.Items;
|
||||
import net.minecraft.util.collection.DefaultedList;
|
||||
import net.minecraft.util.math.Direction;
|
||||
import net.minecraftforge.common.capabilities.Capability;
|
||||
import net.minecraftforge.common.util.LazyOptional;
|
||||
import net.minecraftforge.items.CapabilityItemHandler;
|
||||
import net.minecraftforge.registries.ForgeRegistries;
|
||||
|
||||
import appeng.tile.AEBaseBlockEntity;
|
||||
|
||||
public class ItemGenBlockEntity extends AEBaseBlockEntity {
|
||||
|
||||
private static final Queue<ItemStack> POSSIBLE_ITEMS = new ArrayDeque<>();
|
||||
|
||||
private final FixedItemInv handler = new QueuedItemHandler();
|
||||
|
||||
public ItemGenBlockEntity(BlockEntityType<?> tileEntityTypeIn) {
|
||||
super(tileEntityTypeIn);
|
||||
if (POSSIBLE_ITEMS.isEmpty()) {
|
||||
for (final Item mi : Registry.ITEM) {
|
||||
if (mi != null && mi != Items.AIR) {
|
||||
if (mi.isDamageable()) {
|
||||
ItemStack sampleStack = new ItemStack(mi);
|
||||
int maxDamage = sampleStack.getMaxDamage();
|
||||
for (int dmg = 0; dmg < maxDamage; dmg++) {
|
||||
ItemStack is = sampleStack.copy();
|
||||
is.setDamage(dmg);
|
||||
POSSIBLE_ITEMS.add(is);
|
||||
}
|
||||
} else {
|
||||
if (mi.getGroup() == null) {
|
||||
continue;
|
||||
}
|
||||
|
||||
final DefaultedList<ItemStack> list = DefaultedList.of();
|
||||
mi.appendStacks(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);
|
||||
}
|
||||
|
||||
class QueuedItemHandler implements FixedItemInv {
|
||||
|
||||
@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
|
||||
public boolean isItemValid(int slot, @Nonnull ItemStack stack) {
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getSlots() {
|
||||
return 1;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getMaxAmount(int slot, ItemStack stack) {
|
||||
return 1;
|
||||
}
|
||||
|
||||
@Override
|
||||
@Nonnull
|
||||
public ItemStack extractItem(int slot, int amount, boolean simulate) {
|
||||
final ItemStack is = POSSIBLE_ITEMS.peek();
|
||||
|
||||
if (is == null) {
|
||||
return ItemStack.EMPTY;
|
||||
}
|
||||
|
||||
return simulate ? is.copy() : this.getNextItem();
|
||||
}
|
||||
|
||||
private ItemStack getNextItem() {
|
||||
final ItemStack is = POSSIBLE_ITEMS.poll();
|
||||
|
||||
POSSIBLE_ITEMS.add(is);
|
||||
return is.copy();
|
||||
}
|
||||
};
|
||||
}
|
||||
@@ -1,136 +0,0 @@
|
||||
/*
|
||||
* 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 net.minecraft.entity.player.PlayerEntity;
|
||||
import net.minecraft.server.network.ServerPlayerEntity;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.item.ItemUsageContext;
|
||||
import net.minecraft.nbt.CompoundTag;
|
||||
import net.minecraft.network.play.server.SChunkDataPacket;
|
||||
import net.minecraft.text.LiteralText;
|
||||
import net.minecraft.util.TypedActionResult;
|
||||
import net.minecraft.util.ActionResult;
|
||||
import net.minecraft.util.Hand;
|
||||
import net.minecraft.util.math.BlockPos;
|
||||
import net.minecraft.util.math.ChunkPos;
|
||||
import net.minecraft.util.math.MutableBoundingBox;
|
||||
import net.minecraft.world.World;
|
||||
import net.minecraft.world.chunk.Chunk;
|
||||
import net.minecraft.server.world.ServerWorld;
|
||||
|
||||
import appeng.items.AEBaseItem;
|
||||
import appeng.util.Platform;
|
||||
import appeng.worldgen.meteorite.CraterType;
|
||||
import appeng.worldgen.meteorite.MeteoritePlacer;
|
||||
import appeng.worldgen.meteorite.PlacedMeteoriteSettings;
|
||||
import appeng.worldgen.meteorite.debug.MeteoriteSpawner;
|
||||
|
||||
public class MeteoritePlacerItem extends AEBaseItem {
|
||||
|
||||
private static final String MODE_TAG = "mode";
|
||||
|
||||
public MeteoritePlacerItem(Properties properties) {
|
||||
super(properties);
|
||||
}
|
||||
|
||||
@Override
|
||||
public TypedActionResult<ItemStack> use(World world, PlayerEntity player, Hand hand) {
|
||||
if (world.isClient()) {
|
||||
return TypedActionResult.resultPass(player.getStackInHand(hand));
|
||||
}
|
||||
|
||||
if (player.isSneaking()) {
|
||||
final ItemStack itemStack = player.getStackInHand(hand);
|
||||
final CompoundTag tag = itemStack.getOrCreateTag();
|
||||
|
||||
if (tag.contains(MODE_TAG)) {
|
||||
final byte mode = tag.getByte("mode");
|
||||
tag.putByte(MODE_TAG, (byte) ((mode + 1) % CraterType.values().length));
|
||||
} else {
|
||||
tag.putByte(MODE_TAG, (byte) CraterType.NORMAL.ordinal());
|
||||
}
|
||||
|
||||
CraterType craterType = CraterType.values()[tag.getByte(MODE_TAG)];
|
||||
|
||||
player.sendSystemMessage(new LiteralText(craterType.name()), Util.NIL_UUID);
|
||||
|
||||
return TypedActionResult.resultSuccess(itemStack);
|
||||
}
|
||||
|
||||
return super.use(world, player, hand);
|
||||
}
|
||||
|
||||
@Override
|
||||
public ActionResult onItemUseFirst(ItemStack stack, ItemUsageContext context) {
|
||||
if (context.getWorld().isClient()) {
|
||||
return ActionResult.PASS;
|
||||
}
|
||||
|
||||
ServerPlayerEntity player = (ServerPlayerEntity) context.getPlayer();
|
||||
ServerWorld world = (ServerWorld) context.getWorld();
|
||||
BlockPos pos = context.getBlockPos();
|
||||
|
||||
if (player == null) {
|
||||
return ActionResult.PASS;
|
||||
}
|
||||
|
||||
CompoundTag tag = stack.getOrCreateTag();
|
||||
if (!tag.contains(MODE_TAG)) {
|
||||
tag.putByte(MODE_TAG, (byte) CraterType.NORMAL.ordinal());
|
||||
}
|
||||
|
||||
// See MeteoriteStructure for original code
|
||||
float coreRadius = (Platform.getRandomFloat() * 6.0f) + 2;
|
||||
boolean pureCrater = Platform.getRandomFloat() > 0.5f;
|
||||
CraterType craterType = CraterType.values()[tag.getByte(MODE_TAG)];
|
||||
|
||||
MeteoriteSpawner spawner = new MeteoriteSpawner();
|
||||
PlacedMeteoriteSettings spawned = spawner.trySpawnMeteoriteAtSuitableHeight(world, pos, coreRadius, craterType,
|
||||
pureCrater, false);
|
||||
|
||||
if (spawned == null) {
|
||||
player.sendMessage(new LiteralText("Un-suitable Location."));
|
||||
return ActionResult.FAIL;
|
||||
}
|
||||
|
||||
// Since we don't know yet if the meteorite will be underground or not,
|
||||
// we have to assume maximum size
|
||||
int range = (int) Math.ceil((coreRadius * 2 + 5) * 5f);
|
||||
|
||||
MutableBoundingBox boundingBox = new MutableBoundingBox(pos.getX() - range, pos.getY(), pos.getZ() - range,
|
||||
pos.getX() + range, pos.getY(), pos.getZ() + range);
|
||||
|
||||
final MeteoritePlacer placer = new MeteoritePlacer(world, spawned, boundingBox);
|
||||
placer.place();
|
||||
|
||||
player.sendMessage(new LiteralText("Spawned at y=" + spawned.getPos().getY() + " range=" + range
|
||||
+ " biomeCategory=" + world.getBiome(pos).getCategory()));
|
||||
|
||||
// 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 ActionResult.SUCCESS;
|
||||
}
|
||||
}
|
||||
@@ -1,48 +0,0 @@
|
||||
/*
|
||||
* This file is part of Applied Energistics 2.
|
||||
* Copyright (c) 2013 - 2015, 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 javax.annotation.Nullable;
|
||||
|
||||
import net.minecraft.block.Material;
|
||||
import net.minecraft.entity.player.PlayerEntity;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.util.ActionResult;
|
||||
import net.minecraft.util.Hand;
|
||||
import net.minecraft.util.hit.BlockHitResult;
|
||||
import net.minecraft.util.math.BlockPos;
|
||||
import net.minecraft.world.World;
|
||||
|
||||
import appeng.block.AEBaseTileBlock;
|
||||
|
||||
public class PhantomNodeBlock extends AEBaseTileBlock<PhantomNodeBlockEntity> {
|
||||
|
||||
public PhantomNodeBlock() {
|
||||
super(defaultProps(Material.METAL));
|
||||
}
|
||||
|
||||
@Override
|
||||
public ActionResult onActivated(final World w, final BlockPos pos, final PlayerEntity player, final Hand hand,
|
||||
final @Nullable ItemStack heldItem, final BlockHitResult hit) {
|
||||
final PhantomNodeBlockEntity tpn = this.getBlockEntity(w, pos);
|
||||
tpn.triggerCrashMode();
|
||||
return ActionResult.SUCCESS;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,63 +0,0 @@
|
||||
/*
|
||||
* This file is part of Applied Energistics 2.
|
||||
* Copyright (c) 2013 - 2015, 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.EnumSet;
|
||||
|
||||
import net.minecraft.block.entity.BlockEntityType;
|
||||
import net.minecraft.util.math.Direction;
|
||||
|
||||
import appeng.api.networking.IGridNode;
|
||||
import appeng.api.util.AEPartLocation;
|
||||
import appeng.me.helpers.AENetworkProxy;
|
||||
import appeng.tile.grid.AENetworkBlockEntity;
|
||||
|
||||
public class PhantomNodeBlockEntity extends AENetworkBlockEntity {
|
||||
|
||||
private AENetworkProxy proxy = null;
|
||||
private boolean crashMode = false;
|
||||
|
||||
public PhantomNodeBlockEntity(BlockEntityType<?> tileEntityTypeIn) {
|
||||
super(tileEntityTypeIn);
|
||||
}
|
||||
|
||||
@Override
|
||||
public IGridNode getGridNode(final AEPartLocation dir) {
|
||||
if (!this.crashMode) {
|
||||
return super.getGridNode(dir);
|
||||
}
|
||||
|
||||
return this.proxy.getNode();
|
||||
}
|
||||
|
||||
@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));
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,169 +0,0 @@
|
||||
/*
|
||||
* 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 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.util.ActionResult;
|
||||
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.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 {
|
||||
|
||||
public ReplicatorCardItem(Properties 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.putInt("dimid", world.getDimension().getType().getId());
|
||||
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 int dimid = ish.getInt("dimid");
|
||||
final World src_w = world.getServer().getWorld(DimensionType.getById(dimid));
|
||||
|
||||
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.write(data);
|
||||
nte.read(data.copy());
|
||||
world.setTileEntity(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.sendMessage(new LiteralText(string));
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user