Java Code Examples for net.minecraft.util.Tuple#getFirst()

The following examples show how to use net.minecraft.util.Tuple#getFirst() . 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: TabGroup.java    From GregTech with GNU Lesser General Public License v3.0 6 votes vote down vote up
@Override
public boolean mouseClicked(int mouseX, int mouseY, int button) {
    super.mouseClicked(mouseX, mouseY, button);
    Tuple<ITabInfo, int[]> tabOnMouse = getTabOnMouse(mouseX, mouseY);
    if (tabOnMouse != null) {
        ITabInfo tabInfo = tabOnMouse.getFirst();
        int tabIndex = tabInfos.indexOf(tabInfo);
        if (selectedTabIndex != tabIndex) {
            setSelectedTab(tabIndex);
            playButtonClickSound();
            writeClientAction(2, buf -> buf.writeVarInt(tabIndex));
            return true;
        }
    }
    return false;
}
 
Example 2
Source File: ImplRotationNodeWorld.java    From Valkyrien-Skies with Apache License 2.0 6 votes vote down vote up
/**
 * Set the angular velocity for an entire gear train based on the gear ratios.
 *
 * @param start        The node that will get get angular velocity of newOmega.
 * @param newOmega     The new angular velocity of the node start.
 * @param deltaTime    The timestep used in our gear train simulation.
 * @param visitedNodes Nodes that won't have their angular velocity changed.
 */
private void applyNewOmega(IRotationNode start, double newOmega, double deltaTime,
    Set<IRotationNode> visitedNodes) {
    visitedNodes.add(start); // kind of a bad spot to put this

    start.setAngularRotation(
        start.getAngularRotation() + (start.getAngularVelocity() * deltaTime) + (
            (newOmega - start.getAngularVelocity()) * deltaTime / 2D));

    start.setAngularVelocity(newOmega);

    for (Tuple<IRotationNode, EnumFacing> connectedNode : start.connectedTorqueTilesList()) {
        IRotationNode endNode = connectedNode.getFirst();
        EnumFacing exploreDirection = connectedNode.getSecond();
        if (visitedNodes.contains(connectedNode.getFirst())) {
            continue;
        }
        double ratioStart = start.getAngularVelocityRatioFor(exploreDirection).get();
        double ratioEnd = endNode.getAngularVelocityRatioFor(exploreDirection.getOpposite())
            .get();
        double multiplier = -ratioStart / ratioEnd;

        applyNewOmega(endNode, newOmega * multiplier, deltaTime, visitedNodes);
    }
}
 
Example 3
Source File: ImplRotationNodeWorld.java    From Valkyrien-Skies with Apache License 2.0 6 votes vote down vote up
/**
 * Calculate the rotational total energy stored in a gear train (not including any nodes in
 * visitedNodes).
 *
 * @param start
 * @param visitedNodes Nodes we ignore in our calculations.
 * @return
 */
private double calculateTotalEnergy(IRotationNode start, Set<IRotationNode> visitedNodes) {
    visitedNodes.add(start); // kind of a bad spot to put this
    // actual code start
    double totalEnergy = start.getEnergy();
    for (Tuple<IRotationNode, EnumFacing> connectedNode : start.connectedTorqueTilesList()) {
        IRotationNode endNode = connectedNode.getFirst();
        EnumFacing exploreDirection = connectedNode.getSecond();
        if (visitedNodes.contains(connectedNode.getFirst())) {
            continue;
        }
        // double ratioStart = start.getAngularVelocityRatioFor(exploreDirection).get();
        // double ratioEnd = endNode.getAngularVelocityRatioFor(exploreDirection.getOpposite()).get();
        // double multiplier = -ratioStart / ratioEnd;

        totalEnergy += calculateTotalEnergy(endNode, visitedNodes);
    }
    return totalEnergy;
}
 
