even more drone crate stuff

This commit is contained in:
Boblet 2023-09-25 16:42:02 +02:00
parent 9528ce8afe
commit 250ee7c383
22 changed files with 259 additions and 156 deletions

View File

@ -821,8 +821,11 @@ public class ModBlocks {
public static Block crane_splitter;
public static Block drone_waypoint;
public static Block drone_waypoint_request;
public static Block drone_crate;
public static Block drone_waypoint_request;
public static Block drone_dock;
public static Block drone_crate_provider;
public static Block drone_crate_requester;
public static Block fan;
@ -1995,8 +1998,11 @@ public class ModBlocks {
piston_inserter = new PistonInserter().setBlockName("piston_inserter").setHardness(5.0F).setResistance(10.0F).setCreativeTab(MainRegistry.machineTab).setBlockTextureName(RefStrings.MODID + ":block_steel");
drone_waypoint = new DroneWaypoint().setBlockName("drone_waypoint").setHardness(0.1F).setResistance(10.0F).setCreativeTab(MainRegistry.machineTab).setBlockTextureName(RefStrings.MODID + ":drone_waypoint");
drone_waypoint_request = new DroneWaypointRequest().setBlockName("drone_waypoint_request").setHardness(0.1F).setResistance(10.0F).setCreativeTab(MainRegistry.machineTab).setBlockTextureName(RefStrings.MODID + ":drone_waypoint_request");
drone_crate = new DroneCrate().setBlockName("drone_crate").setHardness(0.1F).setResistance(10.0F).setCreativeTab(MainRegistry.machineTab);
drone_waypoint_request = new DroneWaypointRequest().setBlockName("drone_waypoint_request").setHardness(0.1F).setResistance(10.0F).setCreativeTab(MainRegistry.machineTab).setBlockTextureName(RefStrings.MODID + ":drone_waypoint_request");
drone_dock = new DroneDock().setBlockName("drone_dock").setHardness(0.1F).setResistance(10.0F).setCreativeTab(MainRegistry.machineTab).setBlockTextureName(RefStrings.MODID + ":drone_dock");
drone_crate_provider = new DroneDock().setBlockName("drone_crate_provider").setHardness(0.1F).setResistance(10.0F).setCreativeTab(MainRegistry.machineTab).setBlockTextureName(RefStrings.MODID + ":drone_crate_provider");
drone_crate_requester = new DroneDock().setBlockName("drone_crate_requester").setHardness(0.1F).setResistance(10.0F).setCreativeTab(MainRegistry.machineTab).setBlockTextureName(RefStrings.MODID + ":drone_crate_requester");
chain = new BlockChain(Material.iron).setBlockName("dungeon_chain").setHardness(0.25F).setResistance(2.0F).setCreativeTab(MainRegistry.blockTab).setBlockTextureName(RefStrings.MODID + ":chain");
@ -3258,8 +3264,11 @@ public class ModBlocks {
register(conveyor_lift);
register(crane_splitter);
register(drone_waypoint);
register(drone_waypoint_request);
register(drone_crate);
register(drone_waypoint_request);
register(drone_dock);
register(drone_crate_provider);
register(drone_crate_requester);
register(fan);
register(piston_inserter);

View File

@ -0,0 +1,39 @@
package com.hbm.blocks.network;
import cpw.mods.fml.relauncher.Side;
import cpw.mods.fml.relauncher.SideOnly;
import net.minecraft.block.BlockContainer;
import net.minecraft.block.material.Material;
import net.minecraft.client.renderer.texture.IIconRegister;
import net.minecraft.tileentity.TileEntity;
import net.minecraft.util.IIcon;
import net.minecraft.world.World;
public class DroneDock extends BlockContainer {
@SideOnly(Side.CLIENT) private IIcon iconTop;
@SideOnly(Side.CLIENT) private IIcon iconBottom;
public DroneDock() {
super(Material.iron);
}
@Override
public TileEntity createNewTileEntity(World world, int meta) {
return null;
}
@Override
@SideOnly(Side.CLIENT)
public void registerBlockIcons(IIconRegister reg) {
this.blockIcon = reg.registerIcon(this.textureName + "_side");
this.iconTop = reg.registerIcon(this.textureName + "_top");
this.iconBottom = reg.registerIcon(this.textureName + "_bottom");
}
@Override
@SideOnly(Side.CLIENT)
public IIcon getIcon(int side, int metadata) {
return side == 1 ? this.iconTop : (side == 0 ? this.iconBottom : this.blockIcon);
}
}

View File

@ -1,107 +1,21 @@
package com.hbm.tileentity.network;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.HashSet;
import java.util.Set;
import com.hbm.util.ParticleUtil;
import com.hbm.util.fauxpointtwelve.BlockPos;
import net.minecraft.nbt.NBTTagCompound;
import net.minecraft.tileentity.TileEntity;
import net.minecraft.util.MathHelper;
import net.minecraft.util.MovingObjectPosition;
import net.minecraft.util.Vec3;
import net.minecraft.world.ChunkCoordIntPair;
import net.minecraft.world.World;
import net.minecraftforge.common.util.ForgeDirection;
public class TileEntityDroneWaypointRequest 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 Set<BlockPos> reachableNodes = new HashSet();
public Set<BlockPos> knownNodes = new HashSet();
public static final int maxRange = 24;
public static final int maxAge = 1_000;
public class TileEntityDroneWaypointRequest extends TileEntityRequestNetwork {
public int height = 5;
@Override
public void updateEntity() {
if(!worldObj.isRemote) {
if(worldObj.getTotalWorldTime() % 20 == 0) {
BlockPos pos = getCoord();
push(worldObj, pos);
for(BlockPos 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,
reachableNodes.contains(known) ? 0x00ff00 : 0xff0000);
}
//rescan known nodes
if(worldObj.getTotalWorldTime() % 40 == 0 && knownNodes.size() > 0) {
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);
}
}
//discover new nodes
} else {
Set<BlockPos> nodes = getAllLocalNodes(worldObj, pos.getX(), pos.getZ());
for(BlockPos node : nodes) {
if(!knownNodes.contains(node) && !node.equals(pos)) {
knownNodes.add(node);
if(hasPath(worldObj, pos, node)) reachableNodes.add(node);
break;
}
}
}
}
}
}
public BlockPos getCoord() {
ForgeDirection dir = ForgeDirection.getOrientation(this.getBlockMetadata());
return new BlockPos(xCoord + dir.offsetX * height, yCoord + dir.offsetY * height, zCoord + dir.offsetZ * height);
}
public static boolean hasPath(World world, BlockPos pos1, BlockPos pos2) {
Vec3 vec1 = Vec3.createVectorHelper(pos1.getX() + 0.5, pos1.getY() + 0.5, pos1.getZ() + 0.5);
Vec3 vec2 = Vec3.createVectorHelper(pos2.getX() + 0.5, pos2.getY() + 0.5, pos2.getZ() + 0.5);
Vec3 vec3 = vec1.subtract(vec2);
if(vec3.lengthVector() > maxRange) return false;
//for some fucking reason beyond any human comprehension, this function will randomly yield incorrect results but only from one side
//therefore we just run the stupid fucking thing twice and then compare the results
//thanks for this marvelous piece of programming, mojang
MovingObjectPosition mop0 = world.func_147447_a(vec1, vec2, false, true, false);
MovingObjectPosition mop2 = world.func_147447_a(vec2, vec1, false, true, false);
return (mop0 == null || mop0.typeOfHit == mop0.typeOfHit.MISS) && (mop2 == null || mop2.typeOfHit == mop2.typeOfHit.MISS);
}
public void addHeight(int h) {
height += h;
height = MathHelper.clamp_int(height, 1, 15);
@ -120,70 +34,4 @@ public class TileEntityDroneWaypointRequest extends TileEntity {
nbt.setInteger("height", height);
}
/**
* Adds the position to that chunk's node list.
* @param world
* @param x
* @param y
* @param z
*/
public static void push(World world, BlockPos pos) {
HashMap<ChunkCoordIntPair, Set<BlockPos>> coordMap = activeWaypoints.get(world);
if(coordMap == null) {
coordMap = new HashMap();
activeWaypoints.put(world, coordMap);
}
ChunkCoordIntPair chunkPos = new ChunkCoordIntPair(pos.getX() >> 4, pos.getZ() >> 4);
Set<BlockPos> posList = coordMap.get(chunkPos);
if(posList == null) {
posList = new HashSet();
coordMap.put(chunkPos, posList);
}
posList.add(pos);
lastActive.put(pos, System.currentTimeMillis());
}
/**
* Gets all active nodes in a 5x5 chunk area, centered around the given position.
* Used for finding neighbors to check connections to.
* @param world
* @param x
* @param z
* @return
*/
public static Set<BlockPos> getAllLocalNodes(World world, int x, int z) {
Set<BlockPos> nodes = new HashSet();
x >>= 4;
z >>= 4;
HashMap<ChunkCoordIntPair, Set<BlockPos>> coordMap = activeWaypoints.get(world);
if(coordMap == null) return nodes;
for(int i = -2; i <= 2; i++) {
for(int j = -2; j <= 2; j++) {
Set<BlockPos> posList = 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);
}
}
}
}
return nodes;
}
}

