net.minecraft.util.MovingObjectPosition.MovingObjectType Java Examples

The following examples show how to use net.minecraft.util.MovingObjectPosition.MovingObjectType. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: HUDRenderer.java    From NotEnoughItems with MIT License 6 votes vote down vote up
public static void renderOverlay() {
    Minecraft mc = Minecraft.getMinecraft();
    if (mc.currentScreen == null &&
            mc.theWorld != null &&
            !mc.gameSettings.keyBindPlayerList.isKeyDown() &&
            NEIClientConfig.getBooleanSetting("world.highlight_tips") &&
            mc.objectMouseOver != null &&
            mc.objectMouseOver.typeOfHit == MovingObjectType.BLOCK) {
        World world = mc.theWorld;
        ArrayList<ItemStack> items = ItemInfo.getIdentifierItems(world, mc.thePlayer, mc.objectMouseOver);
        if (items.isEmpty())
            return;

        int minDamage = Integer.MAX_VALUE;
        ItemStack stack = null;
        for(ItemStack astack : items) {
            if(astack.getItem() != null && astack.getItemDamage() < minDamage) {
                stack = astack;
                minDamage = stack.getItemDamage();
            }
        }

        renderOverlay(stack, ItemInfo.getText(stack, world, mc.thePlayer, mc.objectMouseOver), getPositioning());
    }
}
 
Example #2
Source File: WirelessBolt.java    From WirelessRedstone with MIT License 6 votes vote down vote up
private float rayTraceResistance(Vector3 start, Vector3 end, float prevresistance) {
    MovingObjectPosition mop = world.rayTraceBlocks(start.toVec3D(), end.toVec3D());

    if (mop == null)
        return prevresistance;

    if (mop.typeOfHit == MovingObjectType.BLOCK) {
        Block block = world.getBlock(mop.blockX, mop.blockY, mop.blockZ);
        if (block.isAir(world, mop.blockX, mop.blockY, mop.blockZ))
            return prevresistance;
        
        /*if(Block.blocksList[blockID] instanceof ISpecialResistance) 
        {
            ISpecialResistance isr = (ISpecialResistance) Block.blocksList[blockID];
             return prevresistance + (isr.getSpecialExplosionResistance(world, mop.blockX, mop.blockY, mop.blockZ, 
                     start.x, start.y, start.z, wrapper) + 0.3F);
        } 
        else 
        {*/
        return prevresistance + block.getExplosionResistance(wrapper) + 0.3F;
        //}
    }
    return prevresistance;
}
 
Example #3
Source File: VisNetHandler.java    From Chisel-2 with GNU General Public License v2.0 5 votes vote down vote up
public static boolean canNodeBeSeen(TileVisNode source,TileVisNode target)
{		 
 MovingObjectPosition mop = ThaumcraftApiHelper.rayTraceIgnoringSource(source.getWorldObj(), 
		 Vec3.createVectorHelper(source.xCoord+.5, source.yCoord+.5,source.zCoord+.5),
		 Vec3.createVectorHelper(target.xCoord+.5, target.yCoord+.5,target.zCoord+.5),
		 false, true, false);
 return  mop == null || (mop.typeOfHit==MovingObjectType.BLOCK &&
		 mop.blockX==target.xCoord && mop.blockY==target.yCoord && mop.blockZ==target.zCoord);
}
 
Example #4
Source File: VisNetHandler.java    From GardenCollection with MIT License 5 votes vote down vote up
public static boolean canNodeBeSeen(TileVisNode source,TileVisNode target)
{		 
 MovingObjectPosition mop = ThaumcraftApiHelper.rayTraceIgnoringSource(source.getWorldObj(), 
		 Vec3.createVectorHelper(source.xCoord+.5, source.yCoord+.5,source.zCoord+.5),
		 Vec3.createVectorHelper(target.xCoord+.5, target.yCoord+.5,target.zCoord+.5),
		 false, true, false);
 return  mop == null || (mop.typeOfHit==MovingObjectType.BLOCK &&
		 mop.blockX==target.xCoord && mop.blockY==target.yCoord && mop.blockZ==target.zCoord);
}
 