Example 4
Source File: ImplRotationNodeWorld.java    From Valkyrien-Skies with Apache License 2.0 6 votes vote down vote up
/**
 * Calculate the rotational inertia of the start node with the gear train (not including any
 * nodes in visitedNodes) attached. Reference: https://www.engineersedge.com/motors/gear_drive_system.htm
 *
 * @param start        The node which we calculate the inertia relative to.
 * @param visitedNodes Nodes we ignore in our calculations.
 * @return
 */
private double calculateApparentInertia(IRotationNode start, Set<IRotationNode> visitedNodes) {
    visitedNodes.add(start); // kind of a bad spot to put this
    // actual code start
    double apparentInertia = start.getRotationalInertia();
    for (Tuple<IRotationNode, EnumFacing> connectedNode : start.connectedTorqueTilesList()) {
        IRotationNode endNode = connectedNode.getFirst();
        EnumFacing exploreDirection = connectedNode.getSecond();
        if (visitedNodes.contains(connectedNode.getFirst())) {
            continue;
        }
        double ratioStart = start.getAngularVelocityRatioFor(exploreDirection).get();
        double ratioEnd = endNode.getAngularVelocityRatioFor(exploreDirection.getOpposite())
            .get();
        double multiplier = -ratioStart / ratioEnd;

        apparentInertia += (multiplier * multiplier * calculateApparentInertia(endNode,
            visitedNodes));
    }
    return apparentInertia;
}
 
Example 5
Source File: ImplRotationNodeWorld.java    From Valkyrien-Skies with Apache License 2.0 6 votes vote down vote up
/**
 * Calculate the 'apparent' angular velocity of a gear train (not including any nodes in
 * visitedNodes) relative to start. This probably isn't physically correct, but its good enough
 * for our purposes.
 *
 * @param start        The node we calculate the apparent angular velocity relative to.
 * @param visitedNodes Nodes we ignore in our calculations.
 * @return
 */
private double calculateApparentOmega(IRotationNode start, Set<IRotationNode> visitedNodes) {
    visitedNodes.add(start); // kind of a bad spot to put this
    // actual code start
    double apparentOmega = start.getAngularVelocity();
    for (Tuple<IRotationNode, EnumFacing> connectedNode : start.connectedTorqueTilesList()) {
        IRotationNode endNode = connectedNode.getFirst();
        EnumFacing exploreDirection = connectedNode.getSecond();
        if (visitedNodes.contains(connectedNode.getFirst())) {
            continue;
        }
        double ratioStart = start.getAngularVelocityRatioFor(exploreDirection).get();
        double ratioEnd = endNode.getAngularVelocityRatioFor(exploreDirection.getOpposite())
            .get();
        double multiplier = -ratioStart / ratioEnd;
        apparentOmega += (multiplier * calculateApparentOmega(endNode, visitedNodes));
    }
    return apparentOmega;
}
 
Example 6
Source File: ImplRotationNodeWorld.java    From Valkyrien-Skies with Apache License 2.0 6 votes vote down vote up
/**
 * Calculate the net torque experienced by the gear train (not including any nodes in
 * visitedNodes) relative to start.
 *
 * @param start        The node we calculate the apparent torque relative to.
 * @param visitedNodes Nodes we ignore in our calculations.
 * @return
 */
private double calculateApparentTorque(IRotationNode start, Set<IRotationNode> visitedNodes) {
    visitedNodes.add(start); // kind of a bad spot to put this
    // actual code start
    double apparentTorque = start.calculateInstantaneousTorque(parent);
    for (Tuple<IRotationNode, EnumFacing> connectedNode : start.connectedTorqueTilesList()) {
        IRotationNode endNode = connectedNode.getFirst();
        EnumFacing exploreDirection = connectedNode.getSecond();
        if (visitedNodes.contains(connectedNode.getFirst())) {
            continue;
        }
        double ratioStart = start.getAngularVelocityRatioFor(exploreDirection).get();
        double ratioEnd = endNode.getAngularVelocityRatioFor(exploreDirection.getOpposite())
            .get();
        double multiplier = -ratioStart / ratioEnd;
        apparentTorque += (multiplier * calculateApparentTorque(endNode, visitedNodes));
    }
    return apparentTorque;
}
 
