mirror of
https://github.com/HbmMods/Hbm-s-Nuclear-Tech-GIT.git
synced 2026-01-25 10:32:49 +00:00
𓂧𓅃𓄿𓋴𓈎𓃭𓅓 CURSE OF RAH 𓅓𓆑𓅱𓆓𓎼𓅃
This commit is contained in:
parent
44aaac040c
commit
ad2174b639
@ -175,6 +175,7 @@ public class EntityMappings {
|
||||
addEntity(EntityMovingItem.class, "entity_c_item", 1000);
|
||||
addEntity(EntityMovingPackage.class, "entity_c_package", 1000);
|
||||
addEntity(EntityDeliveryDrone.class, "entity_delivery_drone", 250, false);
|
||||
addEntity(EntityRequestDrone.class, "entity_request_drone", 250, false);
|
||||
addEntity(EntityCloudTom.class, "entity_moonstone_blast", 1000);
|
||||
addEntity(EntityBeamVortex.class, "entity_vortex_beam", 1000);
|
||||
addEntity(EntityFireworks.class, "entity_firework_ball", 1000);
|
||||
|
||||
37
src/main/java/com/hbm/entity/item/EntityRequestDrone.java
Normal file
37
src/main/java/com/hbm/entity/item/EntityRequestDrone.java
Normal file
@ -0,0 +1,37 @@
|
||||
package com.hbm.entity.item;
|
||||
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.nbt.NBTTagCompound;
|
||||
import net.minecraft.world.World;
|
||||
|
||||
public class EntityRequestDrone extends EntityDroneBase {
|
||||
|
||||
public ItemStack heldItem;
|
||||
|
||||
public EntityRequestDrone(World world) {
|
||||
super(world);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void readEntityFromNBT(NBTTagCompound nbt) {
|
||||
|
||||
if(nbt.hasKey("held")) {
|
||||
NBTTagCompound stack = nbt.getCompoundTag("held");
|
||||
this.heldItem = ItemStack.loadItemStackFromNBT(stack);
|
||||
}
|
||||
|
||||
this.dataWatcher.updateObject(10, nbt.getByte("app"));
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void writeEntityToNBT(NBTTagCompound nbt) {
|
||||
|
||||
if(heldItem != null) {
|
||||
NBTTagCompound stack = new NBTTagCompound();
|
||||
this.heldItem.writeToNBT(stack);
|
||||
nbt.setTag("held", stack);
|
||||
}
|
||||
|
||||
nbt.setByte("app", this.dataWatcher.getWatchableObjectByte(10));
|
||||
}
|
||||
}
|
||||
@ -2,10 +2,8 @@ package com.hbm.inventory.container;
|
||||
|
||||
import com.hbm.tileentity.network.TileEntityDroneProvider;
|
||||
|
||||
import net.minecraft.entity.player.EntityPlayer;
|
||||
import net.minecraft.entity.player.InventoryPlayer;
|
||||
import net.minecraft.inventory.Slot;
|
||||
import net.minecraft.item.ItemStack;
|
||||
|
||||
public class ContainerDroneProvider extends ContainerCrateBase {
|
||||
|
||||
@ -28,35 +26,4 @@ public class ContainerDroneProvider extends ContainerCrateBase {
|
||||
this.addSlotToContainer(new Slot(invPlayer, i, 8 + i * 18, 161));
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public ItemStack transferStackInSlot(EntityPlayer p_82846_1_, int par2) {
|
||||
ItemStack var3 = null;
|
||||
Slot var4 = (Slot) this.inventorySlots.get(par2);
|
||||
|
||||
if(var4 != null && var4.getHasStack()) {
|
||||
ItemStack var5 = var4.getStack();
|
||||
var3 = var5.copy();
|
||||
|
||||
if(par2 < 9) return null; //ignore filters
|
||||
|
||||
if(par2 <= crate.getSizeInventory() - 1) {
|
||||
if(!this.mergeItemStack(var5, crate.getSizeInventory(), this.inventorySlots.size(), true)) {
|
||||
return null;
|
||||
}
|
||||
} else if(!this.mergeItemStack(var5, 9, crate.getSizeInventory(), false)) {
|
||||
return null;
|
||||
}
|
||||
|
||||
if(var5.stackSize == 0) {
|
||||
var4.putStack((ItemStack) null);
|
||||
} else {
|
||||
var4.onSlotChanged();
|
||||
}
|
||||
|
||||
var4.onPickupFromSlot(p_82846_1_, var5);
|
||||
}
|
||||
|
||||
return var3;
|
||||
}
|
||||
}
|
||||
|
||||
@ -36,6 +36,37 @@ public class ContainerDroneRequester extends ContainerCrateBase {
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public ItemStack transferStackInSlot(EntityPlayer p_82846_1_, int par2) {
|
||||
ItemStack var3 = null;
|
||||
Slot var4 = (Slot) this.inventorySlots.get(par2);
|
||||
|
||||
if(var4 != null && var4.getHasStack()) {
|
||||
ItemStack var5 = var4.getStack();
|
||||
var3 = var5.copy();
|
||||
|
||||
if(par2 < 9) return null; //ignore filters
|
||||
|
||||
if(par2 <= crate.getSizeInventory() - 1) {
|
||||
if(!this.mergeItemStack(var5, crate.getSizeInventory(), this.inventorySlots.size(), true)) {
|
||||
return null;
|
||||
}
|
||||
} else if(!this.mergeItemStack(var5, 9, crate.getSizeInventory(), false)) {
|
||||
return null;
|
||||
}
|
||||
|
||||
if(var5.stackSize == 0) {
|
||||
var4.putStack((ItemStack) null);
|
||||
} else {
|
||||
var4.onSlotChanged();
|
||||
}
|
||||
|
||||
var4.onPickupFromSlot(p_82846_1_, var5);
|
||||
}
|
||||
|
||||
return var3;
|
||||
}
|
||||
|
||||
@Override
|
||||
public ItemStack slotClick(int index, int button, int mode, EntityPlayer player) {
|
||||
|
||||
|
||||
@ -571,6 +571,15 @@ public class AssemblerRecipes {
|
||||
new ComparableStack(ModItems.bolt_compound, 16),
|
||||
new ComparableStack(ModItems.pipes_steel, 3)
|
||||
}, 600);
|
||||
|
||||
makeRecipe(new ComparableStack(ModBlocks.machine_condenser_powered, 1), new AStack[] {
|
||||
new OreDictStack(STEEL.plateCast(), 16),
|
||||
new OreDictStack(ANY_RESISTANTALLOY.ingot(), 16),
|
||||
new OreDictStack(CU.plate528(), 16),
|
||||
new ComparableStack(ModItems.motor_desh, 3),
|
||||
new ComparableStack(ModItems.pipes_steel, 4),
|
||||
new OreDictStack(Fluids.LUBRICANT.getDict(1_000), 4)
|
||||
}, 600);
|
||||
|
||||
makeRecipe(new ComparableStack(ModItems.pellet_chlorophyte, 2), new AStack[] {
|
||||
new ComparableStack(ModItems.powder_chlorophyte, 1),
|
||||
|
||||
@ -715,6 +715,7 @@ public class ClientProxy extends ServerProxy {
|
||||
RenderingRegistry.registerEntityRenderingHandler(EntityMovingPackage.class, new RenderMovingPackage());
|
||||
RenderingRegistry.registerEntityRenderingHandler(EntityTNTPrimedBase.class, new RenderTNTPrimedBase());
|
||||
RenderingRegistry.registerEntityRenderingHandler(EntityDeliveryDrone.class, new RenderDeliveryDrone());
|
||||
RenderingRegistry.registerEntityRenderingHandler(EntityRequestDrone.class, new RenderDeliveryDrone());
|
||||
RenderingRegistry.registerEntityRenderingHandler(EntityFallingBlockNT.class, new RenderFallingBlockNT());
|
||||
//mobs
|
||||
RenderingRegistry.registerEntityRenderingHandler(EntityCreeperNuclear.class, new RenderCreeperUniversal(RefStrings.MODID + ":" + "textures/entity/creeper.png", RefStrings.MODID + ":" + "textures/entity/creeper_armor.png").setSwellMod(5F));
|
||||
|
||||
@ -67,6 +67,7 @@ import com.hbm.packet.PlayerInformPacket;
|
||||
import com.hbm.potion.HbmPotion;
|
||||
import com.hbm.saveddata.AuxSavedData;
|
||||
import com.hbm.tileentity.network.RTTYSystem;
|
||||
import com.hbm.tileentity.network.RequestNetwork;
|
||||
import com.hbm.util.AchievementHandler;
|
||||
import com.hbm.util.ArmorRegistry;
|
||||
import com.hbm.util.ArmorUtil;
|
||||
@ -1097,6 +1098,7 @@ public class ModEventHandler {
|
||||
|
||||
if(event.phase == event.phase.START) {
|
||||
RTTYSystem.updateBroadcastQueue();
|
||||
RequestNetwork.updateEntries();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@ -1374,6 +1374,7 @@ public class ResourceManager {
|
||||
//Drone
|
||||
public static final ResourceLocation delivery_drone_tex = new ResourceLocation(RefStrings.MODID, "textures/models/machines/drone.png");
|
||||
public static final ResourceLocation delivery_drone_express_tex = new ResourceLocation(RefStrings.MODID, "textures/models/machines/drone_express.png");
|
||||
public static final ResourceLocation delivery_drone_request_tex = new ResourceLocation(RefStrings.MODID, "textures/models/machines/drone_request.png");
|
||||
|
||||
//ISBRHs
|
||||
public static final IModelCustom scaffold = AdvancedModelLoader.loadModel(new ResourceLocation(RefStrings.MODID, "models/blocks/scaffold.obj"));
|
||||
|
||||
@ -3,6 +3,7 @@ package com.hbm.render.entity.item;
|
||||
import org.lwjgl.opengl.GL11;
|
||||
|
||||
import com.hbm.entity.item.EntityDeliveryDrone;
|
||||
import com.hbm.entity.item.EntityRequestDrone;
|
||||
import com.hbm.main.ResourceManager;
|
||||
|
||||
import net.minecraft.client.renderer.entity.Render;
|
||||
@ -20,7 +21,9 @@ public class RenderDeliveryDrone extends Render {
|
||||
GL11.glDisable(GL11.GL_CULL_FACE);
|
||||
GL11.glShadeModel(GL11.GL_SMOOTH);
|
||||
|
||||
if(entity.getDataWatcher().getWatchableObjectByte(11) == 1)
|
||||
if(entity instanceof EntityRequestDrone) {
|
||||
bindTexture(ResourceManager.delivery_drone_request_tex);
|
||||
} else if(entity.getDataWatcher().getWatchableObjectByte(11) == 1)
|
||||
bindTexture(ResourceManager.delivery_drone_express_tex);
|
||||
else
|
||||
bindTexture(ResourceManager.delivery_drone_tex);
|
||||
|
||||
97
src/main/java/com/hbm/tileentity/network/RequestNetwork.java
Normal file
97
src/main/java/com/hbm/tileentity/network/RequestNetwork.java
Normal file
@ -0,0 +1,97 @@
|
||||
package com.hbm.tileentity.network;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.Iterator;
|
||||
import java.util.List;
|
||||
import java.util.Map.Entry;
|
||||
import java.util.Set;
|
||||
|
||||
import com.hbm.inventory.RecipesCommon.AStack;
|
||||
import com.hbm.util.fauxpointtwelve.BlockPos;
|
||||
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.world.ChunkCoordIntPair;
|
||||
import net.minecraft.world.World;
|
||||
|
||||
public class RequestNetwork {
|
||||
|
||||
private static int timer = 0;
|
||||
public static HashMap<World, HashMap<ChunkCoordIntPair, Set<PathNode>>> activeWaypoints = new HashMap();
|
||||
public static final int maxAge = 2_000;
|
||||
|
||||
public static void updateEntries() {
|
||||
|
||||
if(timer < 0) {
|
||||
timer--;
|
||||
return;
|
||||
}
|
||||
|
||||
timer = 20;
|
||||
|
||||
Iterator worldIt = activeWaypoints.entrySet().iterator();
|
||||
|
||||
// iterate over each dim
|
||||
while(worldIt.hasNext()) {
|
||||
Entry<World, HashMap<ChunkCoordIntPair, Set<PathNode>>> worldEntry = (Entry) worldIt.next();
|
||||
Iterator chunkIt = worldEntry.getValue().entrySet().iterator();
|
||||
|
||||
// iterate over each chunk
|
||||
while(chunkIt.hasNext()) {
|
||||
|
||||
Entry<ChunkCoordIntPair, Set<PathNode>> chunkEntry = (Entry) chunkIt.next();
|
||||
Iterator<PathNode> pathIt = chunkEntry.getValue().iterator();
|
||||
|
||||
// iterate over each path node
|
||||
while(pathIt.hasNext()) {
|
||||
PathNode node = pathIt.next();
|
||||
|
||||
// if the lease timestamp is too far back, time out the node
|
||||
if(node.lease < System.currentTimeMillis() - maxAge) {
|
||||
pathIt.remove();
|
||||
}
|
||||
}
|
||||
|
||||
// if no more nodes exist, delete the chunk entry
|
||||
if(chunkEntry.getValue().size() == 0) chunkIt.remove();
|
||||
}
|
||||
|
||||
// if no more chunk entries exist, delete the world entry
|
||||
if(worldEntry.getValue().size() == 0) worldIt.remove();
|
||||
|
||||
// cleaning up all the entries if the lists are empty ensures that even if a different save is loaded,
|
||||
// the positions will eventually time out leading to all the old save crap being deleted, preventing a memory leak.
|
||||
// it's probably an inconsequential memory leak but i'd rather we don't
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
/** Generic path node, contains nothing but a position and a timestamp */
|
||||
public static class PathNode {
|
||||
public BlockPos pos;
|
||||
public long lease;
|
||||
public PathNode(BlockPos pos) {
|
||||
this.pos = pos;
|
||||
this.lease = System.currentTimeMillis();
|
||||
}
|
||||
@Override public int hashCode() { return pos.hashCode(); }
|
||||
@Override public boolean equals(Object o) { return pos.equals(o); }
|
||||
}
|
||||
|
||||
/** Node created by providers, lists available items */
|
||||
public static class OfferNode extends PathNode {
|
||||
public List<ItemStack> offer;
|
||||
public OfferNode(BlockPos pos, List<ItemStack> offer) {
|
||||
super(pos);
|
||||
this.offer = offer;
|
||||
}
|
||||
}
|
||||
|
||||
/** Node created by requesters, lists requested AStacks */
|
||||
public static class RequestNode extends PathNode {
|
||||
public List<AStack> request;
|
||||
public RequestNode(BlockPos pos, List<AStack> request) {
|
||||
super(pos);
|
||||
this.request = request;
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -3,6 +3,8 @@ package com.hbm.tileentity.network;
|
||||
import com.hbm.inventory.container.ContainerDroneDock;
|
||||
import com.hbm.inventory.gui.GUIDroneDock;
|
||||
import com.hbm.tileentity.IGUIProvider;
|
||||
import com.hbm.tileentity.network.RequestNetwork.PathNode;
|
||||
import com.hbm.util.fauxpointtwelve.BlockPos;
|
||||
|
||||
import cpw.mods.fml.relauncher.Side;
|
||||
import cpw.mods.fml.relauncher.SideOnly;
|
||||
@ -37,4 +39,9 @@ public class TileEntityDroneDock extends TileEntityRequestNetworkContainer imple
|
||||
public GuiScreen provideGUI(int ID, EntityPlayer player, World world, int x, int y, int z) {
|
||||
return new GUIDroneDock(player.inventory, this);
|
||||
}
|
||||
|
||||
@Override
|
||||
public PathNode createNode(BlockPos pos) {
|
||||
return new PathNode(pos);
|
||||
}
|
||||
}
|
||||
|
||||
@ -1,8 +1,14 @@
|
||||
package com.hbm.tileentity.network;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
import com.hbm.inventory.container.ContainerDroneProvider;
|
||||
import com.hbm.inventory.gui.GUIDroneProvider;
|
||||
import com.hbm.tileentity.IGUIProvider;
|
||||
import com.hbm.tileentity.network.RequestNetwork.OfferNode;
|
||||
import com.hbm.tileentity.network.RequestNetwork.PathNode;
|
||||
import com.hbm.util.fauxpointtwelve.BlockPos;
|
||||
|
||||
import cpw.mods.fml.relauncher.Side;
|
||||
import cpw.mods.fml.relauncher.SideOnly;
|
||||
@ -48,4 +54,11 @@ public class TileEntityDroneProvider extends TileEntityRequestNetworkContainer i
|
||||
public GuiScreen provideGUI(int ID, EntityPlayer player, World world, int x, int y, int z) {
|
||||
return new GUIDroneProvider(player.inventory, this);
|
||||
}
|
||||
|
||||
@Override
|
||||
public PathNode createNode(BlockPos pos) {
|
||||
List<ItemStack> offer = new ArrayList();
|
||||
for(ItemStack stack : slots) if(stack != null) offer.add(stack.copy());
|
||||
return new OfferNode(pos, offer);
|
||||
}
|
||||
}
|
||||
|
||||
@ -1,9 +1,19 @@
|
||||
package com.hbm.tileentity.network;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
import com.hbm.inventory.RecipesCommon.AStack;
|
||||
import com.hbm.inventory.RecipesCommon.ComparableStack;
|
||||
import com.hbm.inventory.RecipesCommon.OreDictStack;
|
||||
import com.hbm.inventory.container.ContainerDroneRequester;
|
||||
import com.hbm.inventory.gui.GUIDroneRequester;
|
||||
import com.hbm.module.ModulePatternMatcher;
|
||||
import com.hbm.tileentity.IGUIProvider;
|
||||
import com.hbm.tileentity.INBTPacketReceiver;
|
||||
import com.hbm.tileentity.network.RequestNetwork.PathNode;
|
||||
import com.hbm.tileentity.network.RequestNetwork.RequestNode;
|
||||
import com.hbm.util.fauxpointtwelve.BlockPos;
|
||||
|
||||
import cpw.mods.fml.relauncher.Side;
|
||||
import cpw.mods.fml.relauncher.SideOnly;
|
||||
@ -11,9 +21,11 @@ import net.minecraft.client.gui.GuiScreen;
|
||||
import net.minecraft.entity.player.EntityPlayer;
|
||||
import net.minecraft.inventory.Container;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.nbt.NBTTagCompound;
|
||||
import net.minecraft.world.World;
|
||||
import net.minecraftforge.oredict.OreDictionary;
|
||||
|
||||
public class TileEntityDroneRequester extends TileEntityRequestNetworkContainer implements IGUIProvider {
|
||||
public class TileEntityDroneRequester extends TileEntityRequestNetworkContainer implements INBTPacketReceiver, IGUIProvider {
|
||||
|
||||
public ModulePatternMatcher matcher;
|
||||
|
||||
@ -27,6 +39,23 @@ public class TileEntityDroneRequester extends TileEntityRequestNetworkContainer
|
||||
return "container.droneRequester";
|
||||
}
|
||||
|
||||
@Override
|
||||
public void updateEntity() {
|
||||
super.updateEntity();
|
||||
|
||||
if(!worldObj.isRemote) {
|
||||
|
||||
NBTTagCompound data = new NBTTagCompound();
|
||||
this.matcher.writeToNBT(data);
|
||||
INBTPacketReceiver.networkPack(this, data, 15);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void networkUnpack(NBTTagCompound nbt) {
|
||||
this.matcher.readFromNBT(nbt);
|
||||
}
|
||||
|
||||
public boolean matchesFilter(ItemStack stack) {
|
||||
|
||||
for(int i = 0; i < 9; i++) {
|
||||
@ -69,4 +98,26 @@ public class TileEntityDroneRequester extends TileEntityRequestNetworkContainer
|
||||
public GuiScreen provideGUI(int ID, EntityPlayer player, World world, int x, int y, int z) {
|
||||
return new GUIDroneRequester(player.inventory, this);
|
||||
}
|
||||
|
||||
@Override
|
||||
public PathNode createNode(BlockPos pos) {
|
||||
List<AStack> request = new ArrayList();
|
||||
for(int i = 0; i < 9; i++) {
|
||||
ItemStack filter = slots[i];
|
||||
if(filter == null) continue;
|
||||
String mode = this.matcher.modes[i];
|
||||
AStack aStack = null;
|
||||
|
||||
if(ModulePatternMatcher.MODE_EXACT.equals(mode)) {
|
||||
aStack = new ComparableStack(filter).makeSingular();
|
||||
} else if(ModulePatternMatcher.MODE_WILDCARD.equals(mode)) {
|
||||
aStack = new ComparableStack(filter.getItem(), 1, OreDictionary.WILDCARD_VALUE);
|
||||
} else {
|
||||
aStack = new OreDictStack(mode);
|
||||
}
|
||||
|
||||
request.add(aStack);
|
||||
}
|
||||
return new RequestNode(pos, request);
|
||||
}
|
||||
}
|
||||
|
||||
@ -1,5 +1,6 @@
|
||||
package com.hbm.tileentity.network;
|
||||
|
||||
import com.hbm.tileentity.network.RequestNetwork.PathNode;
|
||||
import com.hbm.util.fauxpointtwelve.BlockPos;
|
||||
|
||||
import net.minecraft.nbt.NBTTagCompound;
|
||||
@ -34,4 +35,9 @@ public class TileEntityDroneWaypointRequest extends TileEntityRequestNetwork {
|
||||
|
||||
nbt.setInteger("height", height);
|
||||
}
|
||||
|
||||
@Override
|
||||
public PathNode createNode(BlockPos pos) {
|
||||
return new PathNode(pos);
|
||||
}
|
||||
}
|
||||
|
||||
@ -1,10 +1,11 @@
|
||||
package com.hbm.tileentity.network;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
import java.util.HashSet;
|
||||
import java.util.Iterator;
|
||||
import java.util.Set;
|
||||
|
||||
import com.hbm.tileentity.network.RequestNetwork.PathNode;
|
||||
import com.hbm.util.ParticleUtil;
|
||||
import com.hbm.util.fauxpointtwelve.BlockPos;
|
||||
|
||||
@ -24,16 +25,11 @@ import net.minecraft.world.World;
|
||||
* @author hbm
|
||||
*
|
||||
*/
|
||||
public class TileEntityRequestNetwork extends TileEntity {
|
||||
|
||||
public static HashMap<World, HashMap<ChunkCoordIntPair, Set<BlockPos>>> activeWaypoints = new HashMap();
|
||||
public static HashMap<BlockPos, Long> lastActive = new HashMap();
|
||||
public static long lastWipe = 0;
|
||||
public abstract class TileEntityRequestNetwork extends TileEntity {
|
||||
|
||||
public Set<BlockPos> reachableNodes = new HashSet();
|
||||
public Set<BlockPos> knownNodes = new HashSet();
|
||||
public Set<PathNode> reachableNodes = new HashSet();
|
||||
public Set<PathNode> knownNodes = new HashSet();
|
||||
public static final int maxRange = 24;
|
||||
public static final int maxAge = 2_000;
|
||||
|
||||
@Override
|
||||
public void updateEntity() {
|
||||
@ -42,53 +38,59 @@ public class TileEntityRequestNetwork extends TileEntity {
|
||||
|
||||
if(worldObj.getTotalWorldTime() % 20 == 0) {
|
||||
BlockPos pos = getCoord();
|
||||
push(worldObj, pos);
|
||||
// push new node
|
||||
push(worldObj, createNode(pos));
|
||||
|
||||
for(BlockPos known : knownNodes) {
|
||||
// remove known nodes that no longer exist
|
||||
// since we can assume a sane number of nodes to exist at any given time, we can run this check in full every second
|
||||
Iterator<PathNode> it = knownNodes.iterator();
|
||||
Set<PathNode> localNodes = this.getAllLocalNodes(worldObj, xCoord, zCoord, 2); // this bit may spiral into multiple nested hashtable lookups but it's limited to only a few chunks so it shouldn't be an issue
|
||||
while(it.hasNext()) {
|
||||
PathNode node = it.next();
|
||||
if(!localNodes.contains(node)) {
|
||||
reachableNodes.remove(node);
|
||||
it.remove();
|
||||
}
|
||||
}
|
||||
|
||||
// draw debug crap
|
||||
for(PathNode known : knownNodes) {
|
||||
ParticleUtil.spawnDebugLine(worldObj,
|
||||
pos.getX() + 0.5, pos.getY() + 0.5, pos.getZ() + 0.5,
|
||||
(known.getX() - pos.getX()) / 2D, (known.getY() - pos.getY()) / 2D, (known.getZ() - pos.getZ()) / 2D,
|
||||
(known.pos.getX() - pos.getX()) / 2D, (known.pos.getY() - pos.getY()) / 2D, (known.pos.getZ() - pos.getZ()) / 2D,
|
||||
reachableNodes.contains(known) ? 0x00ff00 : 0xff0000);
|
||||
}
|
||||
|
||||
//both following checks run the `hasPath` function which is costly, so it only runs one op at a time
|
||||
|
||||
//rescan known nodes
|
||||
if(worldObj.getTotalWorldTime() % 40 == 0 && knownNodes.size() > 0) {
|
||||
for(PathNode known : knownNodes) {
|
||||
|
||||
BlockPos node = (BlockPos) new ArrayList(knownNodes).get(knownNodes.size() > 1 ? worldObj.rand.nextInt(knownNodes.size() - 1) : 0);
|
||||
|
||||
if(node != null) {
|
||||
|
||||
Long timestamp = lastActive.get(node);
|
||||
|
||||
if(timestamp == null || timestamp < System.currentTimeMillis() - maxAge) {
|
||||
knownNodes.remove(node);
|
||||
reachableNodes.remove(node);
|
||||
lastActive.remove(node);
|
||||
} else if(!hasPath(worldObj, pos, node)) {
|
||||
reachableNodes.remove(node);
|
||||
} else {
|
||||
reachableNodes.add(node);
|
||||
}
|
||||
if(!hasPath(worldObj, pos, known.pos)) {
|
||||
reachableNodes.remove(known);
|
||||
} else {
|
||||
reachableNodes.add(known);
|
||||
}
|
||||
}
|
||||
|
||||
//discover new nodes
|
||||
} else {
|
||||
|
||||
Set<BlockPos> nodes = getAllLocalNodes(worldObj, pos.getX(), pos.getZ());
|
||||
|
||||
for(BlockPos node : nodes) {
|
||||
int newNodeLimit = 5;
|
||||
for(PathNode node : localNodes) {
|
||||
|
||||
if(!knownNodes.contains(node) && !node.equals(pos)) {
|
||||
knownNodes.add(node);
|
||||
if(hasPath(worldObj, pos, node)) reachableNodes.add(node);
|
||||
break;
|
||||
}
|
||||
if(!knownNodes.contains(node) && !node.equals(pos)) {
|
||||
newNodeLimit--;
|
||||
knownNodes.add(node);
|
||||
if(hasPath(worldObj, pos, node.pos)) reachableNodes.add(node);
|
||||
}
|
||||
|
||||
if(newNodeLimit <= 0) break;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public abstract PathNode createNode(BlockPos pos);
|
||||
|
||||
public BlockPos getCoord() {
|
||||
return new BlockPos(xCoord, yCoord + 1, zCoord);
|
||||
}
|
||||
@ -120,26 +122,24 @@ public class TileEntityRequestNetwork extends TileEntity {
|
||||
* @param y
|
||||
* @param z
|
||||
*/
|
||||
public static void push(World world, BlockPos pos) {
|
||||
public static void push(World world, PathNode node) {
|
||||
|
||||
HashMap<ChunkCoordIntPair, Set<BlockPos>> coordMap = activeWaypoints.get(world);
|
||||
HashMap<ChunkCoordIntPair, Set<PathNode>> coordMap = RequestNetwork.activeWaypoints.get(world);
|
||||
|
||||
if(coordMap == null) {
|
||||
coordMap = new HashMap();
|
||||
activeWaypoints.put(world, coordMap);
|
||||
RequestNetwork.activeWaypoints.put(world, coordMap);
|
||||
}
|
||||
|
||||
ChunkCoordIntPair chunkPos = new ChunkCoordIntPair(pos.getX() >> 4, pos.getZ() >> 4);
|
||||
Set<BlockPos> posList = coordMap.get(chunkPos);
|
||||
ChunkCoordIntPair chunkPos = new ChunkCoordIntPair(node.pos.getX() >> 4, node.pos.getZ() >> 4);
|
||||
Set<PathNode> posList = coordMap.get(chunkPos);
|
||||
|
||||
if(posList == null) {
|
||||
posList = new HashSet();
|
||||
coordMap.put(chunkPos, posList);
|
||||
}
|
||||
|
||||
posList.add(pos);
|
||||
|
||||
lastActive.put(pos, System.currentTimeMillis());
|
||||
posList.add(node);
|
||||
}
|
||||
|
||||
/**
|
||||
@ -150,28 +150,24 @@ public class TileEntityRequestNetwork extends TileEntity {
|
||||
* @param z
|
||||
* @return
|
||||
*/
|
||||
public static Set<BlockPos> getAllLocalNodes(World world, int x, int z) {
|
||||
public static Set<PathNode> getAllLocalNodes(World world, int x, int z, int range) {
|
||||
|
||||
Set<BlockPos> nodes = new HashSet();
|
||||
Set<PathNode> nodes = new HashSet();
|
||||
|
||||
x >>= 4;
|
||||
z >>= 4;
|
||||
|
||||
HashMap<ChunkCoordIntPair, Set<BlockPos>> coordMap = activeWaypoints.get(world);
|
||||
HashMap<ChunkCoordIntPair, Set<PathNode>> coordMap = RequestNetwork.activeWaypoints.get(world);
|
||||
|
||||
if(coordMap == null) return nodes;
|
||||
|
||||
for(int i = -2; i <= 2; i++) {
|
||||
for(int j = -2; j <= 2; j++) {
|
||||
for(int i = -range; i <= range; i++) {
|
||||
for(int j = -range; j <= range; j++) {
|
||||
|
||||
Set<BlockPos> posList = coordMap.get(new ChunkCoordIntPair(x + i, z + j));
|
||||
Set<PathNode> nodeList = coordMap.get(new ChunkCoordIntPair(x + i, z + j));
|
||||
|
||||
if(posList != null) for(BlockPos node : posList) {
|
||||
Long timestamp = lastActive.get(node);
|
||||
|
||||
if(timestamp != null && timestamp >= System.currentTimeMillis() - maxAge) {
|
||||
nodes.add(node);
|
||||
}
|
||||
if(nodeList != null) for(PathNode node : nodeList) {
|
||||
nodes.add(node);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@ -111,8 +111,6 @@ public abstract class TileEntityRequestNetworkContainer extends TileEntityReques
|
||||
if(!worldObj.isRemote) PacketDispatcher.wrapper.sendToAllAround(new NBTPacket(nbt, xCoord, yCoord, zCoord), new TargetPoint(this.worldObj.provider.dimensionId, xCoord, yCoord, zCoord, range));
|
||||
}
|
||||
|
||||
public void networkUnpack(NBTTagCompound nbt) { }
|
||||
|
||||
@Override
|
||||
public void readFromNBT(NBTTagCompound nbt) {
|
||||
super.readFromNBT(nbt);
|
||||
|
||||
@ -4026,6 +4026,7 @@ tile.machine_combine_factory.name=CMB-Stahl Hochofen
|
||||
tile.machine_combustion_engine.name=Industrieller Verbrennungsmotor
|
||||
tile.machine_compressor.name=Kompressor
|
||||
tile.machine_condenser.name=Dampfkondensierer
|
||||
tile.machine_condenser_powered.name=Hochleistungs-Dampfkondensierer
|
||||
tile.machine_controller.name=Reaktorfernsteuerung
|
||||
tile.machine_converter_he_rf.name=HE zu RF Konverter
|
||||
tile.machine_converter_rf_he.name=RF zu HE Konverter
|
||||
|
||||
@ -4999,6 +4999,7 @@ tile.machine_combine_factory.name=CMB Steel Furnace
|
||||
tile.machine_combustion_engine.name=Industrial Combustion Engine
|
||||
tile.machine_compressor.name=Compressor
|
||||
tile.machine_condenser.name=Steam Condenser
|
||||
tile.machine_condenser_powered.name=High-Power Steam Condenser
|
||||
tile.machine_controller.name=Reactor Remote Control Block
|
||||
tile.machine_converter_he_rf.name=HE to RF Converter
|
||||
tile.machine_converter_rf_he.name=RF to HE Converter
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user