Example #5
Source File: MouseOverPacket.java    From NBTEdit with GNU General Public License v3.0 5 votes vote down vote up
@Override
public void handleClientSide(EntityPlayer player) {
	MovingObjectPosition pos = Minecraft.getMinecraft().objectMouseOver;
	AbstractPacket packet = null;
	if (pos != null)
		if (pos.entityHit != null)
			packet = new EntityRequestPacket(pos.entityHit.getEntityId());
		else if (pos.typeOfHit == MovingObjectType.BLOCK)
			packet = new TileRequestPacket(pos.blockX, pos.blockY, pos.blockZ);
	if (packet == null) 
		sendMessageToPlayer(player, SECTION_SIGN + "cError - No tile or entity selected");
	else
		NBTEdit.DISPATCHER.sendToServer(packet);
}
 
Example #6
Source File: ItemRockbreakerDrill.java    From Electro-Magic-Tools with GNU General Public License v3.0 5 votes vote down vote up
@Override
public boolean onBlockStartBreak(ItemStack itemstack, int X, int Y, int Z, EntityPlayer player) {
    MovingObjectPosition movingobjectposition = BlockUtils.getTargetBlock(((Entity) (player)).worldObj, player, true);
    if (movingobjectposition != null && movingobjectposition.typeOfHit == MovingObjectType.BLOCK) {
        side = movingobjectposition.sideHit;
    }
    return super.onBlockStartBreak(itemstack, X, Y, Z, player);
}
 
Example #7
Source File: VisNetHandler.java    From ForbiddenMagic with Do What The F*ck You Want To Public License 5 votes vote down vote up
public static boolean canNodeBeSeen(TileVisNode source,TileVisNode target)
{		 
 MovingObjectPosition mop = ThaumcraftApiHelper.rayTraceIgnoringSource(source.getWorldObj(), 
		 Vec3.createVectorHelper(source.xCoord+.5, source.yCoord+.5,source.zCoord+.5),
		 Vec3.createVectorHelper(target.xCoord+.5, target.yCoord+.5,target.zCoord+.5),
		 false, true, false);
 return  mop == null || (mop.typeOfHit==MovingObjectType.BLOCK &&
		 mop.blockX==target.xCoord && mop.blockY==target.yCoord && mop.blockZ==target.zCoord);
}
 
Example #8
Source File: VisNetHandler.java    From PneumaticCraft with GNU General Public License v3.0 5 votes vote down vote up
public static boolean canNodeBeSeen(TileVisNode source,TileVisNode target)
{		 
 MovingObjectPosition mop = ThaumcraftApiHelper.rayTraceIgnoringSource(source.getWorldObj(), 
		 Vec3.createVectorHelper(source.xCoord+.5, source.yCoord+.5,source.zCoord+.5),
		 Vec3.createVectorHelper(target.xCoord+.5, target.yCoord+.5,target.zCoord+.5),
		 false, true, false);
 return  mop == null || (mop.typeOfHit==MovingObjectType.BLOCK &&
		 mop.blockX==target.xCoord && mop.blockY==target.yCoord && mop.blockZ==target.zCoord);
}
 
Example #9
Source File: BlockEnderStorage.java    From EnderStorage with MIT License 4 votes vote down vote up
@SideOnly(Side.CLIENT)
@SubscribeEvent
public void onBlockHighlight(DrawBlockHighlightEvent event) {
    if (event.target.typeOfHit == MovingObjectType.BLOCK && event.player.worldObj.getBlock(event.target.blockX, event.target.blockY, event.target.blockZ) == this)
        RayTracer.retraceBlock(event.player.worldObj, event.player, event.target.blockX, event.target.blockY, event.target.blockZ);
}
 