Example 7
Source File: TabGroup.java    From GregTech with GNU Lesser General Public License v3.0 5 votes vote down vote up
@Override
public void drawInForeground(int mouseX, int mouseY) {
    super.drawInForeground(mouseX, mouseY);
    Tuple<ITabInfo, int[]> tabOnMouse = getTabOnMouse(mouseX, mouseY);
    if (tabOnMouse != null) {
        int[] tabSizes = tabOnMouse.getSecond();
        ITabInfo tabInfo = tabOnMouse.getFirst();
        boolean isSelected = tabInfos.get(selectedTabIndex) == tabInfo;
        tabInfo.renderHoverText(tabSizes[0], tabSizes[1], tabSizes[2], tabSizes[3], sizes.getWidth(), sizes.getHeight(), isSelected, mouseX, mouseY);
    }
}
 
Example 8
Source File: WrappedBlockStateImpl.java    From customstuff4 with GNU General Public License v3.0 5 votes vote down vote up
@Override
@SuppressWarnings("unchecked")
public IBlockState createState()
{
    Block block = getBlock();
    if (block != null)
    {
        IBlockState state = block.getDefaultState();

        for (Tuple<String, String> tuple : properties)
        {
            String name = tuple.getFirst();

            Optional<IProperty> prop = getProperty(state, name);
            if (prop.isPresent())
            {
                IProperty property = prop.get();
                state = state.withProperty(property, (Comparable) property.parseValue(tuple.getSecond()).get());
            }
        }

        return state;
    } else
    {
        return null;
    }
}
 
Example 9
Source File: ImplRotationNodeWorld.java    From Valkyrien-Skies with Apache License 2.0 5 votes vote down vote up
/**
 * @param start        The node where we start our traversal of the gear train graph to reset
 *                     the train.
 * @param visitedNodes Nodes that have already been reset.
 */
private void resetGearTrain(IRotationNode start, Set<IRotationNode> visitedNodes) {
    visitedNodes.add(start); // kind of a bad spot to put this
    start.setAngularRotation(0);
    start.setAngularVelocity(0);

    for (Tuple<IRotationNode, EnumFacing> connectedNode : start.connectedTorqueTilesList()) {
        IRotationNode endNode = connectedNode.getFirst();
        if (visitedNodes.contains(connectedNode.getFirst())) {
            continue;
        }
        resetGearTrain(endNode, visitedNodes);
    }
}
 
Example 10
Source File: Sponge.java    From Et-Futurum with The Unlicense 5 votes vote down vote up
private boolean absorb(World world, int x, int y, int z) {
	LinkedList<Tuple> linkedlist = Lists.newLinkedList();
	ArrayList<WorldCoord> arraylist = Lists.newArrayList();
	linkedlist.add(new Tuple(new WorldCoord(x, y, z), 0));
	int i = 0;
	WorldCoord blockpos1;

	while (!linkedlist.isEmpty()) {
		Tuple tuple = linkedlist.poll();
		blockpos1 = (WorldCoord) tuple.getFirst();
		int j = (Integer) tuple.getSecond();

		for (ForgeDirection dir : ForgeDirection.VALID_DIRECTIONS) {
			WorldCoord blockpos2 = blockpos1.add(dir);

			if (world.getBlock(blockpos2.x, blockpos2.y, blockpos2.z).getMaterial() == Material.water) {
				world.setBlockToAir(blockpos2.x, blockpos2.y, blockpos2.z);
				arraylist.add(blockpos2);
				i++;
				if (j < 6)
					linkedlist.add(new Tuple(blockpos2, j + 1));
			}
		}

		if (i > 64)
			break;
	}

	Iterator<WorldCoord> iterator = arraylist.iterator();

	while (iterator.hasNext()) {
		blockpos1 = iterator.next();
		world.notifyBlockOfNeighborChange(blockpos1.x, blockpos1.y, blockpos1.z, Blocks.air);
	}

	return i > 0;
}