View File

@ -0,0 +1,172 @@
package com.hbm.tileentity.network;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.HashSet;
import java.util.Set;
import com.hbm.util.ParticleUtil;
import com.hbm.util.fauxpointtwelve.BlockPos;
import net.minecraft.tileentity.TileEntity;
import net.minecraft.util.MovingObjectPosition;
import net.minecraft.util.Vec3;
import net.minecraft.world.ChunkCoordIntPair;
import net.minecraft.world.World;
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 Set<BlockPos> reachableNodes = new HashSet();
public Set<BlockPos> knownNodes = new HashSet();
public static final int maxRange = 24;
public static final int maxAge = 2_000;
@Override
public void updateEntity() {
if(!worldObj.isRemote) {
if(worldObj.getTotalWorldTime() % 20 == 0) {
BlockPos pos = getCoord();
push(worldObj, pos);
for(BlockPos 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,
reachableNodes.contains(known) ? 0x00ff00 : 0xff0000);
}
//rescan known nodes
if(worldObj.getTotalWorldTime() % 40 == 0 && knownNodes.size() > 0) {
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);
}
}
//discover new nodes
} else {
Set<BlockPos> nodes = getAllLocalNodes(worldObj, pos.getX(), pos.getZ());
for(BlockPos node : nodes) {
if(!knownNodes.contains(node) && !node.equals(pos)) {
knownNodes.add(node);
if(hasPath(worldObj, pos, node)) reachableNodes.add(node);
break;
}
}
}
}
}
}
public BlockPos getCoord() {
return new BlockPos(xCoord, yCoord + 1, zCoord);
}
/**
* Performs a bidirectional scan to see if the nodes have line of sight
* @param world
* @param pos1
* @param pos2
* @return
*/
public static boolean hasPath(World world, BlockPos pos1, BlockPos pos2) {
Vec3 vec1 = Vec3.createVectorHelper(pos1.getX() + 0.5, pos1.getY() + 0.5, pos1.getZ() + 0.5);
Vec3 vec2 = Vec3.createVectorHelper(pos2.getX() + 0.5, pos2.getY() + 0.5, pos2.getZ() + 0.5);
Vec3 vec3 = vec1.subtract(vec2);
if(vec3.lengthVector() > maxRange) return false;
//for some fucking reason beyond any human comprehension, this function will randomly yield incorrect results but only from one side
//therefore we just run the stupid fucking thing twice and then compare the results
//thanks for this marvelous piece of programming, mojang
MovingObjectPosition mop0 = world.func_147447_a(vec1, vec2, false, true, false);
MovingObjectPosition mop2 = world.func_147447_a(vec2, vec1, false, true, false);
return (mop0 == null || mop0.typeOfHit == mop0.typeOfHit.MISS) && (mop2 == null || mop2.typeOfHit == mop2.typeOfHit.MISS);
}
/**
* Adds the position to that chunk's node list.
* @param world
* @param x
* @param y
* @param z
*/
public static void push(World world, BlockPos pos) {
HashMap<ChunkCoordIntPair, Set<BlockPos>> coordMap = activeWaypoints.get(world);
if(coordMap == null) {
coordMap = new HashMap();
activeWaypoints.put(world, coordMap);
}
ChunkCoordIntPair chunkPos = new ChunkCoordIntPair(pos.getX() >> 4, pos.getZ() >> 4);
Set<BlockPos> posList = coordMap.get(chunkPos);
if(posList == null) {
posList = new HashSet();
coordMap.put(chunkPos, posList);
}
posList.add(pos);
lastActive.put(pos, System.currentTimeMillis());
}
/**
* Gets all active nodes in a 5x5 chunk area, centered around the given position.
* Used for finding neighbors to check connections to.
* @param world
* @param x
* @param z
* @return
*/
public static Set<BlockPos> getAllLocalNodes(World world, int x, int z) {
Set<BlockPos> nodes = new HashSet();
x >>= 4;
z >>= 4;
HashMap<ChunkCoordIntPair, Set<BlockPos>> coordMap = activeWaypoints.get(world);
if(coordMap == null) return nodes;
for(int i = -2; i <= 2; i++) {
for(int j = -2; j <= 2; j++) {
Set<BlockPos> posList = 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);
}
}
}
}
return nodes;
}
}

