use of blusunrize.immersiveengineering.api.tool.ConveyorHandler.IConveyorTile in project ImmersiveEngineering by BluSunrize.
the class IEContent method preInit.
public static void preInit() {
WireType.init();
/*CONVEYORS*/
ConveyorHandler.registerMagnetSupression((entity, iConveyorTile) -> {
NBTTagCompound data = entity.getEntityData();
if (!data.getBoolean(Lib.MAGNET_PREVENT_NBT))
data.setBoolean(Lib.MAGNET_PREVENT_NBT, true);
}, (entity, iConveyorTile) -> {
entity.getEntityData().removeTag(Lib.MAGNET_PREVENT_NBT);
});
ConveyorHandler.registerConveyorHandler(new ResourceLocation(ImmersiveEngineering.MODID, "conveyor"), ConveyorBasic.class, (tileEntity) -> new ConveyorBasic());
ConveyorHandler.registerConveyorHandler(new ResourceLocation(ImmersiveEngineering.MODID, "uncontrolled"), ConveyorUncontrolled.class, (tileEntity) -> new ConveyorUncontrolled());
ConveyorHandler.registerConveyorHandler(new ResourceLocation(ImmersiveEngineering.MODID, "dropper"), ConveyorDrop.class, (tileEntity) -> new ConveyorDrop());
ConveyorHandler.registerConveyorHandler(new ResourceLocation(ImmersiveEngineering.MODID, "vertical"), ConveyorVertical.class, (tileEntity) -> new ConveyorVertical());
ConveyorHandler.registerConveyorHandler(new ResourceLocation(ImmersiveEngineering.MODID, "splitter"), ConveyorSplit.class, (tileEntity) -> new ConveyorSplit(tileEntity instanceof IConveyorTile ? ((IConveyorTile) tileEntity).getFacing() : EnumFacing.NORTH));
ConveyorHandler.registerConveyorHandler(new ResourceLocation(ImmersiveEngineering.MODID, "extract"), ConveyorExtract.class, (tileEntity) -> new ConveyorExtract(tileEntity instanceof IConveyorTile ? ((IConveyorTile) tileEntity).getFacing() : EnumFacing.NORTH));
ConveyorHandler.registerConveyorHandler(new ResourceLocation(ImmersiveEngineering.MODID, "covered"), ConveyorCovered.class, (tileEntity) -> new ConveyorCovered());
ConveyorHandler.registerConveyorHandler(new ResourceLocation(ImmersiveEngineering.MODID, "droppercovered"), ConveyorDropCovered.class, (tileEntity) -> new ConveyorDropCovered());
ConveyorHandler.registerConveyorHandler(new ResourceLocation(ImmersiveEngineering.MODID, "verticalcovered"), ConveyorVerticalCovered.class, (tileEntity) -> new ConveyorVerticalCovered());
ConveyorHandler.registerConveyorHandler(new ResourceLocation(ImmersiveEngineering.MODID, "extractcovered"), ConveyorExtractCovered.class, (tileEntity) -> new ConveyorExtractCovered(tileEntity instanceof IConveyorTile ? ((IConveyorTile) tileEntity).getFacing() : EnumFacing.NORTH));
ConveyorHandler.registerSubstitute(new ResourceLocation(ImmersiveEngineering.MODID, "conveyor"), new ResourceLocation(ImmersiveEngineering.MODID, "uncontrolled"));
ConveyorHandler.registerConveyorHandler(new ResourceLocation(ImmersiveEngineering.MODID, "chute_" + BlockTypes_MetalsAll.IRON.getName()), ConveyorChuteIron.class, (tileEntity) -> new ConveyorChuteIron());
ConveyorHandler.registerConveyorHandler(new ResourceLocation(ImmersiveEngineering.MODID, "chute_" + BlockTypes_MetalsAll.STEEL.getName()), ConveyorChuteSteel.class, (tileEntity) -> new ConveyorChuteSteel());
ConveyorHandler.registerConveyorHandler(new ResourceLocation(ImmersiveEngineering.MODID, "chute_" + BlockTypes_MetalsAll.ALUMINUM.getName()), ConveyorChuteAluminum.class, (tileEntity) -> new ConveyorChuteAluminum());
ConveyorHandler.registerConveyorHandler(new ResourceLocation(ImmersiveEngineering.MODID, "chute_" + BlockTypes_MetalsAll.COPPER.getName()), ConveyorChuteCopper.class, (tileEntity) -> new ConveyorChuteCopper());
/*BULLETS*/
ItemBullet.initBullets();
DataSerializers.registerSerializer(IEFluid.OPTIONAL_FLUID_STACK);
IELootFunctions.preInit();
}
use of blusunrize.immersiveengineering.api.tool.ConveyorHandler.IConveyorTile in project ImmersiveEngineering by BluSunrize.
the class BlockConveyor method onIEBlockPlacedBy.
@Override
public void onIEBlockPlacedBy(World world, BlockPos pos, IBlockState state, EnumFacing side, float hitX, float hitY, float hitZ, EntityLivingBase placer, ItemStack stack) {
super.onIEBlockPlacedBy(world, pos, state, side, hitX, hitY, hitZ, placer, stack);
TileEntity tile = world.getTileEntity(pos);
if (tile instanceof TileEntityConveyorBelt && !(tile instanceof TileEntityConveyorVertical)) {
TileEntityConveyorBelt conveyor = (TileEntityConveyorBelt) tile;
EnumFacing f = conveyor.facing;
ResourceLocation rl = new ResourceLocation(ItemNBTHelper.getString(stack, "conveyorType"));
IConveyorBelt subType = ConveyorHandler.getConveyor(rl, conveyor);
conveyor.setConveyorSubtype(subType);
tile = world.getTileEntity(pos.offset(f));
TileEntity tileUp = world.getTileEntity(pos.offset(f).add(0, 1, 0));
if (subType != null && (!(tile instanceof IConveyorTile) || ((IConveyorTile) tile).getFacing() == f.getOpposite()) && tileUp instanceof IConveyorTile && ((IConveyorTile) tileUp).getFacing() != f.getOpposite() && world.isAirBlock(pos.add(0, 1, 0)))
subType.setConveyorDirection(ConveyorDirection.UP);
tile = world.getTileEntity(pos.offset(f.getOpposite()).add(0, 1, 0));
// if(tile instanceof TileEntityConveyorBelt&&!(tile instanceof TileEntityConveyorVertical) && ((TileEntityConveyorBelt)tile).facing==f)
// conveyor.transportDown = true;
// if(conveyor.transportUp && conveyor.transportDown)
// conveyor.transportDown = false;
}
}
use of blusunrize.immersiveengineering.api.tool.ConveyorHandler.IConveyorTile in project ImmersiveEngineering by BluSunrize.
the class ConveyorChute method onEntityCollision.
@Override
public void onEntityCollision(TileEntity tile, Entity entity, EnumFacing facing) {
boolean contact = false;
if (!diagonal)
contact = entity.posY - tile.getPos().getY() <= .125;
else if (facing == EnumFacing.NORTH)
contact = entity.posZ - tile.getPos().getZ() <= .125;
else if (facing == EnumFacing.SOUTH)
contact = entity.posZ - tile.getPos().getZ() >= .875;
else if (facing == EnumFacing.WEST)
contact = entity.posX - tile.getPos().getX() <= .125;
else if (facing == EnumFacing.EAST)
contact = entity.posX - tile.getPos().getX() >= .875;
if (this.diagonal && entity.posY - tile.getPos().getY() <= .625) {
long time = System.currentTimeMillis();
String hash = Integer.toHexString(tile.getPos().hashCode());
if (entity.width > 0.75 || entity.height > 0.75) {
double py = entity.height > 1 ? tile.getPos().getY() - (entity.height - 1) : entity.posY;
entity.setPosition(entity.posX + facing.getXOffset(), py, entity.posZ + facing.getZOffset());
} else {
if (entity.motionY == 0)
entity.motionY = 0.015;
entity.motionX = facing.getXOffset();
entity.motionZ = facing.getZOffset();
}
if (!contact && (!entity.getEntityData().hasKey(NBT_POS) || !hash.equals(entity.getEntityData().getString(NBT_POS)) || time - entity.getEntityData().getLong(NBT_TIME) > 1000)) {
tile.getWorld().playSound(null, entity.posX, entity.posY, entity.posZ, IESounds.chute, SoundCategory.BLOCKS, .6f + (.4f * tile.getWorld().rand.nextFloat()), .5f + (.5f * tile.getWorld().rand.nextFloat()));
entity.getEntityData().setString(NBT_POS, hash);
entity.getEntityData().setLong(NBT_TIME, time);
}
}
if (entity instanceof EntityItem) {
EntityItem item = (EntityItem) entity;
item.setPickupDelay(10);
if (!contact) {
// misnamed, actually sets despawn timer to 10 minutes
item.setNoDespawn();
ConveyorHandler.applyMagnetSupression(entity, (IConveyorTile) tile);
} else {
TileEntity inventoryTile = Utils.getExistingTileEntity(tile.getWorld(), diagonal ? tile.getPos().offset(facing) : tile.getPos().down());
if (!(inventoryTile instanceof IConveyorTile)) {
ConveyorHandler.revertMagnetSupression(entity, (IConveyorTile) tile);
if (!tile.getWorld().isRemote && inventoryTile != null) {
ItemStack stack = item.getItem();
if (!stack.isEmpty()) {
ItemStack ret = Utils.insertStackIntoInventory(inventoryTile, stack, diagonal ? facing.getOpposite() : EnumFacing.UP);
if (ret.isEmpty())
entity.setDead();
else if (ret.getCount() < stack.getCount())
item.setItem(ret);
}
}
}
}
}
}
use of blusunrize.immersiveengineering.api.tool.ConveyorHandler.IConveyorTile in project ImmersiveEngineering by BluSunrize.
the class ConveyorVertical method getDirection.
@Override
public Vec3d getDirection(TileEntity conveyorTile, Entity entity, EnumFacing facing) {
BlockPos posWall = conveyorTile.getPos().offset(facing);
double d = .625 + entity.width;
double distToWall = Math.abs((facing.getAxis() == Axis.Z ? posWall.getZ() : posWall.getX()) + .5 - (facing.getAxis() == Axis.Z ? entity.posZ : entity.posX));
if (distToWall > d)
return super.getDirection(conveyorTile, entity, facing);
double vBase = entity instanceof EntityLivingBase ? 1.5 : 1.15;
double distY = Math.abs(conveyorTile.getPos().add(0, 1, 0).getY() + .5 - entity.posY);
double treshold = .9;
boolean contact = distY < treshold;
double vX = entity.motionX;
double vY = 0.1 * vBase;
double vZ = entity.motionZ;
if (entity.motionY < 0)
vY += entity.motionY * .9;
if (!(entity instanceof EntityPlayer)) {
vX = 0.05 * facing.getXOffset();
vZ = 0.05 * facing.getZOffset();
if (facing == EnumFacing.WEST || facing == EnumFacing.EAST) {
if (entity.posZ > conveyorTile.getPos().getZ() + 0.65D)
vZ = -0.1D * vBase;
else if (entity.posZ < conveyorTile.getPos().getZ() + 0.35D)
vZ = 0.1D * vBase;
} else if (facing == EnumFacing.NORTH || facing == EnumFacing.SOUTH) {
if (entity.posX > conveyorTile.getPos().getX() + 0.65D)
vX = -0.1D * vBase;
else if (entity.posX < conveyorTile.getPos().getX() + 0.35D)
vX = 0.1D * vBase;
}
}
// Little boost at the top of a conveyor to help players and minecarts to get off
BlockPos upForward = conveyorTile.getPos().add(0, 1, 0);
if (contact && !(Utils.getExistingTileEntity(conveyorTile.getWorld(), upForward) instanceof IConveyorTile))
vY *= 2.25;
return new Vec3d(vX, vY, vZ);
}
use of blusunrize.immersiveengineering.api.tool.ConveyorHandler.IConveyorTile in project ImmersiveEngineering by BluSunrize.
the class ConveyorVertical method onEntityCollision.
@Override
public void onEntityCollision(TileEntity tile, Entity entity, EnumFacing facing) {
if (!isActive(tile))
return;
BlockPos posWall = tile.getPos().offset(facing);
double d = .625 + entity.width;
double distToWall = Math.abs((facing.getAxis() == Axis.Z ? posWall.getZ() : posWall.getX()) + .5 - (facing.getAxis() == Axis.Z ? entity.posZ : entity.posX));
if (distToWall > d) {
super.onEntityCollision(tile, entity, facing);
return;
}
if (entity != null && !entity.isDead && !(entity instanceof EntityPlayer && entity.isSneaking())) {
double distY = Math.abs(tile.getPos().add(0, 1, 0).getY() + .5 - entity.posY);
double treshold = .9;
boolean contact = distY < treshold;
entity.onGround = false;
if (entity.fallDistance < 3)
entity.fallDistance = 0;
else
entity.fallDistance *= .9;
Vec3d vec = getDirection(tile, entity, facing);
entity.motionX = vec.x;
entity.motionY = vec.y;
entity.motionZ = vec.z;
if (!contact)
ConveyorHandler.applyMagnetSupression(entity, (IConveyorTile) tile);
else {
BlockPos posTop = tile.getPos().add(0, 1, 0);
if (!((tile.getWorld().getTileEntity(posTop) instanceof IConveyorTile) || (tile.getWorld().isAirBlock(posTop) && (tile.getWorld().getTileEntity(posTop.offset(facing)) instanceof IConveyorTile))))
ConveyorHandler.revertMagnetSupression(entity, (IConveyorTile) tile);
}
if (entity instanceof EntityItem) {
EntityItem item = (EntityItem) entity;
if (!contact)
// misnamed, actually sets despawn timer to 10 minutes
item.setNoDespawn();
else {
TileEntity inventoryTile;
inventoryTile = tile.getWorld().getTileEntity(tile.getPos().add(0, 1, 0));
if (!tile.getWorld().isRemote) {
if (inventoryTile != null && !(inventoryTile instanceof IConveyorTile)) {
ItemStack stack = item.getItem();
if (!stack.isEmpty()) {
ItemStack ret = Utils.insertStackIntoInventory(inventoryTile, stack, EnumFacing.DOWN);
if (ret.isEmpty())
entity.setDead();
else if (ret.getCount() < stack.getCount())
item.setItem(ret);
}
}
}
}
}
}
}
Aggregations