Example #10
Source File: EntityLivingMetaProvider.java    From OpenPeripheral-Integration with MIT License 4 votes vote down vote up
@Override
public Object getMeta(EntityLivingBase target, Vec3 relativePos) {
	Map<String, Object> map = Maps.newHashMap();

	{
		Map<String, ItemStack> armor = Maps.newHashMap();
		armor.put("boots", target.getEquipmentInSlot(1));
		armor.put("leggings", target.getEquipmentInSlot(2));
		armor.put("chestplate", target.getEquipmentInSlot(3));
		armor.put("helmet", target.getEquipmentInSlot(4));
		map.put("armor", armor);
	}

	map.put("heldItem", target.getEquipmentInSlot(0));

	{
		Map<Object, String> potionEffects = Maps.newHashMap();
		@SuppressWarnings("unchecked")
		Collection<PotionEffect> effects = target.getActivePotionEffects();

		int count = 1;
		for (PotionEffect effect : effects) {
			potionEffects.put(count++, effect.getEffectName());
		}
		map.put("potionEffects", potionEffects);
	}

	map.put("health", target.getHealth());
	map.put("maxHealth", target.getMaxHealth());
	map.put("isAirborne", target.isAirBorne);
	map.put("isBurning", target.isBurning());
	map.put("isAlive", target.isEntityAlive());
	map.put("isInWater", target.isInWater());
	map.put("isOnLadder", target.isOnLadder());
	map.put("isSleeping", target.isPlayerSleeping());
	map.put("isRiding", target.isRiding());
	map.put("isSneaking", target.isSneaking());
	map.put("isSprinting", target.isSprinting());
	map.put("isWet", target.isWet());
	map.put("isChild", target.isChild());
	map.put("isDead", target.isDead);
	map.put("yaw", target.rotationYaw);
	map.put("pitch", target.rotationPitch);
	map.put("yawHead", target.rotationYawHead);

	{
		Vec3 posVec = Vec3.createVectorHelper(target.posX, target.posY + 1.62F, target.posZ);
		Vec3 lookVec = target.getLook(1.0f);
		Vec3 targetVec = posVec.addVector(lookVec.xCoord * 10f, lookVec.yCoord * 10f, lookVec.zCoord * 10f);

		MovingObjectPosition mop = target.worldObj.rayTraceBlocks(posVec, targetVec);

		if (mop != null) {
			Map<String, Object> hit = Maps.newHashMap();
			if (mop.typeOfHit == MovingObjectType.BLOCK) {
				hit.put("type", "block");
				Map<String, Object> lookingAt = Maps.newHashMap();
				if (relativePos != null) {
					lookingAt.put("x", mop.blockX - relativePos.xCoord);
					lookingAt.put("y", mop.blockY - relativePos.yCoord);
					lookingAt.put("z", mop.blockZ - relativePos.zCoord);
				} else {
					lookingAt.put("x", mop.blockX);
					lookingAt.put("y", mop.blockY);
					lookingAt.put("z", mop.blockZ);
				}
				hit.put("position", lookingAt);
			} else if (mop.typeOfHit == MovingObjectType.ENTITY) {
				hit.put("type", "entity");
				hit.put("id", mop.entityHit.getEntityId());
			}

			map.put("lookingAt", hit);
		}
	}

	map.put("potion_effects", getPotionEffects(target));

	return map;
}
 