Binary file not shown.

After

Width:  |  Height:  |  Size: 764 B

View File

@ -0,0 +1,5 @@
{
"animation": {
"frametime": 10
}
}

Binary file not shown.

After

Width:  |  Height:  |  Size: 834 B

View File

@ -0,0 +1,5 @@
{
"animation": {
"frametime": 10
}
}

Binary file not shown.

After

Width:  |  Height:  |  Size: 732 B

View File

@ -0,0 +1,5 @@
{
"animation": {
"frametime": 10
}
}

Binary file not shown.

After

Width:  |  Height:  |  Size: 797 B

View File

@ -0,0 +1,5 @@
{
"animation": {
"frametime": 10
}
}

Binary file not shown.

After

Width:  |  Height:  |  Size: 896 B

View File

@ -0,0 +1,5 @@
{
"animation": {
"frametime": 10
}
}

Binary file not shown.

After

Width:  |  Height:  |  Size: 772 B

View File

@ -0,0 +1,5 @@
{
"animation": {
"frametime": 10
}
}

Binary file not shown.

After

Width:  |  Height:  |  Size: 528 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 675 B

View File

@ -0,0 +1,5 @@
{
"animation": {
"frametime": 10
}
}

Binary file not shown.

After

Width:  |  Height:  |  Size: 523 B

Binary file not shown.

Before

Width:  |  Height:  |  Size: 1.2 KiB

After

Width:  |  Height:  |  Size: 1.2 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 1.4 KiB

After

Width:  |  Height:  |  Size: 1.4 KiB