conveyor API stuff

This commit is contained in:
Bob 2022-06-02 22:46:22 +02:00
parent e4c0336324
commit 1ae7160128
12 changed files with 146 additions and 9 deletions

View File

@ -0,0 +1,10 @@
package api.hbm.conveyor;
import net.minecraft.util.Vec3;
import net.minecraft.world.World;
public interface IConveyorBelt {
public Vec3 getTravelLocation(World world, int x, int y, int z, Vec3 itemPos, double speed);
public Vec3 getClosestSnappingPosition(World world, int x, int y, int z, Vec3 itemPos);
}

View File

@ -1,9 +1,10 @@
package api.hbm.conveyor;
import net.minecraft.world.World;
import net.minecraftforge.common.util.ForgeDirection;
public interface IEnterableBlock {
public boolean canEnter(IConveyorItem entity, ForgeDirection dir);
public void onEnter(IConveyorItem entity, ForgeDirection dir);
public boolean canEnter(World world, int x, int y, int z, ForgeDirection dir, IConveyorItem entity);
public void onEnter(World world, int x, int y, int z, ForgeDirection dir, IConveyorItem entity);
}

View File

@ -8,13 +8,16 @@ import com.hbm.explosion.ExplosionNT;
import com.hbm.explosion.ExplosionNT.ExAttrib;
import com.hbm.interfaces.IBomb;
import api.hbm.conveyor.IConveyorItem;
import api.hbm.conveyor.IEnterableBlock;
import net.minecraft.block.Block;
import net.minecraft.block.material.Material;
import net.minecraft.item.Item;
import net.minecraft.world.Explosion;
import net.minecraft.world.World;
import net.minecraftforge.common.util.ForgeDirection;
public class DetMiner extends BlockPillar implements IBomb {
public class DetMiner extends BlockPillar implements IBomb, IEnterableBlock {
public DetMiner(Material mat, String top) {
super(mat, top);
@ -55,4 +58,14 @@ public class DetMiner extends BlockPillar implements IBomb {
}
}
@Override
public boolean canEnter(World world, int x, int y, int z, ForgeDirection dir, IConveyorItem entity) {
return true;
}
@Override
public void onEnter(World world, int x, int y, int z, ForgeDirection dir, IConveyorItem entity) {
this.explode(world, x, y, z);
}
}

View File

@ -3,6 +3,7 @@ package com.hbm.blocks.network;
import com.hbm.entity.item.EntityMovingItem;
import com.hbm.lib.RefStrings;
import api.hbm.conveyor.IConveyorBelt;
import cpw.mods.fml.client.registry.RenderingRegistry;
import cpw.mods.fml.relauncher.Side;
import cpw.mods.fml.relauncher.SideOnly;
@ -16,10 +17,12 @@ import net.minecraft.item.ItemStack;
import net.minecraft.util.AxisAlignedBB;
import net.minecraft.util.IIcon;
import net.minecraft.util.MathHelper;
import net.minecraft.util.Vec3;
import net.minecraft.world.IBlockAccess;
import net.minecraft.world.World;
import net.minecraftforge.common.util.ForgeDirection;
public class BlockConveyor extends Block {
public class BlockConveyor extends Block implements IConveyorBelt {
@SideOnly(Side.CLIENT)
protected IIcon sideIcon;
@ -47,6 +50,53 @@ public class BlockConveyor extends Block {
return super.getIcon(side, metadata);
}
@Override
public Vec3 getTravelLocation(World world, int x, int y, int z, Vec3 itemPos, double speed) {
/*Vec3 snap = this.getClosestSnappingPosition(world, x, y, z, itemPos);
ForgeDirection dir = ForgeDirection.getOrientation(world.getBlockMetadata(x, y, z));
return Vec3.createVectorHelper(snap.xCoord + dir.offsetX * speed, snap.yCoord, snap.zCoord + dir.offsetZ * speed);*/
Vec3 snap = this.getClosestSnappingPosition(world, x, y, z, itemPos);
/*double dist = snap.distanceTo(itemPos);
if(dist > speed) {
return Vec3.createVectorHelper(
itemPos.xCoord + (snap.xCoord - itemPos.xCoord) / dist * speed,
snap.yCoord,
itemPos.zCoord + (snap.zCoord - itemPos.zCoord) / dist * speed
);
} else {
ForgeDirection dir = ForgeDirection.getOrientation(world.getBlockMetadata(x, y, z));
return Vec3.createVectorHelper(snap.xCoord + dir.offsetX * speed, snap.yCoord, snap.zCoord + dir.offsetZ * speed);
}*/
ForgeDirection dir = ForgeDirection.getOrientation(world.getBlockMetadata(x, y, z));
return Vec3.createVectorHelper(snap.xCoord - dir.offsetX * speed, snap.yCoord, snap.zCoord - dir.offsetZ * speed);
}
@Override
public Vec3 getClosestSnappingPosition(World world, int x, int y, int z, Vec3 itemPos) {
ForgeDirection dir = ForgeDirection.getOrientation(world.getBlockMetadata(x, y, z));
itemPos.xCoord = MathHelper.clamp_double(itemPos.xCoord, x, x + 1);
itemPos.zCoord = MathHelper.clamp_double(itemPos.zCoord, z, z + 1);
double posX = x + 0.5;
double posZ = z + 0.5;
if(dir.offsetX != 0) {
posX = itemPos.xCoord;
}
if(dir.offsetZ != 0) {
posZ = itemPos.zCoord;
}
return Vec3.createVectorHelper(posX, y + 0.25, posZ);
}
@Override
public void onEntityCollidedWithBlock(World world, int x, int y, int z, Entity entity) {
@ -108,5 +158,4 @@ public class BlockConveyor extends Block {
world.setBlockMetadataWithNotify(x, y, z, 4, 2);
}
}
}

View File

@ -1,10 +1,14 @@
package com.hbm.entity.item;
import com.hbm.blocks.ModBlocks;
import com.hbm.util.fauxpointtwelve.BlockPos;
import api.hbm.conveyor.IConveyorBelt;
import api.hbm.conveyor.IConveyorItem;
import api.hbm.conveyor.IEnterableBlock;
import cpw.mods.fml.relauncher.Side;
import cpw.mods.fml.relauncher.SideOnly;
import net.minecraft.block.Block;
import net.minecraft.entity.Entity;
import net.minecraft.entity.item.EntityItem;
import net.minecraft.entity.player.EntityPlayer;
@ -12,6 +16,7 @@ import net.minecraft.init.Blocks;
import net.minecraft.item.ItemStack;
import net.minecraft.nbt.NBTTagCompound;
import net.minecraft.util.DamageSource;
import net.minecraft.util.Vec3;
import net.minecraft.world.World;
import net.minecraftforge.common.util.ForgeDirection;
@ -104,7 +109,13 @@ public class EntityMovingItem extends Entity implements IConveyorItem {
if(!worldObj.isRemote) {
if(worldObj.getBlock((int) Math.floor(posX), (int) Math.floor(posY), (int) Math.floor(posZ)) != ModBlocks.conveyor) {
int blockX = (int) Math.floor(posX);
int blockY = (int) Math.floor(posY);
int blockZ = (int) Math.floor(posZ);
Block b = worldObj.getBlock(blockX, blockY, blockZ);
if(!(b instanceof IConveyorBelt)) {
this.setDead();
EntityItem item = new EntityItem(worldObj, posX, posY, posZ, this.getItemStack());
item.motionX = this.motionX * 3;
@ -113,9 +124,16 @@ public class EntityMovingItem extends Entity implements IConveyorItem {
item.velocityChanged = true;
worldObj.spawnEntityInWorld(item);
return;
} else {
Vec3 target = ((IConveyorBelt) b).getTravelLocation(worldObj, blockX, blockY, blockZ, Vec3.createVectorHelper(posX, posY, posZ), 0.0625);
//this.worldObj.spawnParticle("reddust", target.xCoord, target.yCoord, target.zCoord, 0, 0, 0);
this.motionX = target.xCoord - posX;
this.motionY = target.yCoord - posY;
this.motionZ = target.zCoord - posZ;
}
if(worldObj.getBlock((int) Math.floor(posX), (int) Math.floor(posY), (int) Math.floor(posZ)) == ModBlocks.conveyor) {
/*if(worldObj.getBlock((int) Math.floor(posX), (int) Math.floor(posY), (int) Math.floor(posZ)) == ModBlocks.conveyor) {
if(schedule <= 0) {
ForgeDirection dir = ForgeDirection.getOrientation(worldObj.getBlockMetadata((int) Math.floor(posX), (int) Math.floor(posY), (int) Math.floor(posZ)));
@ -139,9 +157,27 @@ public class EntityMovingItem extends Entity implements IConveyorItem {
}
schedule--;
}
}*/
BlockPos lastPos = new BlockPos(posX, posY, posZ);
this.moveEntity(motionX, motionY, motionZ);
BlockPos newPos = new BlockPos(posX, posY, posZ);
if(!lastPos.equals(newPos)) {
Block newBlock = worldObj.getBlock(newPos.getX(), newPos.getY(), newPos.getZ());
if(newBlock instanceof IEnterableBlock) {
ForgeDirection dir = ForgeDirection.UNKNOWN;
IEnterableBlock enterable = (IEnterableBlock) newBlock;
if(enterable.canEnter(worldObj, newPos.getX(), newPos.getY(), newPos.getZ(), dir, this)) {
enterable.onEnter(worldObj, newPos.getX(), newPos.getY(), newPos.getZ(), dir, this);
this.setDead();
}
}
}
}
}

View File

@ -7,7 +7,7 @@ import net.minecraft.util.MathHelper;
* Adjusted code from MC 1.12 (com.minecraft.util.math.BlockPos)
*/
public class BlockPos {
private final int x;
private final int y;
private final int z;
@ -55,4 +55,32 @@ public class BlockPos {
public int getZ() {
return this.z;
}
@Override
public int hashCode() {
final int prime = 31;
int result = 1;
result = prime * result + x;
result = prime * result + y;
result = prime * result + z;
return result;
}
@Override
public boolean equals(Object obj) {
if(this == obj)
return true;
if(obj == null)
return false;
if(getClass() != obj.getClass())
return false;
BlockPos other = (BlockPos) obj;
if(x != other.x)
return false;
if(y != other.y)
return false;
if(z != other.z)
return false;
return true;
}
}

Binary file not shown.

Before

Width:  |  Height:  |  Size: 239 B

After

Width:  |  Height:  |  Size: 221 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 245 B

Binary file not shown.

Before

Width:  |  Height:  |  Size: 199 B

After

Width:  |  Height:  |  Size: 178 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 253 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 239 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 199 B