Example #11
Source File: BlockMoving.java    From Framez with GNU General Public License v3.0 4 votes vote down vote up
@SubscribeEvent
@SideOnly(Side.CLIENT)
public void onDrawHighlight(DrawBlockHighlightEvent event) {

    if (event == null || event.context == null || event.currentItem == null || event.player == null || event.target == null
            || event.target.typeOfHit != MovingObjectType.BLOCK)
        return;

    if (drawingHighlight)
        return;

    drawingHighlight = true;

    try {
        TileMoving te = get(event.player.worldObj, event.target.blockX, event.target.blockY, event.target.blockZ);
        if (te != null) {
            MovingObjectPosition mop = te.rayTrace(event.player);

            if (mop != null && mop.typeOfHit == MovingObjectType.BLOCK) {
                DrawBlockHighlightEvent ev = new DrawBlockHighlightEvent(event.context, event.player, mop, mop.subHit,
                        event.currentItem, event.partialTicks);
                World world = event.player.worldObj;
                World w = null;
                MovingBlock a = te.getBlockA();
                MovingBlock b = te.getBlockB();

                Vec3i pos = null;
                MovingStructure structure = null;
                if (a != null) {
                    w = a.getRenderList() > 0 ? FakeWorld.getFakeWorld(a) : null;
                    pos = new Vec3i(a);
                    structure = a.getStructure();
                } else if (b != null) {
                    w = b.getRenderList() > 0 ? FakeWorld.getFakeWorld(b) : null;
                    pos = new Vec3i(a);
                    structure = b.getStructure();
                }

                if (w != null) {
                    event.player.worldObj = w;

                    GL11.glPushMatrix();
                    {
                        GL11.glTranslated(-pos.getX(), -pos.getY(), -pos.getZ());
                        Vec3d t = structure.getMovement().transform(new Vec3d(pos.getX(), pos.getY(), pos.getZ()),
                                structure.getInterpolatedProgress(Framez.proxy.getFrame() - 1));
                        GL11.glTranslated(t.getX(), t.getY(), t.getZ());
                        MinecraftForge.EVENT_BUS.post(ev);
                    }
                    GL11.glPopMatrix();

                    if (ev.isCanceled())
                        event.setCanceled(true);

                    event.player.worldObj = world;
                }
            }
        }
    } catch (Exception ex) {
        event.setCanceled(false);
    }

    drawingHighlight = false;
}
 
Example #12
Source File: RenderMovementBlocking.java    From Framez with GNU General Public License v3.0 4 votes vote down vote up
@SubscribeEvent
public void onRenderTick(RenderWorldLastEvent event) {

    World world = Minecraft.getMinecraft().theWorld;
    EntityPlayer player = Minecraft.getMinecraft().thePlayer;
    MovingObjectPosition mop = world.rayTraceBlocks(RayTracer.instance().getStartVector(player).toVec3(), RayTracer.instance()
            .getEndVector(player).toVec3());
    ItemStack item = player.getCurrentEquippedItem();
    if (item == null)
        return;
    if (!(item.getItem() instanceof IFramezWrench))
        return;
    if (Minecraft.getMinecraft().gameSettings.hideGUI && Minecraft.getMinecraft().currentScreen == null)
        return;

    double thickness = 1 / 32D;

    GL11.glPushMatrix();
    {
        GL11.glDisable(GL11.GL_TEXTURE_2D);

        Vec3 playerPos = player.getPosition(event.partialTicks);

        GL11.glEnable(GL11.GL_BLEND);
        GL11.glBlendFunc(GL11.GL_SRC_ALPHA, GL11.GL_ONE_MINUS_SRC_ALPHA);

        GL11.glColor4d(1, 1, 1, 1);

        List<TileMotor> l = null;

        if (mop != null && mop.typeOfHit == MovingObjectType.BLOCK) {
            TileEntity te = world.getTileEntity(mop.blockX, mop.blockY, mop.blockZ);
            if (te != null && te instanceof TileMotor) {
                l = new ArrayList<TileMotor>();
                l.add((TileMotor) te);
            }
        }

        if (l == null)
            l = MotorCache.getLoadedMotors();

        for (TileMotor m : l) {
            if (m.getWorldObj() == world) {
                List<Vec3i> blocking = m.getBlocking();
                if (blocking == null || blocking.size() == 0)
                    continue;

                for (Vec3i b : blocking) {
                    double x = b.getX() - playerPos.xCoord;
                    double y = b.getY() - playerPos.yCoord;
                    double z = b.getZ() - playerPos.zCoord;

                    GL11.glPushMatrix();
                    {
                        GL11.glTranslated(x - thickness, y - thickness, z - thickness);
                        GL11.glScaled(1 + (thickness * 2), 1 + (thickness * 2), 1 + (thickness * 2));

                        GL11.glColor4d(1, 0, 0, .25);

                        GL11.glBegin(GL11.GL_QUADS);
                        RenderUtils.drawColoredCube();
                        GL11.glEnd();
                    }
                    GL11.glPopMatrix();

                    GL11.glPushMatrix();
                    {
                        GL11.glDisable(GL11.GL_DEPTH_TEST);
                        GL11.glColor4d(.75, 0, 0, .5);

                        GL11.glLineWidth(2);

                        GL11.glBegin(GL11.GL_LINES);
                        GL11.glVertex3d(m.xCoord - playerPos.xCoord + 0.5, m.yCoord - playerPos.yCoord + 0.5, m.zCoord
                                - playerPos.zCoord + 0.5);
                        GL11.glVertex3d(x + 0.5, y + 0.5, z + 0.5);
                        GL11.glEnd();
                        GL11.glEnable(GL11.GL_DEPTH_TEST);
                    }
                    GL11.glPopMatrix();
                }
            }
        }

        GL11.glDisable(GL11.GL_BLEND);
        GL11.glEnable(GL11.GL_TEXTURE_2D);
    }
    GL11.glPopMatrix();
}
 
