mirror of
https://github.com/HbmMods/Hbm-s-Nuclear-Tech-GIT.git
synced 2026-01-25 10:32:49 +00:00
commit
2be3c60e59
@ -4,8 +4,11 @@ import com.hbm.entity.logic.IChunkLoader;
|
||||
import com.hbm.inventory.FluidStack;
|
||||
import com.hbm.inventory.fluid.FluidType;
|
||||
import com.hbm.inventory.fluid.Fluids;
|
||||
import com.hbm.items.ModItems;
|
||||
import com.hbm.items.tool.ItemDrone;
|
||||
import com.hbm.main.MainRegistry;
|
||||
|
||||
import net.minecraft.entity.Entity;
|
||||
import net.minecraft.entity.player.EntityPlayer;
|
||||
import net.minecraft.inventory.IInventory;
|
||||
import net.minecraft.item.ItemStack;
|
||||
@ -29,6 +32,30 @@ public class EntityDeliveryDrone extends EntityDroneBase implements IInventory,
|
||||
super(world);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean hitByEntity(Entity attacker) {
|
||||
|
||||
if(attacker instanceof EntityPlayer && !worldObj.isRemote) {
|
||||
this.setDead();
|
||||
for (ItemStack stack : slots) {
|
||||
if(stack != null)
|
||||
this.entityDropItem(stack, 1F);
|
||||
}
|
||||
int meta = 0;
|
||||
|
||||
//whether it is an express drone
|
||||
if(this.dataWatcher.getWatchableObjectByte(11) == 1)
|
||||
meta = 2;
|
||||
|
||||
if(chunkLoading)
|
||||
meta += 1;
|
||||
|
||||
this.entityDropItem(new ItemStack(ModItems.drone, 1, meta), 1F);
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void entityInit() {
|
||||
super.entityInit();
|
||||
@ -53,7 +80,7 @@ public class EntityDeliveryDrone extends EntityDroneBase implements IInventory,
|
||||
|
||||
@Override
|
||||
public double getSpeed() {
|
||||
return this.dataWatcher.getWatchableObjectByte(11) == 1 ? 0.375 : 0.125;
|
||||
return this.dataWatcher.getWatchableObjectByte(11) == 1 ? 0.375 * 3 : 0.375;
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@ -112,7 +112,9 @@ public abstract class EntityDroneBase extends Entity {
|
||||
this.motionZ = dist.zCoord * speed;
|
||||
}
|
||||
}
|
||||
|
||||
if(isCollidedHorizontally){
|
||||
motionY += 1;
|
||||
}
|
||||
this.moveEntity(motionX, motionY, motionZ);
|
||||
}
|
||||
}
|
||||
|
||||
@ -13,10 +13,13 @@ import com.hbm.tileentity.network.TileEntityDroneProvider;
|
||||
import com.hbm.tileentity.network.TileEntityDroneRequester;
|
||||
import com.hbm.util.fauxpointtwelve.BlockPos;
|
||||
|
||||
import net.minecraft.entity.Entity;
|
||||
import net.minecraft.entity.player.EntityPlayer;
|
||||
import net.minecraft.item.Item;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.nbt.NBTTagCompound;
|
||||
import net.minecraft.tileentity.TileEntity;
|
||||
import net.minecraft.util.MovingObjectPosition;
|
||||
import net.minecraft.util.Vec3;
|
||||
import net.minecraft.world.World;
|
||||
|
||||
@ -30,6 +33,25 @@ public class EntityRequestDrone extends EntityDroneBase {
|
||||
UNLOAD, DOCK
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setTarget(double x, double y, double z) {
|
||||
this.targetX = x;
|
||||
this.targetY = y + 1;
|
||||
this.targetZ = z;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean hitByEntity(Entity attacker) {
|
||||
|
||||
if(attacker instanceof EntityPlayer && !worldObj.isRemote) {
|
||||
this.setDead();
|
||||
if(heldItem != null)
|
||||
this.entityDropItem(heldItem, 1F);
|
||||
this.entityDropItem(new ItemStack(ModItems.drone, 1, EnumDroneType.REQUEST.ordinal()), 1F);
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
public EntityRequestDrone(World world) {
|
||||
super(world);
|
||||
}
|
||||
@ -61,78 +83,114 @@ public class EntityRequestDrone extends EntityDroneBase {
|
||||
} else if(next instanceof AStack && heldItem == null) {
|
||||
|
||||
AStack aStack = (AStack) next;
|
||||
TileEntity tile = worldObj.getTileEntity((int) Math.floor(posX), (int) Math.floor(posY - 1), (int) Math.floor(posZ));
|
||||
|
||||
if(tile instanceof TileEntityDroneProvider) {
|
||||
TileEntityDroneProvider provider = (TileEntityDroneProvider) tile;
|
||||
|
||||
for(int i = 0; i < provider.slots.length; i++) {
|
||||
ItemStack stack = provider.slots[i];
|
||||
|
||||
if(stack != null && aStack.matchesRecipe(stack, true)) {
|
||||
this.heldItem = stack.copy();
|
||||
this.setAppearance(1);
|
||||
worldObj.playSoundEffect(posX, posY, posZ, "hbm:item.unpack", 0.5F, 0.75F);
|
||||
provider.slots[i] = null;
|
||||
provider.markDirty();
|
||||
break;
|
||||
//to make DAMN sure this fuckin idiot doesnt miss the dock
|
||||
Vec3 pos = Vec3.createVectorHelper(this.posX, this.posY, this.posZ);
|
||||
Vec3 nextPos = Vec3.createVectorHelper(this.posX, this.posY - 4, this.posZ);
|
||||
MovingObjectPosition mop = this.worldObj.rayTraceBlocks(pos, nextPos);
|
||||
|
||||
if (mop != null && mop.typeOfHit == MovingObjectPosition.MovingObjectType.BLOCK) {
|
||||
|
||||
TileEntity tile = worldObj.getTileEntity(mop.blockX, mop.blockY, mop.blockZ);
|
||||
if (tile instanceof TileEntityDroneProvider) {
|
||||
TileEntityDroneProvider provider = (TileEntityDroneProvider) tile;
|
||||
|
||||
for (int i = 0; i < provider.slots.length; i++) {
|
||||
ItemStack stack = provider.slots[i];
|
||||
|
||||
if (stack != null && aStack.matchesRecipe(stack, true)) {
|
||||
this.heldItem = stack.copy();
|
||||
this.setAppearance(1);
|
||||
worldObj.playSoundEffect(posX, posY, posZ, "hbm:item.unpack", 0.5F, 0.75F);
|
||||
provider.slots[i] = null;
|
||||
provider.markDirty();
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
nextActionTimer = 5;
|
||||
} else if(next == DroneProgram.UNLOAD && this.heldItem != null) {
|
||||
|
||||
TileEntity tile = worldObj.getTileEntity((int) Math.floor(posX), (int) Math.floor(posY - 1), (int) Math.floor(posZ));
|
||||
if(tile instanceof TileEntityDroneRequester) {
|
||||
TileEntityDroneRequester requester = (TileEntityDroneRequester) tile;
|
||||
|
||||
for(int i = 9; i < 18; i++) {
|
||||
ItemStack stack = requester.slots[i];
|
||||
if(stack != null && stack.getItem() == heldItem.getItem() && stack.getItemDamage() == heldItem.getItemDamage()) {
|
||||
int toTransfer = Math.min(stack.getMaxStackSize() - stack.stackSize, heldItem.stackSize);
|
||||
requester.slots[i].stackSize += toTransfer;
|
||||
this.heldItem.stackSize -= toTransfer;
|
||||
Vec3 pos = Vec3.createVectorHelper(this.posX, this.posY, this.posZ);
|
||||
Vec3 nextPos = Vec3.createVectorHelper(this.posX, this.posY - 4, this.posZ);
|
||||
MovingObjectPosition mop = this.worldObj.rayTraceBlocks(pos, nextPos);
|
||||
|
||||
if (mop != null && mop.typeOfHit == MovingObjectPosition.MovingObjectType.BLOCK) {
|
||||
|
||||
TileEntity tile = worldObj.getTileEntity(mop.blockX, mop.blockY, mop.blockZ);
|
||||
if (tile instanceof TileEntityDroneRequester) {
|
||||
TileEntityDroneRequester requester = (TileEntityDroneRequester) tile;
|
||||
|
||||
for (int i = 9; i < 18; i++) {
|
||||
ItemStack stack = requester.slots[i];
|
||||
if (stack != null && stack.getItem() == heldItem.getItem() && stack.getItemDamage() == heldItem.getItemDamage()) {
|
||||
int toTransfer = Math.min(stack.getMaxStackSize() - stack.stackSize, heldItem.stackSize);
|
||||
requester.slots[i].stackSize += toTransfer;
|
||||
this.heldItem.stackSize -= toTransfer;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if(this.heldItem.stackSize <= 0) this.heldItem = null;
|
||||
|
||||
if(this.heldItem != null) for(int i = 9; i < 18; i++) {
|
||||
if(requester.slots[i] == null) {
|
||||
requester.slots[i] = this.heldItem.copy();
|
||||
this.heldItem = null;
|
||||
break;
|
||||
|
||||
if (this.heldItem.stackSize <= 0) this.heldItem = null;
|
||||
|
||||
if (this.heldItem != null) for (int i = 9; i < 18; i++) {
|
||||
if (requester.slots[i] == null) {
|
||||
requester.slots[i] = this.heldItem.copy();
|
||||
this.heldItem = null;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if (this.heldItem == null) {
|
||||
this.setAppearance(0);
|
||||
worldObj.playSoundEffect(posX, posY, posZ, "hbm:item.unpack", 0.5F, 0.75F);
|
||||
}
|
||||
|
||||
requester.markDirty();
|
||||
}
|
||||
|
||||
if(this.heldItem == null) {
|
||||
this.setAppearance(0);
|
||||
worldObj.playSoundEffect(posX, posY, posZ, "hbm:item.unpack", 0.5F, 0.75F);
|
||||
}
|
||||
|
||||
requester.markDirty();
|
||||
}
|
||||
nextActionTimer = 5;
|
||||
} else if(next == DroneProgram.DOCK) {
|
||||
|
||||
TileEntity tile = worldObj.getTileEntity((int) Math.floor(posX), (int) Math.floor(posY - 1), (int) Math.floor(posZ));
|
||||
if(tile instanceof TileEntityDroneDock) {
|
||||
TileEntityDroneDock dock = (TileEntityDroneDock) tile;
|
||||
|
||||
for(int i = 0; i < dock.slots.length; i++) {
|
||||
if(dock.slots[i] == null) {
|
||||
this.setDead();
|
||||
dock.slots[i] = new ItemStack(ModItems.drone, 1, EnumDroneType.REQUEST.ordinal());
|
||||
this.worldObj.playSoundEffect(dock.xCoord + 0.5, dock.yCoord + 0.5, dock.zCoord + 0.5, "hbm:block.storageClose", 2.0F, 1.0F);
|
||||
break;
|
||||
Vec3 pos = Vec3.createVectorHelper(this.posX, this.posY, this.posZ);
|
||||
Vec3 nextPos = Vec3.createVectorHelper(this.posX, this.posY - 4, this.posZ);
|
||||
MovingObjectPosition mop = this.worldObj.rayTraceBlocks(pos, nextPos);
|
||||
|
||||
if (mop != null && mop.typeOfHit == MovingObjectPosition.MovingObjectType.BLOCK) {
|
||||
|
||||
TileEntity tile = worldObj.getTileEntity(mop.blockX, mop.blockY, mop.blockZ);
|
||||
if (tile instanceof TileEntityDroneDock) {
|
||||
TileEntityDroneDock dock = (TileEntityDroneDock) tile;
|
||||
ItemStack drone = new ItemStack(ModItems.drone, 1, EnumDroneType.REQUEST.ordinal());
|
||||
for (int i = 0; i < dock.slots.length; i++) {
|
||||
if (dock.slots[i] == null) {
|
||||
this.setDead();
|
||||
if(heldItem != null){
|
||||
if(i != 9 && dock.slots[i + 1] == null){
|
||||
dock.slots[i + 1] = heldItem.copy();
|
||||
}
|
||||
}
|
||||
dock.slots[i] = drone.copy();
|
||||
this.worldObj.playSoundEffect(dock.xCoord + 0.5, dock.yCoord + 0.5, dock.zCoord + 0.5, "hbm:block.storageClose", 2.0F, 1.0F);
|
||||
break;
|
||||
} else if (dock.slots[i].isItemEqual(drone) && dock.slots[i].stackSize < 64){
|
||||
this.setDead();
|
||||
if(heldItem != null){
|
||||
if(i != 9 && dock.slots[i + 1] == null){
|
||||
dock.slots[i + 1] = heldItem.copy();
|
||||
}
|
||||
}
|
||||
dock.slots[i].stackSize++;
|
||||
this.worldObj.playSoundEffect(dock.xCoord + 0.5, dock.yCoord + 0.5, dock.zCoord + 0.5, "hbm:block.storageClose", 2.0F, 1.0F);
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if(!this.isDead) {
|
||||
if (!this.isDead) {
|
||||
this.setDead();
|
||||
if(heldItem != null)
|
||||
this.entityDropItem(heldItem, 1F);
|
||||
this.entityDropItem(new ItemStack(ModItems.drone, 1, EnumDroneType.REQUEST.ordinal()), 1F);
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -141,7 +199,7 @@ public class EntityRequestDrone extends EntityDroneBase {
|
||||
|
||||
@Override
|
||||
public double getSpeed() {
|
||||
return 0.5D;
|
||||
return 0.6D;
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@ -1962,7 +1962,9 @@ public class ClientProxy extends ServerProxy {
|
||||
held == Item.getItemFromBlock(ModBlocks.drone_crate_provider) ||
|
||||
held == Item.getItemFromBlock(ModBlocks.drone_crate_requester) ||
|
||||
held == Item.getItemFromBlock(ModBlocks.drone_dock) ||
|
||||
held == Item.getItemFromBlock(ModBlocks.drone_waypoint_request)) {
|
||||
held == Item.getItemFromBlock(ModBlocks.drone_waypoint_request) ||
|
||||
held == Item.getItemFromBlock(ModBlocks.drone_waypoint) ||
|
||||
held == ModItems.drone_linker) {
|
||||
double mX = data.getDouble("mX");
|
||||
double mY = data.getDouble("mY");
|
||||
double mZ = data.getDouble("mZ");
|
||||
|
||||
@ -70,10 +70,11 @@ public class RequestNetwork {
|
||||
public static class PathNode {
|
||||
public BlockPos pos;
|
||||
public long lease;
|
||||
public HashedSet<PathNode> reachableNodes = new HashedSet();
|
||||
public boolean active = true;
|
||||
public HashedSet<PathNode> reachableNodes;
|
||||
public PathNode(BlockPos pos, HashedSet<PathNode> reachableNodes) {
|
||||
this.pos = pos;
|
||||
this.reachableNodes = new HashedSet(reachableNodes);
|
||||
this.reachableNodes = new HashedSet<>(reachableNodes);
|
||||
this.lease = System.currentTimeMillis();
|
||||
}
|
||||
|
||||
|
||||
@ -12,6 +12,7 @@ import com.hbm.inventory.gui.GUIDroneCrate;
|
||||
import com.hbm.tileentity.IGUIProvider;
|
||||
import com.hbm.tileentity.INBTPacketReceiver;
|
||||
import com.hbm.tileentity.TileEntityMachineBase;
|
||||
import com.hbm.util.ParticleUtil;
|
||||
import com.hbm.util.fauxpointtwelve.BlockPos;
|
||||
|
||||
import api.hbm.fluid.IFluidStandardTransceiver;
|
||||
@ -51,7 +52,7 @@ public class TileEntityDroneCrate extends TileEntityMachineBase implements IGUIP
|
||||
public void updateEntity() {
|
||||
|
||||
if(!worldObj.isRemote) {
|
||||
|
||||
BlockPos pos = getCoord();
|
||||
this.tank.setType(18, slots);
|
||||
|
||||
if(sendingMode && !itemType && worldObj.getTotalWorldTime() % 20 == 0) {
|
||||
@ -75,7 +76,13 @@ public class TileEntityDroneCrate extends TileEntityMachineBase implements IGUIP
|
||||
if(!sendingMode && !itemType) unloadFluid(drone);
|
||||
}
|
||||
}
|
||||
|
||||
ParticleUtil.spawnDroneLine(worldObj,
|
||||
pos.getX() + 0.5, pos.getY() + 0.5, pos.getZ() + 0.5,
|
||||
(nextX - pos.getX()), (nextY - pos.getY()), (nextZ - pos.getZ()), 0x00ffff);
|
||||
}
|
||||
|
||||
|
||||
|
||||
NBTTagCompound data = new NBTTagCompound();
|
||||
data.setIntArray("pos", new int[] {nextX, nextY, nextZ});
|
||||
@ -218,6 +225,10 @@ public class TileEntityDroneCrate extends TileEntityMachineBase implements IGUIP
|
||||
this.itemType = nbt.getBoolean("type");
|
||||
tank.readFromNBT(nbt, "t");
|
||||
}
|
||||
|
||||
public BlockPos getCoord() {
|
||||
return new BlockPos(xCoord, yCoord + 1, zCoord);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void writeToNBT(NBTTagCompound nbt) {
|
||||
|
||||
@ -43,7 +43,7 @@ public class TileEntityDroneDock extends TileEntityRequestNetworkContainer imple
|
||||
public void updateEntity() {
|
||||
super.updateEntity();
|
||||
|
||||
if(!worldObj.isRemote && worldObj.getTotalWorldTime() % 100 == 0 && this.hasDrone()) {
|
||||
if(!worldObj.isRemote && worldObj.getTotalWorldTime() % 20 == 0 && this.hasDrone()) {
|
||||
|
||||
// grab all nodes in a 5 chunk radius
|
||||
HashedSet<PathNode> localNodes = this.getAllLocalNodes(worldObj, xCoord, zCoord, 5);
|
||||
@ -64,7 +64,7 @@ public class TileEntityDroneDock extends TileEntityRequestNetworkContainer imple
|
||||
|
||||
// simply pick the first request node that has unfulfilled requests
|
||||
for(RequestNode request : requests) {
|
||||
if(!request.request.isEmpty()) {
|
||||
if(request.active && !request.request.isEmpty()) {
|
||||
firstRequest = request;
|
||||
break;
|
||||
}
|
||||
@ -78,7 +78,7 @@ public class TileEntityDroneDock extends TileEntityRequestNetworkContainer imple
|
||||
outer: for(OfferNode offer : offers) {
|
||||
|
||||
for(ItemStack stack : offer.offer) {
|
||||
if(stack != null && request.matchesRecipe(stack, true)) {
|
||||
if(offer.active && stack != null && request.matchesRecipe(stack, true)) {
|
||||
if(tryEmbark(own, firstRequest, offer, request, localNodes)) break attempt; // if the drone can be pathed and spawned, stop doing more attempts
|
||||
break outer; // if not, simply continue iterating over offer nodes
|
||||
}
|
||||
|
||||
@ -3,6 +3,8 @@ package com.hbm.tileentity.network;
|
||||
import java.util.List;
|
||||
|
||||
import com.hbm.entity.item.EntityDeliveryDrone;
|
||||
import com.hbm.tileentity.INBTPacketReceiver;
|
||||
import com.hbm.util.ParticleUtil;
|
||||
import com.hbm.packet.BufPacket;
|
||||
import com.hbm.packet.PacketDispatcher;
|
||||
import com.hbm.tileentity.IBufPacketReceiver;
|
||||
@ -26,11 +28,9 @@ public class TileEntityDroneWaypoint extends TileEntity implements IBufPacketRec
|
||||
|
||||
@Override
|
||||
public void updateEntity() {
|
||||
|
||||
ForgeDirection dir = ForgeDirection.getOrientation(this.getBlockMetadata());
|
||||
|
||||
if(!worldObj.isRemote) {
|
||||
|
||||
if(nextY != -1) {
|
||||
List<EntityDeliveryDrone> drones = worldObj.getEntitiesWithinAABB(EntityDeliveryDrone.class, AxisAlignedBB.getBoundingBox(xCoord, yCoord, zCoord, xCoord + 1, yCoord + 1, zCoord + 1).offset(dir.offsetX * height, dir.offsetY * height, dir.offsetZ * height));
|
||||
for(EntityDeliveryDrone drone : drones) {
|
||||
@ -42,13 +42,17 @@ public class TileEntityDroneWaypoint extends TileEntity implements IBufPacketRec
|
||||
|
||||
PacketDispatcher.wrapper.sendToAllAround(new BufPacket(xCoord, yCoord, zCoord, this), new TargetPoint(this.worldObj.provider.dimensionId, xCoord, yCoord, zCoord, 15));
|
||||
} else {
|
||||
|
||||
BlockPos pos = getCoord(dir);
|
||||
if(nextY != -1 && worldObj.getTotalWorldTime() % 2 == 0) {
|
||||
double x = xCoord + height * dir.offsetX + 0.5;
|
||||
double y = yCoord + height * dir.offsetY + 0.5;
|
||||
double z = zCoord + height * dir.offsetZ + 0.5;
|
||||
|
||||
worldObj.spawnParticle("reddust", x, y, z, 0, 0, 0);
|
||||
|
||||
ParticleUtil.spawnDroneLine(worldObj,
|
||||
pos.getX() + 0.5, pos.getY() + 0.5, pos.getZ() + 0.5,
|
||||
(nextX - pos.getX()), (nextY - pos.getY()), (nextZ - pos.getZ()), 0x0000ff);
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -106,4 +110,7 @@ public class TileEntityDroneWaypoint extends TileEntity implements IBufPacketRec
|
||||
nbt.setInteger("height", height);
|
||||
nbt.setIntArray("pos", new int[] {nextX, nextY, nextZ});
|
||||
}
|
||||
public BlockPos getCoord(ForgeDirection dir) {
|
||||
return new BlockPos(xCoord + height * dir.offsetX + 0.5, yCoord + height * dir.offsetY + 0.5, zCoord + height * dir.offsetZ + 0.5);
|
||||
}
|
||||
}
|
||||
|
||||
@ -37,14 +37,18 @@ public abstract class TileEntityRequestNetwork extends TileEntity {
|
||||
|
||||
if(worldObj.getTotalWorldTime() % 20 == 0) {
|
||||
BlockPos pos = getCoord();
|
||||
|
||||
PathNode newNode = createNode(pos);
|
||||
if(this.worldObj.isBlockIndirectlyGettingPowered(xCoord, yCoord, zCoord)) newNode.active = false;
|
||||
// push new node
|
||||
push(worldObj, createNode(pos));
|
||||
push(worldObj, newNode);
|
||||
|
||||
// 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();
|
||||
HashedSet<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
|
||||
localNodes.remove(pos);
|
||||
|
||||
while(it.hasNext()) {
|
||||
PathNode node = it.next();
|
||||
if(!localNodes.contains(node)) {
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user