From d7cb7da7d560d838683f67bc23f1a73897a76edf Mon Sep 17 00:00:00 2001 From: yueh Date: Thu, 8 Dec 2016 18:23:49 +0100 Subject: [PATCH] Added missed file --- .../java/appeng/util/helpers/P2PHelper.java | 60 +++++++++++++++++++ 1 file changed, 60 insertions(+) create mode 100644 src/main/java/appeng/util/helpers/P2PHelper.java diff --git a/src/main/java/appeng/util/helpers/P2PHelper.java b/src/main/java/appeng/util/helpers/P2PHelper.java new file mode 100644 index 00000000..9a4a525c --- /dev/null +++ b/src/main/java/appeng/util/helpers/P2PHelper.java @@ -0,0 +1,60 @@ +/* + * This file is part of Applied Energistics 2. + * Copyright (c) 2013 - 2015, AlgorithmX2, All rights reserved. + * + * Applied Energistics 2 is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * Applied Energistics 2 is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public License + * along with Applied Energistics 2. If not, see . + */ + +package appeng.util.helpers; + + +import com.google.common.base.Preconditions; + +import appeng.api.util.AEColor; + + +public class P2PHelper +{ + + public AEColor[] toColours( short frequency ) + { + final AEColor[] colours = new AEColor[4]; + + for( int i = 0; i < 4; i++ ) + { + int twoBits = ( frequency >> 4 * ( 3 - i ) ) & 0xF; + + colours[i] = AEColor.values()[twoBits]; + } + + return colours; + } + + public short fromColours( AEColor[] colours ) + { + Preconditions.checkArgument( colours.length == 4 ); + + int t = 0; + + for( int i = 0; i < 4; i++ ) + { + int code = colours[3 - i].ordinal() << 4 * i; + + t |= code; + } + + return (short) ( t & 0xFFFF ); + } + +}