Example #13
Source File: BlockCraftingGrid.java    From Translocators with MIT License 4 votes vote down vote up
@SideOnly(Side.CLIENT)
@SubscribeEvent
public void onBlockHighlight(DrawBlockHighlightEvent event) {
    if (event.target.typeOfHit == MovingObjectType.BLOCK && event.player.worldObj.getBlock(event.target.blockX, event.target.blockY, event.target.blockZ) == this)
        RayTracer.retraceBlock(event.player.worldObj, event.player, event.target.blockX, event.target.blockY, event.target.blockZ);
}
 
Example #14
Source File: BlockTranslocator.java    From Translocators with MIT License 4 votes vote down vote up
@SideOnly(Side.CLIENT)
@SubscribeEvent
public void onBlockHighlight(DrawBlockHighlightEvent event) {
    if (event.target.typeOfHit == MovingObjectType.BLOCK && event.player.worldObj.getBlock(event.target.blockX, event.target.blockY, event.target.blockZ) == this)
        RayTracer.retraceBlock(event.player.worldObj, event.player, event.target.blockX, event.target.blockY, event.target.blockZ);
}
 
Example #15
Source File: ItemThorHammer.java    From Electro-Magic-Tools with GNU General Public License v3.0 4 votes vote down vote up
@Override
public ItemStack onItemRightClick(ItemStack itemstack, World world, EntityPlayer player) {
    player.swingItem();
    float f = 1.0F;
    float f1 = player.prevRotationPitch + ((player.rotationPitch - player.prevRotationPitch) * f);
    float f2 = player.prevRotationYaw + ((player.rotationYaw - player.prevRotationYaw) * f);
    double d = player.prevPosX + ((player.posX - player.prevPosX) * f);
    double d1 = (player.prevPosY + ((player.posY - player.prevPosY) * f) + 1.6200000000000001D) - player.yOffset;
    double d2 = player.prevPosZ + ((player.posZ - player.prevPosZ) * f);
    Vec3 vec3d = Vec3.createVectorHelper(d, d1, d2);
    float f3 = MathHelper.cos((-f2 * 0.01745329F) - 3.141593F);
    float f4 = MathHelper.sin((-f2 * 0.01745329F) - 3.141593F);
    float f5 = -MathHelper.cos(-f1 * 0.01745329F);
    float f6 = MathHelper.sin(-f1 * 0.01745329F);
    float f7 = f4 * f5;
    float f8 = f6;
    float f9 = f3 * f5;
    double d3 = 5000D;
    Vec3 vec3d1 = vec3d.addVector(f7 * d3, f8 * d3, f9 * d3);
    MovingObjectPosition movingobjectposition = player.worldObj.rayTraceBlocks(vec3d, vec3d1, true);
    if (movingobjectposition == null) {
        return itemstack;
    }
    if (movingobjectposition.typeOfHit == MovingObjectType.BLOCK) {
        int i = movingobjectposition.blockX;
        int j = movingobjectposition.blockY;
        int k = movingobjectposition.blockZ;
        world.spawnEntityInWorld(new EntityLightningBolt(world, i, j, k));
    } else if (movingobjectposition.typeOfHit == MovingObjectType.ENTITY) {
        Entity entityhit = movingobjectposition.entityHit;
        double x = entityhit.posX;
        double y = entityhit.posY;
        double z = entityhit.posZ;
        world.spawnEntityInWorld(new EntityLightningBolt(world, x, y, z));
    }
    if (player.capabilities.isCreativeMode) {
        return itemstack;
    } else {
        itemstack.damageItem(20, player);
        return itemstack;
    }
}
 
Example #16
Source File: ItemMaterials.java    From Electro-Magic-Tools with GNU General Public License v3.0 4 votes vote down vote up
@Override
public ItemStack onItemRightClick(ItemStack stack, World world, EntityPlayer player) {
    if (stack != null && stack.getItemDamage() == 6) {
        player.swingItem();
        float f = 1.0F;
        float f1 = player.prevRotationPitch + ((player.rotationPitch - player.prevRotationPitch) * f);
        float f2 = player.prevRotationYaw + ((player.rotationYaw - player.prevRotationYaw) * f);
        double d = player.prevPosX + ((player.posX - player.prevPosX) * f);
        double d1 = (player.prevPosY + ((player.posY - player.prevPosY) * f) + 1.6200000000000001D) - player.yOffset;
        double d2 = player.prevPosZ + ((player.posZ - player.prevPosZ) * f);
        Vec3 vec3d = Vec3.createVectorHelper(d, d1, d2);
        float f3 = MathHelper.cos((-f2 * 0.01745329F) - 3.141593F);
        float f4 = MathHelper.sin((-f2 * 0.01745329F) - 3.141593F);
        float f5 = -MathHelper.cos(-f1 * 0.01745329F);
        float f6 = MathHelper.sin(-f1 * 0.01745329F);
        float f7 = f4 * f5;
        float f8 = f6;
        float f9 = f3 * f5;
        double d3 = 5000D;
        Vec3 vec3d1 = vec3d.addVector(f7 * d3, f8 * d3, f9 * d3);
        MovingObjectPosition movingobjectposition = player.worldObj.rayTraceBlocks(vec3d, vec3d1, true);
        if (movingobjectposition == null) {
            return stack;
        }
        if (movingobjectposition.typeOfHit == MovingObjectType.BLOCK) {
            int i = movingobjectposition.blockX;
            int j = movingobjectposition.blockY;
            int k = movingobjectposition.blockZ;
            world.spawnEntityInWorld(new EntityLightningBolt(world, i, j, k));
        } else if (movingobjectposition.typeOfHit == MovingObjectType.ENTITY) {
            Entity entityhit = movingobjectposition.entityHit;
            double x = entityhit.posX;
            double y = entityhit.posY;
            double z = entityhit.posZ;
            world.spawnEntityInWorld(new EntityLightningBolt(world, x, y, z));
        }
        if (player.capabilities.isCreativeMode) {
            return stack;
        } else {
            player.inventory.consumeInventoryItem(this);
            return stack;
        }
    }
    return stack;
}