chore: format code
This commit is contained in:
parent
5eb9c35623
commit
c7b42f3a94
865 changed files with 117011 additions and 113170 deletions
130
.clang-format
Normal file
130
.clang-format
Normal file
|
@ -0,0 +1,130 @@
|
|||
---
|
||||
AccessModifierOffset: 0
|
||||
AlignAfterOpenBracket: BlockIndent
|
||||
AlignArrayOfStructures: None
|
||||
AlignConsecutiveAssignments: None
|
||||
AlignConsecutiveMacros: None
|
||||
AlignConsecutiveBitFields: None
|
||||
AlignConsecutiveDeclarations: None
|
||||
AlignEscapedNewlines: DontAlign
|
||||
AlignOperands: DontAlign
|
||||
AlignTrailingComments: false
|
||||
AllowAllArgumentsOnNextLine: true
|
||||
AllowAllParametersOfDeclarationOnNextLine: true
|
||||
AllowShortBlocksOnASingleLine: Empty
|
||||
AllowShortCaseLabelsOnASingleLine: false
|
||||
AllowShortEnumsOnASingleLine: false
|
||||
AllowShortFunctionsOnASingleLine: Empty
|
||||
AllowShortIfStatementsOnASingleLine: Never
|
||||
AllowShortLambdasOnASingleLine: All
|
||||
AllowShortLoopsOnASingleLine: false
|
||||
AlwaysBreakAfterReturnType: None
|
||||
AlwaysBreakBeforeMultilineStrings: true
|
||||
AlwaysBreakTemplateDeclarations: MultiLine
|
||||
AttributeMacros: []
|
||||
BinPackArguments: false
|
||||
BinPackParameters: false
|
||||
BitFieldColonSpacing: After
|
||||
BraceWrapping:
|
||||
AfterCaseLabel: false
|
||||
AfterClass: false
|
||||
AfterControlStatement: Never
|
||||
AfterEnum: false
|
||||
AfterFunction: false
|
||||
AfterNamespace: false
|
||||
AfterStruct: false
|
||||
AfterUnion: false
|
||||
AfterExternBlock: false
|
||||
BeforeCatch: false
|
||||
BeforeElse: false
|
||||
BeforeLambdaBody: false
|
||||
BeforeWhile: false
|
||||
IndentBraces: false
|
||||
SplitEmptyFunction: false
|
||||
SplitEmptyRecord: false
|
||||
SplitEmptyNamespace: false
|
||||
BreakAfterJavaFieldAnnotations: true
|
||||
#BreakArrays: false
|
||||
BreakBeforeBinaryOperators: All
|
||||
BreakBeforeBraces: Custom
|
||||
BreakBeforeConceptDeclarations: true
|
||||
BreakBeforeTernaryOperators: true
|
||||
BreakConstructorInitializers: AfterColon
|
||||
BreakInheritanceList: AfterColon
|
||||
BreakStringLiterals: true
|
||||
ColumnLimit: 90
|
||||
CompactNamespaces: false
|
||||
ConstructorInitializerIndentWidth: 4
|
||||
ContinuationIndentWidth: 4
|
||||
Cpp11BracedListStyle: false
|
||||
DeriveLineEnding: false
|
||||
DerivePointerAlignment: false
|
||||
DisableFormat: false # wtf
|
||||
EmptyLineAfterAccessModifier: Never
|
||||
EmptyLineBeforeAccessModifier: Always
|
||||
ExperimentalAutoDetectBinPacking: false
|
||||
FixNamespaceComments: false
|
||||
ForEachMacros: ["BOOST_FOREACH"]
|
||||
IfMacros: []
|
||||
IncludeBlocks: Regroup
|
||||
IndentAccessModifiers: false
|
||||
IndentCaseBlocks: false
|
||||
IndentCaseLabels: true
|
||||
IndentExternBlock: Indent
|
||||
IndentGotoLabels: true
|
||||
IndentPPDirectives: BeforeHash
|
||||
#IndentRequiresClause: false
|
||||
IndentWidth: 4
|
||||
IndentWrappedFunctionNames: false
|
||||
#InsertBraces: false
|
||||
InsertTrailingCommas: Wrapped
|
||||
JavaImportGroups: ["java"]
|
||||
JavaScriptQuotes: Double
|
||||
JavaScriptWrapImports: true
|
||||
KeepEmptyLinesAtTheStartOfBlocks: false
|
||||
LambdaBodyIndentation: OuterScope
|
||||
MaxEmptyLinesToKeep: 1
|
||||
NamespaceIndentation: All
|
||||
PackConstructorInitializers: NextLine
|
||||
PointerAlignment: Left
|
||||
QualifierAlignment: Left
|
||||
ReferenceAlignment: Left
|
||||
ReflowComments: true
|
||||
#RemoveSemicolon: true
|
||||
#RequiresClausePosition: OwnLine
|
||||
#RequiresExpressionIndentation: OuterScope
|
||||
SeparateDefinitionBlocks: Always
|
||||
SortIncludes: CaseInsensitive
|
||||
SortJavaStaticImport: Before
|
||||
SortUsingDeclarations: true
|
||||
SpaceAfterCStyleCast: true
|
||||
SpaceAfterLogicalNot: false
|
||||
SpaceAfterTemplateKeyword: false
|
||||
SpaceAroundPointerQualifiers: After
|
||||
SpaceBeforeAssignmentOperators: true
|
||||
SpaceBeforeCaseColon: false
|
||||
SpaceBeforeCpp11BracedList: false
|
||||
SpaceBeforeCtorInitializerColon: false
|
||||
SpaceBeforeInheritanceColon: false
|
||||
SpaceBeforeParens: ControlStatementsExceptControlMacros
|
||||
SpaceBeforeRangeBasedForLoopColon: true
|
||||
SpaceBeforeSquareBrackets: false
|
||||
SpaceInEmptyBlock: false
|
||||
SpaceInEmptyParentheses: false
|
||||
SpacesInAngles: Never
|
||||
SpacesInCStyleCastParentheses: false
|
||||
SpacesInConditionalStatement: false
|
||||
SpacesInContainerLiterals: false
|
||||
SpacesInLineCommentPrefix:
|
||||
Minimum: 0
|
||||
Maximum: -1
|
||||
SpacesInParentheses: false
|
||||
SpacesInSquareBrackets: false
|
||||
Standard: c++20
|
||||
StatementAttributeLikeMacros: []
|
||||
StatementMacros: []
|
||||
TabWidth: 4
|
||||
TypenameMacros: []
|
||||
UseCRLF: false # wtf
|
||||
UseTab: Never
|
||||
WhitespaceSensitiveMacros: ["BOOST_PP_STRINGSIZE"]
|
|
@ -1,11 +1,7 @@
|
|||
package cofh.api;
|
||||
|
||||
public class CoFHAPIProps {
|
||||
|
||||
private CoFHAPIProps() {
|
||||
|
||||
}
|
||||
private CoFHAPIProps() {}
|
||||
|
||||
public static final String VERSION = "1.7.10R1.3.1";
|
||||
|
||||
}
|
||||
|
|
|
@ -3,37 +3,33 @@ package cofh.api.energy;
|
|||
import net.minecraft.nbt.NBTTagCompound;
|
||||
|
||||
/**
|
||||
* Reference implementation of {@link IEnergyStorage}. Use/extend this or implement your own.
|
||||
* Reference implementation of {@link IEnergyStorage}. Use/extend this or implement your
|
||||
* own.
|
||||
*
|
||||
* @author King Lemming
|
||||
*
|
||||
*/
|
||||
public class EnergyStorage implements IEnergyStorage {
|
||||
|
||||
protected int energy;
|
||||
protected int capacity;
|
||||
protected int maxReceive;
|
||||
protected int maxExtract;
|
||||
|
||||
public EnergyStorage(int capacity) {
|
||||
|
||||
this(capacity, capacity, capacity);
|
||||
}
|
||||
|
||||
public EnergyStorage(int capacity, int maxTransfer) {
|
||||
|
||||
this(capacity, maxTransfer, maxTransfer);
|
||||
}
|
||||
|
||||
public EnergyStorage(int capacity, int maxReceive, int maxExtract) {
|
||||
|
||||
this.capacity = capacity;
|
||||
this.maxReceive = maxReceive;
|
||||
this.maxExtract = maxExtract;
|
||||
}
|
||||
|
||||
public EnergyStorage readFromNBT(NBTTagCompound nbt) {
|
||||
|
||||
this.energy = nbt.getInteger("Energy");
|
||||
|
||||
if (energy > capacity) {
|
||||
|
@ -43,7 +39,6 @@ public class EnergyStorage implements IEnergyStorage {
|
|||
}
|
||||
|
||||
public NBTTagCompound writeToNBT(NBTTagCompound nbt) {
|
||||
|
||||
if (energy < 0) {
|
||||
energy = 0;
|
||||
}
|
||||
|
@ -52,7 +47,6 @@ public class EnergyStorage implements IEnergyStorage {
|
|||
}
|
||||
|
||||
public void setCapacity(int capacity) {
|
||||
|
||||
this.capacity = capacity;
|
||||
|
||||
if (energy > capacity) {
|
||||
|
@ -61,39 +55,34 @@ public class EnergyStorage implements IEnergyStorage {
|
|||
}
|
||||
|
||||
public void setMaxTransfer(int maxTransfer) {
|
||||
|
||||
setMaxReceive(maxTransfer);
|
||||
setMaxExtract(maxTransfer);
|
||||
}
|
||||
|
||||
public void setMaxReceive(int maxReceive) {
|
||||
|
||||
this.maxReceive = maxReceive;
|
||||
}
|
||||
|
||||
public void setMaxExtract(int maxExtract) {
|
||||
|
||||
this.maxExtract = maxExtract;
|
||||
}
|
||||
|
||||
public int getMaxReceive() {
|
||||
|
||||
return maxReceive;
|
||||
}
|
||||
|
||||
public int getMaxExtract() {
|
||||
|
||||
return maxExtract;
|
||||
}
|
||||
|
||||
/**
|
||||
* This function is included to allow for server -> client sync. Do not call this externally to the containing Tile Entity, as not all IEnergyHandlers
|
||||
* are guaranteed to have it.
|
||||
* This function is included to allow for server -> client sync. Do not call this
|
||||
* externally to the containing Tile Entity, as not all IEnergyHandlers are guaranteed
|
||||
* to have it.
|
||||
*
|
||||
* @param energy
|
||||
*/
|
||||
public void setEnergyStored(int energy) {
|
||||
|
||||
this.energy = energy;
|
||||
|
||||
if (this.energy > capacity) {
|
||||
|
@ -104,13 +93,13 @@ public class EnergyStorage implements IEnergyStorage {
|
|||
}
|
||||
|
||||
/**
|
||||
* This function is included to allow the containing tile to directly and efficiently modify the energy contained in the EnergyStorage. Do not rely on this
|
||||
* externally, as not all IEnergyHandlers are guaranteed to have it.
|
||||
* This function is included to allow the containing tile to directly and efficiently
|
||||
* modify the energy contained in the EnergyStorage. Do not rely on this externally,
|
||||
* as not all IEnergyHandlers are guaranteed to have it.
|
||||
*
|
||||
* @param energy
|
||||
*/
|
||||
public void modifyEnergyStored(int energy) {
|
||||
|
||||
this.energy += energy;
|
||||
|
||||
if (this.energy > capacity) {
|
||||
|
@ -123,8 +112,8 @@ public class EnergyStorage implements IEnergyStorage {
|
|||
/* IEnergyStorage */
|
||||
@Override
|
||||
public int receiveEnergy(int maxReceive, boolean simulate) {
|
||||
|
||||
int energyReceived = Math.min(capacity - energy, Math.min(this.maxReceive, maxReceive));
|
||||
int energyReceived
|
||||
= Math.min(capacity - energy, Math.min(this.maxReceive, maxReceive));
|
||||
|
||||
if (!simulate) {
|
||||
energy += energyReceived;
|
||||
|
@ -134,7 +123,6 @@ public class EnergyStorage implements IEnergyStorage {
|
|||
|
||||
@Override
|
||||
public int extractEnergy(int maxExtract, boolean simulate) {
|
||||
|
||||
int energyExtracted = Math.min(energy, Math.min(this.maxExtract, maxExtract));
|
||||
|
||||
if (!simulate) {
|
||||
|
@ -145,14 +133,11 @@ public class EnergyStorage implements IEnergyStorage {
|
|||
|
||||
@Override
|
||||
public int getEnergyStored() {
|
||||
|
||||
return energy;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getMaxEnergyStored() {
|
||||
|
||||
return capacity;
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -3,19 +3,17 @@ package cofh.api.energy;
|
|||
import net.minecraftforge.common.util.ForgeDirection;
|
||||
|
||||
/**
|
||||
* Implement this interface on TileEntities which should connect to energy transportation blocks. This is intended for blocks which generate energy but do not
|
||||
* accept it; otherwise just use IEnergyHandler.
|
||||
* <p>
|
||||
* Note that {@link IEnergyHandler} is an extension of this.
|
||||
* Implement this interface on TileEntities which should connect to energy transportation
|
||||
* blocks. This is intended for blocks which generate energy but do not accept it;
|
||||
* otherwise just use IEnergyHandler. <p> Note that {@link IEnergyHandler} is an extension
|
||||
* of this.
|
||||
*
|
||||
* @author King Lemming
|
||||
*
|
||||
*/
|
||||
public interface IEnergyConnection {
|
||||
|
||||
/**
|
||||
* Returns TRUE if the TileEntity can connect on a given side.
|
||||
*/
|
||||
boolean canConnectEnergy(ForgeDirection from);
|
||||
|
||||
}
|
||||
|
|
|
@ -3,17 +3,17 @@ package cofh.api.energy;
|
|||
import net.minecraft.item.ItemStack;
|
||||
|
||||
/**
|
||||
* Implement this interface on Item classes that support external manipulation of their internal energy storages.
|
||||
* <p>
|
||||
* A reference implementation is provided {@link ItemEnergyContainer}.
|
||||
* Implement this interface on Item classes that support external manipulation of their
|
||||
* internal energy storages. <p> A reference implementation is provided {@link
|
||||
* ItemEnergyContainer}.
|
||||
*
|
||||
* @author King Lemming
|
||||
*
|
||||
*/
|
||||
public interface IEnergyContainerItem {
|
||||
|
||||
/**
|
||||
* Adds energy to a container item. Returns the quantity of energy that was accepted. This should always return 0 if the item cannot be externally charged.
|
||||
* Adds energy to a container item. Returns the quantity of energy that was accepted.
|
||||
* This should always return 0 if the item cannot be externally charged.
|
||||
*
|
||||
* @param container
|
||||
* ItemStack to be charged.
|
||||
|
@ -21,13 +21,14 @@ public interface IEnergyContainerItem {
|
|||
* Maximum amount of energy to be sent into the item.
|
||||
* @param simulate
|
||||
* If TRUE, the charge will only be simulated.
|
||||
* @return Amount of energy that was (or would have been, if simulated) received by the item.
|
||||
* @return Amount of energy that was (or would have been, if simulated) received by
|
||||
* the item.
|
||||
*/
|
||||
int receiveEnergy(ItemStack container, int maxReceive, boolean simulate);
|
||||
|
||||
/**
|
||||
* Removes energy from a container item. Returns the quantity of energy that was removed. This should always return 0 if the item cannot be externally
|
||||
* discharged.
|
||||
* Removes energy from a container item. Returns the quantity of energy that was
|
||||
* removed. This should always return 0 if the item cannot be externally discharged.
|
||||
*
|
||||
* @param container
|
||||
* ItemStack to be discharged.
|
||||
|
@ -35,7 +36,8 @@ public interface IEnergyContainerItem {
|
|||
* Maximum amount of energy to be extracted from the item.
|
||||
* @param simulate
|
||||
* If TRUE, the discharge will only be simulated.
|
||||
* @return Amount of energy that was (or would have been, if simulated) extracted from the item.
|
||||
* @return Amount of energy that was (or would have been, if simulated) extracted from
|
||||
* the item.
|
||||
*/
|
||||
int extractEnergy(ItemStack container, int maxExtract, boolean simulate);
|
||||
|
||||
|
@ -48,5 +50,4 @@ public interface IEnergyContainerItem {
|
|||
* Get the max amount of energy that can be stored in the container item.
|
||||
*/
|
||||
int getMaxEnergyStored(ItemStack container);
|
||||
|
||||
}
|
||||
|
|
|
@ -3,19 +3,20 @@ package cofh.api.energy;
|
|||
import net.minecraftforge.common.util.ForgeDirection;
|
||||
|
||||
/**
|
||||
* Implement this interface on Tile Entities which should handle energy, generally storing it in one or more internal {@link IEnergyStorage} objects.
|
||||
* <p>
|
||||
* A reference implementation is provided {@link TileEnergyHandler}.
|
||||
* Implement this interface on Tile Entities which should handle energy, generally storing
|
||||
* it in one or more internal {@link IEnergyStorage} objects. <p> A reference
|
||||
* implementation is provided {@link TileEnergyHandler}.
|
||||
*
|
||||
* @author King Lemming
|
||||
*
|
||||
*/
|
||||
public interface IEnergyHandler extends IEnergyProvider, IEnergyReceiver {
|
||||
|
||||
// merely a convenience interface (remove these methods in 1.8; provided here for back-compat via compiler doing things)
|
||||
// merely a convenience interface (remove these methods in 1.8; provided here for
|
||||
// back-compat via compiler doing things)
|
||||
|
||||
/**
|
||||
* Add energy to an IEnergyReceiver, internal distribution is left entirely to the IEnergyReceiver.
|
||||
* Add energy to an IEnergyReceiver, internal distribution is left entirely to the
|
||||
* IEnergyReceiver.
|
||||
*
|
||||
* @param from
|
||||
* Orientation the energy is received from.
|
||||
|
@ -29,7 +30,8 @@ public interface IEnergyHandler extends IEnergyProvider, IEnergyReceiver {
|
|||
int receiveEnergy(ForgeDirection from, int maxReceive, boolean simulate);
|
||||
|
||||
/**
|
||||
* Remove energy from an IEnergyProvider, internal distribution is left entirely to the IEnergyProvider.
|
||||
* Remove energy from an IEnergyProvider, internal distribution is left entirely to
|
||||
* the IEnergyProvider.
|
||||
*
|
||||
* @param from
|
||||
* Orientation the energy is extracted from.
|
||||
|
@ -53,5 +55,4 @@ public interface IEnergyHandler extends IEnergyProvider, IEnergyReceiver {
|
|||
*/
|
||||
@Override
|
||||
int getMaxEnergyStored(ForgeDirection from);
|
||||
|
||||
}
|
||||
|
|
|
@ -3,17 +3,17 @@ package cofh.api.energy;
|
|||
import net.minecraftforge.common.util.ForgeDirection;
|
||||
|
||||
/**
|
||||
* Implement this interface on Tile Entities which should provide energy, generally storing it in one or more internal {@link IEnergyStorage} objects.
|
||||
* <p>
|
||||
* A reference implementation is provided {@link TileEnergyHandler}.
|
||||
* Implement this interface on Tile Entities which should provide energy, generally
|
||||
* storing it in one or more internal {@link IEnergyStorage} objects. <p> A reference
|
||||
* implementation is provided {@link TileEnergyHandler}.
|
||||
*
|
||||
* @author King Lemming
|
||||
*
|
||||
*/
|
||||
public interface IEnergyProvider extends IEnergyConnection {
|
||||
|
||||
/**
|
||||
* Remove energy from an IEnergyProvider, internal distribution is left entirely to the IEnergyProvider.
|
||||
* Remove energy from an IEnergyProvider, internal distribution is left entirely to
|
||||
* the IEnergyProvider.
|
||||
*
|
||||
* @param from
|
||||
* Orientation the energy is extracted from.
|
||||
|
@ -34,5 +34,4 @@ public interface IEnergyProvider extends IEnergyConnection {
|
|||
* Returns the maximum amount of energy that can be stored.
|
||||
*/
|
||||
int getMaxEnergyStored(ForgeDirection from);
|
||||
|
||||
}
|
||||
|
|
|
@ -3,17 +3,17 @@ package cofh.api.energy;
|
|||
import net.minecraftforge.common.util.ForgeDirection;
|
||||
|
||||
/**
|
||||
* Implement this interface on Tile Entities which should receive energy, generally storing it in one or more internal {@link IEnergyStorage} objects.
|
||||
* <p>
|
||||
* A reference implementation is provided {@link TileEnergyHandler}.
|
||||
* Implement this interface on Tile Entities which should receive energy, generally
|
||||
* storing it in one or more internal {@link IEnergyStorage} objects. <p> A reference
|
||||
* implementation is provided {@link TileEnergyHandler}.
|
||||
*
|
||||
* @author King Lemming
|
||||
*
|
||||
*/
|
||||
public interface IEnergyReceiver extends IEnergyConnection {
|
||||
|
||||
/**
|
||||
* Add energy to an IEnergyReceiver, internal distribution is left entirely to the IEnergyReceiver.
|
||||
* Add energy to an IEnergyReceiver, internal distribution is left entirely to the
|
||||
* IEnergyReceiver.
|
||||
*
|
||||
* @param from
|
||||
* Orientation the energy is received from.
|
||||
|
@ -34,5 +34,4 @@ public interface IEnergyReceiver extends IEnergyConnection {
|
|||
* Returns the maximum amount of energy that can be stored.
|
||||
*/
|
||||
int getMaxEnergyStored(ForgeDirection from);
|
||||
|
||||
}
|
||||
|
|
|
@ -10,7 +10,6 @@ package cofh.api.energy;
|
|||
*
|
||||
*/
|
||||
public interface IEnergyStorage {
|
||||
|
||||
/**
|
||||
* Adds energy to the storage. Returns quantity of energy that was accepted.
|
||||
*
|
||||
|
@ -18,7 +17,8 @@ public interface IEnergyStorage {
|
|||
* Maximum amount of energy to be inserted.
|
||||
* @param simulate
|
||||
* If TRUE, the insertion will only be simulated.
|
||||
* @return Amount of energy that was (or would have been, if simulated) accepted by the storage.
|
||||
* @return Amount of energy that was (or would have been, if simulated) accepted by
|
||||
* the storage.
|
||||
*/
|
||||
int receiveEnergy(int maxReceive, boolean simulate);
|
||||
|
||||
|
@ -29,7 +29,8 @@ public interface IEnergyStorage {
|
|||
* Maximum amount of energy to be extracted.
|
||||
* @param simulate
|
||||
* If TRUE, the extraction will only be simulated.
|
||||
* @return Amount of energy that was (or would have been, if simulated) extracted from the storage.
|
||||
* @return Amount of energy that was (or would have been, if simulated) extracted from
|
||||
* the storage.
|
||||
*/
|
||||
int extractEnergy(int maxExtract, boolean simulate);
|
||||
|
||||
|
@ -42,5 +43,4 @@ public interface IEnergyStorage {
|
|||
* Returns the maximum amount of energy that can be stored.
|
||||
*/
|
||||
int getMaxEnergyStored();
|
||||
|
||||
}
|
||||
|
|
|
@ -5,11 +5,11 @@ import net.minecraftforge.common.util.ForgeDirection;
|
|||
/**
|
||||
* Implement this interface on Tile Entities which transport energy.
|
||||
* <p>
|
||||
* This is used to "negotiate" connection types between two separate IEnergyTransports, allowing users to set flow direction and allowing for networks Of
|
||||
* IEnergyTransports to intelligently transfer energy to other networks.
|
||||
* This is used to "negotiate" connection types between two separate IEnergyTransports,
|
||||
* allowing users to set flow direction and allowing for networks Of IEnergyTransports to
|
||||
* intelligently transfer energy to other networks.
|
||||
*/
|
||||
public interface IEnergyTransport extends IEnergyProvider, IEnergyReceiver {
|
||||
|
||||
/**
|
||||
* The type of interface for a given side of a {@link IEnergyTransport}.
|
||||
* <p>
|
||||
|
@ -20,22 +20,25 @@ public interface IEnergyTransport extends IEnergyProvider, IEnergyReceiver {
|
|||
*/
|
||||
public enum InterfaceType {
|
||||
/**
|
||||
* Indicates that this {@link IEnergyTransport} is only sending power on this side.
|
||||
* Indicates that this {@link IEnergyTransport} is only sending power on this
|
||||
* side.
|
||||
*/
|
||||
SEND,
|
||||
/**
|
||||
* Indicates that this {@link IEnergyTransport} is only receiving power on this side.
|
||||
* Indicates that this {@link IEnergyTransport} is only receiving power on this
|
||||
* side.
|
||||
*/
|
||||
RECEIVE,
|
||||
/**
|
||||
* Indicates that this {@link IEnergyTransport} wants to balance power between itself and the
|
||||
* senders/receivers on this side. This is the default state.<br>
|
||||
* Indicates that this {@link IEnergyTransport} wants to balance power between
|
||||
* itself and the senders/receivers on this side. This is the default state.<br>
|
||||
* To block any connection, use {@link IEnergyConnection#canConnectEnergy}
|
||||
* <p>
|
||||
* IEnergyTransport based senders should check that the total power in the destination IEnergyTransport is less than the power in themselves before sending.
|
||||
* <br>
|
||||
* Active IEnergyTransport receivers (i.e., those that call {@link IEnergyProvider#extractEnergy}) should check that they contain less power than the
|
||||
* source IEnergyTransport.
|
||||
* IEnergyTransport based senders should check that the total power in the
|
||||
* destination IEnergyTransport is less than the power in themselves before
|
||||
* sending. <br> Active IEnergyTransport receivers (i.e., those that call {@link
|
||||
* IEnergyProvider#extractEnergy}) should check that they contain less power than
|
||||
* the source IEnergyTransport.
|
||||
*/
|
||||
BALANCE;
|
||||
|
||||
|
@ -46,26 +49,27 @@ public interface IEnergyTransport extends IEnergyProvider, IEnergyReceiver {
|
|||
* {@link #SEND} is the opposite of {@link #RECEIVE} and visa versa.
|
||||
*/
|
||||
public InterfaceType getOpposite() {
|
||||
|
||||
return this == BALANCE ? BALANCE : this == SEND ? RECEIVE : SEND;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the next InterfaceType as described in {@link IEnergyTransport#getTransportState}
|
||||
* Returns the next InterfaceType as described in {@link
|
||||
* IEnergyTransport#getTransportState}
|
||||
*/
|
||||
public InterfaceType rotate() {
|
||||
|
||||
return rotate(true);
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the next InterfaceType as described in {@link IEnergyTransport#getTransportState}
|
||||
* Returns the next InterfaceType as described in {@link
|
||||
* IEnergyTransport#getTransportState}
|
||||
*
|
||||
* @param forward
|
||||
* Whether to step in the order specified by {@link IEnergyTransport#getTransportState} (<tt>true</tt>) or to step in the opposite direction
|
||||
* Whether to step in the order specified by {@link
|
||||
* IEnergyTransport#getTransportState} (<tt>true</tt>) or to step in the opposite
|
||||
* direction
|
||||
*/
|
||||
public InterfaceType rotate(boolean forward) {
|
||||
|
||||
if (forward) {
|
||||
return this == BALANCE ? RECEIVE : this == RECEIVE ? SEND : BALANCE;
|
||||
} else {
|
||||
|
@ -82,28 +86,27 @@ public interface IEnergyTransport extends IEnergyProvider, IEnergyReceiver {
|
|||
int getEnergyStored(ForgeDirection from);
|
||||
|
||||
/**
|
||||
* Indicates to other IEnergyTransports the state of the given side. See {@link #InterfaceType} for details.
|
||||
* <p>
|
||||
* For clarity of state tracking, on a tile update from another IEnergyTransport, if its mode has changed from the opposite of your own mode on that side, you
|
||||
* should change your mode to the opposite of its mode.
|
||||
* <p>
|
||||
* Indicates to other IEnergyTransports the state of the given side. See {@link
|
||||
* #InterfaceType} for details. <p> For clarity of state tracking, on a tile update
|
||||
* from another IEnergyTransport, if its mode has changed from the opposite of your
|
||||
* own mode on that side, you should change your mode to the opposite of its mode. <p>
|
||||
* When the user alters your mode and your state is:<br>
|
||||
* BALANCE, your mode should change to {@link InterFaceType#RECEIVE}.<br>
|
||||
* RECEIVE, your mode should change to {@link InterFaceType#SEND}.<br>
|
||||
* SEND, your mode should change to {@link InterFaceType#BALANCE}.<br>
|
||||
* This is not required, but will be easier for users.
|
||||
*
|
||||
* @return The type of connection to establish on this side. <b>null is NOT a valid value</b>
|
||||
* @return The type of connection to establish on this side. <b>null is NOT a valid
|
||||
* value</b>
|
||||
*/
|
||||
InterfaceType getTransportState(ForgeDirection from);
|
||||
|
||||
/**
|
||||
* This method is provided primarily for the purposes of automation tools, and should not need to be called by another IEnergyTransport.
|
||||
* <p>
|
||||
* Calls to this method may fail if this IEnergyTransport has been secured by a user.
|
||||
* This method is provided primarily for the purposes of automation tools, and should
|
||||
* not need to be called by another IEnergyTransport. <p> Calls to this method may
|
||||
* fail if this IEnergyTransport has been secured by a user.
|
||||
*
|
||||
* @return Whether or not state was successfully altered.
|
||||
*/
|
||||
boolean setTransportState(InterfaceType state, ForgeDirection from);
|
||||
|
||||
}
|
||||
|
|
|
@ -5,69 +5,60 @@ import net.minecraft.item.ItemStack;
|
|||
import net.minecraft.nbt.NBTTagCompound;
|
||||
|
||||
/**
|
||||
* Reference implementation of {@link IEnergyContainerItem}. Use/extend this or implement your own.
|
||||
* Reference implementation of {@link IEnergyContainerItem}. Use/extend this or implement
|
||||
* your own.
|
||||
*
|
||||
* @author King Lemming
|
||||
*
|
||||
*/
|
||||
public class ItemEnergyContainer extends Item implements IEnergyContainerItem {
|
||||
|
||||
protected int capacity;
|
||||
protected int maxReceive;
|
||||
protected int maxExtract;
|
||||
|
||||
public ItemEnergyContainer() {
|
||||
|
||||
}
|
||||
public ItemEnergyContainer() {}
|
||||
|
||||
public ItemEnergyContainer(int capacity) {
|
||||
|
||||
this(capacity, capacity, capacity);
|
||||
}
|
||||
|
||||
public ItemEnergyContainer(int capacity, int maxTransfer) {
|
||||
|
||||
this(capacity, maxTransfer, maxTransfer);
|
||||
}
|
||||
|
||||
public ItemEnergyContainer(int capacity, int maxReceive, int maxExtract) {
|
||||
|
||||
this.capacity = capacity;
|
||||
this.maxReceive = maxReceive;
|
||||
this.maxExtract = maxExtract;
|
||||
}
|
||||
|
||||
public ItemEnergyContainer setCapacity(int capacity) {
|
||||
|
||||
this.capacity = capacity;
|
||||
return this;
|
||||
}
|
||||
|
||||
public void setMaxTransfer(int maxTransfer) {
|
||||
|
||||
setMaxReceive(maxTransfer);
|
||||
setMaxExtract(maxTransfer);
|
||||
}
|
||||
|
||||
public void setMaxReceive(int maxReceive) {
|
||||
|
||||
this.maxReceive = maxReceive;
|
||||
}
|
||||
|
||||
public void setMaxExtract(int maxExtract) {
|
||||
|
||||
this.maxExtract = maxExtract;
|
||||
}
|
||||
|
||||
/* IEnergyContainerItem */
|
||||
@Override
|
||||
public int receiveEnergy(ItemStack container, int maxReceive, boolean simulate) {
|
||||
|
||||
if (container.stackTagCompound == null) {
|
||||
container.stackTagCompound = new NBTTagCompound();
|
||||
}
|
||||
int energy = container.stackTagCompound.getInteger("Energy");
|
||||
int energyReceived = Math.min(capacity - energy, Math.min(this.maxReceive, maxReceive));
|
||||
int energyReceived
|
||||
= Math.min(capacity - energy, Math.min(this.maxReceive, maxReceive));
|
||||
|
||||
if (!simulate) {
|
||||
energy += energyReceived;
|
||||
|
@ -78,8 +69,8 @@ public class ItemEnergyContainer extends Item implements IEnergyContainerItem {
|
|||
|
||||
@Override
|
||||
public int extractEnergy(ItemStack container, int maxExtract, boolean simulate) {
|
||||
|
||||
if (container.stackTagCompound == null || !container.stackTagCompound.hasKey("Energy")) {
|
||||
if (container.stackTagCompound == null
|
||||
|| !container.stackTagCompound.hasKey("Energy")) {
|
||||
return 0;
|
||||
}
|
||||
int energy = container.stackTagCompound.getInteger("Energy");
|
||||
|
@ -94,8 +85,8 @@ public class ItemEnergyContainer extends Item implements IEnergyContainerItem {
|
|||
|
||||
@Override
|
||||
public int getEnergyStored(ItemStack container) {
|
||||
|
||||
if (container.stackTagCompound == null || !container.stackTagCompound.hasKey("Energy")) {
|
||||
if (container.stackTagCompound == null
|
||||
|| !container.stackTagCompound.hasKey("Energy")) {
|
||||
return 0;
|
||||
}
|
||||
return container.stackTagCompound.getInteger("Energy");
|
||||
|
@ -103,8 +94,6 @@ public class ItemEnergyContainer extends Item implements IEnergyContainerItem {
|
|||
|
||||
@Override
|
||||
public int getMaxEnergyStored(ItemStack container) {
|
||||
|
||||
return capacity;
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -5,25 +5,23 @@ import net.minecraft.tileentity.TileEntity;
|
|||
import net.minecraftforge.common.util.ForgeDirection;
|
||||
|
||||
/**
|
||||
* Reference implementation of {@link IEnergyHandler}. Use/extend this or implement your own.
|
||||
* Reference implementation of {@link IEnergyHandler}. Use/extend this or implement your
|
||||
* own.
|
||||
*
|
||||
* @author King Lemming
|
||||
*
|
||||
*/
|
||||
public class TileEnergyHandler extends TileEntity implements IEnergyHandler {
|
||||
|
||||
protected EnergyStorage storage = new EnergyStorage(32000);
|
||||
|
||||
@Override
|
||||
public void readFromNBT(NBTTagCompound nbt) {
|
||||
|
||||
super.readFromNBT(nbt);
|
||||
storage.readFromNBT(nbt);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void writeToNBT(NBTTagCompound nbt) {
|
||||
|
||||
super.writeToNBT(nbt);
|
||||
storage.writeToNBT(nbt);
|
||||
}
|
||||
|
@ -31,35 +29,29 @@ public class TileEnergyHandler extends TileEntity implements IEnergyHandler {
|
|||
/* IEnergyConnection */
|
||||
@Override
|
||||
public boolean canConnectEnergy(ForgeDirection from) {
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
/* IEnergyReceiver */
|
||||
@Override
|
||||
public int receiveEnergy(ForgeDirection from, int maxReceive, boolean simulate) {
|
||||
|
||||
return storage.receiveEnergy(maxReceive, simulate);
|
||||
}
|
||||
|
||||
/* IEnergyProvider */
|
||||
@Override
|
||||
public int extractEnergy(ForgeDirection from, int maxExtract, boolean simulate) {
|
||||
|
||||
return storage.extractEnergy(maxExtract, simulate);
|
||||
}
|
||||
|
||||
/* IEnergyReceiver and IEnergyProvider */
|
||||
@Override
|
||||
public int getEnergyStored(ForgeDirection from) {
|
||||
|
||||
return storage.getEnergyStored();
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getMaxEnergyStored(ForgeDirection from) {
|
||||
|
||||
return storage.getMaxEnergyStored();
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -7,4 +7,3 @@ package cofh.api.energy;
|
|||
|
||||
import cofh.api.CoFHAPIProps;
|
||||
import cpw.mods.fml.common.API;
|
||||
|
||||
|
|
|
@ -5,7 +5,6 @@ import java.util.Set;
|
|||
import net.minecraft.item.ItemStack;
|
||||
|
||||
public interface IAugmentItem {
|
||||
|
||||
/**
|
||||
* Get the augmentation level for a given Augment and Augment Type.
|
||||
*
|
||||
|
@ -13,7 +12,8 @@ public interface IAugmentItem {
|
|||
* ItemStack representing the Augment.
|
||||
* @param type
|
||||
* String containing the Augment type name.
|
||||
* @return The Augment level of the stack for the requested type - 0 if it does not affect that attribute.
|
||||
* @return The Augment level of the stack for the requested type - 0 if it does not
|
||||
* affect that attribute.
|
||||
*/
|
||||
int getAugmentLevel(ItemStack stack, String type);
|
||||
|
||||
|
@ -22,8 +22,8 @@ public interface IAugmentItem {
|
|||
*
|
||||
* @param stack
|
||||
* ItemStack representing the Augment.
|
||||
* @return Set of the Augmentation Types. Should return an empty set if there are none (but this would be really stupid to make). DO NOT RETURN NULL.
|
||||
* @return Set of the Augmentation Types. Should return an empty set if there are none
|
||||
* (but this would be really stupid to make). DO NOT RETURN NULL.
|
||||
*/
|
||||
Set<String> getAugmentTypes(ItemStack stack);
|
||||
|
||||
}
|
||||
|
|
|
@ -4,14 +4,13 @@ import net.minecraft.entity.player.EntityPlayer;
|
|||
import net.minecraft.item.ItemStack;
|
||||
|
||||
/**
|
||||
* Implement this interface on Item classes which may be "Empowered" - what that means is completely up to you. This just provides a uniform way of dealing with
|
||||
* them.
|
||||
* Implement this interface on Item classes which may be "Empowered" - what that means is
|
||||
* completely up to you. This just provides a uniform way of dealing with them.
|
||||
*
|
||||
* @author King Lemming
|
||||
*
|
||||
*/
|
||||
public interface IEmpowerableItem {
|
||||
|
||||
/**
|
||||
* Check whether or not a given item is currently in an empowered state.
|
||||
*/
|
||||
|
@ -37,5 +36,4 @@ public interface IEmpowerableItem {
|
|||
* The item being held.
|
||||
*/
|
||||
void onStateChange(EntityPlayer player, ItemStack stack);
|
||||
|
||||
}
|
||||
|
|
|
@ -11,10 +11,8 @@ import net.minecraft.item.ItemStack;
|
|||
*
|
||||
*/
|
||||
public interface IInventoryContainerItem {
|
||||
|
||||
/**
|
||||
* Get the size of this inventory of this container item.
|
||||
*/
|
||||
int getSizeInventory(ItemStack container);
|
||||
|
||||
}
|
||||
|
|
|
@ -4,14 +4,13 @@ import net.minecraft.entity.player.EntityPlayer;
|
|||
import net.minecraft.item.ItemStack;
|
||||
|
||||
/**
|
||||
* Implement this interface on Item classes which may be "Empowered" - what that means is completely up to you. This just provides a uniform way of dealing with
|
||||
* them.
|
||||
* Implement this interface on Item classes which may be "Empowered" - what that means is
|
||||
* completely up to you. This just provides a uniform way of dealing with them.
|
||||
*
|
||||
* @author King Lemming
|
||||
*
|
||||
*/
|
||||
public interface IMultiModeItem {
|
||||
|
||||
/**
|
||||
* Get the current mode of an item.
|
||||
*/
|
||||
|
@ -52,5 +51,4 @@ public interface IMultiModeItem {
|
|||
* The item being held.
|
||||
*/
|
||||
void onModeChange(EntityPlayer player, ItemStack stack);
|
||||
|
||||
}
|
||||
|
|
|
@ -4,21 +4,23 @@ import net.minecraft.item.ItemStack;
|
|||
import net.minecraftforge.fluids.FluidStack;
|
||||
|
||||
/**
|
||||
* Implement this interface on subclasses of Item to change how the item works in Thermal Dynamics Fluiducts filter slots.
|
||||
* Implement this interface on subclasses of Item to change how the item works in Thermal
|
||||
* Dynamics Fluiducts filter slots.
|
||||
*
|
||||
* This can be used to create customizable Items which are determined to be "equal" for the purposes of filtering.
|
||||
* This can be used to create customizable Items which are determined to be "equal" for
|
||||
* the purposes of filtering.
|
||||
*/
|
||||
public interface ISpecialFilterFluid {
|
||||
|
||||
/**
|
||||
* This method is called to find out if the given FluidStack should be matched by the given Filter ItemStack.
|
||||
* This method is called to find out if the given FluidStack should be matched by the
|
||||
* given Filter ItemStack.
|
||||
*
|
||||
* @param filter
|
||||
* ItemStack representing the filter.
|
||||
* @param fluid
|
||||
* FluidStack representing the queried fluid.
|
||||
* @return True if the filter should match the FluidStack. False if the default matching should be used.
|
||||
* @return True if the filter should match the FluidStack. False if the default
|
||||
* matching should be used.
|
||||
*/
|
||||
public boolean matchesFluid(ItemStack filter, FluidStack fluid);
|
||||
|
||||
}
|
||||
|
|
|
@ -3,21 +3,23 @@ package cofh.api.item;
|
|||
import net.minecraft.item.ItemStack;
|
||||
|
||||
/**
|
||||
* Implement this interface on subclasses of Item to change how the item works in Thermal Dynamics Itemducts filter slots.
|
||||
* Implement this interface on subclasses of Item to change how the item works in Thermal
|
||||
* Dynamics Itemducts filter slots.
|
||||
*
|
||||
* This can be used to create customizable Items which are determined to be "equal" for the purposes of filtering.
|
||||
* This can be used to create customizable Items which are determined to be "equal" for
|
||||
* the purposes of filtering.
|
||||
*/
|
||||
public interface ISpecialFilterItem {
|
||||
|
||||
/**
|
||||
* This method is called to find out if the given ItemStack should be matched by the given Filter ItemStack.
|
||||
* This method is called to find out if the given ItemStack should be matched by the
|
||||
* given Filter ItemStack.
|
||||
*
|
||||
* @param filter
|
||||
* ItemStack representing the filter.
|
||||
* @param item
|
||||
* ItemStack representing the queried item.
|
||||
* @return True if the filter should match. False if the default matching should be used.
|
||||
* @return True if the filter should match. False if the default matching should be
|
||||
* used.
|
||||
*/
|
||||
public boolean matchesItem(ItemStack filter, ItemStack item);
|
||||
|
||||
}
|
||||
|
|
|
@ -4,15 +4,16 @@ import net.minecraft.entity.EntityLivingBase;
|
|||
import net.minecraft.item.ItemStack;
|
||||
|
||||
/**
|
||||
* Implement this interface on subclasses of Item to have that item work as a tool for CoFH mods.
|
||||
* Implement this interface on subclasses of Item to have that item work as a tool for
|
||||
* CoFH mods.
|
||||
*/
|
||||
public interface IToolHammer {
|
||||
|
||||
/**
|
||||
* Called to ensure that the tool can be used.
|
||||
*
|
||||
* @param item
|
||||
* The itemstack for the tool. Not required to match equipped item (e.g., multi-tools that contain other tools)
|
||||
* The itemstack for the tool. Not required to match equipped item (e.g.,
|
||||
* multi-tools that contain other tools)
|
||||
* @param user
|
||||
* The entity using the tool
|
||||
* @param x
|
||||
|
@ -29,7 +30,8 @@ public interface IToolHammer {
|
|||
* Callback for when the tool has been used reactively.
|
||||
*
|
||||
* @param item
|
||||
* The ItemStack for the tool. Not required to match equipped item (e.g., multi-tools that contain other tools)
|
||||
* The ItemStack for the tool. Not required to match equipped item (e.g.,
|
||||
* multi-tools that contain other tools)
|
||||
* @param user
|
||||
* The entity using the tool
|
||||
* @param x
|
||||
|
@ -40,5 +42,4 @@ public interface IToolHammer {
|
|||
* Z location of the block/tile
|
||||
*/
|
||||
void toolUsed(ItemStack item, EntityLivingBase user, int x, int y, int z);
|
||||
|
||||
}
|
||||
|
|
|
@ -7,4 +7,3 @@ package cofh.api.item;
|
|||
|
||||
import cofh.api.CoFHAPIProps;
|
||||
import cpw.mods.fml.common.API;
|
||||
|
||||
|
|
|
@ -6,4 +6,3 @@
|
|||
package cofh.api;
|
||||
|
||||
import cpw.mods.fml.common.API;
|
||||
|
||||
|
|
|
@ -6,19 +6,20 @@
|
|||
*/
|
||||
package com.jadarstudios.developercapes;
|
||||
|
||||
import java.io.*;
|
||||
import java.net.MalformedURLException;
|
||||
import java.net.URL;
|
||||
import java.net.URLConnection;
|
||||
|
||||
import com.jadarstudios.developercapes.cape.CapeConfig;
|
||||
import com.jadarstudios.developercapes.cape.CapeConfigManager;
|
||||
import net.minecraftforge.common.MinecraftForge;
|
||||
import org.apache.logging.log4j.LogManager;
|
||||
import org.apache.logging.log4j.Logger;
|
||||
|
||||
import java.io.*;
|
||||
import java.net.MalformedURLException;
|
||||
import java.net.URL;
|
||||
import java.net.URLConnection;
|
||||
|
||||
/**
|
||||
* DeveloperCapes is a library for Minecraft. It allows developers to quickly add capes for players they specify. DevCapes uses Minecraft Forge.
|
||||
* DeveloperCapes is a library for Minecraft. It allows developers to quickly add capes
|
||||
* for players they specify. DevCapes uses Minecraft Forge.
|
||||
*
|
||||
* @author jadar
|
||||
*/
|
||||
|
@ -47,7 +48,9 @@ public class DevCapes {
|
|||
InputStream is = null;
|
||||
try {
|
||||
URLConnection connection = url.openConnection();
|
||||
connection.setRequestProperty("User-Agent", System.getProperty("java.version"));
|
||||
connection.setRequestProperty(
|
||||
"User-Agent", System.getProperty("java.version")
|
||||
);
|
||||
connection.connect();
|
||||
|
||||
is = connection.getInputStream();
|
||||
|
@ -132,7 +135,9 @@ public class DevCapes {
|
|||
InputStream is = this.getStreamForURL(jsonUrl);
|
||||
|
||||
if (is == null) {
|
||||
DevCapes.logger.error(String.format("Unable to establish a connection to the server, %s", jsonUrl.getHost()));
|
||||
DevCapes.logger.error(String.format(
|
||||
"Unable to establish a connection to the server, %s", jsonUrl.getHost()
|
||||
));
|
||||
return id;
|
||||
}
|
||||
|
||||
|
@ -153,7 +158,6 @@ public class DevCapes {
|
|||
private static void silentClose(InputStream is) {
|
||||
try {
|
||||
is.close();
|
||||
} catch (IOException ignored) {
|
||||
}
|
||||
} catch (IOException ignored) {}
|
||||
}
|
||||
}
|
|
@ -6,13 +6,13 @@
|
|||
*/
|
||||
package com.jadarstudios.developercapes;
|
||||
|
||||
import java.awt.Graphics;
|
||||
import java.awt.image.BufferedImage;
|
||||
|
||||
import cpw.mods.fml.relauncher.Side;
|
||||
import cpw.mods.fml.relauncher.SideOnly;
|
||||
import net.minecraft.client.renderer.IImageBuffer;
|
||||
|
||||
import java.awt.Graphics;
|
||||
import java.awt.image.BufferedImage;
|
||||
|
||||
/**
|
||||
* This class is an implementation of {@link IImageBuffer} that allows capes to be in HD
|
||||
*
|
||||
|
|
|
@ -19,17 +19,18 @@ import net.minecraftforge.client.event.RenderPlayerEvent;
|
|||
* @author jadar
|
||||
*/
|
||||
public class RenderEventHandler {
|
||||
|
||||
@SubscribeEvent
|
||||
public void renderPlayer(RenderPlayerEvent.Specials.Pre event) {
|
||||
AbstractClientPlayer player = (AbstractClientPlayer) event.entityPlayer;
|
||||
|
||||
UserManager manager = UserManager.getInstance();
|
||||
User user = manager.getUser(player.getUniqueID().toString());
|
||||
if (user == null) return;
|
||||
if (user == null)
|
||||
return;
|
||||
|
||||
ICape cape = user.capes.get(0);
|
||||
if (cape == null) return;
|
||||
if (cape == null)
|
||||
return;
|
||||
|
||||
boolean flag = cape.isTextureLoaded(player);
|
||||
if (!flag) {
|
||||
|
|
|
@ -6,11 +6,11 @@
|
|||
*/
|
||||
package com.jadarstudios.developercapes.cape;
|
||||
|
||||
import java.util.HashMap;
|
||||
|
||||
import com.jadarstudios.developercapes.user.Group;
|
||||
import com.jadarstudios.developercapes.user.User;
|
||||
|
||||
import java.util.HashMap;
|
||||
|
||||
/**
|
||||
* The players that need to be outfitted are stored here
|
||||
*
|
||||
|
|
|
@ -6,6 +6,13 @@
|
|||
*/
|
||||
package com.jadarstudios.developercapes.cape;
|
||||
|
||||
import java.io.BufferedReader;
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
import java.io.InputStreamReader;
|
||||
import java.util.BitSet;
|
||||
import java.util.Map;
|
||||
|
||||
import com.google.common.collect.HashBiMap;
|
||||
import com.google.common.primitives.UnsignedBytes;
|
||||
import com.google.gson.Gson;
|
||||
|
@ -17,20 +24,12 @@ import com.jadarstudios.developercapes.user.User;
|
|||
import com.jadarstudios.developercapes.user.UserManager;
|
||||
import org.apache.commons.lang3.ObjectUtils;
|
||||
|
||||
import java.io.BufferedReader;
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
import java.io.InputStreamReader;
|
||||
import java.util.BitSet;
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
* All configs need a manager, this is it.
|
||||
*
|
||||
* @author jadar
|
||||
*/
|
||||
public class CapeConfigManager {
|
||||
|
||||
protected static CapeConfigManager instance;
|
||||
|
||||
protected static BitSet availableIds = new BitSet(256);
|
||||
|
@ -88,7 +87,9 @@ public class CapeConfigManager {
|
|||
|
||||
public static int claimId(int id) throws InvalidCapeConfigIdException {
|
||||
if (id <= 0) {
|
||||
throw new InvalidCapeConfigIdException("The config ID must be a positive non-zero integer");
|
||||
throw new InvalidCapeConfigIdException(
|
||||
"The config ID must be a positive non-zero integer"
|
||||
);
|
||||
}
|
||||
try {
|
||||
UnsignedBytes.checkedCast(id);
|
||||
|
@ -98,7 +99,9 @@ public class CapeConfigManager {
|
|||
|
||||
boolean isRegistered = availableIds.get(id);
|
||||
if (isRegistered) {
|
||||
throw new InvalidCapeConfigIdException(String.format("The config ID %d is already claimed.", id));
|
||||
throw new InvalidCapeConfigIdException(
|
||||
String.format("The config ID %d is already claimed.", id)
|
||||
);
|
||||
}
|
||||
|
||||
availableIds.set(id);
|
||||
|
@ -148,8 +151,9 @@ public class CapeConfigManager {
|
|||
}
|
||||
|
||||
/**
|
||||
* DEPRECATED! Please use {@link com.jadarstudios.developercapes.cape.CapeConfigManager#parse(java.io.InputStream is)}
|
||||
* This will be removed in the next major release.
|
||||
* DEPRECATED! Please use {@link
|
||||
* com.jadarstudios.developercapes.cape.CapeConfigManager#parse(java.io.InputStream
|
||||
* is)} This will be removed in the next major release.
|
||||
*/
|
||||
@Deprecated
|
||||
public CapeConfig parseFromStream(InputStream is) {
|
||||
|
|
|
@ -6,20 +6,19 @@
|
|||
*/
|
||||
package com.jadarstudios.developercapes.cape;
|
||||
|
||||
import com.jadarstudios.developercapes.DevCapes;
|
||||
|
||||
import java.net.MalformedURLException;
|
||||
import java.net.URL;
|
||||
import java.util.Collection;
|
||||
import java.util.HashMap;
|
||||
|
||||
import com.jadarstudios.developercapes.DevCapes;
|
||||
|
||||
/**
|
||||
* This manages all of the capes, be nice to it or you won't get one!
|
||||
*
|
||||
* @author jadar
|
||||
*/
|
||||
public class CapeManager {
|
||||
|
||||
protected static CapeManager instance;
|
||||
|
||||
private HashMap<String, ICape> capes;
|
||||
|
@ -62,7 +61,10 @@ public class CapeManager {
|
|||
if (object instanceof String || object instanceof URL) {
|
||||
cape = parse(name, object.toString());
|
||||
} else {
|
||||
DevCapes.logger.error(String.format("Cape, %s, could not be parsed because it is not in an accepted format!", object));
|
||||
DevCapes.logger.error(String.format(
|
||||
"Cape, %s, could not be parsed because it is not in an accepted format!",
|
||||
object
|
||||
));
|
||||
}
|
||||
return cape;
|
||||
}
|
||||
|
@ -73,7 +75,9 @@ public class CapeManager {
|
|||
try {
|
||||
cape = new StaticCape(name, new URL(url));
|
||||
} catch (MalformedURLException e) {
|
||||
DevCapes.logger.error(String.format("Are you crazy?? \"%s\" is not a valid URL!", url));
|
||||
DevCapes.logger.error(
|
||||
String.format("Are you crazy?? \"%s\" is not a valid URL!", url)
|
||||
);
|
||||
e.printStackTrace();
|
||||
}
|
||||
return cape;
|
||||
|
|
|
@ -16,7 +16,6 @@ import net.minecraft.util.ResourceLocation;
|
|||
* @author jadar
|
||||
*/
|
||||
public interface ICape {
|
||||
|
||||
public String getName();
|
||||
|
||||
public ITextureObject getTexture();
|
||||
|
|
|
@ -6,6 +6,8 @@
|
|||
*/
|
||||
package com.jadarstudios.developercapes.cape;
|
||||
|
||||
import java.net.URL;
|
||||
|
||||
import com.jadarstudios.developercapes.HDImageBuffer;
|
||||
import com.mojang.authlib.minecraft.MinecraftProfileTexture;
|
||||
import net.minecraft.client.Minecraft;
|
||||
|
@ -13,15 +15,12 @@ import net.minecraft.client.entity.AbstractClientPlayer;
|
|||
import net.minecraft.client.renderer.ThreadDownloadImageData;
|
||||
import net.minecraft.util.ResourceLocation;
|
||||
|
||||
import java.net.URL;
|
||||
|
||||
/**
|
||||
* Default Cape implementation
|
||||
*
|
||||
* @author jadar
|
||||
*/
|
||||
public class StaticCape extends AbstractCape {
|
||||
|
||||
public StaticCape(String name, URL url) {
|
||||
this.setName(name);
|
||||
this.setURL(url);
|
||||
|
@ -50,7 +49,9 @@ public class StaticCape extends AbstractCape {
|
|||
this.texture = null;
|
||||
return;
|
||||
}
|
||||
this.texture = new ThreadDownloadImageData(null, url.toString(), null, new HDImageBuffer());
|
||||
this.texture = new ThreadDownloadImageData(
|
||||
null, url.toString(), null, new HDImageBuffer()
|
||||
);
|
||||
}
|
||||
|
||||
public void setName(String name) {
|
||||
|
|
|
@ -6,18 +6,17 @@
|
|||
*/
|
||||
package com.jadarstudios.developercapes.user;
|
||||
|
||||
import com.jadarstudios.developercapes.cape.ICape;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.Set;
|
||||
|
||||
import com.jadarstudios.developercapes.cape.ICape;
|
||||
|
||||
/**
|
||||
* This represents a group of players that share a cape
|
||||
*
|
||||
* @author jadar
|
||||
*/
|
||||
public class Group {
|
||||
|
||||
protected HashMap<String, User> users;
|
||||
protected ICape cape;
|
||||
public final String name;
|
||||
|
|
|
@ -6,21 +6,20 @@
|
|||
*/
|
||||
package com.jadarstudios.developercapes.user;
|
||||
|
||||
import com.jadarstudios.developercapes.DevCapes;
|
||||
import com.jadarstudios.developercapes.cape.CapeManager;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collection;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
import com.jadarstudios.developercapes.DevCapes;
|
||||
import com.jadarstudios.developercapes.cape.CapeManager;
|
||||
|
||||
/**
|
||||
* All groups have to be managed
|
||||
*
|
||||
* @author jadar
|
||||
*/
|
||||
public class GroupManager {
|
||||
|
||||
protected static GroupManager instance;
|
||||
|
||||
private HashMap<String, Group> groups;
|
||||
|
@ -57,7 +56,6 @@ public class GroupManager {
|
|||
return groups.get(capeName);
|
||||
}
|
||||
|
||||
|
||||
public Group newGroup(String name) {
|
||||
if (this.getGroup(name) != null) {
|
||||
return this.getGroup(name);
|
||||
|
@ -73,7 +71,10 @@ public class GroupManager {
|
|||
Object capeUrlObj = data.get("capeUrl");
|
||||
|
||||
if (!(usersObj instanceof ArrayList) || !(capeUrlObj instanceof String)) {
|
||||
DevCapes.logger.error(String.format("Group %s could not be parsed because it either is invalid or missing elements.", name));
|
||||
DevCapes.logger.error(String.format(
|
||||
"Group %s could not be parsed because it either is invalid or missing elements.",
|
||||
name
|
||||
));
|
||||
return null;
|
||||
}
|
||||
|
||||
|
|
|
@ -6,18 +6,17 @@
|
|||
*/
|
||||
package com.jadarstudios.developercapes.user;
|
||||
|
||||
import com.jadarstudios.developercapes.cape.ICape;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
import com.jadarstudios.developercapes.cape.ICape;
|
||||
|
||||
/**
|
||||
* This player is getting their own cape
|
||||
*
|
||||
* @author jadar
|
||||
*/
|
||||
public class User {
|
||||
|
||||
public List<ICape> capes;
|
||||
public final String userUUID;
|
||||
|
||||
|
|
|
@ -6,20 +6,19 @@
|
|||
*/
|
||||
package com.jadarstudios.developercapes.user;
|
||||
|
||||
import java.util.Collection;
|
||||
import java.util.HashMap;
|
||||
|
||||
import com.jadarstudios.developercapes.DevCapes;
|
||||
import com.jadarstudios.developercapes.cape.CapeManager;
|
||||
import com.jadarstudios.developercapes.cape.ICape;
|
||||
|
||||
import java.util.Collection;
|
||||
import java.util.HashMap;
|
||||
|
||||
/**
|
||||
* Users can not be trusted to put capes on by themselves
|
||||
*
|
||||
* @author jadar
|
||||
*/
|
||||
public class UserManager {
|
||||
|
||||
protected static UserManager instance;
|
||||
|
||||
protected HashMap<String, User> users;
|
||||
|
@ -69,12 +68,15 @@ public class UserManager {
|
|||
public User parse(String user, Object cape) {
|
||||
User userInstance = new User(user);
|
||||
|
||||
ICape capeInstance = (cape instanceof ICape) ? (ICape)cape : CapeManager.getInstance().parse(user, cape.toString());
|
||||
ICape capeInstance = (cape instanceof ICape)
|
||||
? (ICape) cape
|
||||
: CapeManager.getInstance().parse(user, cape.toString());
|
||||
|
||||
if (capeInstance != null) {
|
||||
userInstance.capes.add(capeInstance);
|
||||
} else {
|
||||
DevCapes.logger.error(String.format("Error parsing cape, %s", cape.toString()));
|
||||
DevCapes.logger.error(String.format("Error parsing cape, %s", cape.toString())
|
||||
);
|
||||
}
|
||||
|
||||
return userInstance;
|
||||
|
|
|
@ -6,26 +6,25 @@ import net.minecraft.world.World;
|
|||
import net.minecraft.world.chunk.Chunk;
|
||||
|
||||
/**
|
||||
* Chunk3D - an integer-based way to keep track of and perform operations on chunks in a Minecraft-based environment. This also takes
|
||||
* in account the dimension the chunk is in.
|
||||
* Chunk3D - an integer-based way to keep track of and perform operations on chunks in a
|
||||
* Minecraft-based environment. This also takes in account the dimension the chunk is in.
|
||||
* @author aidancbrady
|
||||
*
|
||||
*/
|
||||
public class Chunk3D
|
||||
{
|
||||
public class Chunk3D {
|
||||
public int dimensionId;
|
||||
|
||||
public int xCoord;
|
||||
public int zCoord;
|
||||
|
||||
/**
|
||||
* Creates a Chunk3D object from the given x and z coordinates, as well as a dimension.
|
||||
* Creates a Chunk3D object from the given x and z coordinates, as well as a
|
||||
* dimension.
|
||||
* @param x - chunk x location
|
||||
* @param z - chunk z location
|
||||
* @param dimension - the dimension this Chunk3D is in
|
||||
*/
|
||||
public Chunk3D(int x, int z, int dimension)
|
||||
{
|
||||
public Chunk3D(int x, int z, int dimension) {
|
||||
xCoord = x;
|
||||
zCoord = z;
|
||||
|
||||
|
@ -36,8 +35,7 @@ public class Chunk3D
|
|||
* Creates a Chunk3D from an entity based on it's location and dimension.
|
||||
* @param entity - the entity to get the Chunk3D object from
|
||||
*/
|
||||
public Chunk3D(Entity entity)
|
||||
{
|
||||
public Chunk3D(Entity entity) {
|
||||
xCoord = ((int) entity.posX) >> 4;
|
||||
zCoord = ((int) entity.posZ) >> 4;
|
||||
|
||||
|
@ -48,8 +46,7 @@ public class Chunk3D
|
|||
* Creates a Chunk3D from a Coord4D based on it's coordinates and dimension.
|
||||
* @param coord - the Coord4D object to get this Chunk3D from
|
||||
*/
|
||||
public Chunk3D(Coord4D coord)
|
||||
{
|
||||
public Chunk3D(Coord4D coord) {
|
||||
xCoord = coord.xCoord >> 4;
|
||||
zCoord = coord.zCoord >> 4;
|
||||
|
||||
|
@ -61,8 +58,7 @@ public class Chunk3D
|
|||
* @param world - the world to check in
|
||||
* @return if the chunk exists
|
||||
*/
|
||||
public boolean exists(World world)
|
||||
{
|
||||
public boolean exists(World world) {
|
||||
return world.getChunkProvider().chunkExists(xCoord, zCoord);
|
||||
}
|
||||
|
||||
|
@ -71,8 +67,7 @@ public class Chunk3D
|
|||
* @param world - the world to get the Chunk object from
|
||||
* @return the corresponding Chunk object
|
||||
*/
|
||||
public Chunk getChunk(World world)
|
||||
{
|
||||
public Chunk getChunk(World world) {
|
||||
return world.getChunkFromChunkCoords(xCoord, zCoord);
|
||||
}
|
||||
|
||||
|
@ -80,35 +75,29 @@ public class Chunk3D
|
|||
* Returns this Chunk3D in the Minecraft-based ChunkCoordIntPair format.
|
||||
* @return this Chunk3D as a ChunkCoordIntPair
|
||||
*/
|
||||
public ChunkCoordIntPair toPair()
|
||||
{
|
||||
public ChunkCoordIntPair toPair() {
|
||||
return new ChunkCoordIntPair(xCoord, zCoord);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Chunk3D clone()
|
||||
{
|
||||
public Chunk3D clone() {
|
||||
return new Chunk3D(xCoord, zCoord, dimensionId);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString()
|
||||
{
|
||||
public String toString() {
|
||||
return "[Chunk3D: " + xCoord + ", " + zCoord + ", dim=" + dimensionId + "]";
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean equals(Object obj)
|
||||
{
|
||||
return obj instanceof Chunk3D &&
|
||||
((Chunk3D)obj).xCoord == xCoord &&
|
||||
((Chunk3D)obj).zCoord == zCoord &&
|
||||
((Chunk3D)obj).dimensionId == dimensionId;
|
||||
public boolean equals(Object obj) {
|
||||
return obj instanceof Chunk3D && ((Chunk3D) obj).xCoord == xCoord
|
||||
&& ((Chunk3D) obj).zCoord == zCoord
|
||||
&& ((Chunk3D) obj).dimensionId == dimensionId;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int hashCode()
|
||||
{
|
||||
public int hashCode() {
|
||||
int code = 1;
|
||||
code = 31 * code + xCoord;
|
||||
code = 31 * code + zCoord;
|
||||
|
|
|
@ -1,9 +1,9 @@
|
|||
package mekanism.api;
|
||||
|
||||
import io.netty.buffer.ByteBuf;
|
||||
|
||||
import java.util.ArrayList;
|
||||
|
||||
import cpw.mods.fml.common.network.NetworkRegistry.TargetPoint;
|
||||
import io.netty.buffer.ByteBuf;
|
||||
import net.minecraft.block.Block;
|
||||
import net.minecraft.entity.Entity;
|
||||
import net.minecraft.init.Blocks;
|
||||
|
@ -17,16 +17,15 @@ import net.minecraft.world.IBlockAccess;
|
|||
import net.minecraft.world.World;
|
||||
import net.minecraft.world.chunk.Chunk;
|
||||
import net.minecraftforge.common.util.ForgeDirection;
|
||||
import cpw.mods.fml.common.network.NetworkRegistry.TargetPoint;
|
||||
|
||||
/**
|
||||
* Coord4D - an integer-based way to keep track of and perform operations on blocks in a Minecraft-based environment. This also takes
|
||||
* in account the dimension the coordinate is in.
|
||||
* Coord4D - an integer-based way to keep track of and perform operations on blocks in a
|
||||
* Minecraft-based environment. This also takes in account the dimension the coordinate is
|
||||
* in.
|
||||
* @author aidancbrady
|
||||
*
|
||||
*/
|
||||
public class Coord4D
|
||||
{
|
||||
public class Coord4D {
|
||||
public int xCoord;
|
||||
public int yCoord;
|
||||
public int zCoord;
|
||||
|
@ -39,8 +38,7 @@ public class Coord4D
|
|||
* @param y - y coordinate
|
||||
* @param z - z coordinate
|
||||
*/
|
||||
public Coord4D(int x, int y, int z)
|
||||
{
|
||||
public Coord4D(int x, int y, int z) {
|
||||
xCoord = x;
|
||||
yCoord = y;
|
||||
zCoord = z;
|
||||
|
@ -52,8 +50,7 @@ public class Coord4D
|
|||
* Creates a Coord4D from an entity's position, rounded down.
|
||||
* @param entity - entity to create the Coord4D from
|
||||
*/
|
||||
public Coord4D(Entity entity)
|
||||
{
|
||||
public Coord4D(Entity entity) {
|
||||
xCoord = (int) entity.posX;
|
||||
yCoord = (int) entity.posY;
|
||||
zCoord = (int) entity.posZ;
|
||||
|
@ -68,8 +65,7 @@ public class Coord4D
|
|||
* @param z - z coordinate
|
||||
* @param dimension - dimension ID
|
||||
*/
|
||||
public Coord4D(int x, int y, int z, int dimension)
|
||||
{
|
||||
public Coord4D(int x, int y, int z, int dimension) {
|
||||
xCoord = x;
|
||||
yCoord = y;
|
||||
zCoord = z;
|
||||
|
@ -77,8 +73,7 @@ public class Coord4D
|
|||
dimensionId = dimension;
|
||||
}
|
||||
|
||||
public Coord4D(MovingObjectPosition mop)
|
||||
{
|
||||
public Coord4D(MovingObjectPosition mop) {
|
||||
xCoord = mop.blockX;
|
||||
yCoord = mop.blockY;
|
||||
zCoord = mop.blockZ;
|
||||
|
@ -89,8 +84,7 @@ public class Coord4D
|
|||
* @param world - world this Coord4D is in
|
||||
* @return the metadata of this Coord4D's block
|
||||
*/
|
||||
public int getMetadata(IBlockAccess world)
|
||||
{
|
||||
public int getMetadata(IBlockAccess world) {
|
||||
return world.getBlockMetadata(xCoord, yCoord, zCoord);
|
||||
}
|
||||
|
||||
|
@ -99,10 +93,8 @@ public class Coord4D
|
|||
* @param world - world this Coord4D is in
|
||||
* @return the TileEntity of this Coord4D's block
|
||||
*/
|
||||
public TileEntity getTileEntity(IBlockAccess world)
|
||||
{
|
||||
if(world instanceof World && !exists((World)world))
|
||||
{
|
||||
public TileEntity getTileEntity(IBlockAccess world) {
|
||||
if (world instanceof World && !exists((World) world)) {
|
||||
return null;
|
||||
}
|
||||
|
||||
|
@ -114,10 +106,8 @@ public class Coord4D
|
|||
* @param world - world this Coord4D is in
|
||||
* @return the Block value of this Coord4D's block
|
||||
*/
|
||||
public Block getBlock(IBlockAccess world)
|
||||
{
|
||||
if(world instanceof World && !exists((World)world))
|
||||
{
|
||||
public Block getBlock(IBlockAccess world) {
|
||||
if (world instanceof World && !exists((World) world)) {
|
||||
return null;
|
||||
}
|
||||
|
||||
|
@ -129,8 +119,7 @@ public class Coord4D
|
|||
* @param nbtTags - tag compound to write to
|
||||
* @return the tag compound with this Coord4D's data
|
||||
*/
|
||||
public NBTTagCompound write(NBTTagCompound nbtTags)
|
||||
{
|
||||
public NBTTagCompound write(NBTTagCompound nbtTags) {
|
||||
nbtTags.setInteger("x", xCoord);
|
||||
nbtTags.setInteger("y", yCoord);
|
||||
nbtTags.setInteger("z", zCoord);
|
||||
|
@ -143,8 +132,7 @@ public class Coord4D
|
|||
* Writes this Coord4D's data to an ArrayList for packet transfer.
|
||||
* @param data - the ArrayList to add the data to
|
||||
*/
|
||||
public void write(ArrayList data)
|
||||
{
|
||||
public void write(ArrayList data) {
|
||||
data.add(xCoord);
|
||||
data.add(yCoord);
|
||||
data.add(zCoord);
|
||||
|
@ -155,8 +143,7 @@ public class Coord4D
|
|||
* Writes this Coord4D's data to a ByteBuf for packet transfer.
|
||||
* @param dataStream - the ByteBuf to add the data to
|
||||
*/
|
||||
public void write(ByteBuf dataStream)
|
||||
{
|
||||
public void write(ByteBuf dataStream) {
|
||||
dataStream.writeInt(xCoord);
|
||||
dataStream.writeInt(yCoord);
|
||||
dataStream.writeInt(zCoord);
|
||||
|
@ -170,8 +157,7 @@ public class Coord4D
|
|||
* @param z - z value to translate
|
||||
* @return translated Coord4D
|
||||
*/
|
||||
public Coord4D translate(int x, int y, int z)
|
||||
{
|
||||
public Coord4D translate(int x, int y, int z) {
|
||||
xCoord += x;
|
||||
yCoord += y;
|
||||
zCoord += z;
|
||||
|
@ -180,12 +166,12 @@ public class Coord4D
|
|||
}
|
||||
|
||||
/**
|
||||
* Translates this Coord4D by the defined Coord4D's coordinates, regardless of dimension.
|
||||
* Translates this Coord4D by the defined Coord4D's coordinates, regardless of
|
||||
* dimension.
|
||||
* @param coord - coordinates to translate by
|
||||
* @return translated Coord4D
|
||||
*/
|
||||
public Coord4D translate(Coord4D coord)
|
||||
{
|
||||
public Coord4D translate(Coord4D coord) {
|
||||
translate(coord.xCoord, coord.yCoord, coord.zCoord);
|
||||
|
||||
return this;
|
||||
|
@ -196,28 +182,30 @@ public class Coord4D
|
|||
* @param side - side to translate this Coord4D to
|
||||
* @return translated Coord4D
|
||||
*/
|
||||
public Coord4D getFromSide(ForgeDirection side)
|
||||
{
|
||||
public Coord4D getFromSide(ForgeDirection side) {
|
||||
return getFromSide(side, 1);
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates and returns a new Coord4D translated to the defined offsets of the side by the defined amount.
|
||||
* Creates and returns a new Coord4D translated to the defined offsets of the side by
|
||||
* the defined amount.
|
||||
* @param side - side to translate this Coord4D to
|
||||
* @param amount - how far to translate this Coord4D
|
||||
* @return translated Coord4D
|
||||
*/
|
||||
public Coord4D getFromSide(ForgeDirection side, int amount)
|
||||
{
|
||||
return new Coord4D(xCoord+(side.offsetX*amount), yCoord+(side.offsetY*amount), zCoord+(side.offsetZ*amount), dimensionId);
|
||||
public Coord4D getFromSide(ForgeDirection side, int amount) {
|
||||
return new Coord4D(
|
||||
xCoord + (side.offsetX * amount),
|
||||
yCoord + (side.offsetY * amount),
|
||||
zCoord + (side.offsetZ * amount),
|
||||
dimensionId
|
||||
);
|
||||
}
|
||||
|
||||
public ItemStack getStack(IBlockAccess world)
|
||||
{
|
||||
public ItemStack getStack(IBlockAccess world) {
|
||||
Block block = getBlock(world);
|
||||
|
||||
if(block == null || block == Blocks.air)
|
||||
{
|
||||
if (block == null || block == Blocks.air) {
|
||||
return null;
|
||||
}
|
||||
|
||||
|
@ -229,9 +217,13 @@ public class Coord4D
|
|||
* @param tileEntity - TileEntity at the location that will represent this Coord4D
|
||||
* @return the Coord4D object from the TileEntity
|
||||
*/
|
||||
public static Coord4D get(TileEntity tileEntity)
|
||||
{
|
||||
return new Coord4D(tileEntity.xCoord, tileEntity.yCoord, tileEntity.zCoord, tileEntity.getWorldObj().provider.dimensionId);
|
||||
public static Coord4D get(TileEntity tileEntity) {
|
||||
return new Coord4D(
|
||||
tileEntity.xCoord,
|
||||
tileEntity.yCoord,
|
||||
tileEntity.zCoord,
|
||||
tileEntity.getWorldObj().provider.dimensionId
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -239,9 +231,13 @@ public class Coord4D
|
|||
* @param tag - tag compound to read from
|
||||
* @return the Coord4D from the tag compound
|
||||
*/
|
||||
public static Coord4D read(NBTTagCompound tag)
|
||||
{
|
||||
return new Coord4D(tag.getInteger("x"), tag.getInteger("y"), tag.getInteger("z"), tag.getInteger("id"));
|
||||
public static Coord4D read(NBTTagCompound tag) {
|
||||
return new Coord4D(
|
||||
tag.getInteger("x"),
|
||||
tag.getInteger("y"),
|
||||
tag.getInteger("z"),
|
||||
tag.getInteger("id")
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -249,35 +245,43 @@ public class Coord4D
|
|||
* @param dataStream - data input to read from
|
||||
* @return the Coord4D from the data input
|
||||
*/
|
||||
public static Coord4D read(ByteBuf dataStream)
|
||||
{
|
||||
return new Coord4D(dataStream.readInt(), dataStream.readInt(), dataStream.readInt(), dataStream.readInt());
|
||||
public static Coord4D read(ByteBuf dataStream) {
|
||||
return new Coord4D(
|
||||
dataStream.readInt(),
|
||||
dataStream.readInt(),
|
||||
dataStream.readInt(),
|
||||
dataStream.readInt()
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates and returns a new Coord4D with values representing the difference between the defined Coord4D
|
||||
* Creates and returns a new Coord4D with values representing the difference between
|
||||
* the defined Coord4D
|
||||
* @param other - the Coord4D to subtract from this
|
||||
* @return a Coord4D representing the distance between the defined Coord4D
|
||||
*/
|
||||
public Coord4D difference(Coord4D other)
|
||||
{
|
||||
return new Coord4D(xCoord-other.xCoord, yCoord-other.yCoord, zCoord-other.zCoord, dimensionId);
|
||||
public Coord4D difference(Coord4D other) {
|
||||
return new Coord4D(
|
||||
xCoord - other.xCoord,
|
||||
yCoord - other.yCoord,
|
||||
zCoord - other.zCoord,
|
||||
dimensionId
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* A method used to find the ForgeDirection represented by the distance of the defined Coord4D. Most likely won't have many
|
||||
* applicable uses.
|
||||
* A method used to find the ForgeDirection represented by the distance of the defined
|
||||
* Coord4D. Most likely won't have many applicable uses.
|
||||
* @param other - Coord4D to find the side difference of
|
||||
* @return ForgeDirection representing the side the defined relative Coord4D is on to this
|
||||
* @return ForgeDirection representing the side the defined relative Coord4D is on to
|
||||
* this
|
||||
*/
|
||||
public ForgeDirection sideDifference(Coord4D other)
|
||||
{
|
||||
public ForgeDirection sideDifference(Coord4D other) {
|
||||
Coord4D diff = difference(other);
|
||||
|
||||
for(ForgeDirection side : ForgeDirection.VALID_DIRECTIONS)
|
||||
{
|
||||
if(side.offsetX == diff.xCoord && side.offsetY == diff.yCoord && side.offsetZ == diff.zCoord)
|
||||
{
|
||||
for (ForgeDirection side : ForgeDirection.VALID_DIRECTIONS) {
|
||||
if (side.offsetX == diff.xCoord && side.offsetY == diff.yCoord
|
||||
&& side.offsetZ == diff.zCoord) {
|
||||
return side;
|
||||
}
|
||||
}
|
||||
|
@ -290,8 +294,7 @@ public class Coord4D
|
|||
* @param obj - the Coord4D to find the distance to
|
||||
* @return the distance to the defined Coord4D
|
||||
*/
|
||||
public int distanceTo(Coord4D obj)
|
||||
{
|
||||
public int distanceTo(Coord4D obj) {
|
||||
int subX = xCoord - obj.xCoord;
|
||||
int subY = yCoord - obj.yCoord;
|
||||
int subZ = zCoord - obj.zCoord;
|
||||
|
@ -304,18 +307,19 @@ public class Coord4D
|
|||
* @param world - world this Coord4D is in
|
||||
* @return
|
||||
*/
|
||||
public boolean sideVisible(ForgeDirection side, IBlockAccess world)
|
||||
{
|
||||
return world.isAirBlock(xCoord+side.offsetX, yCoord+side.offsetY, zCoord+side.offsetZ);
|
||||
public boolean sideVisible(ForgeDirection side, IBlockAccess world) {
|
||||
return world.isAirBlock(
|
||||
xCoord + side.offsetX, yCoord + side.offsetY, zCoord + side.offsetZ
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets a TargetPoint with the defined range from this Coord4D with the appropriate coordinates and dimension ID.
|
||||
* Gets a TargetPoint with the defined range from this Coord4D with the appropriate
|
||||
* coordinates and dimension ID.
|
||||
* @param range - the range the packet can be sent in of this Coord4D
|
||||
* @return TargetPoint relative to this Coord4D
|
||||
*/
|
||||
public TargetPoint getTargetPoint(double range)
|
||||
{
|
||||
public TargetPoint getTargetPoint(double range) {
|
||||
return new TargetPoint(dimensionId, xCoord, yCoord, zCoord, range);
|
||||
}
|
||||
|
||||
|
@ -324,8 +328,7 @@ public class Coord4D
|
|||
* @param side - side to step towards
|
||||
* @return this Coord4D
|
||||
*/
|
||||
public Coord4D step(ForgeDirection side)
|
||||
{
|
||||
public Coord4D step(ForgeDirection side) {
|
||||
return translate(side.offsetX, side.offsetY, side.offsetZ);
|
||||
}
|
||||
|
||||
|
@ -334,9 +337,9 @@ public class Coord4D
|
|||
* @param world - world this Coord4D is in
|
||||
* @return the chunk of this Coord4D
|
||||
*/
|
||||
public boolean exists(World world)
|
||||
{
|
||||
return world.getChunkProvider() == null || world.getChunkProvider().chunkExists(xCoord >> 4, zCoord >> 4);
|
||||
public boolean exists(World world) {
|
||||
return world.getChunkProvider() == null
|
||||
|| world.getChunkProvider().chunkExists(xCoord >> 4, zCoord >> 4);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -344,17 +347,16 @@ public class Coord4D
|
|||
* @param world - world this Coord4D is in
|
||||
* @return the chunk of this Coord4D
|
||||
*/
|
||||
public Chunk getChunk(World world)
|
||||
{
|
||||
public Chunk getChunk(World world) {
|
||||
return world.getChunkFromBlockCoords(xCoord, zCoord);
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the Chunk3D object with chunk coordinates correlating to this Coord4D's location
|
||||
* Gets the Chunk3D object with chunk coordinates correlating to this Coord4D's
|
||||
* location
|
||||
* @return Chunk3D with correlating chunk coordinates.
|
||||
*/
|
||||
public Chunk3D getChunk3D()
|
||||
{
|
||||
public Chunk3D getChunk3D() {
|
||||
return new Chunk3D(this);
|
||||
}
|
||||
|
||||
|
@ -363,8 +365,7 @@ public class Coord4D
|
|||
* @param world - world this Coord4D is in
|
||||
* @return if this Coord4D is an air block
|
||||
*/
|
||||
public boolean isAirBlock(IBlockAccess world)
|
||||
{
|
||||
public boolean isAirBlock(IBlockAccess world) {
|
||||
return world.isAirBlock(xCoord, yCoord, zCoord);
|
||||
}
|
||||
|
||||
|
@ -373,8 +374,7 @@ public class Coord4D
|
|||
* @param world - world this Coord4D is in
|
||||
* @return if this Coord4D is replaceable
|
||||
*/
|
||||
public boolean isReplaceable(IBlockAccess world)
|
||||
{
|
||||
public boolean isReplaceable(IBlockAccess world) {
|
||||
return getBlock(world).isReplaceable(world, xCoord, yCoord, zCoord);
|
||||
}
|
||||
|
||||
|
@ -382,36 +382,32 @@ public class Coord4D
|
|||
* Gets a bounding box that contains the area this Coord4D would take up in a world.
|
||||
* @return this Coord4D's bounding box
|
||||
*/
|
||||
public AxisAlignedBB getBoundingBox()
|
||||
{
|
||||
return AxisAlignedBB.getBoundingBox(xCoord, yCoord, zCoord, xCoord+1, yCoord+1, zCoord+1);
|
||||
public AxisAlignedBB getBoundingBox() {
|
||||
return AxisAlignedBB.getBoundingBox(
|
||||
xCoord, yCoord, zCoord, xCoord + 1, yCoord + 1, zCoord + 1
|
||||
);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Coord4D clone()
|
||||
{
|
||||
public Coord4D clone() {
|
||||
return new Coord4D(xCoord, yCoord, zCoord, dimensionId);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString()
|
||||
{
|
||||
return "[Coord4D: " + xCoord + ", " + yCoord + ", " + zCoord + ", dim=" + dimensionId + "]";
|
||||
public String toString() {
|
||||
return "[Coord4D: " + xCoord + ", " + yCoord + ", " + zCoord
|
||||
+ ", dim=" + dimensionId + "]";
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean equals(Object obj)
|
||||
{
|
||||
return obj instanceof Coord4D &&
|
||||
((Coord4D)obj).xCoord == xCoord &&
|
||||
((Coord4D)obj).yCoord == yCoord &&
|
||||
((Coord4D)obj).zCoord == zCoord &&
|
||||
((Coord4D)obj).dimensionId == dimensionId;
|
||||
public boolean equals(Object obj) {
|
||||
return obj instanceof Coord4D && ((Coord4D) obj).xCoord == xCoord
|
||||
&& ((Coord4D) obj).yCoord == yCoord && ((Coord4D) obj).zCoord == zCoord
|
||||
&& ((Coord4D) obj).dimensionId == dimensionId;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int hashCode()
|
||||
{
|
||||
public int hashCode() {
|
||||
int code = 1;
|
||||
code = 31 * code + xCoord;
|
||||
code = 31 * code + yCoord;
|
||||
|
|
|
@ -7,8 +7,7 @@ import net.minecraft.util.StatCollector;
|
|||
* @author AidanBrady
|
||||
*
|
||||
*/
|
||||
public enum EnumColor
|
||||
{
|
||||
public enum EnumColor {
|
||||
BLACK("\u00a70", "black", "Black", new int[] { 0, 0, 0 }, 0),
|
||||
DARK_BLUE("\u00a71", "darkBlue", "Blue", new int[] { 0, 0, 170 }, 4),
|
||||
DARK_GREEN("\u00a72", "darkGreen", "Green", new int[] { 0, 170, 0 }, 2),
|
||||
|
@ -29,7 +28,10 @@ public enum EnumColor
|
|||
BROWN("\u00a76", "brown", "Brown", new int[] { 150, 75, 0 }, 3),
|
||||
BRIGHT_PINK("\u00a7d", "brightPink", "Pink", new int[] { 255, 192, 203 }, 9);
|
||||
|
||||
public static EnumColor[] DYES = new EnumColor[] {BLACK, RED, DARK_GREEN, BROWN, DARK_BLUE, PURPLE, DARK_AQUA, GREY, DARK_GREY, BRIGHT_PINK, BRIGHT_GREEN, YELLOW, INDIGO, PINK, ORANGE, WHITE};
|
||||
public static EnumColor[] DYES = new EnumColor[] {
|
||||
BLACK, RED, DARK_GREEN, BROWN, DARK_BLUE, PURPLE, DARK_AQUA, GREY,
|
||||
DARK_GREY, BRIGHT_PINK, BRIGHT_GREEN, YELLOW, INDIGO, PINK, ORANGE, WHITE
|
||||
};
|
||||
|
||||
/** The color code that will be displayed */
|
||||
public final String code;
|
||||
|
@ -43,8 +45,7 @@ public enum EnumColor
|
|||
|
||||
public String dyeName;
|
||||
|
||||
private EnumColor(String s, String n, String dye, int[] rgb, int meta)
|
||||
{
|
||||
private EnumColor(String s, String n, String dye, int[] rgb, int meta) {
|
||||
code = s;
|
||||
unlocalizedName = n;
|
||||
dyeName = dye;
|
||||
|
@ -56,18 +57,15 @@ public enum EnumColor
|
|||
* Gets the localized name of this color by translating the unlocalized name.
|
||||
* @return localized name
|
||||
*/
|
||||
public String getLocalizedName()
|
||||
{
|
||||
public String getLocalizedName() {
|
||||
return StatCollector.translateToLocal("color." + unlocalizedName);
|
||||
}
|
||||
|
||||
public String getDyeName()
|
||||
{
|
||||
public String getDyeName() {
|
||||
return StatCollector.translateToLocal("dye." + unlocalizedName);
|
||||
}
|
||||
|
||||
public String getOreDictName()
|
||||
{
|
||||
public String getOreDictName() {
|
||||
return dyeName;
|
||||
}
|
||||
|
||||
|
@ -75,38 +73,35 @@ public enum EnumColor
|
|||
* Gets the name of this color with it's color prefix code.
|
||||
* @return the color's name and color prefix
|
||||
*/
|
||||
public String getName()
|
||||
{
|
||||
public String getName() {
|
||||
return code + getLocalizedName();
|
||||
}
|
||||
|
||||
public String getDyedName()
|
||||
{
|
||||
public String getDyedName() {
|
||||
return code + getDyeName();
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the 0-1 of this color's RGB value by dividing by 255 (used for OpenGL coloring).
|
||||
* Gets the 0-1 of this color's RGB value by dividing by 255 (used for OpenGL
|
||||
* coloring).
|
||||
* @param index - R:0, G:1, B:2
|
||||
* @return the color value
|
||||
*/
|
||||
public float getColor(int index)
|
||||
{
|
||||
public float getColor(int index) {
|
||||
return (float) rgbCode[index] / 255F;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the value of this color mapped to MC in-game item colors present in dyes and wool.
|
||||
* Gets the value of this color mapped to MC in-game item colors present in dyes and
|
||||
* wool.
|
||||
* @return mc meta value
|
||||
*/
|
||||
public int getMetaValue()
|
||||
{
|
||||
public int getMetaValue() {
|
||||
return mcMeta;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString()
|
||||
{
|
||||
public String toString() {
|
||||
return code;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -7,12 +7,12 @@ import net.minecraft.entity.player.EntityPlayer;
|
|||
* @author aidancbrady
|
||||
*
|
||||
*/
|
||||
public interface IAlloyInteraction
|
||||
{
|
||||
public interface IAlloyInteraction {
|
||||
/**
|
||||
* Called when a player right-clicks this block with an alloy.
|
||||
* @param player - the player right-clicking the block
|
||||
* @param tierOrdinal - the ordinal tier of the alloy (1 = advanced, 2 = elite, 3 = ultimate)
|
||||
* @param tierOrdinal - the ordinal tier of the alloy (1 = advanced, 2 = elite, 3 =
|
||||
* ultimate)
|
||||
*/
|
||||
public void onAlloyInteraction(EntityPlayer player, int tierOrdinal);
|
||||
}
|
||||
|
|
|
@ -1,7 +1,6 @@
|
|||
package mekanism.api;
|
||||
|
||||
public interface IClientTicker
|
||||
{
|
||||
public interface IClientTicker {
|
||||
public void clientTick();
|
||||
|
||||
public boolean needsTicks();
|
||||
|
|
|
@ -3,30 +3,31 @@ package mekanism.api;
|
|||
import net.minecraft.nbt.NBTTagCompound;
|
||||
|
||||
/**
|
||||
* Implement this in your TileEntity class if you wish for Mekanism filters to be able to store any of their
|
||||
* information.
|
||||
* Implement this in your TileEntity class if you wish for Mekanism filters to be able to
|
||||
* store any of their information.
|
||||
* @author aidancbrady
|
||||
*
|
||||
*/
|
||||
public interface IConfigCardAccess
|
||||
{
|
||||
public static interface ISpecialConfigData extends IConfigCardAccess
|
||||
{
|
||||
public interface IConfigCardAccess {
|
||||
public static interface ISpecialConfigData extends IConfigCardAccess {
|
||||
/**
|
||||
* Collects the TileEntity's filter card data into the parameterized NBTTagCompound.
|
||||
* Collects the TileEntity's filter card data into the parameterized
|
||||
* NBTTagCompound.
|
||||
* @param nbtTags - the NBTTagCompound of the filter card ItemStack
|
||||
* @return the NBTTagCompound that now contains the TileEntity's filter card data
|
||||
*/
|
||||
public NBTTagCompound getConfigurationData(NBTTagCompound nbtTags);
|
||||
|
||||
/**
|
||||
* Retrieves the TileEntity's data contained in the filter card based on the given NBTTagCompopund.
|
||||
* Retrieves the TileEntity's data contained in the filter card based on the given
|
||||
* NBTTagCompopund.
|
||||
* @param nbtTags - the NBTTagCompound of the filter card ItemStack
|
||||
*/
|
||||
public void setConfigurationData(NBTTagCompound nbtTags);
|
||||
|
||||
/**
|
||||
* A String name of this TileEntity that will be displayed as the type of data on the filter card.
|
||||
* A String name of this TileEntity that will be displayed as the type of data on
|
||||
* the filter card.
|
||||
* @return the String name of this TileEntity
|
||||
*/
|
||||
public String getDataType();
|
||||
|
|
|
@ -3,12 +3,12 @@ package mekanism.api;
|
|||
import net.minecraft.entity.player.EntityPlayer;
|
||||
|
||||
/**
|
||||
* Implement this in your TileEntity class if your block can be modified by a Configurator.
|
||||
* Implement this in your TileEntity class if your block can be modified by a
|
||||
* Configurator.
|
||||
* @author aidancbrady
|
||||
*
|
||||
*/
|
||||
public interface IConfigurable
|
||||
{
|
||||
public interface IConfigurable {
|
||||
/**
|
||||
* Called when a player shift-right clicks this block with a Configurator.
|
||||
* @param player - the player who clicked the block
|
||||
|
|
|
@ -1,11 +1,11 @@
|
|||
package mekanism.api;
|
||||
|
||||
/**
|
||||
* Implement this class in a TileEntity if you wish for it to be able to heat up a Salination Plant.
|
||||
* Implement this class in a TileEntity if you wish for it to be able to heat up a
|
||||
* Salination Plant.
|
||||
* @author aidancbrady
|
||||
*
|
||||
*/
|
||||
public interface IEvaporationSolar
|
||||
{
|
||||
public interface IEvaporationSolar {
|
||||
public boolean seesSun();
|
||||
}
|
||||
|
|
|
@ -2,8 +2,7 @@ package mekanism.api;
|
|||
|
||||
import net.minecraftforge.common.util.ForgeDirection;
|
||||
|
||||
public interface IHeatTransfer
|
||||
{
|
||||
public interface IHeatTransfer {
|
||||
/**The value of the zero point of our temperature scale in kelvin*/
|
||||
public static final double AMBIENT_TEMP = 300;
|
||||
|
||||
|
|
|
@ -2,7 +2,6 @@ package mekanism.api;
|
|||
|
||||
import net.minecraft.entity.player.EntityPlayer;
|
||||
|
||||
public interface IMekWrench
|
||||
{
|
||||
public interface IMekWrench {
|
||||
public boolean canUseWrench(EntityPlayer player, int x, int y, int z);
|
||||
}
|
||||
|
|
|
@ -10,8 +10,7 @@ import net.minecraft.item.ItemStack;
|
|||
* @author AidanBrady
|
||||
*
|
||||
*/
|
||||
public final class ItemRetriever
|
||||
{
|
||||
public final class ItemRetriever {
|
||||
/** The 'MekanismItems' class that items are retrieved from. */
|
||||
private static Class MekanismItems;
|
||||
|
||||
|
@ -41,25 +40,24 @@ public final class ItemRetriever
|
|||
* @param identifier - a String to be searched in the 'MekanismItems' class
|
||||
* @return an ItemStack of the declared identifier, otherwise null.
|
||||
*/
|
||||
public static ItemStack getItem(String identifier)
|
||||
{
|
||||
public static ItemStack getItem(String identifier) {
|
||||
try {
|
||||
if(MekanismItems == null)
|
||||
{
|
||||
if (MekanismItems == null) {
|
||||
MekanismItems = Class.forName("mekanism.common.MekanismItems");
|
||||
}
|
||||
|
||||
Object ret = MekanismItems.getField(identifier).get(null);
|
||||
|
||||
if(ret instanceof Item)
|
||||
{
|
||||
if (ret instanceof Item) {
|
||||
return new ItemStack((Item) ret, 1);
|
||||
}
|
||||
else {
|
||||
} else {
|
||||
return null;
|
||||
}
|
||||
} catch (Exception e) {
|
||||
System.err.println("Error retrieving item with identifier '" + identifier + "': " + e.getMessage());
|
||||
System.err.println(
|
||||
"Error retrieving item with identifier '" + identifier
|
||||
+ "': " + e.getMessage()
|
||||
);
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
@ -87,25 +85,24 @@ public final class ItemRetriever
|
|||
* @param identifier - a String to be searched in the 'MekanismBlocks' class
|
||||
* @return an ItemStack of the declared identifier, otherwise null.
|
||||
*/
|
||||
public static ItemStack getBlock(String identifier)
|
||||
{
|
||||
public static ItemStack getBlock(String identifier) {
|
||||
try {
|
||||
if(MekanismBlocks == null)
|
||||
{
|
||||
if (MekanismBlocks == null) {
|
||||
MekanismBlocks = Class.forName("mekanism.common.MekanismBlocks");
|
||||
}
|
||||
|
||||
Object ret = MekanismBlocks.getField(identifier).get(null);
|
||||
|
||||
if(ret instanceof Block)
|
||||
{
|
||||
if (ret instanceof Block) {
|
||||
return new ItemStack((Block) ret, 1);
|
||||
}
|
||||
else {
|
||||
} else {
|
||||
return null;
|
||||
}
|
||||
} catch (Exception e) {
|
||||
System.err.println("Error retrieving block with identifier '" + identifier + "': " + e.getMessage());
|
||||
System.err.println(
|
||||
"Error retrieving block with identifier '" + identifier
|
||||
+ "': " + e.getMessage()
|
||||
);
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -3,26 +3,24 @@ package mekanism.api;
|
|||
import java.util.HashSet;
|
||||
import java.util.Set;
|
||||
|
||||
import cpw.mods.fml.common.eventhandler.Event;
|
||||
import mekanism.api.util.BlockInfo;
|
||||
import net.minecraft.block.Block;
|
||||
import net.minecraft.item.Item;
|
||||
import net.minecraftforge.oredict.OreDictionary;
|
||||
import cpw.mods.fml.common.eventhandler.Event;
|
||||
|
||||
public class MekanismAPI
|
||||
{
|
||||
//Add a BlockInfo value here if you don't want a certain block to be picked up by cardboard boxes
|
||||
public class MekanismAPI {
|
||||
//Add a BlockInfo value here if you don't want a certain block to be picked up by
|
||||
//cardboard boxes
|
||||
private static Set<BlockInfo> cardboardBoxIgnore = new HashSet<BlockInfo>();
|
||||
|
||||
/** Mekanism debug mode */
|
||||
public static boolean debug = false;
|
||||
|
||||
public static boolean isBlockCompatible(Item item, int meta)
|
||||
{
|
||||
for(BlockInfo i : cardboardBoxIgnore)
|
||||
{
|
||||
if(i.block == Block.getBlockFromItem(item) && (i.meta == OreDictionary.WILDCARD_VALUE || i.meta == meta))
|
||||
{
|
||||
public static boolean isBlockCompatible(Item item, int meta) {
|
||||
for (BlockInfo i : cardboardBoxIgnore) {
|
||||
if (i.block == Block.getBlockFromItem(item)
|
||||
&& (i.meta == OreDictionary.WILDCARD_VALUE || i.meta == meta)) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
@ -30,18 +28,15 @@ public class MekanismAPI
|
|||
return true;
|
||||
}
|
||||
|
||||
public static void addBoxBlacklist(Block block, int meta)
|
||||
{
|
||||
public static void addBoxBlacklist(Block block, int meta) {
|
||||
cardboardBoxIgnore.add(new BlockInfo(block, meta));
|
||||
}
|
||||
|
||||
public static void removeBoxBlacklist(Block block, int meta)
|
||||
{
|
||||
public static void removeBoxBlacklist(Block block, int meta) {
|
||||
cardboardBoxIgnore.remove(new BlockInfo(block, meta));
|
||||
}
|
||||
|
||||
public static Set<BlockInfo> getBoxIgnore()
|
||||
{
|
||||
public static Set<BlockInfo> getBoxIgnore() {
|
||||
return cardboardBoxIgnore;
|
||||
}
|
||||
|
||||
|
|
|
@ -6,10 +6,8 @@ import java.util.Map;
|
|||
import mekanism.api.util.UnitDisplayUtils.EnergyType;
|
||||
import mekanism.api.util.UnitDisplayUtils.TempType;
|
||||
|
||||
public class MekanismConfig
|
||||
{
|
||||
public static class general
|
||||
{
|
||||
public class MekanismConfig {
|
||||
public static class general {
|
||||
public static boolean updateNotifications = true;
|
||||
public static boolean controlCircuitOreDict = true;
|
||||
public static boolean logPackets = false;
|
||||
|
@ -76,8 +74,7 @@ public class MekanismConfig
|
|||
public static int elementizerFailChanceMultiplier;
|
||||
}
|
||||
|
||||
public static class client
|
||||
{
|
||||
public static class client {
|
||||
public static boolean enablePlayerSounds = true;
|
||||
public static boolean enableMachineSounds = true;
|
||||
public static boolean holidays = true;
|
||||
|
@ -93,23 +90,19 @@ public class MekanismConfig
|
|||
public static int multiblockSparkleIntensity = 6;
|
||||
}
|
||||
|
||||
public static class machines
|
||||
{
|
||||
public static class machines {
|
||||
private static Map<String, Boolean> config = new HashMap<String, Boolean>();
|
||||
|
||||
public static boolean isEnabled(String type)
|
||||
{
|
||||
public static boolean isEnabled(String type) {
|
||||
return config.get(type) != null && config.get(type);
|
||||
}
|
||||
|
||||
public static void setEntry(String type, boolean enabled)
|
||||
{
|
||||
public static void setEntry(String type, boolean enabled) {
|
||||
config.put(type, enabled);
|
||||
}
|
||||
}
|
||||
|
||||
public static class usage
|
||||
{
|
||||
public static class usage {
|
||||
public static double enrichmentChamberUsage;
|
||||
public static double osmiumCompressorUsage;
|
||||
public static double combinerUsage;
|
||||
|
@ -137,8 +130,7 @@ public class MekanismConfig
|
|||
public static double formulaicAssemblicatorUsage;
|
||||
}
|
||||
|
||||
public static class generators
|
||||
{
|
||||
public static class generators {
|
||||
public static double advancedSolarGeneration;
|
||||
public static double bioGeneration;
|
||||
public static double heatGeneration;
|
||||
|
@ -160,8 +152,7 @@ public class MekanismConfig
|
|||
public static int condenserRate;
|
||||
}
|
||||
|
||||
public static class tools
|
||||
{
|
||||
public static class tools {
|
||||
public static double armorSpawnRate;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -14,40 +14,34 @@ import net.minecraftforge.common.util.ForgeDirection;
|
|||
* @author aidancbrady
|
||||
*
|
||||
*/
|
||||
public class Pos3D
|
||||
{
|
||||
public class Pos3D {
|
||||
public double xPos;
|
||||
public double yPos;
|
||||
public double zPos;
|
||||
|
||||
public Pos3D()
|
||||
{
|
||||
public Pos3D() {
|
||||
this(0, 0, 0);
|
||||
}
|
||||
|
||||
public Pos3D(Vec3 vec)
|
||||
{
|
||||
public Pos3D(Vec3 vec) {
|
||||
xPos = vec.xCoord;
|
||||
yPos = vec.yCoord;
|
||||
zPos = vec.zCoord;
|
||||
}
|
||||
|
||||
public Pos3D(MovingObjectPosition mop)
|
||||
{
|
||||
public Pos3D(MovingObjectPosition mop) {
|
||||
xPos = mop.blockX;
|
||||
yPos = mop.blockY;
|
||||
zPos = mop.blockZ;
|
||||
}
|
||||
|
||||
public Pos3D(double x, double y, double z)
|
||||
{
|
||||
public Pos3D(double x, double y, double z) {
|
||||
xPos = x;
|
||||
yPos = y;
|
||||
zPos = z;
|
||||
}
|
||||
|
||||
public Pos3D(Coord4D coord)
|
||||
{
|
||||
public Pos3D(Coord4D coord) {
|
||||
xPos = coord.xCoord;
|
||||
yPos = coord.yCoord;
|
||||
zPos = coord.zCoord;
|
||||
|
@ -57,8 +51,7 @@ public class Pos3D
|
|||
* Creates a Pos3D with an entity's posX, posY, and posZ values.
|
||||
* @param entity - entity to create the Pos3D from
|
||||
*/
|
||||
public Pos3D(Entity entity)
|
||||
{
|
||||
public Pos3D(Entity entity) {
|
||||
this(entity.posX, entity.posY, entity.posZ);
|
||||
}
|
||||
|
||||
|
@ -66,8 +59,7 @@ public class Pos3D
|
|||
* Creates a Pos3D with a TileEntity's xCoord, yCoord and zCoord values.
|
||||
* @param tileEntity - TileEntity to create the Pos3D from
|
||||
*/
|
||||
public Pos3D(TileEntity tileEntity)
|
||||
{
|
||||
public Pos3D(TileEntity tileEntity) {
|
||||
this(tileEntity.xCoord, tileEntity.yCoord, tileEntity.zCoord);
|
||||
}
|
||||
|
||||
|
@ -76,8 +68,7 @@ public class Pos3D
|
|||
* @param tag - tag compound to read from
|
||||
* @return the Pos3D from the tag compound
|
||||
*/
|
||||
public static Pos3D read(NBTTagCompound tag)
|
||||
{
|
||||
public static Pos3D read(NBTTagCompound tag) {
|
||||
return new Pos3D(tag.getDouble("x"), tag.getDouble("y"), tag.getDouble("z"));
|
||||
}
|
||||
|
||||
|
@ -86,8 +77,7 @@ public class Pos3D
|
|||
* @param nbtTags - tag compound to write to
|
||||
* @return the tag compound with this Pos3D's data
|
||||
*/
|
||||
public NBTTagCompound write(NBTTagCompound nbtTags)
|
||||
{
|
||||
public NBTTagCompound write(NBTTagCompound nbtTags) {
|
||||
nbtTags.setDouble("x", xPos);
|
||||
nbtTags.setDouble("y", yPos);
|
||||
nbtTags.setDouble("z", zPos);
|
||||
|
@ -96,12 +86,12 @@ public class Pos3D
|
|||
}
|
||||
|
||||
/**
|
||||
* Creates and returns a Pos3D with values representing the difference between this and the Pos3D in the parameters.
|
||||
* Creates and returns a Pos3D with values representing the difference between this
|
||||
* and the Pos3D in the parameters.
|
||||
* @param pos - Pos3D to subtract
|
||||
* @return difference of the two Pos3Ds
|
||||
*/
|
||||
public Pos3D diff(Pos3D pos)
|
||||
{
|
||||
public Pos3D diff(Pos3D pos) {
|
||||
return new Pos3D(xPos - pos.xPos, yPos - pos.yPos, zPos - pos.zPos);
|
||||
}
|
||||
|
||||
|
@ -110,8 +100,7 @@ public class Pos3D
|
|||
* @param entity
|
||||
* @return Pos3D representing the motion of the given entity
|
||||
*/
|
||||
public static Pos3D fromMotion(Entity entity)
|
||||
{
|
||||
public static Pos3D fromMotion(Entity entity) {
|
||||
return new Pos3D(entity.motionX, entity.motionY, entity.motionZ);
|
||||
}
|
||||
|
||||
|
@ -120,16 +109,14 @@ public class Pos3D
|
|||
* @param dimensionId - the dimension this Pos3D is in
|
||||
* @return Coord4D representing this Pos3D
|
||||
*/
|
||||
public Coord4D getCoord(int dimensionId)
|
||||
{
|
||||
public Coord4D getCoord(int dimensionId) {
|
||||
return new Coord4D((int) xPos, (int) yPos, (int) zPos, dimensionId);
|
||||
}
|
||||
|
||||
/**
|
||||
* Centres a block-derived Pos3D
|
||||
*/
|
||||
public Pos3D centre()
|
||||
{
|
||||
public Pos3D centre() {
|
||||
return translate(0.5, 0.5, 0.5);
|
||||
}
|
||||
|
||||
|
@ -140,8 +127,7 @@ public class Pos3D
|
|||
* @param z - amount to translate on the z axis
|
||||
* @return the translated Pos3D
|
||||
*/
|
||||
public Pos3D translate(double x, double y, double z)
|
||||
{
|
||||
public Pos3D translate(double x, double y, double z) {
|
||||
xPos += x;
|
||||
yPos += y;
|
||||
zPos += z;
|
||||
|
@ -154,27 +140,33 @@ public class Pos3D
|
|||
* @param pos - Pos3D value to translate by
|
||||
* @return translated Pos3D
|
||||
*/
|
||||
public Pos3D translate(Pos3D pos)
|
||||
{
|
||||
public Pos3D translate(Pos3D pos) {
|
||||
return translate(pos.xPos, pos.yPos, pos.zPos);
|
||||
}
|
||||
|
||||
/**
|
||||
* Performs the same operation as translate(x, y, z), but by a set amount in a ForgeDirection
|
||||
* Performs the same operation as translate(x, y, z), but by a set amount in a
|
||||
* ForgeDirection
|
||||
*/
|
||||
public Pos3D translate(ForgeDirection direction, double amount)
|
||||
{
|
||||
return translate(direction.offsetX * amount, direction.offsetY * amount, direction.offsetZ * amount);
|
||||
public Pos3D translate(ForgeDirection direction, double amount) {
|
||||
return translate(
|
||||
direction.offsetX * amount,
|
||||
direction.offsetY * amount,
|
||||
direction.offsetZ * amount
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Performs the same operation as translate(x, y, z), but by a set amount in a ForgeDirection
|
||||
* Performs the same operation as translate(x, y, z), but by a set amount in a
|
||||
* ForgeDirection
|
||||
*/
|
||||
public Pos3D translateExcludingSide(ForgeDirection direction, double amount)
|
||||
{
|
||||
if(direction.offsetX == 0) xPos += amount;
|
||||
if(direction.offsetY == 0) yPos += amount;
|
||||
if(direction.offsetZ == 0) zPos += amount;
|
||||
public Pos3D translateExcludingSide(ForgeDirection direction, double amount) {
|
||||
if (direction.offsetX == 0)
|
||||
xPos += amount;
|
||||
if (direction.offsetY == 0)
|
||||
yPos += amount;
|
||||
if (direction.offsetZ == 0)
|
||||
zPos += amount;
|
||||
|
||||
return this;
|
||||
}
|
||||
|
@ -184,8 +176,7 @@ public class Pos3D
|
|||
* @param pos - the Pos3D to find the distance to
|
||||
* @return the distance between this and the defined Pos3D
|
||||
*/
|
||||
public double distance(Pos3D pos)
|
||||
{
|
||||
public double distance(Pos3D pos) {
|
||||
double subX = xPos - pos.xPos;
|
||||
double subY = yPos - pos.yPos;
|
||||
double subZ = zPos - pos.zPos;
|
||||
|
@ -197,15 +188,13 @@ public class Pos3D
|
|||
* @param yaw - yaw to rotate by
|
||||
* @return rotated Pos3D
|
||||
*/
|
||||
public Pos3D rotateYaw(double yaw)
|
||||
{
|
||||
public Pos3D rotateYaw(double yaw) {
|
||||
double yawRadians = Math.toRadians(yaw);
|
||||
|
||||
double x = xPos;
|
||||
double z = zPos;
|
||||
|
||||
if(yaw != 0)
|
||||
{
|
||||
if (yaw != 0) {
|
||||
xPos = x * Math.cos(yawRadians) - z * Math.sin(yawRadians);
|
||||
zPos = z * Math.cos(yawRadians) + x * Math.sin(yawRadians);
|
||||
}
|
||||
|
@ -213,15 +202,13 @@ public class Pos3D
|
|||
return this;
|
||||
}
|
||||
|
||||
public Pos3D rotatePitch(double pitch)
|
||||
{
|
||||
public Pos3D rotatePitch(double pitch) {
|
||||
double pitchRadians = Math.toRadians(pitch);
|
||||
|
||||
double y = yPos;
|
||||
double z = zPos;
|
||||
|
||||
if(pitch != 0)
|
||||
{
|
||||
if (pitch != 0) {
|
||||
yPos = y * Math.cos(pitchRadians) - z * Math.sin(pitchRadians);
|
||||
zPos = z * Math.cos(pitchRadians) + y * Math.sin(pitchRadians);
|
||||
}
|
||||
|
@ -229,13 +216,11 @@ public class Pos3D
|
|||
return this;
|
||||
}
|
||||
|
||||
public Pos3D rotate(double yaw, double pitch)
|
||||
{
|
||||
public Pos3D rotate(double yaw, double pitch) {
|
||||
return rotate(yaw, pitch, 0);
|
||||
}
|
||||
|
||||
public Pos3D rotate(double yaw, double pitch, double roll)
|
||||
{
|
||||
public Pos3D rotate(double yaw, double pitch, double roll) {
|
||||
double yawRadians = Math.toRadians(yaw);
|
||||
double pitchRadians = Math.toRadians(pitch);
|
||||
double rollRadians = Math.toRadians(roll);
|
||||
|
@ -244,15 +229,28 @@ public class Pos3D
|
|||
double y = yPos;
|
||||
double z = zPos;
|
||||
|
||||
xPos = x * Math.cos(yawRadians) * Math.cos(pitchRadians) + z * (Math.cos(yawRadians) * Math.sin(pitchRadians) * Math.sin(rollRadians) - Math.sin(yawRadians) * Math.cos(rollRadians)) + y * (Math.cos(yawRadians) * Math.sin(pitchRadians) * Math.cos(rollRadians) + Math.sin(yawRadians) * Math.sin(rollRadians));
|
||||
zPos = x * Math.sin(yawRadians) * Math.cos(pitchRadians) + z * (Math.sin(yawRadians) * Math.sin(pitchRadians) * Math.sin(rollRadians) + Math.cos(yawRadians) * Math.cos(rollRadians)) + y * (Math.sin(yawRadians) * Math.sin(pitchRadians) * Math.cos(rollRadians) - Math.cos(yawRadians) * Math.sin(rollRadians));
|
||||
yPos = -x * Math.sin(pitchRadians) + z * Math.cos(pitchRadians) * Math.sin(rollRadians) + y * Math.cos(pitchRadians) * Math.cos(rollRadians);
|
||||
xPos = x * Math.cos(yawRadians) * Math.cos(pitchRadians)
|
||||
+ z
|
||||
* (Math.cos(yawRadians) * Math.sin(pitchRadians) * Math.sin(rollRadians)
|
||||
- Math.sin(yawRadians) * Math.cos(rollRadians))
|
||||
+ y
|
||||
* (Math.cos(yawRadians) * Math.sin(pitchRadians) * Math.cos(rollRadians)
|
||||
+ Math.sin(yawRadians) * Math.sin(rollRadians));
|
||||
zPos = x * Math.sin(yawRadians) * Math.cos(pitchRadians)
|
||||
+ z
|
||||
* (Math.sin(yawRadians) * Math.sin(pitchRadians) * Math.sin(rollRadians)
|
||||
+ Math.cos(yawRadians) * Math.cos(rollRadians))
|
||||
+ y
|
||||
* (Math.sin(yawRadians) * Math.sin(pitchRadians) * Math.cos(rollRadians)
|
||||
- Math.cos(yawRadians) * Math.sin(rollRadians));
|
||||
yPos = -x * Math.sin(pitchRadians)
|
||||
+ z * Math.cos(pitchRadians) * Math.sin(rollRadians)
|
||||
+ y * Math.cos(pitchRadians) * Math.cos(rollRadians);
|
||||
|
||||
return this;
|
||||
}
|
||||
|
||||
public Pos3D multiply(Pos3D pos)
|
||||
{
|
||||
public Pos3D multiply(Pos3D pos) {
|
||||
xPos *= pos.xPos;
|
||||
yPos *= pos.yPos;
|
||||
zPos *= pos.zPos;
|
||||
|
@ -267,8 +265,7 @@ public class Pos3D
|
|||
* @param z - z value to scale by
|
||||
* @return scaled Pos3D
|
||||
*/
|
||||
public Pos3D scale(double x, double y, double z)
|
||||
{
|
||||
public Pos3D scale(double x, double y, double z) {
|
||||
xPos *= x;
|
||||
yPos *= y;
|
||||
zPos *= z;
|
||||
|
@ -277,22 +274,20 @@ public class Pos3D
|
|||
}
|
||||
|
||||
/**
|
||||
* Performs the same operation as scale(x, y, z), but with a value representing all three dimensions.
|
||||
* Performs the same operation as scale(x, y, z), but with a value representing all
|
||||
* three dimensions.
|
||||
* @param scale - value to scale by
|
||||
* @return scaled Pos3D
|
||||
*/
|
||||
public Pos3D scale(double scale)
|
||||
{
|
||||
public Pos3D scale(double scale) {
|
||||
return scale(scale, scale, scale);
|
||||
}
|
||||
|
||||
public Pos3D rotate(float angle, Pos3D axis)
|
||||
{
|
||||
public Pos3D rotate(float angle, Pos3D axis) {
|
||||
return translateMatrix(getRotationMatrix(angle, axis), this);
|
||||
}
|
||||
|
||||
public double[] getRotationMatrix(float angle)
|
||||
{
|
||||
public double[] getRotationMatrix(float angle) {
|
||||
double[] matrix = new double[16];
|
||||
Pos3D axis = clone().normalize();
|
||||
|
||||
|
@ -320,11 +315,13 @@ public class Pos3D
|
|||
return matrix;
|
||||
}
|
||||
|
||||
public static Pos3D translateMatrix(double[] matrix, Pos3D translation)
|
||||
{
|
||||
double x = translation.xPos * matrix[0] + translation.yPos * matrix[1] + translation.zPos * matrix[2] + matrix[3];
|
||||
double y = translation.xPos * matrix[4] + translation.yPos * matrix[5] + translation.zPos * matrix[6] + matrix[7];
|
||||
double z = translation.xPos * matrix[8] + translation.yPos * matrix[9] + translation.zPos * matrix[10] + matrix[11];
|
||||
public static Pos3D translateMatrix(double[] matrix, Pos3D translation) {
|
||||
double x = translation.xPos * matrix[0] + translation.yPos * matrix[1]
|
||||
+ translation.zPos * matrix[2] + matrix[3];
|
||||
double y = translation.xPos * matrix[4] + translation.yPos * matrix[5]
|
||||
+ translation.zPos * matrix[6] + matrix[7];
|
||||
double z = translation.xPos * matrix[8] + translation.yPos * matrix[9]
|
||||
+ translation.zPos * matrix[10] + matrix[11];
|
||||
|
||||
translation.xPos = x;
|
||||
translation.yPos = y;
|
||||
|
@ -333,33 +330,27 @@ public class Pos3D
|
|||
return translation;
|
||||
}
|
||||
|
||||
public static double[] getRotationMatrix(float angle, Pos3D axis)
|
||||
{
|
||||
public static double[] getRotationMatrix(float angle, Pos3D axis) {
|
||||
return axis.getRotationMatrix(angle);
|
||||
}
|
||||
|
||||
public double anglePreNorm(Pos3D pos2)
|
||||
{
|
||||
public double anglePreNorm(Pos3D pos2) {
|
||||
return Math.acos(dotProduct(pos2));
|
||||
}
|
||||
|
||||
public static double anglePreNorm(Pos3D pos1, Pos3D pos2)
|
||||
{
|
||||
public static double anglePreNorm(Pos3D pos1, Pos3D pos2) {
|
||||
return Math.acos(pos1.clone().dotProduct(pos2));
|
||||
}
|
||||
|
||||
public double dotProduct(Pos3D pos)
|
||||
{
|
||||
public double dotProduct(Pos3D pos) {
|
||||
return xPos * pos.xPos + yPos * pos.yPos + zPos * pos.zPos;
|
||||
}
|
||||
|
||||
public Pos3D crossProduct(Pos3D compare)
|
||||
{
|
||||
public Pos3D crossProduct(Pos3D compare) {
|
||||
return clone().toCrossProduct(compare);
|
||||
}
|
||||
|
||||
public Pos3D toCrossProduct(Pos3D compare)
|
||||
{
|
||||
public Pos3D toCrossProduct(Pos3D compare) {
|
||||
double newX = yPos * compare.zPos - zPos * compare.yPos;
|
||||
double newY = zPos * compare.xPos - xPos * compare.zPos;
|
||||
double newZ = xPos * compare.yPos - yPos * compare.xPos;
|
||||
|
@ -371,50 +362,41 @@ public class Pos3D
|
|||
return this;
|
||||
}
|
||||
|
||||
public Pos3D xCrossProduct()
|
||||
{
|
||||
public Pos3D xCrossProduct() {
|
||||
return new Pos3D(0.0D, zPos, -yPos);
|
||||
}
|
||||
|
||||
public Pos3D zCrossProduct()
|
||||
{
|
||||
public Pos3D zCrossProduct() {
|
||||
return new Pos3D(-yPos, xPos, 0.0D);
|
||||
}
|
||||
|
||||
public Pos3D getPerpendicular()
|
||||
{
|
||||
if(zPos == 0)
|
||||
{
|
||||
public Pos3D getPerpendicular() {
|
||||
if (zPos == 0) {
|
||||
return zCrossProduct();
|
||||
}
|
||||
|
||||
return xCrossProduct();
|
||||
}
|
||||
|
||||
public Pos3D floor()
|
||||
{
|
||||
public Pos3D floor() {
|
||||
return new Pos3D(Math.floor(xPos), Math.floor(yPos), Math.floor(zPos));
|
||||
}
|
||||
|
||||
public double getMagnitude()
|
||||
{
|
||||
public double getMagnitude() {
|
||||
return Math.sqrt(xPos * xPos + yPos * yPos + zPos * zPos);
|
||||
}
|
||||
|
||||
public Pos3D normalize()
|
||||
{
|
||||
public Pos3D normalize() {
|
||||
double d = getMagnitude();
|
||||
|
||||
if (d != 0)
|
||||
{
|
||||
if (d != 0) {
|
||||
this.scale(1 / d);
|
||||
}
|
||||
|
||||
return this;
|
||||
}
|
||||
|
||||
public static AxisAlignedBB getAABB(Pos3D pos1, Pos3D pos2)
|
||||
{
|
||||
public static AxisAlignedBB getAABB(Pos3D pos1, Pos3D pos2) {
|
||||
return AxisAlignedBB.getBoundingBox(
|
||||
Math.min(pos1.xPos, pos2.xPos),
|
||||
Math.min(pos1.yPos, pos2.yPos),
|
||||
|
@ -426,29 +408,23 @@ public class Pos3D
|
|||
}
|
||||
|
||||
@Override
|
||||
public Pos3D clone()
|
||||
{
|
||||
public Pos3D clone() {
|
||||
return new Pos3D(xPos, yPos, zPos);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString()
|
||||
{
|
||||
public String toString() {
|
||||
return "[Pos3D: " + xPos + ", " + yPos + ", " + zPos + "]";
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean equals(Object obj)
|
||||
{
|
||||
return obj instanceof Pos3D &&
|
||||
((Pos3D)obj).xPos == xPos &&
|
||||
((Pos3D)obj).yPos == yPos &&
|
||||
((Pos3D)obj).zPos == zPos;
|
||||
public boolean equals(Object obj) {
|
||||
return obj instanceof Pos3D && ((Pos3D) obj).xPos == xPos
|
||||
&& ((Pos3D) obj).yPos == yPos && ((Pos3D) obj).zPos == zPos;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int hashCode()
|
||||
{
|
||||
public int hashCode() {
|
||||
int code = 1;
|
||||
code = 31 * code + new Double(xPos).hashCode();
|
||||
code = 31 * code + new Double(yPos).hashCode();
|
||||
|
|
|
@ -1,10 +1,9 @@
|
|||
package mekanism.api;
|
||||
|
||||
import net.minecraft.entity.player.EntityPlayer;
|
||||
import cpw.mods.fml.common.FMLCommonHandler;
|
||||
import net.minecraft.entity.player.EntityPlayer;
|
||||
|
||||
public class Range4D
|
||||
{
|
||||
public class Range4D {
|
||||
public int dimensionId;
|
||||
|
||||
public int xMin;
|
||||
|
@ -14,8 +13,9 @@ public class Range4D
|
|||
public int yMax;
|
||||
public int zMax;
|
||||
|
||||
public Range4D(int minX, int minY, int minZ, int maxX, int maxY, int maxZ, int dimension)
|
||||
{
|
||||
public Range4D(
|
||||
int minX, int minY, int minZ, int maxX, int maxY, int maxZ, int dimension
|
||||
) {
|
||||
xMin = minX;
|
||||
yMin = minY;
|
||||
zMin = minZ;
|
||||
|
@ -26,8 +26,7 @@ public class Range4D
|
|||
dimensionId = dimension;
|
||||
}
|
||||
|
||||
public Range4D(Chunk3D chunk)
|
||||
{
|
||||
public Range4D(Chunk3D chunk) {
|
||||
xMin = chunk.xCoord * 16;
|
||||
yMin = 0;
|
||||
zMin = chunk.zCoord * 16;
|
||||
|
@ -38,8 +37,7 @@ public class Range4D
|
|||
dimensionId = chunk.dimensionId;
|
||||
}
|
||||
|
||||
public Range4D(Coord4D coord)
|
||||
{
|
||||
public Range4D(Coord4D coord) {
|
||||
xMin = coord.xCoord;
|
||||
yMin = coord.yCoord;
|
||||
zMin = coord.zCoord;
|
||||
|
@ -51,15 +49,16 @@ public class Range4D
|
|||
dimensionId = coord.dimensionId;
|
||||
}
|
||||
|
||||
public static Range4D getChunkRange(EntityPlayer player)
|
||||
{
|
||||
int radius = FMLCommonHandler.instance().getMinecraftServerInstance().getConfigurationManager().getViewDistance();
|
||||
public static Range4D getChunkRange(EntityPlayer player) {
|
||||
int radius = FMLCommonHandler.instance()
|
||||
.getMinecraftServerInstance()
|
||||
.getConfigurationManager()
|
||||
.getViewDistance();
|
||||
|
||||
return new Range4D(new Chunk3D(player)).expandChunks(radius);
|
||||
}
|
||||
|
||||
public Range4D expandChunks(int chunks)
|
||||
{
|
||||
public Range4D expandChunks(int chunks) {
|
||||
xMin -= chunks * 16;
|
||||
xMax += chunks * 16;
|
||||
zMin -= chunks * 16;
|
||||
|
@ -68,39 +67,33 @@ public class Range4D
|
|||
return this;
|
||||
}
|
||||
|
||||
public boolean intersects(Range4D range)
|
||||
{
|
||||
return (xMax+1 - 1.E-05D > range.xMin) && (range.xMax+1 - 1.E-05D > xMin) && (yMax+1 - 1.E-05D > range.yMin) && (range.yMax+1 - 1.E-05D > yMin) && (zMax+1 - 1.E-05D > range.zMin) && (range.zMax+1 - 1.E-05D > zMin);
|
||||
public boolean intersects(Range4D range) {
|
||||
return (xMax + 1 - 1.E-05D > range.xMin) && (range.xMax + 1 - 1.E-05D > xMin)
|
||||
&& (yMax + 1 - 1.E-05D > range.yMin) && (range.yMax + 1 - 1.E-05D > yMin)
|
||||
&& (zMax + 1 - 1.E-05D > range.zMin) && (range.zMax + 1 - 1.E-05D > zMin);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Range4D clone()
|
||||
{
|
||||
public Range4D clone() {
|
||||
return new Range4D(xMin, yMin, zMin, xMax, yMax, zMax, dimensionId);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString()
|
||||
{
|
||||
return "[Range4D: " + xMin + ", " + yMin + ", " + zMin + ", " + xMax + ", " + yMax + ", " + zMax + ", dim=" + dimensionId + "]";
|
||||
public String toString() {
|
||||
return "[Range4D: " + xMin + ", " + yMin + ", " + zMin + ", " + xMax + ", " + yMax
|
||||
+ ", " + zMax + ", dim=" + dimensionId + "]";
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean equals(Object obj)
|
||||
{
|
||||
return obj instanceof Range4D &&
|
||||
((Range4D)obj).xMin == xMin &&
|
||||
((Range4D)obj).yMin == yMin &&
|
||||
((Range4D)obj).zMin == zMin &&
|
||||
((Range4D)obj).xMax == xMax &&
|
||||
((Range4D)obj).yMax == yMax &&
|
||||
((Range4D)obj).zMax == zMax &&
|
||||
((Range4D)obj).dimensionId == dimensionId;
|
||||
public boolean equals(Object obj) {
|
||||
return obj instanceof Range4D && ((Range4D) obj).xMin == xMin
|
||||
&& ((Range4D) obj).yMin == yMin && ((Range4D) obj).zMin == zMin
|
||||
&& ((Range4D) obj).xMax == xMax && ((Range4D) obj).yMax == yMax
|
||||
&& ((Range4D) obj).zMax == zMax && ((Range4D) obj).dimensionId == dimensionId;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int hashCode()
|
||||
{
|
||||
public int hashCode() {
|
||||
int code = 1;
|
||||
code = 31 * code + xMin;
|
||||
code = 31 * code + yMin;
|
||||
|
|
|
@ -7,29 +7,25 @@ import net.minecraft.creativetab.CreativeTabs;
|
|||
* @author AidanBrady
|
||||
*
|
||||
*/
|
||||
public final class TabProxy
|
||||
{
|
||||
public final class TabProxy {
|
||||
/** The 'Mekanism' class where the tab instance is stored. */
|
||||
public static Class Mekanism;
|
||||
|
||||
/**
|
||||
* Attempts to get the Mekanism creative tab instance from the 'Mekanism' class. Will return
|
||||
* the tab if the mod is loaded, but otherwise will return the defined 'preferred' creative tab. This way
|
||||
* you don't need to worry about NPEs!
|
||||
* Attempts to get the Mekanism creative tab instance from the 'Mekanism' class. Will
|
||||
* return the tab if the mod is loaded, but otherwise will return the defined
|
||||
* 'preferred' creative tab. This way you don't need to worry about NPEs!
|
||||
* @return Mekanism creative tab if can, otherwise preferred tab
|
||||
*/
|
||||
public static CreativeTabs tabMekanism(CreativeTabs preferred)
|
||||
{
|
||||
public static CreativeTabs tabMekanism(CreativeTabs preferred) {
|
||||
try {
|
||||
if(Mekanism == null)
|
||||
{
|
||||
if (Mekanism == null) {
|
||||
Mekanism = Class.forName("mekanism.common.Mekanism");
|
||||
}
|
||||
|
||||
Object ret = Mekanism.getField("tabMekanism").get(null);
|
||||
|
||||
if(ret instanceof CreativeTabs)
|
||||
{
|
||||
if (ret instanceof CreativeTabs) {
|
||||
return (CreativeTabs) ret;
|
||||
}
|
||||
|
||||
|
|
|
@ -2,26 +2,27 @@ package mekanism.api.energy;
|
|||
|
||||
import net.minecraft.item.ItemStack;
|
||||
|
||||
public class EnergizedItemManager
|
||||
{
|
||||
public class EnergizedItemManager {
|
||||
/**
|
||||
* Discharges an IEnergizedItem with the defined amount of energy.
|
||||
* @param itemStack - ItemStack to discharge
|
||||
* @param amount - amount of energy to discharge from the item, usually the total amount of energy needed in a TileEntity
|
||||
* @param amount - amount of energy to discharge from the item, usually the total
|
||||
* amount of energy needed in a TileEntity
|
||||
* @return amount of energy discharged
|
||||
*/
|
||||
public static double discharge(ItemStack itemStack, double amount)
|
||||
{
|
||||
if(itemStack != null)
|
||||
{
|
||||
if(itemStack.getItem() instanceof IEnergizedItem)
|
||||
{
|
||||
public static double discharge(ItemStack itemStack, double amount) {
|
||||
if (itemStack != null) {
|
||||
if (itemStack.getItem() instanceof IEnergizedItem) {
|
||||
IEnergizedItem energizedItem = (IEnergizedItem) itemStack.getItem();
|
||||
|
||||
if(energizedItem.canSend(itemStack))
|
||||
{
|
||||
double energyToUse = Math.min(energizedItem.getMaxTransfer(itemStack), Math.min(energizedItem.getEnergy(itemStack), amount));
|
||||
energizedItem.setEnergy(itemStack, energizedItem.getEnergy(itemStack) - energyToUse);
|
||||
if (energizedItem.canSend(itemStack)) {
|
||||
double energyToUse = Math.min(
|
||||
energizedItem.getMaxTransfer(itemStack),
|
||||
Math.min(energizedItem.getEnergy(itemStack), amount)
|
||||
);
|
||||
energizedItem.setEnergy(
|
||||
itemStack, energizedItem.getEnergy(itemStack) - energyToUse
|
||||
);
|
||||
|
||||
return energyToUse;
|
||||
}
|
||||
|
@ -34,21 +35,27 @@ public class EnergizedItemManager
|
|||
/**
|
||||
* Charges an IEnergizedItem with the defined amount of energy.
|
||||
* @param itemStack - ItemStack to charge
|
||||
* @param amount - amount of energy to charge the item with, usually the total amount of energy stored in a TileEntity
|
||||
* @param amount - amount of energy to charge the item with, usually the total amount
|
||||
* of energy stored in a TileEntity
|
||||
* @return amount of energy charged
|
||||
*/
|
||||
public static double charge(ItemStack itemStack, double amount)
|
||||
{
|
||||
if(itemStack != null)
|
||||
{
|
||||
if(itemStack.getItem() instanceof IEnergizedItem)
|
||||
{
|
||||
public static double charge(ItemStack itemStack, double amount) {
|
||||
if (itemStack != null) {
|
||||
if (itemStack.getItem() instanceof IEnergizedItem) {
|
||||
IEnergizedItem energizedItem = (IEnergizedItem) itemStack.getItem();
|
||||
|
||||
if(energizedItem.canReceive(itemStack))
|
||||
{
|
||||
double energyToSend = Math.min(energizedItem.getMaxTransfer(itemStack), Math.min(energizedItem.getMaxEnergy(itemStack) - energizedItem.getEnergy(itemStack), amount));
|
||||
energizedItem.setEnergy(itemStack, energizedItem.getEnergy(itemStack) + energyToSend);
|
||||
if (energizedItem.canReceive(itemStack)) {
|
||||
double energyToSend = Math.min(
|
||||
energizedItem.getMaxTransfer(itemStack),
|
||||
Math.min(
|
||||
energizedItem.getMaxEnergy(itemStack)
|
||||
- energizedItem.getEnergy(itemStack),
|
||||
amount
|
||||
)
|
||||
);
|
||||
energizedItem.setEnergy(
|
||||
itemStack, energizedItem.getEnergy(itemStack) + energyToSend
|
||||
);
|
||||
|
||||
return energyToSend;
|
||||
}
|
||||
|
|
|
@ -3,12 +3,10 @@ package mekanism.api.energy;
|
|||
/**
|
||||
* Created by ben on 27/03/15.
|
||||
*/
|
||||
public class EnergyStack
|
||||
{
|
||||
public class EnergyStack {
|
||||
public double amount;
|
||||
|
||||
public EnergyStack(double newAmount)
|
||||
{
|
||||
public EnergyStack(double newAmount) {
|
||||
amount = newAmount;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -3,12 +3,12 @@ package mekanism.api.energy;
|
|||
import net.minecraftforge.common.util.ForgeDirection;
|
||||
|
||||
/**
|
||||
* Implement this if your TileEntity is capable of outputting energy to cables, overriding Mekanism's default implementation.
|
||||
* Implement this if your TileEntity is capable of outputting energy to cables, overriding
|
||||
* Mekanism's default implementation.
|
||||
* @author AidanBrady
|
||||
*
|
||||
*/
|
||||
public interface ICableOutputter
|
||||
{
|
||||
public interface ICableOutputter {
|
||||
/**
|
||||
* Whether or not this block can output to a cable on a specific side.
|
||||
* @param side - side to check
|
||||
|
|
|
@ -7,8 +7,7 @@ import net.minecraft.item.ItemStack;
|
|||
* @author aidancbrady
|
||||
*
|
||||
*/
|
||||
public interface IEnergizedItem
|
||||
{
|
||||
public interface IEnergizedItem {
|
||||
/**
|
||||
* Gets and returns the amount of energy stored in this item.
|
||||
* @param itemStack - the ItemStack to check
|
||||
|
|
|
@ -3,12 +3,12 @@ package mekanism.api.energy;
|
|||
import net.minecraftforge.common.util.ForgeDirection;
|
||||
|
||||
/**
|
||||
* Implement this if your TileEntity can accept energy at a floating-point double value from Universal Cables.
|
||||
* Implement this if your TileEntity can accept energy at a floating-point double value
|
||||
* from Universal Cables.
|
||||
* @author AidanBrady
|
||||
*
|
||||
*/
|
||||
public interface IStrictEnergyAcceptor extends IStrictEnergyStorage
|
||||
{
|
||||
public interface IStrictEnergyAcceptor extends IStrictEnergyStorage {
|
||||
/**
|
||||
* Transfer a certain amount of energy to this acceptor.
|
||||
* @param amount - amount to transfer
|
||||
|
|
|
@ -1,12 +1,12 @@
|
|||
package mekanism.api.energy;
|
||||
|
||||
/**
|
||||
* Mekanism-specific energy storage for TileEntities, already implemented in IStrictEnergyAcceptor.
|
||||
* Mekanism-specific energy storage for TileEntities, already implemented in
|
||||
* IStrictEnergyAcceptor.
|
||||
* @author aidancbrady
|
||||
*
|
||||
*/
|
||||
public interface IStrictEnergyStorage
|
||||
{
|
||||
public interface IStrictEnergyStorage {
|
||||
/**
|
||||
* Gets the amount of energy this TileEntity is currently storing.
|
||||
* @return stored energy
|
||||
|
|
|
@ -1,4 +1,3 @@
|
|||
@API(apiVersion = "9.0.0", owner = "Mekanism", provides = "MekanismAPI|energy")
|
||||
package mekanism.api.energy;
|
||||
import cpw.mods.fml.common.API;
|
||||
|
||||
|
|
|
@ -11,8 +11,7 @@ import net.minecraftforge.fluids.FluidRegistry;
|
|||
* @author aidancbrady
|
||||
*
|
||||
*/
|
||||
public class Gas
|
||||
{
|
||||
public class Gas {
|
||||
private String name;
|
||||
|
||||
private String unlocalizedName;
|
||||
|
@ -29,16 +28,14 @@ public class Gas
|
|||
* Creates a new Gas object with a defined name or key value.
|
||||
* @param s - name or key to associate this Gas with
|
||||
*/
|
||||
public Gas(String s)
|
||||
{
|
||||
public Gas(String s) {
|
||||
unlocalizedName = name = s;
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates a new Gas object that corresponds to the given Fluid
|
||||
*/
|
||||
public Gas(Fluid f)
|
||||
{
|
||||
public Gas(Fluid f) {
|
||||
unlocalizedName = name = f.getName();
|
||||
icon = f.getStillIcon();
|
||||
fluid = f;
|
||||
|
@ -46,11 +43,11 @@ public class Gas
|
|||
}
|
||||
|
||||
/**
|
||||
* Gets the name (key) of this Gas. This is NOT a translated or localized display name.
|
||||
* Gets the name (key) of this Gas. This is NOT a translated or localized display
|
||||
* name.
|
||||
* @return this Gas's name or key
|
||||
*/
|
||||
public String getName()
|
||||
{
|
||||
public String getName() {
|
||||
return name;
|
||||
}
|
||||
|
||||
|
@ -58,18 +55,18 @@ public class Gas
|
|||
* Whether or not this is a visible gas.
|
||||
* @return if this gas is visible
|
||||
*/
|
||||
public boolean isVisible()
|
||||
{
|
||||
public boolean isVisible() {
|
||||
return visible;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets this gas's "visible" state to a new value. Setting it to 'false' will treat this gas as an internal gas, and it will not be displayed or accessed by other mods.
|
||||
* Sets this gas's "visible" state to a new value. Setting it to 'false' will treat
|
||||
* this gas as an internal gas, and it will not be displayed or accessed by other
|
||||
* mods.
|
||||
* @param v - new visible state
|
||||
* @return this Gas object
|
||||
*/
|
||||
public Gas setVisible(boolean v)
|
||||
{
|
||||
public Gas setVisible(boolean v) {
|
||||
visible = v;
|
||||
|
||||
return this;
|
||||
|
@ -79,8 +76,7 @@ public class Gas
|
|||
* Gets the unlocalized name of this Gas.
|
||||
* @return this Gas's unlocalized name
|
||||
*/
|
||||
public String getUnlocalizedName()
|
||||
{
|
||||
public String getUnlocalizedName() {
|
||||
return "gas." + unlocalizedName;
|
||||
}
|
||||
|
||||
|
@ -88,8 +84,7 @@ public class Gas
|
|||
* Translates this Gas's unlocalized name and returns it as localized.
|
||||
* @return this Gas's localized name
|
||||
*/
|
||||
public String getLocalizedName()
|
||||
{
|
||||
public String getLocalizedName() {
|
||||
return StatCollector.translateToLocal(getUnlocalizedName());
|
||||
}
|
||||
|
||||
|
@ -98,8 +93,7 @@ public class Gas
|
|||
* @param s - unlocalized name to set
|
||||
* @return this Gas object
|
||||
*/
|
||||
public Gas setUnlocalizedName(String s)
|
||||
{
|
||||
public Gas setUnlocalizedName(String s) {
|
||||
unlocalizedName = s;
|
||||
|
||||
return this;
|
||||
|
@ -109,10 +103,8 @@ public class Gas
|
|||
* Gets the IIcon associated with this Gas.
|
||||
* @return associated IIcon
|
||||
*/
|
||||
public IIcon getIcon()
|
||||
{
|
||||
if(from_fluid)
|
||||
{
|
||||
public IIcon getIcon() {
|
||||
if (from_fluid) {
|
||||
return this.getFluid().getIcon();
|
||||
}
|
||||
|
||||
|
@ -124,12 +116,10 @@ public class Gas
|
|||
* @param i - IIcon to associate with this Gas
|
||||
* @return this Gas object
|
||||
*/
|
||||
public Gas setIcon(IIcon i)
|
||||
{
|
||||
public Gas setIcon(IIcon i) {
|
||||
icon = i;
|
||||
|
||||
if(hasFluid())
|
||||
{
|
||||
if (hasFluid()) {
|
||||
fluid.setIcons(getIcon());
|
||||
}
|
||||
|
||||
|
@ -142,8 +132,7 @@ public class Gas
|
|||
* Gets the ID associated with this gas.
|
||||
* @return the associated gas ID
|
||||
*/
|
||||
public int getID()
|
||||
{
|
||||
public int getID() {
|
||||
return GasRegistry.getGasID(this);
|
||||
}
|
||||
|
||||
|
@ -152,8 +141,7 @@ public class Gas
|
|||
* @param nbtTags - tag compound to write this Gas to
|
||||
* @return the tag compound this gas was written to
|
||||
*/
|
||||
public NBTTagCompound write(NBTTagCompound nbtTags)
|
||||
{
|
||||
public NBTTagCompound write(NBTTagCompound nbtTags) {
|
||||
nbtTags.setString("gasName", getName());
|
||||
|
||||
return nbtTags;
|
||||
|
@ -164,10 +152,8 @@ public class Gas
|
|||
* @param nbtTags - tag compound to get the Gas from
|
||||
* @return Gas stored in the tag compound
|
||||
*/
|
||||
public static Gas readFromNBT(NBTTagCompound nbtTags)
|
||||
{
|
||||
if(nbtTags == null || nbtTags.hasNoTags())
|
||||
{
|
||||
public static Gas readFromNBT(NBTTagCompound nbtTags) {
|
||||
if (nbtTags == null || nbtTags.hasNoTags()) {
|
||||
return null;
|
||||
}
|
||||
|
||||
|
@ -178,8 +164,7 @@ public class Gas
|
|||
* Whether or not this Gas has an associated fluid.
|
||||
* @return if this gas has a fluid
|
||||
*/
|
||||
public boolean hasFluid()
|
||||
{
|
||||
public boolean hasFluid() {
|
||||
return fluid != null;
|
||||
}
|
||||
|
||||
|
@ -187,8 +172,7 @@ public class Gas
|
|||
* Gets the fluid associated with this Gas.
|
||||
* @return fluid associated with this gas
|
||||
*/
|
||||
public Fluid getFluid()
|
||||
{
|
||||
public Fluid getFluid() {
|
||||
return fluid;
|
||||
}
|
||||
|
||||
|
@ -196,16 +180,12 @@ public class Gas
|
|||
* Registers a new fluid out of this Gas or gets one from the FluidRegistry.
|
||||
* @return this Gas object
|
||||
*/
|
||||
public Gas registerFluid()
|
||||
{
|
||||
if(fluid == null)
|
||||
{
|
||||
if(FluidRegistry.getFluid(getName()) == null)
|
||||
{
|
||||
public Gas registerFluid() {
|
||||
if (fluid == null) {
|
||||
if (FluidRegistry.getFluid(getName()) == null) {
|
||||
fluid = new Fluid(getName()).setGaseous(true);
|
||||
FluidRegistry.registerFluid(fluid);
|
||||
}
|
||||
else {
|
||||
} else {
|
||||
fluid = FluidRegistry.getFluid(getName());
|
||||
}
|
||||
}
|
||||
|
@ -214,8 +194,7 @@ public class Gas
|
|||
}
|
||||
|
||||
@Override
|
||||
public String toString()
|
||||
{
|
||||
public String toString() {
|
||||
return name;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -7,6 +7,9 @@ import java.util.HashSet;
|
|||
import java.util.List;
|
||||
import java.util.Set;
|
||||
|
||||
import com.google.common.collect.Lists;
|
||||
import cpw.mods.fml.common.FMLCommonHandler;
|
||||
import cpw.mods.fml.common.eventhandler.Event;
|
||||
import mekanism.api.Coord4D;
|
||||
import mekanism.api.transmitters.DynamicNetwork;
|
||||
import mekanism.api.transmitters.IGridTransmitter;
|
||||
|
@ -14,19 +17,14 @@ import net.minecraft.tileentity.TileEntity;
|
|||
import net.minecraftforge.common.MinecraftForge;
|
||||
import net.minecraftforge.common.util.ForgeDirection;
|
||||
|
||||
import com.google.common.collect.Lists;
|
||||
|
||||
import cpw.mods.fml.common.FMLCommonHandler;
|
||||
import cpw.mods.fml.common.eventhandler.Event;
|
||||
|
||||
/**
|
||||
* A DynamicNetwork extension created specifically for the transfer of Gasses. By default this is server-only, but if ticked on
|
||||
* the client side and if it's posted events are handled properly, it has the capability to visually display gasses network-wide.
|
||||
* A DynamicNetwork extension created specifically for the transfer of Gasses. By default
|
||||
* this is server-only, but if ticked on the client side and if it's posted events are
|
||||
* handled properly, it has the capability to visually display gasses network-wide.
|
||||
* @author aidancbrady
|
||||
*
|
||||
*/
|
||||
public class GasNetwork extends DynamicNetwork<IGasHandler, GasNetwork>
|
||||
{
|
||||
public class GasNetwork extends DynamicNetwork<IGasHandler, GasNetwork> {
|
||||
public int transferDelay = 0;
|
||||
|
||||
public boolean didTransfer;
|
||||
|
@ -43,16 +41,11 @@ public class GasNetwork extends DynamicNetwork<IGasHandler, GasNetwork>
|
|||
|
||||
public GasNetwork() {}
|
||||
|
||||
public GasNetwork(Collection<GasNetwork> networks)
|
||||
{
|
||||
for(GasNetwork net : networks)
|
||||
{
|
||||
if(net != null)
|
||||
{
|
||||
if(FMLCommonHandler.instance().getEffectiveSide().isClient())
|
||||
{
|
||||
if(net.refGas != null && net.gasScale > gasScale)
|
||||
{
|
||||
public GasNetwork(Collection<GasNetwork> networks) {
|
||||
for (GasNetwork net : networks) {
|
||||
if (net != null) {
|
||||
if (FMLCommonHandler.instance().getEffectiveSide().isClient()) {
|
||||
if (net.refGas != null && net.gasScale > gasScale) {
|
||||
gasScale = net.gasScale;
|
||||
refGas = net.refGas;
|
||||
buffer = net.buffer;
|
||||
|
@ -61,24 +54,16 @@ public class GasNetwork extends DynamicNetwork<IGasHandler, GasNetwork>
|
|||
net.refGas = null;
|
||||
net.buffer = null;
|
||||
}
|
||||
}
|
||||
else {
|
||||
if(net.buffer != null)
|
||||
{
|
||||
if(buffer == null)
|
||||
{
|
||||
} else {
|
||||
if (net.buffer != null) {
|
||||
if (buffer == null) {
|
||||
buffer = net.buffer.copy();
|
||||
}
|
||||
else {
|
||||
if(buffer.isGasEqual(net.buffer))
|
||||
{
|
||||
} else {
|
||||
if (buffer.isGasEqual(net.buffer)) {
|
||||
buffer.amount += net.buffer.amount;
|
||||
}
|
||||
else if(net.buffer.amount > buffer.amount)
|
||||
{
|
||||
} else if (net.buffer.amount > buffer.amount) {
|
||||
buffer = net.buffer.copy();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
net.buffer = null;
|
||||
|
@ -96,27 +81,24 @@ public class GasNetwork extends DynamicNetwork<IGasHandler, GasNetwork>
|
|||
}
|
||||
|
||||
@Override
|
||||
public void absorbBuffer(IGridTransmitter<IGasHandler, GasNetwork> transmitter)
|
||||
{
|
||||
public void absorbBuffer(IGridTransmitter<IGasHandler, GasNetwork> transmitter) {
|
||||
Object b = transmitter.getBuffer();
|
||||
|
||||
if(!(b instanceof GasStack) || ((GasStack)b).getGas() == null || ((GasStack)b).amount == 0)
|
||||
{
|
||||
if (!(b instanceof GasStack) || ((GasStack) b).getGas() == null
|
||||
|| ((GasStack) b).amount == 0) {
|
||||
return;
|
||||
}
|
||||
|
||||
GasStack gas = (GasStack) b;
|
||||
|
||||
if(buffer == null || buffer.getGas() == null || buffer.amount == 0)
|
||||
{
|
||||
if (buffer == null || buffer.getGas() == null || buffer.amount == 0) {
|
||||
buffer = gas.copy();
|
||||
gas.amount = 0;
|
||||
return;
|
||||
}
|
||||
|
||||
//TODO better multiple buffer impl
|
||||
if(buffer.isGasEqual(gas))
|
||||
{
|
||||
if (buffer.isGasEqual(gas)) {
|
||||
buffer.amount += gas.amount;
|
||||
}
|
||||
|
||||
|
@ -124,21 +106,17 @@ public class GasNetwork extends DynamicNetwork<IGasHandler, GasNetwork>
|
|||
}
|
||||
|
||||
@Override
|
||||
public void clampBuffer()
|
||||
{
|
||||
if(buffer != null && buffer.amount > getCapacity())
|
||||
{
|
||||
public void clampBuffer() {
|
||||
if (buffer != null && buffer.amount > getCapacity()) {
|
||||
buffer.amount = capacity;
|
||||
}
|
||||
}
|
||||
|
||||
public int getGasNeeded()
|
||||
{
|
||||
public int getGasNeeded() {
|
||||
return getCapacity() - (buffer != null ? buffer.amount : 0);
|
||||
}
|
||||
|
||||
public int tickEmit(GasStack stack)
|
||||
{
|
||||
public int tickEmit(GasStack stack) {
|
||||
List<IGasHandler> availableAcceptors = Lists.newArrayList();
|
||||
|
||||
availableAcceptors.addAll(getAcceptors(stack.getGas()));
|
||||
|
@ -148,31 +126,29 @@ public class GasNetwork extends DynamicNetwork<IGasHandler, GasNetwork>
|
|||
int toSend = stack.amount;
|
||||
int prevSending = toSend;
|
||||
|
||||
if(!availableAcceptors.isEmpty())
|
||||
{
|
||||
if (!availableAcceptors.isEmpty()) {
|
||||
int divider = availableAcceptors.size();
|
||||
int remaining = toSend % divider;
|
||||
int sending = (toSend - remaining) / divider;
|
||||
|
||||
for(IGasHandler acceptor : availableAcceptors)
|
||||
{
|
||||
for (IGasHandler acceptor : availableAcceptors) {
|
||||
int currentSending = sending;
|
||||
EnumSet<ForgeDirection> sides = acceptorDirections.get(Coord4D.get((TileEntity)acceptor));
|
||||
EnumSet<ForgeDirection> sides
|
||||
= acceptorDirections.get(Coord4D.get((TileEntity) acceptor));
|
||||
|
||||
if(remaining > 0)
|
||||
{
|
||||
if (remaining > 0) {
|
||||
currentSending++;
|
||||
remaining--;
|
||||
}
|
||||
|
||||
for(ForgeDirection side : sides)
|
||||
{
|
||||
for (ForgeDirection side : sides) {
|
||||
int prev = toSend;
|
||||
|
||||
toSend -= acceptor.receiveGas(side, new GasStack(stack.getGas(), currentSending), true);
|
||||
toSend -= acceptor.receiveGas(
|
||||
side, new GasStack(stack.getGas(), currentSending), true
|
||||
);
|
||||
|
||||
if(toSend < prev)
|
||||
{
|
||||
if (toSend < prev) {
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
@ -181,8 +157,7 @@ public class GasNetwork extends DynamicNetwork<IGasHandler, GasNetwork>
|
|||
|
||||
int sent = prevSending - toSend;
|
||||
|
||||
if(sent > 0 && FMLCommonHandler.instance().getEffectiveSide().isServer())
|
||||
{
|
||||
if (sent > 0 && FMLCommonHandler.instance().getEffectiveSide().isServer()) {
|
||||
didTransfer = true;
|
||||
transferDelay = 2;
|
||||
}
|
||||
|
@ -190,23 +165,18 @@ public class GasNetwork extends DynamicNetwork<IGasHandler, GasNetwork>
|
|||
return sent;
|
||||
}
|
||||
|
||||
public int emit(GasStack stack, boolean doTransfer)
|
||||
{
|
||||
if(buffer != null && buffer.getGas() != stack.getGas())
|
||||
{
|
||||
public int emit(GasStack stack, boolean doTransfer) {
|
||||
if (buffer != null && buffer.getGas() != stack.getGas()) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
int toUse = Math.min(getGasNeeded(), stack.amount);
|
||||
|
||||
if(doTransfer)
|
||||
{
|
||||
if(buffer == null)
|
||||
{
|
||||
if (doTransfer) {
|
||||
if (buffer == null) {
|
||||
buffer = stack.copy();
|
||||
buffer.amount = toUse;
|
||||
}
|
||||
else {
|
||||
} else {
|
||||
buffer.amount += toUse;
|
||||
}
|
||||
}
|
||||
|
@ -215,46 +185,40 @@ public class GasNetwork extends DynamicNetwork<IGasHandler, GasNetwork>
|
|||
}
|
||||
|
||||
@Override
|
||||
public void onUpdate()
|
||||
{
|
||||
public void onUpdate() {
|
||||
super.onUpdate();
|
||||
|
||||
if(FMLCommonHandler.instance().getEffectiveSide().isServer())
|
||||
{
|
||||
if (FMLCommonHandler.instance().getEffectiveSide().isServer()) {
|
||||
prevTransferAmount = 0;
|
||||
|
||||
if(transferDelay == 0)
|
||||
{
|
||||
if (transferDelay == 0) {
|
||||
didTransfer = false;
|
||||
}
|
||||
else {
|
||||
} else {
|
||||
transferDelay--;
|
||||
}
|
||||
|
||||
int stored = buffer != null ? buffer.amount : 0;
|
||||
|
||||
if(stored != prevStored)
|
||||
{
|
||||
if (stored != prevStored) {
|
||||
needsUpdate = true;
|
||||
}
|
||||
|
||||
prevStored = stored;
|
||||
|
||||
if(didTransfer != prevTransfer || needsUpdate)
|
||||
{
|
||||
MinecraftForge.EVENT_BUS.post(new GasTransferEvent(this, buffer, didTransfer));
|
||||
if (didTransfer != prevTransfer || needsUpdate) {
|
||||
MinecraftForge.EVENT_BUS.post(
|
||||
new GasTransferEvent(this, buffer, didTransfer)
|
||||
);
|
||||
needsUpdate = false;
|
||||
}
|
||||
|
||||
prevTransfer = didTransfer;
|
||||
|
||||
if(buffer != null)
|
||||
{
|
||||
if (buffer != null) {
|
||||
prevTransferAmount = tickEmit(buffer);
|
||||
buffer.amount -= prevTransferAmount;
|
||||
|
||||
if(buffer.amount <= 0)
|
||||
{
|
||||
if (buffer.amount <= 0) {
|
||||
buffer = null;
|
||||
}
|
||||
}
|
||||
|
@ -262,54 +226,43 @@ public class GasNetwork extends DynamicNetwork<IGasHandler, GasNetwork>
|
|||
}
|
||||
|
||||
@Override
|
||||
public void clientTick()
|
||||
{
|
||||
public void clientTick() {
|
||||
super.clientTick();
|
||||
|
||||
gasScale = Math.max(gasScale, getScale());
|
||||
|
||||
if(didTransfer && gasScale < 1)
|
||||
{
|
||||
if (didTransfer && gasScale < 1) {
|
||||
gasScale = Math.max(getScale(), Math.min(1, gasScale + 0.02F));
|
||||
}
|
||||
else if(!didTransfer && gasScale > 0)
|
||||
{
|
||||
} else if (!didTransfer && gasScale > 0) {
|
||||
gasScale = Math.max(getScale(), Math.max(0, gasScale - 0.02F));
|
||||
|
||||
if(gasScale == 0)
|
||||
{
|
||||
if (gasScale == 0) {
|
||||
buffer = null;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public Set<IGasHandler> getAcceptors(Object data)
|
||||
{
|
||||
public Set<IGasHandler> getAcceptors(Object data) {
|
||||
Gas type = (Gas) data;
|
||||
Set<IGasHandler> toReturn = new HashSet<IGasHandler>();
|
||||
|
||||
if(FMLCommonHandler.instance().getEffectiveSide().isClient())
|
||||
{
|
||||
if (FMLCommonHandler.instance().getEffectiveSide().isClient()) {
|
||||
return toReturn;
|
||||
}
|
||||
|
||||
for(Coord4D coord : possibleAcceptors.keySet())
|
||||
{
|
||||
for (Coord4D coord : possibleAcceptors.keySet()) {
|
||||
EnumSet<ForgeDirection> sides = acceptorDirections.get(coord);
|
||||
TileEntity tile = coord.getTileEntity(getWorld());
|
||||
|
||||
if(!(tile instanceof IGasHandler) || sides == null || sides.isEmpty())
|
||||
{
|
||||
if (!(tile instanceof IGasHandler) || sides == null || sides.isEmpty()) {
|
||||
continue;
|
||||
}
|
||||
|
||||
IGasHandler acceptor = (IGasHandler) tile;
|
||||
|
||||
for(ForgeDirection side : sides)
|
||||
{
|
||||
if(acceptor != null && acceptor.canReceiveGas(side, type))
|
||||
{
|
||||
for (ForgeDirection side : sides) {
|
||||
if (acceptor != null && acceptor.canReceiveGas(side, type)) {
|
||||
toReturn.add(acceptor);
|
||||
break;
|
||||
}
|
||||
|
@ -319,47 +272,47 @@ public class GasNetwork extends DynamicNetwork<IGasHandler, GasNetwork>
|
|||
return toReturn;
|
||||
}
|
||||
|
||||
public static class GasTransferEvent extends Event
|
||||
{
|
||||
public static class GasTransferEvent extends Event {
|
||||
public final GasNetwork gasNetwork;
|
||||
|
||||
public final GasStack transferType;
|
||||
public final boolean didTransfer;
|
||||
|
||||
public GasTransferEvent(GasNetwork network, GasStack type, boolean did)
|
||||
{
|
||||
public GasTransferEvent(GasNetwork network, GasStack type, boolean did) {
|
||||
gasNetwork = network;
|
||||
transferType = type;
|
||||
didTransfer = did;
|
||||
}
|
||||
}
|
||||
|
||||
public float getScale()
|
||||
{
|
||||
return Math.min(1, (buffer == null || getCapacity() == 0 ? 0 : (float)buffer.amount/getCapacity()));
|
||||
public float getScale() {
|
||||
return Math.min(
|
||||
1,
|
||||
(buffer == null || getCapacity() == 0 ? 0
|
||||
: (float) buffer.amount / getCapacity())
|
||||
);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString()
|
||||
{
|
||||
return "[GasNetwork] " + transmitters.size() + " transmitters, " + possibleAcceptors.size() + " acceptors.";
|
||||
public String toString() {
|
||||
return "[GasNetwork] " + transmitters.size() + " transmitters, "
|
||||
+ possibleAcceptors.size() + " acceptors.";
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getNeededInfo()
|
||||
{
|
||||
public String getNeededInfo() {
|
||||
return Integer.toString(getGasNeeded());
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getStoredInfo()
|
||||
{
|
||||
return buffer != null ? buffer.getGas().getLocalizedName() + " (" + buffer.amount + ")" : "None";
|
||||
public String getStoredInfo() {
|
||||
return buffer != null
|
||||
? buffer.getGas().getLocalizedName() + " (" + buffer.amount + ")"
|
||||
: "None";
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getFlowInfo()
|
||||
{
|
||||
public String getFlowInfo() {
|
||||
return Integer.toString(prevTransferAmount) + "/t";
|
||||
}
|
||||
}
|
||||
|
|
|
@ -5,8 +5,7 @@ import java.util.List;
|
|||
|
||||
import net.minecraftforge.fluids.Fluid;
|
||||
|
||||
public class GasRegistry
|
||||
{
|
||||
public class GasRegistry {
|
||||
private static ArrayList<Gas> registeredGasses = new ArrayList<Gas>();
|
||||
|
||||
/**
|
||||
|
@ -14,10 +13,8 @@ public class GasRegistry
|
|||
* @param gas - Gas to register
|
||||
* @return the gas that has been registered, pulled right out of GasRegistry
|
||||
*/
|
||||
public static Gas register(Gas gas)
|
||||
{
|
||||
if(gas == null)
|
||||
{
|
||||
public static Gas register(Gas gas) {
|
||||
if (gas == null) {
|
||||
return null;
|
||||
}
|
||||
|
||||
|
@ -31,10 +28,8 @@ public class GasRegistry
|
|||
* @param id - ID to check
|
||||
* @return gas associated with defined ID
|
||||
*/
|
||||
public static Gas getGas(int id)
|
||||
{
|
||||
if(id == -1)
|
||||
{
|
||||
public static Gas getGas(int id) {
|
||||
if (id == -1) {
|
||||
return null;
|
||||
}
|
||||
|
||||
|
@ -46,12 +41,9 @@ public class GasRegistry
|
|||
* @param f - fluid to check
|
||||
* @return the gas associated with the fluid
|
||||
*/
|
||||
public static Gas getGas(Fluid f)
|
||||
{
|
||||
for(Gas gas : getRegisteredGasses())
|
||||
{
|
||||
if(gas.hasFluid() && gas.getFluid() == f)
|
||||
{
|
||||
public static Gas getGas(Fluid f) {
|
||||
for (Gas gas : getRegisteredGasses()) {
|
||||
if (gas.hasFluid() && gas.getFluid() == f) {
|
||||
return gas;
|
||||
}
|
||||
}
|
||||
|
@ -64,8 +56,7 @@ public class GasRegistry
|
|||
* @param name - name to check
|
||||
* @return if GasRegistry contains a gas with the defined name
|
||||
*/
|
||||
public static boolean containsGas(String name)
|
||||
{
|
||||
public static boolean containsGas(String name) {
|
||||
return getGas(name) != null;
|
||||
}
|
||||
|
||||
|
@ -73,8 +64,7 @@ public class GasRegistry
|
|||
* Gets the list of all gasses registered in GasRegistry.
|
||||
* @return a cloned list of all registered gasses
|
||||
*/
|
||||
public static List<Gas> getRegisteredGasses()
|
||||
{
|
||||
public static List<Gas> getRegisteredGasses() {
|
||||
return (List<Gas>) registeredGasses.clone();
|
||||
}
|
||||
|
||||
|
@ -83,12 +73,9 @@ public class GasRegistry
|
|||
* @param name - name of the gas to get
|
||||
* @return gas associated with the name
|
||||
*/
|
||||
public static Gas getGas(String name)
|
||||
{
|
||||
for(Gas gas : registeredGasses)
|
||||
{
|
||||
if(gas.getName().toLowerCase().equals(name.toLowerCase()))
|
||||
{
|
||||
public static Gas getGas(String name) {
|
||||
for (Gas gas : registeredGasses) {
|
||||
if (gas.getName().toLowerCase().equals(name.toLowerCase())) {
|
||||
return gas;
|
||||
}
|
||||
}
|
||||
|
@ -101,10 +88,8 @@ public class GasRegistry
|
|||
* @param gas - gas to get the ID from
|
||||
* @return gas ID
|
||||
*/
|
||||
public static int getGasID(Gas gas)
|
||||
{
|
||||
if(gas == null || !containsGas(gas.getName()))
|
||||
{
|
||||
public static int getGasID(Gas gas) {
|
||||
if (gas == null || !containsGas(gas.getName())) {
|
||||
return -1;
|
||||
}
|
||||
|
||||
|
|
|
@ -7,19 +7,18 @@ import net.minecraft.nbt.NBTTagCompound;
|
|||
* @author aidancbrady
|
||||
*
|
||||
*/
|
||||
public class GasStack
|
||||
{
|
||||
public class GasStack {
|
||||
private Gas type;
|
||||
|
||||
public int amount;
|
||||
|
||||
/**
|
||||
* Creates a new GasStack with a defined gas ID and quantity.
|
||||
* @param id - gas ID to associate this GasStack to, will perform a GasRegistry lookup in the constructor
|
||||
* @param id - gas ID to associate this GasStack to, will perform a GasRegistry lookup
|
||||
* in the constructor
|
||||
* @param quantity - amount of gas to be referenced in this GasStack
|
||||
*/
|
||||
public GasStack(int id, int quantity)
|
||||
{
|
||||
public GasStack(int id, int quantity) {
|
||||
type = GasRegistry.getGas(id);
|
||||
amount = quantity;
|
||||
}
|
||||
|
@ -29,8 +28,7 @@ public class GasStack
|
|||
* @param gas - gas type of the stack
|
||||
* @param quantity - amount of gas to be referenced in this GasStack
|
||||
*/
|
||||
public GasStack(Gas gas, int quantity)
|
||||
{
|
||||
public GasStack(Gas gas, int quantity) {
|
||||
type = gas;
|
||||
amount = quantity;
|
||||
}
|
||||
|
@ -41,13 +39,11 @@ public class GasStack
|
|||
* Gets the Gas type of this GasStack.
|
||||
* @return this GasStack's Gas type
|
||||
*/
|
||||
public Gas getGas()
|
||||
{
|
||||
public Gas getGas() {
|
||||
return type;
|
||||
}
|
||||
|
||||
public GasStack withAmount(int newAmount)
|
||||
{
|
||||
public GasStack withAmount(int newAmount) {
|
||||
amount = newAmount;
|
||||
|
||||
return this;
|
||||
|
@ -58,8 +54,7 @@ public class GasStack
|
|||
* @param nbtTags - tag compound to write to
|
||||
* @return tag compound with this GasStack's data
|
||||
*/
|
||||
public NBTTagCompound write(NBTTagCompound nbtTags)
|
||||
{
|
||||
public NBTTagCompound write(NBTTagCompound nbtTags) {
|
||||
type.write(nbtTags);
|
||||
nbtTags.setInteger("amount", amount);
|
||||
|
||||
|
@ -70,29 +65,26 @@ public class GasStack
|
|||
* Reads this GasStack's data from a defined tag compound.
|
||||
* @param nbtTags - tag compound to read from
|
||||
*/
|
||||
public void read(NBTTagCompound nbtTags)
|
||||
{
|
||||
public void read(NBTTagCompound nbtTags) {
|
||||
type = Gas.readFromNBT(nbtTags);
|
||||
amount = nbtTags.getInteger("amount");
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the GasStack stored in the defined tag compound, or null if it doesn't exist.
|
||||
* Returns the GasStack stored in the defined tag compound, or null if it doesn't
|
||||
* exist.
|
||||
* @param nbtTags - tag compound to read from
|
||||
* @return GasStack stored in the tag compound
|
||||
*/
|
||||
public static GasStack readFromNBT(NBTTagCompound nbtTags)
|
||||
{
|
||||
if(nbtTags == null || nbtTags.hasNoTags())
|
||||
{
|
||||
public static GasStack readFromNBT(NBTTagCompound nbtTags) {
|
||||
if (nbtTags == null || nbtTags.hasNoTags()) {
|
||||
return null;
|
||||
}
|
||||
|
||||
GasStack stack = new GasStack();
|
||||
stack.read(nbtTags);
|
||||
|
||||
if(stack.getGas() == null || stack.amount <= 0)
|
||||
{
|
||||
if (stack.getGas() == null || stack.amount <= 0) {
|
||||
return null;
|
||||
}
|
||||
|
||||
|
@ -103,8 +95,7 @@ public class GasStack
|
|||
* Returns a copied form of this GasStack.
|
||||
* @return copied GasStack
|
||||
*/
|
||||
public GasStack copy()
|
||||
{
|
||||
public GasStack copy() {
|
||||
return new GasStack(type, amount);
|
||||
}
|
||||
|
||||
|
@ -113,20 +104,17 @@ public class GasStack
|
|||
* @param stack - GasStack to check
|
||||
* @return if the GasStacks contain the same gas type
|
||||
*/
|
||||
public boolean isGasEqual(GasStack stack)
|
||||
{
|
||||
public boolean isGasEqual(GasStack stack) {
|
||||
return stack != null && getGas() == stack.getGas();
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString()
|
||||
{
|
||||
public String toString() {
|
||||
return "[" + type + ", " + amount + "]";
|
||||
}
|
||||
|
||||
@Override
|
||||
public int hashCode()
|
||||
{
|
||||
public int hashCode() {
|
||||
return type == null ? 0 : type.getID();
|
||||
}
|
||||
}
|
||||
|
|
|
@ -3,12 +3,12 @@ package mekanism.api.gas;
|
|||
import net.minecraft.nbt.NBTTagCompound;
|
||||
|
||||
/**
|
||||
* An optional way of managing and/or storing gasses. Would be very useful in TileEntity and Entity gas storage.
|
||||
* An optional way of managing and/or storing gasses. Would be very useful in TileEntity
|
||||
* and Entity gas storage.
|
||||
* @author aidancbrady
|
||||
*
|
||||
*/
|
||||
public class GasTank
|
||||
{
|
||||
public class GasTank {
|
||||
public GasStack stored;
|
||||
|
||||
private int maxGas;
|
||||
|
@ -19,21 +19,19 @@ public class GasTank
|
|||
* Creates a tank with a defined capacity.
|
||||
* @param max - the maximum amount of gas this GasTank can hold
|
||||
*/
|
||||
public GasTank(int max)
|
||||
{
|
||||
public GasTank(int max) {
|
||||
maxGas = max;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets this tank's GasStack value to a new value. Will cap the amount to this GasTank's capacity.
|
||||
* Sets this tank's GasStack value to a new value. Will cap the amount to this
|
||||
* GasTank's capacity.
|
||||
* @param stack - value to set this tank's GasStack value to
|
||||
*/
|
||||
public void setGas(GasStack stack)
|
||||
{
|
||||
public void setGas(GasStack stack) {
|
||||
stored = stack;
|
||||
|
||||
if(stored != null)
|
||||
{
|
||||
if (stored != null) {
|
||||
stored.amount = Math.min(getMaxGas(), stored.amount);
|
||||
}
|
||||
}
|
||||
|
@ -44,23 +42,18 @@ public class GasTank
|
|||
* @param doDraw - if the gas should actually be removed from this tank
|
||||
* @return gas taken from this GasTank as a GasStack value
|
||||
*/
|
||||
public GasStack draw(int amount, boolean doDraw)
|
||||
{
|
||||
if(stored == null || amount <= 0)
|
||||
{
|
||||
public GasStack draw(int amount, boolean doDraw) {
|
||||
if (stored == null || amount <= 0) {
|
||||
return null;
|
||||
}
|
||||
|
||||
GasStack ret = new GasStack(getGas().getGas(), Math.min(getStored(), amount));
|
||||
|
||||
if(ret.amount > 0)
|
||||
{
|
||||
if(doDraw)
|
||||
{
|
||||
if (ret.amount > 0) {
|
||||
if (doDraw) {
|
||||
stored.amount -= ret.amount;
|
||||
|
||||
if(stored.amount <= 0)
|
||||
{
|
||||
if (stored.amount <= 0) {
|
||||
stored = null;
|
||||
}
|
||||
}
|
||||
|
@ -77,22 +70,19 @@ public class GasTank
|
|||
* @param doReceive - if the gas should actually be added to this tank
|
||||
* @return the amount of gas accepted by this tank
|
||||
*/
|
||||
public int receive(GasStack amount, boolean doReceive)
|
||||
{
|
||||
if(amount == null || (stored != null && !(stored.amount != getMaxGas() && stored.isGasEqual(amount))))
|
||||
{
|
||||
public int receive(GasStack amount, boolean doReceive) {
|
||||
if (amount == null
|
||||
|| (stored != null
|
||||
&& !(stored.amount != getMaxGas() && stored.isGasEqual(amount)))) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
int toFill = Math.min(getMaxGas() - getStored(), amount.amount);
|
||||
|
||||
if(doReceive)
|
||||
{
|
||||
if(stored == null)
|
||||
{
|
||||
if (doReceive) {
|
||||
if (stored == null) {
|
||||
stored = amount.copy().withAmount(getStored() + toFill);
|
||||
}
|
||||
else {
|
||||
} else {
|
||||
stored.amount = Math.min(getMaxGas(), getStored() + amount.amount);
|
||||
}
|
||||
}
|
||||
|
@ -101,14 +91,14 @@ public class GasTank
|
|||
}
|
||||
|
||||
/**
|
||||
* If this GasTank can receive the specified type of gas. Will return false if this tank does not need anymore gas.
|
||||
* If this GasTank can receive the specified type of gas. Will return false if this
|
||||
* tank does not need anymore gas.
|
||||
* @param gas - gas to check
|
||||
* @return if this GasTank can accept the defined gas
|
||||
*/
|
||||
public boolean canReceive(Gas gas)
|
||||
{
|
||||
if(getNeeded() == 0 || stored != null && (gas != null && gas != stored.getGas()))
|
||||
{
|
||||
public boolean canReceive(Gas gas) {
|
||||
if (getNeeded() == 0
|
||||
|| stored != null && (gas != null && gas != stored.getGas())) {
|
||||
return false;
|
||||
}
|
||||
|
||||
|
@ -116,14 +106,13 @@ public class GasTank
|
|||
}
|
||||
|
||||
/**
|
||||
* If this GasTank can receive the specified type of gas. Will return TRUE if this tank does not need anymore gas.
|
||||
* If this GasTank can receive the specified type of gas. Will return TRUE if this
|
||||
* tank does not need anymore gas.
|
||||
* @param gas - gas to check
|
||||
* @return if this GasTank can accept the defined gas
|
||||
*/
|
||||
public boolean canReceiveType(Gas gas)
|
||||
{
|
||||
if(stored != null && (gas != null && gas != stored.getGas()))
|
||||
{
|
||||
public boolean canReceiveType(Gas gas) {
|
||||
if (stored != null && (gas != null && gas != stored.getGas())) {
|
||||
return false;
|
||||
}
|
||||
|
||||
|
@ -131,14 +120,13 @@ public class GasTank
|
|||
}
|
||||
|
||||
/**
|
||||
* If this GasTank can be drawn of the specified type of gas. Will return false if this tank does not contain any gas.
|
||||
* If this GasTank can be drawn of the specified type of gas. Will return false if
|
||||
* this tank does not contain any gas.
|
||||
* @param gas - gas to check
|
||||
* @return if this GasTank can be drawn of the defined gas
|
||||
*/
|
||||
public boolean canDraw(Gas gas)
|
||||
{
|
||||
if(stored == null || (gas != null && gas != stored.getGas()))
|
||||
{
|
||||
public boolean canDraw(Gas gas) {
|
||||
if (stored == null || (gas != null && gas != stored.getGas())) {
|
||||
return false;
|
||||
}
|
||||
|
||||
|
@ -149,8 +137,7 @@ public class GasTank
|
|||
* Gets the amount of gas needed by this GasTank.
|
||||
* @return
|
||||
*/
|
||||
public int getNeeded()
|
||||
{
|
||||
public int getNeeded() {
|
||||
return getMaxGas() - getStored();
|
||||
}
|
||||
|
||||
|
@ -158,16 +145,14 @@ public class GasTank
|
|||
* Gets the maximum amount of gas this tank can hold.
|
||||
* @return - max gas
|
||||
*/
|
||||
public int getMaxGas()
|
||||
{
|
||||
public int getMaxGas() {
|
||||
return maxGas;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the maximum amount of gas this tank can hold
|
||||
*/
|
||||
public void setMaxGas(int capacity)
|
||||
{
|
||||
public void setMaxGas(int capacity) {
|
||||
maxGas = capacity;
|
||||
}
|
||||
|
||||
|
@ -175,8 +160,7 @@ public class GasTank
|
|||
* Gets the GasStack held by this GasTank.
|
||||
* @return - GasStakc held by this tank
|
||||
*/
|
||||
public GasStack getGas()
|
||||
{
|
||||
public GasStack getGas() {
|
||||
return stored;
|
||||
}
|
||||
|
||||
|
@ -184,8 +168,7 @@ public class GasTank
|
|||
* Gets the type of gas currently stored in this GasTank.
|
||||
* @return gas type contained
|
||||
*/
|
||||
public Gas getGasType()
|
||||
{
|
||||
public Gas getGasType() {
|
||||
return stored != null ? stored.getGas() : null;
|
||||
}
|
||||
|
||||
|
@ -193,8 +176,7 @@ public class GasTank
|
|||
* Gets the amount of gas stored by this GasTank.
|
||||
* @return amount of gas stored
|
||||
*/
|
||||
public int getStored()
|
||||
{
|
||||
public int getStored() {
|
||||
return stored != null ? stored.amount : 0;
|
||||
}
|
||||
|
||||
|
@ -203,10 +185,8 @@ public class GasTank
|
|||
* @param nbtTags - tag compound to write to
|
||||
* @return tag compound with this tank's data
|
||||
*/
|
||||
public NBTTagCompound write(NBTTagCompound nbtTags)
|
||||
{
|
||||
if(stored != null && stored.getGas() != null)
|
||||
{
|
||||
public NBTTagCompound write(NBTTagCompound nbtTags) {
|
||||
if (stored != null && stored.getGas() != null) {
|
||||
nbtTags.setTag("stored", stored.write(new NBTTagCompound()));
|
||||
}
|
||||
|
||||
|
@ -219,15 +199,12 @@ public class GasTank
|
|||
* Reads this tank's data from a defined tag compound.
|
||||
* @param nbtTags - tag compound to read from
|
||||
*/
|
||||
public void read(NBTTagCompound nbtTags)
|
||||
{
|
||||
if(nbtTags.hasKey("stored"))
|
||||
{
|
||||
public void read(NBTTagCompound nbtTags) {
|
||||
if (nbtTags.hasKey("stored")) {
|
||||
stored = GasStack.readFromNBT(nbtTags.getCompoundTag("stored"));
|
||||
}
|
||||
|
||||
if(nbtTags.hasKey("maxGas") && nbtTags.getInteger("maxGas") != 0)
|
||||
{
|
||||
if (nbtTags.hasKey("maxGas") && nbtTags.getInteger("maxGas") != 0) {
|
||||
maxGas = nbtTags.getInteger("maxGas");
|
||||
}
|
||||
}
|
||||
|
@ -237,10 +214,8 @@ public class GasTank
|
|||
* @param nbtTags - tag compound to read from
|
||||
* @return tank stored in the tag compound
|
||||
*/
|
||||
public static GasTank readFromNBT(NBTTagCompound nbtTags)
|
||||
{
|
||||
if(nbtTags == null || nbtTags.hasNoTags())
|
||||
{
|
||||
public static GasTank readFromNBT(NBTTagCompound nbtTags) {
|
||||
if (nbtTags == null || nbtTags.hasNoTags()) {
|
||||
return null;
|
||||
}
|
||||
|
||||
|
|
|
@ -18,18 +18,19 @@ import net.minecraftforge.common.util.ForgeDirection;
|
|||
* @author AidanBrady
|
||||
*
|
||||
*/
|
||||
public final class GasTransmission
|
||||
{
|
||||
public static IGasHandler[] getConnectedAcceptors(TileEntity tileEntity, Collection<ForgeDirection> sides)
|
||||
{
|
||||
IGasHandler[] acceptors = new IGasHandler[] {null, null, null, null, null, null};
|
||||
public final class GasTransmission {
|
||||
public static IGasHandler[] getConnectedAcceptors(
|
||||
TileEntity tileEntity, Collection<ForgeDirection> sides
|
||||
) {
|
||||
IGasHandler[] acceptors
|
||||
= new IGasHandler[] { null, null, null, null, null, null };
|
||||
|
||||
for(ForgeDirection orientation : sides)
|
||||
{
|
||||
TileEntity acceptor = Coord4D.get(tileEntity).getFromSide(orientation).getTileEntity(tileEntity.getWorldObj());
|
||||
for (ForgeDirection orientation : sides) {
|
||||
TileEntity acceptor = Coord4D.get(tileEntity)
|
||||
.getFromSide(orientation)
|
||||
.getTileEntity(tileEntity.getWorldObj());
|
||||
|
||||
if(acceptor instanceof IGasHandler)
|
||||
{
|
||||
if (acceptor instanceof IGasHandler) {
|
||||
acceptors[orientation.ordinal()] = (IGasHandler) acceptor;
|
||||
}
|
||||
}
|
||||
|
@ -42,9 +43,10 @@ public final class GasTransmission
|
|||
* @param tileEntity - center tile entity
|
||||
* @return array of IGasAcceptors
|
||||
*/
|
||||
public static IGasHandler[] getConnectedAcceptors(TileEntity tileEntity)
|
||||
{
|
||||
return getConnectedAcceptors(tileEntity, Arrays.asList(ForgeDirection.VALID_DIRECTIONS));
|
||||
public static IGasHandler[] getConnectedAcceptors(TileEntity tileEntity) {
|
||||
return getConnectedAcceptors(
|
||||
tileEntity, Arrays.asList(ForgeDirection.VALID_DIRECTIONS)
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -52,16 +54,16 @@ public final class GasTransmission
|
|||
* @param tileEntity - center tile entity
|
||||
* @return array of ITubeConnections
|
||||
*/
|
||||
public static ITubeConnection[] getConnections(TileEntity tileEntity)
|
||||
{
|
||||
ITubeConnection[] connections = new ITubeConnection[] {null, null, null, null, null, null};
|
||||
public static ITubeConnection[] getConnections(TileEntity tileEntity) {
|
||||
ITubeConnection[] connections
|
||||
= new ITubeConnection[] { null, null, null, null, null, null };
|
||||
|
||||
for(ForgeDirection orientation : ForgeDirection.VALID_DIRECTIONS)
|
||||
{
|
||||
TileEntity connection = Coord4D.get(tileEntity).getFromSide(orientation).getTileEntity(tileEntity.getWorldObj());
|
||||
for (ForgeDirection orientation : ForgeDirection.VALID_DIRECTIONS) {
|
||||
TileEntity connection = Coord4D.get(tileEntity)
|
||||
.getFromSide(orientation)
|
||||
.getTileEntity(tileEntity.getWorldObj());
|
||||
|
||||
if(canConnect(connection, orientation))
|
||||
{
|
||||
if (canConnect(connection, orientation)) {
|
||||
connections[orientation.ordinal()] = (ITubeConnection) connection;
|
||||
}
|
||||
}
|
||||
|
@ -75,12 +77,13 @@ public final class GasTransmission
|
|||
* @param side - side to attempt connection on
|
||||
* @return if this tile and side are connectable
|
||||
*/
|
||||
public static boolean canConnect(TileEntity tileEntity, ForgeDirection side)
|
||||
{
|
||||
if(tileEntity instanceof ITubeConnection && (!(tileEntity instanceof ITransmitterTile) || TransmissionType.checkTransmissionType(((ITransmitterTile)tileEntity).getTransmitter(), TransmissionType.GAS)))
|
||||
{
|
||||
if(((ITubeConnection)tileEntity).canTubeConnect(side.getOpposite()))
|
||||
{
|
||||
public static boolean canConnect(TileEntity tileEntity, ForgeDirection side) {
|
||||
if (tileEntity instanceof ITubeConnection
|
||||
&& (!(tileEntity instanceof ITransmitterTile)
|
||||
|| TransmissionType.checkTransmissionType(
|
||||
((ITransmitterTile) tileEntity).getTransmitter(), TransmissionType.GAS
|
||||
))) {
|
||||
if (((ITubeConnection) tileEntity).canTubeConnect(side.getOpposite())) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
@ -95,14 +98,13 @@ public final class GasTransmission
|
|||
* @param amount - amount of gas to remove from the ItemStack
|
||||
* @return the GasStack removed by the IGasItem
|
||||
*/
|
||||
public static GasStack removeGas(ItemStack itemStack, Gas type, int amount)
|
||||
{
|
||||
if(itemStack != null && itemStack.getItem() instanceof IGasItem)
|
||||
{
|
||||
public static GasStack removeGas(ItemStack itemStack, Gas type, int amount) {
|
||||
if (itemStack != null && itemStack.getItem() instanceof IGasItem) {
|
||||
IGasItem item = (IGasItem) itemStack.getItem();
|
||||
|
||||
if(type != null && item.getGas(itemStack) != null && item.getGas(itemStack).getGas() != type || !item.canProvideGas(itemStack, type))
|
||||
{
|
||||
if (type != null && item.getGas(itemStack) != null
|
||||
&& item.getGas(itemStack).getGas() != type
|
||||
|| !item.canProvideGas(itemStack, type)) {
|
||||
return null;
|
||||
}
|
||||
|
||||
|
@ -118,10 +120,10 @@ public final class GasTransmission
|
|||
* @param stack - stack to add to the IGasItem
|
||||
* @return amount of gas accepted by the IGasItem
|
||||
*/
|
||||
public static int addGas(ItemStack itemStack, GasStack stack)
|
||||
{
|
||||
if(itemStack != null && itemStack.getItem() instanceof IGasItem && ((IGasItem)itemStack.getItem()).canReceiveGas(itemStack, stack.getGas()))
|
||||
{
|
||||
public static int addGas(ItemStack itemStack, GasStack stack) {
|
||||
if (itemStack != null && itemStack.getItem() instanceof IGasItem
|
||||
&& ((IGasItem) itemStack.getItem())
|
||||
.canReceiveGas(itemStack, stack.getGas())) {
|
||||
return ((IGasItem) itemStack.getItem()).addGas(itemStack, stack.copy());
|
||||
}
|
||||
|
||||
|
@ -129,28 +131,29 @@ public final class GasTransmission
|
|||
}
|
||||
|
||||
/**
|
||||
* Emits gas from a central block by splitting the received stack among the sides given.
|
||||
* Emits gas from a central block by splitting the received stack among the sides
|
||||
* given.
|
||||
* @param stack - the stack to output
|
||||
* @param from - the TileEntity to output from
|
||||
* @param sides - the list of sides to output from
|
||||
* @return the amount of gas emitted
|
||||
*/
|
||||
public static int emit(GasStack stack, TileEntity from, Collection<ForgeDirection> sides)
|
||||
{
|
||||
if(stack == null)
|
||||
{
|
||||
public static int
|
||||
emit(GasStack stack, TileEntity from, Collection<ForgeDirection> sides) {
|
||||
if (stack == null) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
List<IGasHandler> availableAcceptors = new ArrayList<IGasHandler>();
|
||||
IGasHandler[] possibleAcceptors = getConnectedAcceptors(from, sides);
|
||||
|
||||
for(int i = 0; i < possibleAcceptors.length; i++)
|
||||
{
|
||||
for (int i = 0; i < possibleAcceptors.length; i++) {
|
||||
IGasHandler handler = possibleAcceptors[i];
|
||||
|
||||
if(handler != null && handler.canReceiveGas(ForgeDirection.getOrientation(i).getOpposite(), stack.getGas()))
|
||||
{
|
||||
if (handler != null
|
||||
&& handler.canReceiveGas(
|
||||
ForgeDirection.getOrientation(i).getOpposite(), stack.getGas()
|
||||
)) {
|
||||
availableAcceptors.add(handler);
|
||||
}
|
||||
}
|
||||
|
@ -160,24 +163,28 @@ public final class GasTransmission
|
|||
int toSend = stack.amount;
|
||||
int prevSending = toSend;
|
||||
|
||||
if(!availableAcceptors.isEmpty())
|
||||
{
|
||||
if (!availableAcceptors.isEmpty()) {
|
||||
int divider = availableAcceptors.size();
|
||||
int remaining = toSend % divider;
|
||||
int sending = (toSend - remaining) / divider;
|
||||
|
||||
for(IGasHandler acceptor : availableAcceptors)
|
||||
{
|
||||
for (IGasHandler acceptor : availableAcceptors) {
|
||||
int currentSending = sending;
|
||||
|
||||
if(remaining > 0)
|
||||
{
|
||||
if (remaining > 0) {
|
||||
currentSending++;
|
||||
remaining--;
|
||||
}
|
||||
|
||||
ForgeDirection dir = ForgeDirection.getOrientation(Arrays.asList(possibleAcceptors).indexOf(acceptor)).getOpposite();
|
||||
toSend -= acceptor.receiveGas(dir, new GasStack(stack.getGas(), currentSending), true);
|
||||
ForgeDirection dir
|
||||
= ForgeDirection
|
||||
.getOrientation(
|
||||
Arrays.asList(possibleAcceptors).indexOf(acceptor)
|
||||
)
|
||||
.getOpposite();
|
||||
toSend -= acceptor.receiveGas(
|
||||
dir, new GasStack(stack.getGas(), currentSending), true
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -7,8 +7,7 @@ import net.minecraftforge.common.util.ForgeDirection;
|
|||
* @author AidanBrady
|
||||
*
|
||||
*/
|
||||
public interface IGasHandler
|
||||
{
|
||||
public interface IGasHandler {
|
||||
/**
|
||||
* Transfer a certain amount of gas to this block.
|
||||
* @param stack - gas to add
|
||||
|
|
|
@ -7,8 +7,7 @@ import net.minecraft.item.ItemStack;
|
|||
* @author AidanBrady
|
||||
*
|
||||
*/
|
||||
public interface IGasItem
|
||||
{
|
||||
public interface IGasItem {
|
||||
/**
|
||||
* Gets the rate of transfer this item can handle.
|
||||
* @return
|
||||
|
|
|
@ -3,7 +3,6 @@ package mekanism.api.gas;
|
|||
import mekanism.api.transmitters.IGridTransmitter;
|
||||
import net.minecraft.tileentity.TileEntity;
|
||||
|
||||
public interface IGasTransmitter extends IGridTransmitter<IGasHandler, GasNetwork>
|
||||
{
|
||||
public interface IGasTransmitter extends IGridTransmitter<IGasHandler, GasNetwork> {
|
||||
public boolean canTransferGasToTube(TileEntity tile);
|
||||
}
|
||||
|
|
|
@ -7,8 +7,7 @@ import net.minecraftforge.common.util.ForgeDirection;
|
|||
* @author AidanBrady
|
||||
*
|
||||
*/
|
||||
public interface ITubeConnection
|
||||
{
|
||||
public interface ITubeConnection {
|
||||
/**
|
||||
* Whether or not a tube can connect to a certain orientation.
|
||||
* @param side - orientation to check
|
||||
|
|
|
@ -2,37 +2,31 @@ package mekanism.api.gas;
|
|||
|
||||
import net.minecraft.util.StatCollector;
|
||||
|
||||
public class OreGas extends Gas
|
||||
{
|
||||
public class OreGas extends Gas {
|
||||
private String oreName;
|
||||
private OreGas cleanGas;
|
||||
|
||||
public OreGas(String s, String name)
|
||||
{
|
||||
public OreGas(String s, String name) {
|
||||
super(s);
|
||||
|
||||
oreName = name;
|
||||
}
|
||||
|
||||
public boolean isClean()
|
||||
{
|
||||
public boolean isClean() {
|
||||
return getCleanGas() == null;
|
||||
}
|
||||
|
||||
public OreGas getCleanGas()
|
||||
{
|
||||
public OreGas getCleanGas() {
|
||||
return cleanGas;
|
||||
}
|
||||
|
||||
public OreGas setCleanGas(OreGas gas)
|
||||
{
|
||||
public OreGas setCleanGas(OreGas gas) {
|
||||
cleanGas = gas;
|
||||
|
||||
return this;
|
||||
}
|
||||
|
||||
public String getOreName()
|
||||
{
|
||||
public String getOreName() {
|
||||
return StatCollector.translateToLocal(oreName);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,4 +1,3 @@
|
|||
@API(apiVersion = "9.0.0", owner = "Mekanism", provides = "MekanismAPI|gas")
|
||||
package mekanism.api.gas;
|
||||
import cpw.mods.fml.common.API;
|
||||
|
||||
|
|
|
@ -1,20 +1,19 @@
|
|||
package mekanism.api.infuse;
|
||||
|
||||
/**
|
||||
* InfuseObject - an object associated with an ItemStack that can modify a Metallurgic Infuser's internal infuse.
|
||||
* InfuseObject - an object associated with an ItemStack that can modify a Metallurgic
|
||||
* Infuser's internal infuse.
|
||||
* @author AidanBrady
|
||||
*
|
||||
*/
|
||||
public class InfuseObject
|
||||
{
|
||||
public class InfuseObject {
|
||||
/** The type of infuse this item stores */
|
||||
public InfuseType type;
|
||||
|
||||
/** How much infuse this item stores */
|
||||
public int stored;
|
||||
|
||||
public InfuseObject(InfuseType infusion, int i)
|
||||
{
|
||||
public InfuseObject(InfuseType infusion, int i) {
|
||||
type = infusion;
|
||||
stored = i;
|
||||
}
|
||||
|
|
|
@ -10,22 +10,21 @@ import net.minecraft.item.ItemStack;
|
|||
* @author AidanBrady
|
||||
*
|
||||
*/
|
||||
public class InfuseRegistry
|
||||
{
|
||||
public class InfuseRegistry {
|
||||
/** The (private) map of ItemStacks and their related InfuseObjects. */
|
||||
private static Map<ItemStack, InfuseObject> infuseObjects = new HashMap<ItemStack, InfuseObject>();
|
||||
private static Map<ItemStack, InfuseObject> infuseObjects
|
||||
= new HashMap<ItemStack, InfuseObject>();
|
||||
|
||||
/** The (private) map of infuse names and their corresponding InfuseTypes. */
|
||||
private static Map<String, InfuseType> infuseTypes = new HashMap<String, InfuseType>();
|
||||
private static Map<String, InfuseType> infuseTypes
|
||||
= new HashMap<String, InfuseType>();
|
||||
|
||||
/**
|
||||
* Registers an InfuseType into the registry. Call this in PreInit!
|
||||
* @param infuse
|
||||
*/
|
||||
public static void registerInfuseType(InfuseType infuse)
|
||||
{
|
||||
if(infuseTypes.containsKey(infuse.name))
|
||||
{
|
||||
public static void registerInfuseType(InfuseType infuse) {
|
||||
if (infuseTypes.containsKey(infuse.name)) {
|
||||
return;
|
||||
}
|
||||
|
||||
|
@ -37,10 +36,8 @@ public class InfuseRegistry
|
|||
* @param name - the name of the InfuseType to get
|
||||
* @return the name's corresponding InfuseType
|
||||
*/
|
||||
public static InfuseType get(String name)
|
||||
{
|
||||
if(name.equals("null"))
|
||||
{
|
||||
public static InfuseType get(String name) {
|
||||
if (name.equals("null")) {
|
||||
return null;
|
||||
}
|
||||
|
||||
|
@ -52,23 +49,22 @@ public class InfuseRegistry
|
|||
* @param name - the name to check
|
||||
* @return if the name has a coorespondent InfuseType
|
||||
*/
|
||||
public static boolean contains(String name)
|
||||
{
|
||||
public static boolean contains(String name) {
|
||||
return get(name) != null;
|
||||
}
|
||||
|
||||
/**
|
||||
* Registers a block or item that serves as an infuse object. An infuse object will store a certain type and amount of infuse,
|
||||
* and will deliver this amount to the Metallurgic Infuser's buffer of infuse. The item's stack size will be decremented when
|
||||
* it is placed in the Metallurgic Infuser's infuse slot, and the machine can accept the type and amount of infuse stored in the
|
||||
* object.
|
||||
* Registers a block or item that serves as an infuse object. An infuse object will
|
||||
* store a certain type and amount of infuse, and will deliver this amount to the
|
||||
* Metallurgic Infuser's buffer of infuse. The item's stack size will be decremented
|
||||
* when it is placed in the Metallurgic Infuser's infuse slot, and the machine can
|
||||
* accept the type and amount of infuse stored in the object.
|
||||
* @param itemStack - stack the infuse object is linked to -- stack size is ignored
|
||||
* @param infuseObject - the infuse object with the type and amount data
|
||||
*/
|
||||
public static void registerInfuseObject(ItemStack itemStack, InfuseObject infuseObject)
|
||||
{
|
||||
if(getObject(itemStack) != null)
|
||||
{
|
||||
public static void
|
||||
registerInfuseObject(ItemStack itemStack, InfuseObject infuseObject) {
|
||||
if (getObject(itemStack) != null) {
|
||||
return;
|
||||
}
|
||||
|
||||
|
@ -80,12 +76,9 @@ public class InfuseRegistry
|
|||
* @param itemStack - the ItemStack to check
|
||||
* @return the ItemStack's InfuseObject
|
||||
*/
|
||||
public static InfuseObject getObject(ItemStack itemStack)
|
||||
{
|
||||
for(Map.Entry<ItemStack, InfuseObject> obj : infuseObjects.entrySet())
|
||||
{
|
||||
if(itemStack.isItemEqual(obj.getKey()))
|
||||
{
|
||||
public static InfuseObject getObject(ItemStack itemStack) {
|
||||
for (Map.Entry<ItemStack, InfuseObject> obj : infuseObjects.entrySet()) {
|
||||
if (itemStack.isItemEqual(obj.getKey())) {
|
||||
return obj.getValue();
|
||||
}
|
||||
}
|
||||
|
@ -97,8 +90,7 @@ public class InfuseRegistry
|
|||
* Gets the private map for InfuseObjects.
|
||||
* @return private InfuseObject map
|
||||
*/
|
||||
public static final Map<ItemStack, InfuseObject> getObjectMap()
|
||||
{
|
||||
public static final Map<ItemStack, InfuseObject> getObjectMap() {
|
||||
return infuseObjects;
|
||||
}
|
||||
|
||||
|
@ -106,8 +98,7 @@ public class InfuseRegistry
|
|||
* Gets the private map for InfuseTypes.
|
||||
* @return private InfuseType map
|
||||
*/
|
||||
public static final Map<String, InfuseType> getInfuseMap()
|
||||
{
|
||||
public static final Map<String, InfuseType> getInfuseMap() {
|
||||
return infuseTypes;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -8,8 +8,7 @@ import net.minecraft.util.StatCollector;
|
|||
* @author AidanBrady
|
||||
*
|
||||
*/
|
||||
public final class InfuseType
|
||||
{
|
||||
public final class InfuseType {
|
||||
/** The name of this infusion */
|
||||
public String name;
|
||||
|
||||
|
@ -22,26 +21,22 @@ public final class InfuseType
|
|||
/** The unlocalized name of this type. */
|
||||
public String unlocalizedName;
|
||||
|
||||
public InfuseType(String s, String tex)
|
||||
{
|
||||
public InfuseType(String s, String tex) {
|
||||
name = s;
|
||||
textureLocation = tex;
|
||||
}
|
||||
|
||||
public void setIcon(IIcon i)
|
||||
{
|
||||
public void setIcon(IIcon i) {
|
||||
icon = i;
|
||||
}
|
||||
|
||||
public InfuseType setUnlocalizedName(String name)
|
||||
{
|
||||
public InfuseType setUnlocalizedName(String name) {
|
||||
unlocalizedName = "infuse." + name;
|
||||
|
||||
return this;
|
||||
}
|
||||
|
||||
public String getLocalizedName()
|
||||
{
|
||||
public String getLocalizedName() {
|
||||
return StatCollector.translateToLocal(unlocalizedName);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,4 +1,3 @@
|
|||
@API(apiVersion = "9.0.0", owner = "Mekanism", provides = "MekanismAPI|infuse")
|
||||
package mekanism.api.infuse;
|
||||
import cpw.mods.fml.common.API;
|
||||
|
||||
|
|
|
@ -2,8 +2,7 @@ package mekanism.api.lasers;
|
|||
|
||||
import net.minecraftforge.common.util.ForgeDirection;
|
||||
|
||||
public interface ILaserReceptor
|
||||
{
|
||||
public interface ILaserReceptor {
|
||||
public void receiveLaserEnergy(double energy, ForgeDirection side);
|
||||
|
||||
public boolean canLasersDig();
|
||||
|
|
|
@ -1,4 +1,3 @@
|
|||
@API(apiVersion = "9.0.0", owner = "Mekanism", provides = "MekanismAPI|laser")
|
||||
package mekanism.api.lasers;
|
||||
import cpw.mods.fml.common.API;
|
||||
|
||||
|
|
|
@ -1,4 +1,3 @@
|
|||
@API(apiVersion = "9.0.0", owner = "Mekanism", provides = "MekanismAPI|core")
|
||||
package mekanism.api;
|
||||
import cpw.mods.fml.common.API;
|
||||
|
||||
|
|
|
@ -5,8 +5,7 @@ import mekanism.api.gas.GasTank;
|
|||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraftforge.fluids.FluidTank;
|
||||
|
||||
public interface IFusionReactor extends IHeatTransfer
|
||||
{
|
||||
public interface IFusionReactor extends IHeatTransfer {
|
||||
public void addTemperatureFromEnergyInput(double energyAdded);
|
||||
|
||||
public void simulate();
|
||||
|
|
|
@ -1,6 +1,5 @@
|
|||
package mekanism.api.reactor;
|
||||
|
||||
public interface INeutronCapture extends IReactorBlock
|
||||
{
|
||||
public interface INeutronCapture extends IReactorBlock {
|
||||
public int absorbNeutrons(int neutrons);
|
||||
}
|
||||
|
|
|
@ -1,12 +1,9 @@
|
|||
package mekanism.api.reactor;
|
||||
|
||||
|
||||
public interface IReactorBlock
|
||||
{
|
||||
public interface IReactorBlock {
|
||||
public boolean isFrame();
|
||||
|
||||
public void setReactor(IFusionReactor reactor);
|
||||
|
||||
public IFusionReactor getReactor();
|
||||
|
||||
}
|
||||
|
|
|
@ -1,4 +1,3 @@
|
|||
@API(apiVersion = "9.0.0", owner = "Mekanism", provides = "MekanismAPI|reactor")
|
||||
package mekanism.api.reactor;
|
||||
import cpw.mods.fml.common.API;
|
||||
|
||||
|
|
|
@ -14,18 +14,18 @@ import net.minecraftforge.fluids.FluidStack;
|
|||
*
|
||||
*/
|
||||
@Deprecated
|
||||
public final class RecipeHelper
|
||||
{
|
||||
public final class RecipeHelper {
|
||||
/**
|
||||
* Add an Enrichment Chamber recipe.
|
||||
* @param input - input ItemStack
|
||||
* @param output - output ItemStack
|
||||
*/
|
||||
public static void addEnrichmentChamberRecipe(ItemStack input, ItemStack output)
|
||||
{
|
||||
public static void addEnrichmentChamberRecipe(ItemStack input, ItemStack output) {
|
||||
try {
|
||||
Class recipeClass = Class.forName("mekanism.common.recipe.RecipeHandler");
|
||||
Method m = recipeClass.getMethod("addEnrichmentChamberRecipe", ItemStack.class, ItemStack.class);
|
||||
Method m = recipeClass.getMethod(
|
||||
"addEnrichmentChamberRecipe", ItemStack.class, ItemStack.class
|
||||
);
|
||||
m.invoke(null, input, output);
|
||||
} catch (Exception e) {
|
||||
System.err.println("Error while adding recipe: " + e.getMessage());
|
||||
|
@ -37,11 +37,12 @@ public final class RecipeHelper
|
|||
* @param input - input ItemStack
|
||||
* @param output - output ItemStack
|
||||
*/
|
||||
public static void addOsmiumCompressorRecipe(ItemStack input, ItemStack output)
|
||||
{
|
||||
public static void addOsmiumCompressorRecipe(ItemStack input, ItemStack output) {
|
||||
try {
|
||||
Class recipeClass = Class.forName("mekanism.common.recipe.RecipeHandler");
|
||||
Method m = recipeClass.getMethod("addOsmiumCompressorRecipe", ItemStack.class, ItemStack.class);
|
||||
Method m = recipeClass.getMethod(
|
||||
"addOsmiumCompressorRecipe", ItemStack.class, ItemStack.class
|
||||
);
|
||||
m.invoke(null, input, output);
|
||||
} catch (Exception e) {
|
||||
System.err.println("Error while adding recipe: " + e.getMessage());
|
||||
|
@ -53,11 +54,12 @@ public final class RecipeHelper
|
|||
* @param input - input ItemStack
|
||||
* @param output - output ItemStack
|
||||
*/
|
||||
public static void addCombinerRecipe(ItemStack input, ItemStack output)
|
||||
{
|
||||
public static void addCombinerRecipe(ItemStack input, ItemStack output) {
|
||||
try {
|
||||
Class recipeClass = Class.forName("mekanism.common.recipe.RecipeHandler");
|
||||
Method m = recipeClass.getMethod("addCombinerRecipe", ItemStack.class, ItemStack.class);
|
||||
Method m
|
||||
= recipeClass
|
||||
.getMethod("addCombinerRecipe", ItemStack.class, ItemStack.class);
|
||||
m.invoke(null, input, output);
|
||||
} catch (Exception e) {
|
||||
System.err.println("Error while adding recipe: " + e.getMessage());
|
||||
|
@ -69,11 +71,12 @@ public final class RecipeHelper
|
|||
* @param input - input ItemStack
|
||||
* @param output - output ItemStack
|
||||
*/
|
||||
public static void addCrusherRecipe(ItemStack input, ItemStack output)
|
||||
{
|
||||
public static void addCrusherRecipe(ItemStack input, ItemStack output) {
|
||||
try {
|
||||
Class recipeClass = Class.forName("mekanism.common.recipe.RecipeHandler");
|
||||
Method m = recipeClass.getMethod("addCrusherRecipe", ItemStack.class, ItemStack.class);
|
||||
Method m
|
||||
= recipeClass
|
||||
.getMethod("addCrusherRecipe", ItemStack.class, ItemStack.class);
|
||||
m.invoke(null, input, output);
|
||||
} catch (Exception e) {
|
||||
System.err.println("Error while adding recipe: " + e.getMessage());
|
||||
|
@ -85,11 +88,12 @@ public final class RecipeHelper
|
|||
* @param input - input ItemStack
|
||||
* @param output - output ItemStack
|
||||
*/
|
||||
public static void addPurificationChamberRecipe(ItemStack input, ItemStack output)
|
||||
{
|
||||
public static void addPurificationChamberRecipe(ItemStack input, ItemStack output) {
|
||||
try {
|
||||
Class recipeClass = Class.forName("mekanism.common.recipe.RecipeHandler");
|
||||
Method m = recipeClass.getMethod("addPurificationChamberRecipe", ItemStack.class, ItemStack.class);
|
||||
Method m = recipeClass.getMethod(
|
||||
"addPurificationChamberRecipe", ItemStack.class, ItemStack.class
|
||||
);
|
||||
m.invoke(null, input, output);
|
||||
} catch (Exception e) {
|
||||
System.err.println("Error while adding recipe: " + e.getMessage());
|
||||
|
@ -101,11 +105,12 @@ public final class RecipeHelper
|
|||
* @param input - input ItemStack
|
||||
* @param output - output GasStack
|
||||
*/
|
||||
public static void addChemicalOxidizerRecipe(ItemStack input, GasStack output)
|
||||
{
|
||||
public static void addChemicalOxidizerRecipe(ItemStack input, GasStack output) {
|
||||
try {
|
||||
Class recipeClass = Class.forName("mekanism.common.recipe.RecipeHandler");
|
||||
Method m = recipeClass.getMethod("addChemicalOxidizerRecipe", ItemStack.class, GasStack.class);
|
||||
Method m = recipeClass.getMethod(
|
||||
"addChemicalOxidizerRecipe", ItemStack.class, GasStack.class
|
||||
);
|
||||
m.invoke(null, input, output);
|
||||
} catch (Exception e) {
|
||||
System.err.println("Error while adding recipe: " + e.getMessage());
|
||||
|
@ -118,11 +123,13 @@ public final class RecipeHelper
|
|||
* @param rightInput - right input GasStack
|
||||
* @param output - output GasStack
|
||||
*/
|
||||
public static void addChemicalInfuserRecipe(GasStack leftInput, GasStack rightInput, GasStack output)
|
||||
{
|
||||
public static void
|
||||
addChemicalInfuserRecipe(GasStack leftInput, GasStack rightInput, GasStack output) {
|
||||
try {
|
||||
Class recipeClass = Class.forName("mekanism.common.recipe.RecipeHandler");
|
||||
Method m = recipeClass.getMethod("addChemicalInfuserRecipe", GasStack.class, GasStack.class, GasStack.class);
|
||||
Method m = recipeClass.getMethod(
|
||||
"addChemicalInfuserRecipe", GasStack.class, GasStack.class, GasStack.class
|
||||
);
|
||||
m.invoke(null, leftInput, rightInput, output);
|
||||
} catch (Exception e) {
|
||||
System.err.println("Error while adding recipe: " + e.getMessage());
|
||||
|
@ -136,11 +143,18 @@ public final class RecipeHelper
|
|||
* @param secondaryOutput - possible extra output
|
||||
* @param chance - probability of obtaining extra output
|
||||
*/
|
||||
public static void addPrecisionSawmillRecipe(ItemStack input, ItemStack primaryOutput, ItemStack secondaryOutput, double chance)
|
||||
{
|
||||
public static void addPrecisionSawmillRecipe(
|
||||
ItemStack input, ItemStack primaryOutput, ItemStack secondaryOutput, double chance
|
||||
) {
|
||||
try {
|
||||
Class recipeClass = Class.forName("mekanism.common.recipe.RecipeHandler");
|
||||
Method m = recipeClass.getMethod("addPrecisionSawmillRecipe", ItemStack.class, ItemStack.class, ItemStack.class, Double.TYPE);
|
||||
Method m = recipeClass.getMethod(
|
||||
"addPrecisionSawmillRecipe",
|
||||
ItemStack.class,
|
||||
ItemStack.class,
|
||||
ItemStack.class,
|
||||
Double.TYPE
|
||||
);
|
||||
m.invoke(null, input, primaryOutput, secondaryOutput, chance);
|
||||
} catch (Exception e) {
|
||||
System.err.println("Error while adding recipe: " + e.getMessage());
|
||||
|
@ -152,11 +166,13 @@ public final class RecipeHelper
|
|||
* @param input - input ItemStack
|
||||
* @param primaryOutput - guaranteed output
|
||||
*/
|
||||
public static void addPrecisionSawmillRecipe(ItemStack input, ItemStack primaryOutput)
|
||||
{
|
||||
public static void
|
||||
addPrecisionSawmillRecipe(ItemStack input, ItemStack primaryOutput) {
|
||||
try {
|
||||
Class recipeClass = Class.forName("mekanism.common.recipe.RecipeHandler");
|
||||
Method m = recipeClass.getMethod("addPrecisionSawmillRecipe", ItemStack.class, ItemStack.class);
|
||||
Method m = recipeClass.getMethod(
|
||||
"addPrecisionSawmillRecipe", ItemStack.class, ItemStack.class
|
||||
);
|
||||
m.invoke(null, input, primaryOutput);
|
||||
} catch (Exception e) {
|
||||
System.err.println("Error while adding recipe: " + e.getMessage());
|
||||
|
@ -168,11 +184,16 @@ public final class RecipeHelper
|
|||
* @param input - input AdvancedInput
|
||||
* @param output - output ItemStack
|
||||
*/
|
||||
public static void addChemicalInjectionChamberRecipe(ItemStack input, String gasName, ItemStack output)
|
||||
{
|
||||
public static void
|
||||
addChemicalInjectionChamberRecipe(ItemStack input, String gasName, ItemStack output) {
|
||||
try {
|
||||
Class recipeClass = Class.forName("mekanism.common.recipe.RecipeHandler");
|
||||
Method m = recipeClass.getMethod("addChemicalInjectionChamberRecipe", ItemStack.class, String.class, ItemStack.class);
|
||||
Method m = recipeClass.getMethod(
|
||||
"addChemicalInjectionChamberRecipe",
|
||||
ItemStack.class,
|
||||
String.class,
|
||||
ItemStack.class
|
||||
);
|
||||
m.invoke(null, input, gasName, output);
|
||||
} catch (Exception e) {
|
||||
System.err.println("Error while adding recipe: " + e.getMessage());
|
||||
|
@ -186,11 +207,18 @@ public final class RecipeHelper
|
|||
* @param leftOutput - left output GasStack
|
||||
* @param rightOutput - right output GasStack
|
||||
*/
|
||||
public static void addElectrolyticSeparatorRecipe(FluidStack input, double energy, GasStack leftOutput, GasStack rightOutput)
|
||||
{
|
||||
public static void addElectrolyticSeparatorRecipe(
|
||||
FluidStack input, double energy, GasStack leftOutput, GasStack rightOutput
|
||||
) {
|
||||
try {
|
||||
Class recipeClass = Class.forName("mekanism.common.recipe.RecipeHandler");
|
||||
Method m = recipeClass.getMethod("addElectrolyticSeparatorRecipe", FluidStack.class, Double.TYPE, GasStack.class, GasStack.class);
|
||||
Method m = recipeClass.getMethod(
|
||||
"addElectrolyticSeparatorRecipe",
|
||||
FluidStack.class,
|
||||
Double.TYPE,
|
||||
GasStack.class,
|
||||
GasStack.class
|
||||
);
|
||||
m.invoke(null, input, energy, leftOutput, rightOutput);
|
||||
} catch (Exception e) {
|
||||
System.err.println("Error while adding recipe: " + e.getMessage());
|
||||
|
@ -202,11 +230,13 @@ public final class RecipeHelper
|
|||
* @param input - input ItemStack
|
||||
* @param output - output GasStack
|
||||
*/
|
||||
public static void addChemicalDissolutionChamberRecipe(ItemStack input, GasStack output)
|
||||
{
|
||||
public static void
|
||||
addChemicalDissolutionChamberRecipe(ItemStack input, GasStack output) {
|
||||
try {
|
||||
Class recipeClass = Class.forName("mekanism.common.recipe.RecipeHandler");
|
||||
Method m = recipeClass.getMethod("addChemicalDissolutionChamberRecipe", ItemStack.class, GasStack.class);
|
||||
Method m = recipeClass.getMethod(
|
||||
"addChemicalDissolutionChamberRecipe", ItemStack.class, GasStack.class
|
||||
);
|
||||
m.invoke(null, input, output);
|
||||
} catch (Exception e) {
|
||||
System.err.println("Error while adding recipe: " + e.getMessage());
|
||||
|
@ -218,11 +248,12 @@ public final class RecipeHelper
|
|||
* @param input - input GasStack
|
||||
* @param output - output GasStack
|
||||
*/
|
||||
public static void addChemicalWasherRecipe(GasStack input, GasStack output)
|
||||
{
|
||||
public static void addChemicalWasherRecipe(GasStack input, GasStack output) {
|
||||
try {
|
||||
Class recipeClass = Class.forName("mekanism.common.recipe.RecipeHandler");
|
||||
Method m = recipeClass.getMethod("addChemicalWasherRecipe", GasStack.class, GasStack.class);
|
||||
Method m = recipeClass.getMethod(
|
||||
"addChemicalWasherRecipe", GasStack.class, GasStack.class
|
||||
);
|
||||
m.invoke(null, input, output);
|
||||
} catch (Exception e) {
|
||||
System.err.println("Error while adding recipe: " + e.getMessage());
|
||||
|
@ -234,11 +265,12 @@ public final class RecipeHelper
|
|||
* @param input - input GasStack
|
||||
* @param output - output ItemStack
|
||||
*/
|
||||
public static void addChemicalCrystallizerRecipe(GasStack input, ItemStack output)
|
||||
{
|
||||
public static void addChemicalCrystallizerRecipe(GasStack input, ItemStack output) {
|
||||
try {
|
||||
Class recipeClass = Class.forName("mekanism.common.recipe.RecipeHandler");
|
||||
Method m = recipeClass.getMethod("addChemicalCrystallizerRecipe", GasStack.class, ItemStack.class);
|
||||
Method m = recipeClass.getMethod(
|
||||
"addChemicalCrystallizerRecipe", GasStack.class, ItemStack.class
|
||||
);
|
||||
m.invoke(null, input, output);
|
||||
} catch (Exception e) {
|
||||
System.err.println("Error while adding recipe: " + e.getMessage());
|
||||
|
@ -252,11 +284,18 @@ public final class RecipeHelper
|
|||
* @param input - input ItemStack
|
||||
* @param output - output ItemStack
|
||||
*/
|
||||
public static void addMetallurgicInfuserRecipe(InfuseType infuse, int amount, ItemStack input, ItemStack output)
|
||||
{
|
||||
public static void addMetallurgicInfuserRecipe(
|
||||
InfuseType infuse, int amount, ItemStack input, ItemStack output
|
||||
) {
|
||||
try {
|
||||
Class recipeClass = Class.forName("mekanism.common.recipe.RecipeHandler");
|
||||
Method m = recipeClass.getMethod("addMetallurgicInfuserRecipe", InfuseType.class, Integer.TYPE, ItemStack.class, ItemStack.class);
|
||||
Method m = recipeClass.getMethod(
|
||||
"addMetallurgicInfuserRecipe",
|
||||
InfuseType.class,
|
||||
Integer.TYPE,
|
||||
ItemStack.class,
|
||||
ItemStack.class
|
||||
);
|
||||
m.invoke(null, infuse, amount, input, output);
|
||||
} catch (Exception e) {
|
||||
System.err.println("Error while adding recipe: " + e.getMessage());
|
||||
|
@ -273,12 +312,37 @@ public final class RecipeHelper
|
|||
* @param extraEnergy - extra energy needed by the recipe
|
||||
* @param ticks - amount of ticks it takes for this recipe to complete
|
||||
*/
|
||||
public static void addPRCRecipe(ItemStack inputSolid, FluidStack inputFluid, GasStack inputGas, ItemStack outputSolid, GasStack outputGas, double extraEnergy, int ticks)
|
||||
{
|
||||
public static void addPRCRecipe(
|
||||
ItemStack inputSolid,
|
||||
FluidStack inputFluid,
|
||||
GasStack inputGas,
|
||||
ItemStack outputSolid,
|
||||
GasStack outputGas,
|
||||
double extraEnergy,
|
||||
int ticks
|
||||
) {
|
||||
try {
|
||||
Class recipeClass = Class.forName("mekanism.common.recipe.RecipeHandler");
|
||||
Method m = recipeClass.getMethod("addPRCRecipe", ItemStack.class, FluidStack.class, GasStack.class, ItemStack.class, GasStack.class, Double.TYPE, Integer.TYPE);
|
||||
m.invoke(null, inputSolid, inputFluid, inputGas, outputSolid, outputGas, extraEnergy, ticks);
|
||||
Method m = recipeClass.getMethod(
|
||||
"addPRCRecipe",
|
||||
ItemStack.class,
|
||||
FluidStack.class,
|
||||
GasStack.class,
|
||||
ItemStack.class,
|
||||
GasStack.class,
|
||||
Double.TYPE,
|
||||
Integer.TYPE
|
||||
);
|
||||
m.invoke(
|
||||
null,
|
||||
inputSolid,
|
||||
inputFluid,
|
||||
inputGas,
|
||||
outputSolid,
|
||||
outputGas,
|
||||
extraEnergy,
|
||||
ticks
|
||||
);
|
||||
} catch (Exception e) {
|
||||
System.err.println("Error while adding recipe: " + e.getMessage());
|
||||
}
|
||||
|
@ -289,11 +353,12 @@ public final class RecipeHelper
|
|||
* @param input - input GasStack
|
||||
* @param output - output GasStack
|
||||
*/
|
||||
public static void addThermalEvaporationRecipe(FluidStack input, FluidStack output)
|
||||
{
|
||||
public static void addThermalEvaporationRecipe(FluidStack input, FluidStack output) {
|
||||
try {
|
||||
Class recipeClass = Class.forName("mekanism.common.recipe.RecipeHandler");
|
||||
Method m = recipeClass.getMethod("addThermalEvaporationRecipe", FluidStack.class, FluidStack.class);
|
||||
Method m = recipeClass.getMethod(
|
||||
"addThermalEvaporationRecipe", FluidStack.class, FluidStack.class
|
||||
);
|
||||
m.invoke(null, input, output);
|
||||
} catch (Exception e) {
|
||||
System.err.println("Error while adding recipe: " + e.getMessage());
|
||||
|
@ -305,11 +370,12 @@ public final class RecipeHelper
|
|||
* @param input - input GasStack
|
||||
* @param output - output GasStack
|
||||
*/
|
||||
public static void addSolarNeutronRecipe(GasStack input, GasStack output)
|
||||
{
|
||||
public static void addSolarNeutronRecipe(GasStack input, GasStack output) {
|
||||
try {
|
||||
Class recipeClass = Class.forName("mekanism.common.recipe.RecipeHandler");
|
||||
Method m = recipeClass.getMethod("addSolarNeutronRecipe", GasStack.class, GasStack.class);
|
||||
Method m
|
||||
= recipeClass
|
||||
.getMethod("addSolarNeutronRecipe", GasStack.class, GasStack.class);
|
||||
m.invoke(null, input, output);
|
||||
} catch (Exception e) {
|
||||
System.err.println("Error while adding recipe: " + e.getMessage());
|
||||
|
|
|
@ -1,4 +1,3 @@
|
|||
@API(apiVersion = "9.0.0", owner = "Mekanism", provides = "MekanismAPI|recipe")
|
||||
package mekanism.api.recipe;
|
||||
import cpw.mods.fml.common.API;
|
||||
|
||||
|
|
|
@ -8,6 +8,11 @@ import java.util.LinkedHashSet;
|
|||
import java.util.Map.Entry;
|
||||
import java.util.Set;
|
||||
|
||||
import com.google.common.collect.Lists;
|
||||
import com.google.common.collect.Maps;
|
||||
import com.google.common.collect.Sets;
|
||||
import cpw.mods.fml.common.FMLCommonHandler;
|
||||
import cpw.mods.fml.common.eventhandler.Event;
|
||||
import mekanism.api.Coord4D;
|
||||
import mekanism.api.IClientTicker;
|
||||
import mekanism.api.Range4D;
|
||||
|
@ -17,22 +22,19 @@ import net.minecraft.world.World;
|
|||
import net.minecraftforge.common.MinecraftForge;
|
||||
import net.minecraftforge.common.util.ForgeDirection;
|
||||
|
||||
import com.google.common.collect.Lists;
|
||||
import com.google.common.collect.Maps;
|
||||
import com.google.common.collect.Sets;
|
||||
|
||||
import cpw.mods.fml.common.FMLCommonHandler;
|
||||
import cpw.mods.fml.common.eventhandler.Event;
|
||||
|
||||
public abstract class DynamicNetwork<A, N extends DynamicNetwork<A, N>> implements IClientTicker, INetworkDataHandler
|
||||
{
|
||||
public abstract class DynamicNetwork<A, N extends DynamicNetwork<A, N>>
|
||||
implements IClientTicker, INetworkDataHandler {
|
||||
public LinkedHashSet<IGridTransmitter<A, N>> transmitters = Sets.newLinkedHashSet();
|
||||
public LinkedHashSet<IGridTransmitter<A, N>> transmittersToAdd = Sets.newLinkedHashSet();
|
||||
public LinkedHashSet<IGridTransmitter<A, N>> transmittersAdded = Sets.newLinkedHashSet();
|
||||
public LinkedHashSet<IGridTransmitter<A, N>> transmittersToAdd
|
||||
= Sets.newLinkedHashSet();
|
||||
public LinkedHashSet<IGridTransmitter<A, N>> transmittersAdded
|
||||
= Sets.newLinkedHashSet();
|
||||
|
||||
public HashMap<Coord4D, A> possibleAcceptors = new HashMap<Coord4D, A>();
|
||||
public HashMap<Coord4D, EnumSet<ForgeDirection>> acceptorDirections = new HashMap<Coord4D, EnumSet<ForgeDirection>>();
|
||||
public HashMap<IGridTransmitter<A, N>, EnumSet<ForgeDirection>> changedAcceptors = Maps.newHashMap();
|
||||
public HashMap<Coord4D, EnumSet<ForgeDirection>> acceptorDirections
|
||||
= new HashMap<Coord4D, EnumSet<ForgeDirection>>();
|
||||
public HashMap<IGridTransmitter<A, N>, EnumSet<ForgeDirection>> changedAcceptors
|
||||
= Maps.newHashMap();
|
||||
|
||||
private Set<DelayQueue> updateQueue = new LinkedHashSet<DelayQueue>();
|
||||
|
||||
|
@ -47,26 +49,19 @@ public abstract class DynamicNetwork<A, N extends DynamicNetwork<A, N>> implemen
|
|||
protected boolean firstUpdate = true;
|
||||
protected World worldObj = null;
|
||||
|
||||
public void addNewTransmitters(Collection<IGridTransmitter<A, N>> newTransmitters)
|
||||
{
|
||||
public void addNewTransmitters(Collection<IGridTransmitter<A, N>> newTransmitters) {
|
||||
transmittersToAdd.addAll(newTransmitters);
|
||||
}
|
||||
|
||||
public void commit()
|
||||
{
|
||||
if(!transmittersToAdd.isEmpty())
|
||||
{
|
||||
for(IGridTransmitter<A, N> transmitter : transmittersToAdd)
|
||||
{
|
||||
if(transmitter.isValid())
|
||||
{
|
||||
if(worldObj == null)
|
||||
{
|
||||
public void commit() {
|
||||
if (!transmittersToAdd.isEmpty()) {
|
||||
for (IGridTransmitter<A, N> transmitter : transmittersToAdd) {
|
||||
if (transmitter.isValid()) {
|
||||
if (worldObj == null) {
|
||||
worldObj = transmitter.world();
|
||||
}
|
||||
|
||||
for(ForgeDirection side : ForgeDirection.VALID_DIRECTIONS)
|
||||
{
|
||||
for (ForgeDirection side : ForgeDirection.VALID_DIRECTIONS) {
|
||||
updateTransmitterOnSide(transmitter, side);
|
||||
}
|
||||
|
||||
|
@ -82,18 +77,15 @@ public abstract class DynamicNetwork<A, N extends DynamicNetwork<A, N>> implemen
|
|||
transmittersToAdd.clear();
|
||||
}
|
||||
|
||||
if(!changedAcceptors.isEmpty())
|
||||
{
|
||||
for(Entry<IGridTransmitter<A, N>, EnumSet<ForgeDirection>> entry : changedAcceptors.entrySet())
|
||||
{
|
||||
if (!changedAcceptors.isEmpty()) {
|
||||
for (Entry<IGridTransmitter<A, N>, EnumSet<ForgeDirection>> entry :
|
||||
changedAcceptors.entrySet()) {
|
||||
IGridTransmitter<A, N> transmitter = entry.getKey();
|
||||
|
||||
if(transmitter.isValid())
|
||||
{
|
||||
if (transmitter.isValid()) {
|
||||
EnumSet<ForgeDirection> directionsChanged = entry.getValue();
|
||||
|
||||
for(ForgeDirection side : directionsChanged)
|
||||
{
|
||||
for (ForgeDirection side : directionsChanged) {
|
||||
updateTransmitterOnSide(transmitter, side);
|
||||
}
|
||||
}
|
||||
|
@ -103,56 +95,46 @@ public abstract class DynamicNetwork<A, N extends DynamicNetwork<A, N>> implemen
|
|||
}
|
||||
}
|
||||
|
||||
public void updateTransmitterOnSide(IGridTransmitter<A, N> transmitter, ForgeDirection side)
|
||||
{
|
||||
public void
|
||||
updateTransmitterOnSide(IGridTransmitter<A, N> transmitter, ForgeDirection side) {
|
||||
A acceptor = transmitter.getAcceptor(side);
|
||||
Coord4D acceptorCoord = transmitter.coord().getFromSide(side);
|
||||
EnumSet<ForgeDirection> directions = acceptorDirections.get(acceptorCoord);
|
||||
|
||||
if(acceptor != null)
|
||||
{
|
||||
if (acceptor != null) {
|
||||
possibleAcceptors.put(acceptorCoord, acceptor);
|
||||
|
||||
if(directions != null)
|
||||
{
|
||||
if (directions != null) {
|
||||
directions.add(side.getOpposite());
|
||||
}
|
||||
else {
|
||||
} else {
|
||||
acceptorDirections.put(acceptorCoord, EnumSet.of(side.getOpposite()));
|
||||
}
|
||||
}
|
||||
else {
|
||||
if(directions != null)
|
||||
{
|
||||
} else {
|
||||
if (directions != null) {
|
||||
directions.remove(side.getOpposite());
|
||||
|
||||
if(directions.isEmpty())
|
||||
{
|
||||
if (directions.isEmpty()) {
|
||||
possibleAcceptors.remove(acceptorCoord);
|
||||
acceptorDirections.remove(acceptorCoord);
|
||||
}
|
||||
} else {
|
||||
possibleAcceptors.remove(acceptorCoord);
|
||||
acceptorDirections.remove(acceptorCoord);
|
||||
}
|
||||
}
|
||||
else {
|
||||
possibleAcceptors.remove(acceptorCoord);
|
||||
acceptorDirections.remove(acceptorCoord);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
public abstract void absorbBuffer(IGridTransmitter<A, N> transmitter);
|
||||
|
||||
public abstract void clampBuffer();
|
||||
|
||||
public void invalidate()
|
||||
{
|
||||
public void invalidate() {
|
||||
//Remove invalid transmitters first for share calculations
|
||||
for(Iterator<IGridTransmitter<A, N>> iter = transmitters.iterator(); iter.hasNext();)
|
||||
{
|
||||
for (Iterator<IGridTransmitter<A, N>> iter = transmitters.iterator();
|
||||
iter.hasNext();) {
|
||||
IGridTransmitter<A, N> transmitter = iter.next();
|
||||
|
||||
if(!transmitter.isValid())
|
||||
{
|
||||
if (!transmitter.isValid()) {
|
||||
iter.remove();
|
||||
continue;
|
||||
}
|
||||
|
@ -162,14 +144,12 @@ public abstract class DynamicNetwork<A, N extends DynamicNetwork<A, N>> implemen
|
|||
clampBuffer();
|
||||
|
||||
//Update all shares
|
||||
for(IGridTransmitter<A, N> transmitter : transmitters)
|
||||
{
|
||||
for (IGridTransmitter<A, N> transmitter : transmitters) {
|
||||
transmitter.updateShare();
|
||||
}
|
||||
|
||||
//Now invalidate the transmitters
|
||||
for(IGridTransmitter<A, N> transmitter : transmitters)
|
||||
{
|
||||
for (IGridTransmitter<A, N> transmitter : transmitters) {
|
||||
invalidateTransmitter(transmitter);
|
||||
}
|
||||
|
||||
|
@ -177,35 +157,28 @@ public abstract class DynamicNetwork<A, N extends DynamicNetwork<A, N>> implemen
|
|||
deregister();
|
||||
}
|
||||
|
||||
public void invalidateTransmitter(IGridTransmitter<A, N> transmitter)
|
||||
{
|
||||
if(!worldObj.isRemote && transmitter.isValid())
|
||||
{
|
||||
public void invalidateTransmitter(IGridTransmitter<A, N> transmitter) {
|
||||
if (!worldObj.isRemote && transmitter.isValid()) {
|
||||
transmitter.takeShare();
|
||||
transmitter.setTransmitterNetwork(null);
|
||||
TransmitterNetworkRegistry.registerOrphanTransmitter(transmitter);
|
||||
}
|
||||
}
|
||||
|
||||
public void acceptorChanged(IGridTransmitter<A, N> transmitter, ForgeDirection side)
|
||||
{
|
||||
public void acceptorChanged(IGridTransmitter<A, N> transmitter, ForgeDirection side) {
|
||||
EnumSet<ForgeDirection> directions = changedAcceptors.get(transmitter);
|
||||
|
||||
if(directions != null)
|
||||
{
|
||||
if (directions != null) {
|
||||
directions.add(side);
|
||||
}
|
||||
else {
|
||||
} else {
|
||||
changedAcceptors.put(transmitter, EnumSet.of(side));
|
||||
}
|
||||
|
||||
TransmitterNetworkRegistry.registerChangedNetwork(this);
|
||||
}
|
||||
|
||||
public void adoptTransmittersAndAcceptorsFrom(N net)
|
||||
{
|
||||
for(IGridTransmitter<A, N> transmitter : net.transmitters)
|
||||
{
|
||||
public void adoptTransmittersAndAcceptorsFrom(N net) {
|
||||
for (IGridTransmitter<A, N> transmitter : net.transmitters) {
|
||||
transmitter.setTransmitterNetwork((N) this);
|
||||
transmitters.add(transmitter);
|
||||
transmittersAdded.add(transmitter);
|
||||
|
@ -213,35 +186,28 @@ public abstract class DynamicNetwork<A, N extends DynamicNetwork<A, N>> implemen
|
|||
|
||||
possibleAcceptors.putAll(net.possibleAcceptors);
|
||||
|
||||
for(Entry<Coord4D, EnumSet<ForgeDirection>> entry : net.acceptorDirections.entrySet())
|
||||
{
|
||||
for (Entry<Coord4D, EnumSet<ForgeDirection>> entry :
|
||||
net.acceptorDirections.entrySet()) {
|
||||
Coord4D coord = entry.getKey();
|
||||
|
||||
if(acceptorDirections.containsKey(coord))
|
||||
{
|
||||
if (acceptorDirections.containsKey(coord)) {
|
||||
acceptorDirections.get(coord).addAll(entry.getValue());
|
||||
}
|
||||
else {
|
||||
} else {
|
||||
acceptorDirections.put(coord, entry.getValue());
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
public Range4D getPacketRange()
|
||||
{
|
||||
if(packetRange == null)
|
||||
{
|
||||
public Range4D getPacketRange() {
|
||||
if (packetRange == null) {
|
||||
return genPacketRange();
|
||||
}
|
||||
|
||||
return packetRange;
|
||||
}
|
||||
|
||||
protected Range4D genPacketRange()
|
||||
{
|
||||
if(getSize() == 0)
|
||||
{
|
||||
protected Range4D genPacketRange() {
|
||||
if (getSize() == 0) {
|
||||
deregister();
|
||||
return null;
|
||||
}
|
||||
|
@ -256,57 +222,61 @@ public abstract class DynamicNetwork<A, N extends DynamicNetwork<A, N>> implemen
|
|||
int maxY = initCoord.yCoord;
|
||||
int maxZ = initCoord.zCoord;
|
||||
|
||||
for(IGridTransmitter transmitter : transmitters)
|
||||
{
|
||||
for (IGridTransmitter transmitter : transmitters) {
|
||||
Coord4D coord = transmitter.coord();
|
||||
|
||||
if(coord.xCoord < minX) minX = coord.xCoord;
|
||||
if(coord.yCoord < minY) minY = coord.yCoord;
|
||||
if(coord.zCoord < minZ) minZ = coord.zCoord;
|
||||
if(coord.xCoord > maxX) maxX = coord.xCoord;
|
||||
if(coord.yCoord > maxY) maxY = coord.yCoord;
|
||||
if(coord.zCoord > maxZ) maxZ = coord.zCoord;
|
||||
if (coord.xCoord < minX)
|
||||
minX = coord.xCoord;
|
||||
if (coord.yCoord < minY)
|
||||
minY = coord.yCoord;
|
||||
if (coord.zCoord < minZ)
|
||||
minZ = coord.zCoord;
|
||||
if (coord.xCoord > maxX)
|
||||
maxX = coord.xCoord;
|
||||
if (coord.yCoord > maxY)
|
||||
maxY = coord.yCoord;
|
||||
if (coord.zCoord > maxZ)
|
||||
maxZ = coord.zCoord;
|
||||
}
|
||||
|
||||
return new Range4D(minX, minY, minZ, maxX, maxY, maxZ, initTransmitter.world().provider.dimensionId);
|
||||
return new Range4D(
|
||||
minX,
|
||||
minY,
|
||||
minZ,
|
||||
maxX,
|
||||
maxY,
|
||||
maxZ,
|
||||
initTransmitter.world().provider.dimensionId
|
||||
);
|
||||
}
|
||||
|
||||
public void register()
|
||||
{
|
||||
if(FMLCommonHandler.instance().getEffectiveSide().isServer())
|
||||
{
|
||||
public void register() {
|
||||
if (FMLCommonHandler.instance().getEffectiveSide().isServer()) {
|
||||
TransmitterNetworkRegistry.getInstance().registerNetwork(this);
|
||||
}
|
||||
else {
|
||||
} else {
|
||||
MinecraftForge.EVENT_BUS.post(new ClientTickUpdate(this, (byte) 1));
|
||||
}
|
||||
}
|
||||
|
||||
public void deregister()
|
||||
{
|
||||
public void deregister() {
|
||||
transmitters.clear();
|
||||
|
||||
if(FMLCommonHandler.instance().getEffectiveSide().isServer())
|
||||
{
|
||||
if (FMLCommonHandler.instance().getEffectiveSide().isServer()) {
|
||||
TransmitterNetworkRegistry.getInstance().removeNetwork(this);
|
||||
}
|
||||
else {
|
||||
} else {
|
||||
MinecraftForge.EVENT_BUS.post(new ClientTickUpdate(this, (byte) 0));
|
||||
}
|
||||
}
|
||||
|
||||
public int getSize()
|
||||
{
|
||||
public int getSize() {
|
||||
return transmitters.size();
|
||||
}
|
||||
|
||||
public int getAcceptorSize()
|
||||
{
|
||||
public int getAcceptorSize() {
|
||||
return possibleAcceptors.size();
|
||||
}
|
||||
|
||||
public synchronized void updateCapacity()
|
||||
{
|
||||
public synchronized void updateCapacity() {
|
||||
updateMeanCapacity();
|
||||
capacity = (int) meanCapacity * transmitters.size();
|
||||
}
|
||||
|
@ -315,50 +285,39 @@ public abstract class DynamicNetwork<A, N extends DynamicNetwork<A, N>> implemen
|
|||
* Override this if things can have variable capacity along the network.
|
||||
* @return An 'average' value of capacity. Calculate it how you will.
|
||||
*/
|
||||
protected synchronized void updateMeanCapacity()
|
||||
{
|
||||
if(transmitters.size() > 0)
|
||||
{
|
||||
protected synchronized void updateMeanCapacity() {
|
||||
if (transmitters.size() > 0) {
|
||||
meanCapacity = transmitters.iterator().next().getCapacity();
|
||||
}
|
||||
else {
|
||||
} else {
|
||||
meanCapacity = 0;
|
||||
}
|
||||
}
|
||||
|
||||
public int getCapacity()
|
||||
{
|
||||
public int getCapacity() {
|
||||
return capacity;
|
||||
}
|
||||
|
||||
public World getWorld()
|
||||
{
|
||||
public World getWorld() {
|
||||
return worldObj;
|
||||
}
|
||||
|
||||
public abstract Set<A> getAcceptors(Object data);
|
||||
|
||||
public void tick()
|
||||
{
|
||||
public void tick() {
|
||||
onUpdate();
|
||||
}
|
||||
|
||||
public void onUpdate()
|
||||
{
|
||||
if(FMLCommonHandler.instance().getEffectiveSide().isServer())
|
||||
{
|
||||
public void onUpdate() {
|
||||
if (FMLCommonHandler.instance().getEffectiveSide().isServer()) {
|
||||
Iterator<DelayQueue> i = updateQueue.iterator();
|
||||
|
||||
try {
|
||||
while(i.hasNext())
|
||||
{
|
||||
while (i.hasNext()) {
|
||||
DelayQueue q = i.next();
|
||||
|
||||
if(q.delay > 0)
|
||||
{
|
||||
if (q.delay > 0) {
|
||||
q.delay--;
|
||||
}
|
||||
else {
|
||||
} else {
|
||||
transmittersAdded.addAll(transmitters);
|
||||
updateDelay = 1;
|
||||
i.remove();
|
||||
|
@ -366,13 +325,13 @@ public abstract class DynamicNetwork<A, N extends DynamicNetwork<A, N>> implemen
|
|||
}
|
||||
} catch (Exception e) {}
|
||||
|
||||
if(updateDelay > 0)
|
||||
{
|
||||
if (updateDelay > 0) {
|
||||
updateDelay--;
|
||||
|
||||
if(updateDelay == 0)
|
||||
{
|
||||
MinecraftForge.EVENT_BUS.post(new TransmittersAddedEvent(this, firstUpdate, (Collection)transmittersAdded));
|
||||
if (updateDelay == 0) {
|
||||
MinecraftForge.EVENT_BUS.post(new TransmittersAddedEvent(
|
||||
this, firstUpdate, (Collection) transmittersAdded
|
||||
));
|
||||
firstUpdate = false;
|
||||
transmittersAdded.clear();
|
||||
needsUpdate = true;
|
||||
|
@ -382,81 +341,70 @@ public abstract class DynamicNetwork<A, N extends DynamicNetwork<A, N>> implemen
|
|||
}
|
||||
|
||||
@Override
|
||||
public boolean needsTicks()
|
||||
{
|
||||
public boolean needsTicks() {
|
||||
return getSize() > 0;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void clientTick() {}
|
||||
|
||||
public void queueClientUpdate(Collection<IGridTransmitter<A, N>> newTransmitters)
|
||||
{
|
||||
public void queueClientUpdate(Collection<IGridTransmitter<A, N>> newTransmitters) {
|
||||
transmittersAdded.addAll(newTransmitters);
|
||||
updateDelay = 3;
|
||||
}
|
||||
|
||||
public static class TransmittersAddedEvent extends Event
|
||||
{
|
||||
public static class TransmittersAddedEvent extends Event {
|
||||
public DynamicNetwork<?, ?> network;
|
||||
public boolean newNetwork;
|
||||
public Collection<IGridTransmitter> newTransmitters;
|
||||
|
||||
public TransmittersAddedEvent(DynamicNetwork net, boolean newNet, Collection<IGridTransmitter> added)
|
||||
{
|
||||
public TransmittersAddedEvent(
|
||||
DynamicNetwork net, boolean newNet, Collection<IGridTransmitter> added
|
||||
) {
|
||||
network = net;
|
||||
newNetwork = newNet;
|
||||
newTransmitters = added;
|
||||
}
|
||||
}
|
||||
|
||||
public static class ClientTickUpdate extends Event
|
||||
{
|
||||
public static class ClientTickUpdate extends Event {
|
||||
public DynamicNetwork network;
|
||||
public byte operation; /*0 remove, 1 add*/
|
||||
|
||||
public ClientTickUpdate(DynamicNetwork net, byte b)
|
||||
{
|
||||
public ClientTickUpdate(DynamicNetwork net, byte b) {
|
||||
network = net;
|
||||
operation = b;
|
||||
}
|
||||
}
|
||||
|
||||
public static class NetworkClientRequest extends Event
|
||||
{
|
||||
public static class NetworkClientRequest extends Event {
|
||||
public TileEntity tileEntity;
|
||||
|
||||
public NetworkClientRequest(TileEntity tile)
|
||||
{
|
||||
public NetworkClientRequest(TileEntity tile) {
|
||||
tileEntity = tile;
|
||||
}
|
||||
}
|
||||
|
||||
public void addUpdate(EntityPlayer player)
|
||||
{
|
||||
public void addUpdate(EntityPlayer player) {
|
||||
updateQueue.add(new DelayQueue(player));
|
||||
}
|
||||
|
||||
public static class DelayQueue
|
||||
{
|
||||
public static class DelayQueue {
|
||||
public EntityPlayer player;
|
||||
public int delay;
|
||||
|
||||
public DelayQueue(EntityPlayer p)
|
||||
{
|
||||
public DelayQueue(EntityPlayer p) {
|
||||
player = p;
|
||||
delay = 5;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int hashCode()
|
||||
{
|
||||
public int hashCode() {
|
||||
return player.hashCode();
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean equals(Object o)
|
||||
{
|
||||
public boolean equals(Object o) {
|
||||
return o instanceof DelayQueue && ((DelayQueue) o).player.equals(this.player);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -2,8 +2,7 @@ package mekanism.api.transmitters;
|
|||
|
||||
import net.minecraftforge.common.util.ForgeDirection;
|
||||
|
||||
public interface IBlockableConnection
|
||||
{
|
||||
public interface IBlockableConnection {
|
||||
public boolean canConnectMutual(ForgeDirection side);
|
||||
|
||||
public boolean canConnect(ForgeDirection side);
|
||||
|
|
|
@ -6,8 +6,8 @@ import mekanism.api.Coord4D;
|
|||
import net.minecraft.world.World;
|
||||
import net.minecraftforge.common.util.ForgeDirection;
|
||||
|
||||
public interface IGridTransmitter<A, N extends DynamicNetwork<A, N>> extends ITransmitter
|
||||
{
|
||||
public interface IGridTransmitter<A, N extends DynamicNetwork<A, N>>
|
||||
extends ITransmitter {
|
||||
public boolean hasTransmitterNetwork();
|
||||
|
||||
/**
|
||||
|
|
|
@ -1,7 +1,6 @@
|
|||
package mekanism.api.transmitters;
|
||||
|
||||
public interface INetworkDataHandler
|
||||
{
|
||||
public interface INetworkDataHandler {
|
||||
public String getNeededInfo();
|
||||
|
||||
public String getStoredInfo();
|
||||
|
|
|
@ -1,7 +1,6 @@
|
|||
package mekanism.api.transmitters;
|
||||
|
||||
public interface ITransmitter
|
||||
{
|
||||
public interface ITransmitter {
|
||||
/**
|
||||
* Get the transmitter's transmission type
|
||||
*
|
||||
|
|
|
@ -1,6 +1,5 @@
|
|||
package mekanism.api.transmitters;
|
||||
|
||||
public interface ITransmitterTile<A, N extends DynamicNetwork<A, N>>
|
||||
{
|
||||
public interface ITransmitterTile<A, N extends DynamicNetwork<A, N>> {
|
||||
public IGridTransmitter<A, N> getTransmitter();
|
||||
}
|
||||
|
|
|
@ -4,8 +4,7 @@ import mekanism.api.gas.IGasTransmitter;
|
|||
import net.minecraft.tileentity.TileEntity;
|
||||
import net.minecraft.util.StatCollector;
|
||||
|
||||
public enum TransmissionType
|
||||
{
|
||||
public enum TransmissionType {
|
||||
ENERGY("EnergyNetwork", "Energy"),
|
||||
FLUID("FluidNetwork", "Fluids"),
|
||||
GAS("GasNetwork", "Gases"),
|
||||
|
@ -15,61 +14,50 @@ public enum TransmissionType
|
|||
private String name;
|
||||
private String transmission;
|
||||
|
||||
private TransmissionType(String n, String t)
|
||||
{
|
||||
private TransmissionType(String n, String t) {
|
||||
name = n;
|
||||
transmission = t;
|
||||
}
|
||||
|
||||
public String getName()
|
||||
{
|
||||
public String getName() {
|
||||
return name;
|
||||
}
|
||||
|
||||
public String getTransmission()
|
||||
{
|
||||
public String getTransmission() {
|
||||
return transmission;
|
||||
}
|
||||
|
||||
public String localize()
|
||||
{
|
||||
public String localize() {
|
||||
return StatCollector.translateToLocal("transmission." + getTransmission());
|
||||
}
|
||||
|
||||
public static boolean checkTransmissionType(ITransmitter sideTile, TransmissionType type)
|
||||
{
|
||||
public static boolean
|
||||
checkTransmissionType(ITransmitter sideTile, TransmissionType type) {
|
||||
return type.checkTransmissionType(sideTile);
|
||||
}
|
||||
|
||||
public static boolean checkTransmissionType(TileEntity tile1, TransmissionType type)
|
||||
{
|
||||
public static boolean checkTransmissionType(TileEntity tile1, TransmissionType type) {
|
||||
return checkTransmissionType(tile1, type, null);
|
||||
}
|
||||
|
||||
public static boolean checkTransmissionType(TileEntity tile1, TransmissionType type, TileEntity tile2)
|
||||
{
|
||||
public static boolean
|
||||
checkTransmissionType(TileEntity tile1, TransmissionType type, TileEntity tile2) {
|
||||
return type.checkTransmissionType(tile1, tile2);
|
||||
}
|
||||
|
||||
public boolean checkTransmissionType(ITransmitter transmitter)
|
||||
{
|
||||
public boolean checkTransmissionType(ITransmitter transmitter) {
|
||||
return transmitter.getTransmissionType() == this;
|
||||
}
|
||||
|
||||
public boolean checkTransmissionType(TileEntity sideTile, TileEntity currentTile)
|
||||
{
|
||||
if(sideTile instanceof ITransmitter)
|
||||
{
|
||||
if(((ITransmitter)sideTile).getTransmissionType() == this)
|
||||
{
|
||||
public boolean checkTransmissionType(TileEntity sideTile, TileEntity currentTile) {
|
||||
if (sideTile instanceof ITransmitter) {
|
||||
if (((ITransmitter) sideTile).getTransmissionType() == this) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
if(this == GAS && currentTile instanceof IGasTransmitter)
|
||||
{
|
||||
if(((IGasTransmitter)currentTile).canTransferGasToTube(sideTile))
|
||||
{
|
||||
if (this == GAS && currentTile instanceof IGasTransmitter) {
|
||||
if (((IGasTransmitter) currentTile).canTransferGasToTube(sideTile)) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -3,24 +3,20 @@ package mekanism.api.transmitters;
|
|||
import java.util.HashMap;
|
||||
import java.util.HashSet;
|
||||
|
||||
import mekanism.api.Coord4D;
|
||||
import mekanism.api.MekanismAPI;
|
||||
import net.minecraftforge.common.util.ForgeDirection;
|
||||
|
||||
import org.apache.logging.log4j.LogManager;
|
||||
import org.apache.logging.log4j.Logger;
|
||||
|
||||
import com.google.common.collect.Maps;
|
||||
import com.google.common.collect.Sets;
|
||||
|
||||
import cpw.mods.fml.common.FMLCommonHandler;
|
||||
import cpw.mods.fml.common.eventhandler.SubscribeEvent;
|
||||
import cpw.mods.fml.common.gameevent.TickEvent.Phase;
|
||||
import cpw.mods.fml.common.gameevent.TickEvent.ServerTickEvent;
|
||||
import cpw.mods.fml.relauncher.Side;
|
||||
import mekanism.api.Coord4D;
|
||||
import mekanism.api.MekanismAPI;
|
||||
import net.minecraftforge.common.util.ForgeDirection;
|
||||
import org.apache.logging.log4j.LogManager;
|
||||
import org.apache.logging.log4j.Logger;
|
||||
|
||||
public class TransmitterNetworkRegistry
|
||||
{
|
||||
public class TransmitterNetworkRegistry {
|
||||
private static TransmitterNetworkRegistry INSTANCE = new TransmitterNetworkRegistry();
|
||||
private static boolean loaderRegistered = false;
|
||||
|
||||
|
@ -32,95 +28,78 @@ public class TransmitterNetworkRegistry
|
|||
|
||||
private Logger logger = LogManager.getLogger("MekanismTransmitters");
|
||||
|
||||
public static void initiate()
|
||||
{
|
||||
if(!loaderRegistered)
|
||||
{
|
||||
public static void initiate() {
|
||||
if (!loaderRegistered) {
|
||||
loaderRegistered = true;
|
||||
|
||||
FMLCommonHandler.instance().bus().register(INSTANCE);
|
||||
}
|
||||
}
|
||||
|
||||
public static void reset()
|
||||
{
|
||||
public static void reset() {
|
||||
getInstance().networks.clear();
|
||||
getInstance().networksToChange.clear();
|
||||
getInstance().invalidTransmitters.clear();
|
||||
getInstance().orphanTransmitters.clear();
|
||||
}
|
||||
|
||||
public static void invalidateTransmitter(IGridTransmitter transmitter)
|
||||
{
|
||||
public static void invalidateTransmitter(IGridTransmitter transmitter) {
|
||||
getInstance().invalidTransmitters.add(transmitter);
|
||||
}
|
||||
|
||||
public static void registerOrphanTransmitter(IGridTransmitter transmitter)
|
||||
{
|
||||
public static void registerOrphanTransmitter(IGridTransmitter transmitter) {
|
||||
getInstance().orphanTransmitters.put(transmitter.coord(), transmitter);
|
||||
}
|
||||
|
||||
public static void registerChangedNetwork(DynamicNetwork network)
|
||||
{
|
||||
public static void registerChangedNetwork(DynamicNetwork network) {
|
||||
getInstance().networksToChange.add(network);
|
||||
}
|
||||
|
||||
public static TransmitterNetworkRegistry getInstance()
|
||||
{
|
||||
public static TransmitterNetworkRegistry getInstance() {
|
||||
return INSTANCE;
|
||||
}
|
||||
|
||||
public void registerNetwork(DynamicNetwork network)
|
||||
{
|
||||
public void registerNetwork(DynamicNetwork network) {
|
||||
networks.add(network);
|
||||
}
|
||||
|
||||
public void removeNetwork(DynamicNetwork network)
|
||||
{
|
||||
if(networks.contains(network))
|
||||
{
|
||||
public void removeNetwork(DynamicNetwork network) {
|
||||
if (networks.contains(network)) {
|
||||
networks.remove(network);
|
||||
}
|
||||
}
|
||||
|
||||
@SubscribeEvent
|
||||
public void onTick(ServerTickEvent event)
|
||||
{
|
||||
if(event.phase == Phase.END && event.side == Side.SERVER)
|
||||
{
|
||||
public void onTick(ServerTickEvent event) {
|
||||
if (event.phase == Phase.END && event.side == Side.SERVER) {
|
||||
tickEnd();
|
||||
}
|
||||
}
|
||||
|
||||
public void tickEnd()
|
||||
{
|
||||
public void tickEnd() {
|
||||
removeInvalidTransmitters();
|
||||
|
||||
assignOrphans();
|
||||
|
||||
commitChanges();
|
||||
|
||||
for(DynamicNetwork net : networks)
|
||||
{
|
||||
for (DynamicNetwork net : networks) {
|
||||
net.tick();
|
||||
}
|
||||
}
|
||||
|
||||
public void removeInvalidTransmitters()
|
||||
{
|
||||
if(MekanismAPI.debug && !invalidTransmitters.isEmpty())
|
||||
{
|
||||
logger.info("Dealing with " + invalidTransmitters.size() + " invalid Transmitters");
|
||||
public void removeInvalidTransmitters() {
|
||||
if (MekanismAPI.debug && !invalidTransmitters.isEmpty()) {
|
||||
logger.info(
|
||||
"Dealing with " + invalidTransmitters.size() + " invalid Transmitters"
|
||||
);
|
||||
}
|
||||
|
||||
for(IGridTransmitter invalid : invalidTransmitters)
|
||||
{
|
||||
if(!(invalid.isOrphan() && invalid.isValid()))
|
||||
{
|
||||
for (IGridTransmitter invalid : invalidTransmitters) {
|
||||
if (!(invalid.isOrphan() && invalid.isValid())) {
|
||||
DynamicNetwork n = invalid.getTransmitterNetwork();
|
||||
|
||||
if(n != null)
|
||||
{
|
||||
if (n != null) {
|
||||
n.invalidate();
|
||||
}
|
||||
}
|
||||
|
@ -129,19 +108,17 @@ public class TransmitterNetworkRegistry
|
|||
invalidTransmitters.clear();
|
||||
}
|
||||
|
||||
public void assignOrphans()
|
||||
{
|
||||
if(MekanismAPI.debug && !orphanTransmitters.isEmpty())
|
||||
{
|
||||
logger.info("Dealing with " + orphanTransmitters.size() + " orphan Transmitters");
|
||||
public void assignOrphans() {
|
||||
if (MekanismAPI.debug && !orphanTransmitters.isEmpty()) {
|
||||
logger.info(
|
||||
"Dealing with " + orphanTransmitters.size() + " orphan Transmitters"
|
||||
);
|
||||
}
|
||||
|
||||
for(IGridTransmitter orphanTransmitter : orphanTransmitters.values())
|
||||
{
|
||||
for (IGridTransmitter orphanTransmitter : orphanTransmitters.values()) {
|
||||
DynamicNetwork network = getNetworkFromOrphan(orphanTransmitter);
|
||||
|
||||
if(network != null)
|
||||
{
|
||||
if (network != null) {
|
||||
networksToChange.add(network);
|
||||
network.register();
|
||||
}
|
||||
|
@ -150,38 +127,42 @@ public class TransmitterNetworkRegistry
|
|||
orphanTransmitters.clear();
|
||||
}
|
||||
|
||||
public <A, N extends DynamicNetwork<A, N>> DynamicNetwork<A, N> getNetworkFromOrphan(IGridTransmitter<A, N> startOrphan)
|
||||
{
|
||||
if(startOrphan.isValid() && startOrphan.isOrphan())
|
||||
{
|
||||
public <A, N extends DynamicNetwork<A, N>> DynamicNetwork<A, N>
|
||||
getNetworkFromOrphan(IGridTransmitter<A, N> startOrphan) {
|
||||
if (startOrphan.isValid() && startOrphan.isOrphan()) {
|
||||
OrphanPathFinder<A, N> finder = new OrphanPathFinder<A, N>(startOrphan);
|
||||
finder.start();
|
||||
N network;
|
||||
|
||||
switch(finder.networksFound.size())
|
||||
{
|
||||
switch (finder.networksFound.size()) {
|
||||
case 0:
|
||||
if(MekanismAPI.debug)
|
||||
{
|
||||
logger.info("No networks found. Creating new network for " + finder.connectedTransmitters.size() + " transmitters");
|
||||
if (MekanismAPI.debug) {
|
||||
logger.info(
|
||||
"No networks found. Creating new network for "
|
||||
+ finder.connectedTransmitters.size() + " transmitters"
|
||||
);
|
||||
}
|
||||
|
||||
network = startOrphan.createEmptyNetwork();
|
||||
|
||||
break;
|
||||
case 1:
|
||||
if(MekanismAPI.debug)
|
||||
{
|
||||
logger.info("Adding " + finder.connectedTransmitters.size() + " transmitters to single found network");
|
||||
if (MekanismAPI.debug) {
|
||||
logger.info(
|
||||
"Adding " + finder.connectedTransmitters.size()
|
||||
+ " transmitters to single found network"
|
||||
);
|
||||
}
|
||||
|
||||
network = finder.networksFound.iterator().next();
|
||||
|
||||
break;
|
||||
default:
|
||||
if(MekanismAPI.debug)
|
||||
{
|
||||
logger.info("Merging " + finder.networksFound.size() + " networks with " + finder.connectedTransmitters.size() + " new transmitters");
|
||||
if (MekanismAPI.debug) {
|
||||
logger.info(
|
||||
"Merging " + finder.networksFound.size() + " networks with "
|
||||
+ finder.connectedTransmitters.size() + " new transmitters"
|
||||
);
|
||||
}
|
||||
|
||||
network = startOrphan.mergeNetworks(finder.networksFound);
|
||||
|
@ -195,10 +176,8 @@ public class TransmitterNetworkRegistry
|
|||
return null;
|
||||
}
|
||||
|
||||
public void commitChanges()
|
||||
{
|
||||
for(DynamicNetwork network : networksToChange)
|
||||
{
|
||||
public void commitChanges() {
|
||||
for (DynamicNetwork network : networksToChange) {
|
||||
network.commit();
|
||||
}
|
||||
|
||||
|
@ -206,26 +185,22 @@ public class TransmitterNetworkRegistry
|
|||
}
|
||||
|
||||
@Override
|
||||
public String toString()
|
||||
{
|
||||
public String toString() {
|
||||
return "Network Registry:\n" + networks;
|
||||
}
|
||||
|
||||
public String[] toStrings()
|
||||
{
|
||||
public String[] toStrings() {
|
||||
String[] strings = new String[networks.size()];
|
||||
int i = 0;
|
||||
|
||||
for(DynamicNetwork network : networks)
|
||||
{
|
||||
for (DynamicNetwork network : networks) {
|
||||
strings[i++] = network.toString();
|
||||
}
|
||||
|
||||
return strings;
|
||||
}
|
||||
|
||||
public class OrphanPathFinder<A, N extends DynamicNetwork<A, N>>
|
||||
{
|
||||
public class OrphanPathFinder<A, N extends DynamicNetwork<A, N>> {
|
||||
public IGridTransmitter<A, N> startPoint;
|
||||
|
||||
public HashSet<Coord4D> iterated = Sets.newHashSet();
|
||||
|
@ -233,57 +208,51 @@ public class TransmitterNetworkRegistry
|
|||
public HashSet<IGridTransmitter<A, N>> connectedTransmitters = Sets.newHashSet();
|
||||
public HashSet<N> networksFound = Sets.newHashSet();
|
||||
|
||||
public OrphanPathFinder(IGridTransmitter<A, N> start)
|
||||
{
|
||||
public OrphanPathFinder(IGridTransmitter<A, N> start) {
|
||||
startPoint = start;
|
||||
}
|
||||
|
||||
public void start()
|
||||
{
|
||||
public void start() {
|
||||
iterate(startPoint.coord(), ForgeDirection.UNKNOWN);
|
||||
}
|
||||
|
||||
public void iterate(Coord4D from, ForgeDirection fromDirection)
|
||||
{
|
||||
if(iterated.contains(from))
|
||||
{
|
||||
public void iterate(Coord4D from, ForgeDirection fromDirection) {
|
||||
if (iterated.contains(from)) {
|
||||
return;
|
||||
}
|
||||
|
||||
iterated.add(from);
|
||||
|
||||
if(orphanTransmitters.containsKey(from))
|
||||
{
|
||||
if (orphanTransmitters.containsKey(from)) {
|
||||
IGridTransmitter<A, N> transmitter = orphanTransmitters.get(from);
|
||||
|
||||
if(transmitter.isValid() && transmitter.isOrphan())
|
||||
{
|
||||
if (transmitter.isValid() && transmitter.isOrphan()) {
|
||||
connectedTransmitters.add(transmitter);
|
||||
transmitter.setOrphan(false);
|
||||
|
||||
for(ForgeDirection direction : ForgeDirection.VALID_DIRECTIONS)
|
||||
{
|
||||
if(direction != fromDirection)
|
||||
{
|
||||
Coord4D directionCoord = transmitter.getAdjacentConnectableTransmitterCoord(direction);
|
||||
for (ForgeDirection direction : ForgeDirection.VALID_DIRECTIONS) {
|
||||
if (direction != fromDirection) {
|
||||
Coord4D directionCoord
|
||||
= transmitter.getAdjacentConnectableTransmitterCoord(
|
||||
direction
|
||||
);
|
||||
|
||||
if(!(directionCoord == null || iterated.contains(directionCoord)))
|
||||
{
|
||||
if (!(directionCoord == null
|
||||
|| iterated.contains(directionCoord))) {
|
||||
iterate(directionCoord, direction.getOpposite());
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
else {
|
||||
} else {
|
||||
addNetworkToIterated(from);
|
||||
}
|
||||
}
|
||||
|
||||
public void addNetworkToIterated(Coord4D from)
|
||||
{
|
||||
public void addNetworkToIterated(Coord4D from) {
|
||||
N net = startPoint.getExternalNetwork(from);
|
||||
if(net != null) networksFound.add(net);
|
||||
if (net != null)
|
||||
networksFound.add(net);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,4 +1,3 @@
|
|||
@API(apiVersion = "9.0.0", owner = "Mekanism", provides = "MekanismAPI|transmitter")
|
||||
package mekanism.api.transmitters;
|
||||
import cpw.mods.fml.common.API;
|
||||
|
||||
|
|
|
@ -3,33 +3,29 @@ package mekanism.api.util;
|
|||
import net.minecraft.block.Block;
|
||||
import net.minecraft.item.ItemStack;
|
||||
|
||||
public class BlockInfo
|
||||
{
|
||||
public class BlockInfo {
|
||||
public Block block;
|
||||
public int meta;
|
||||
|
||||
public BlockInfo(Block b, int j)
|
||||
{
|
||||
public BlockInfo(Block b, int j) {
|
||||
block = b;
|
||||
meta = j;
|
||||
}
|
||||
|
||||
public static BlockInfo get(ItemStack stack)
|
||||
{
|
||||
return new BlockInfo(Block.getBlockFromItem(stack.getItem()), stack.getItemDamage());
|
||||
public static BlockInfo get(ItemStack stack) {
|
||||
return new BlockInfo(
|
||||
Block.getBlockFromItem(stack.getItem()), stack.getItemDamage()
|
||||
);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean equals(Object obj)
|
||||
{
|
||||
return obj instanceof BlockInfo &&
|
||||
((BlockInfo)obj).block == block &&
|
||||
((BlockInfo)obj).meta == meta;
|
||||
public boolean equals(Object obj) {
|
||||
return obj instanceof BlockInfo && ((BlockInfo) obj).block == block
|
||||
&& ((BlockInfo) obj).meta == meta;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int hashCode()
|
||||
{
|
||||
public int hashCode() {
|
||||
int code = 1;
|
||||
code = 31 * code + block.getUnlocalizedName().hashCode();
|
||||
code = 31 * code + meta;
|
||||
|
|
|
@ -3,33 +3,27 @@ package mekanism.api.util;
|
|||
import net.minecraft.item.Item;
|
||||
import net.minecraft.item.ItemStack;
|
||||
|
||||
public class ItemInfo
|
||||
{
|
||||
public class ItemInfo {
|
||||
public Item item;
|
||||
public int meta;
|
||||
|
||||
public ItemInfo(Item i, int j)
|
||||
{
|
||||
public ItemInfo(Item i, int j) {
|
||||
item = i;
|
||||
meta = j;
|
||||
}
|
||||
|
||||
public static ItemInfo get(ItemStack stack)
|
||||
{
|
||||
public static ItemInfo get(ItemStack stack) {
|
||||
return new ItemInfo(stack.getItem(), stack.getItemDamage());
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean equals(Object obj)
|
||||
{
|
||||
return obj instanceof ItemInfo &&
|
||||
((ItemInfo)obj).item == item &&
|
||||
((ItemInfo)obj).meta == meta;
|
||||
public boolean equals(Object obj) {
|
||||
return obj instanceof ItemInfo && ((ItemInfo) obj).item == item
|
||||
&& ((ItemInfo) obj).meta == meta;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int hashCode()
|
||||
{
|
||||
public int hashCode() {
|
||||
int code = 1;
|
||||
code = 31 * code + System.identityHashCode(item);
|
||||
code = 7 * code + meta;
|
||||
|
|
|
@ -5,39 +5,31 @@ import java.util.Arrays;
|
|||
import java.util.List;
|
||||
import java.util.Set;
|
||||
|
||||
public class ListUtils
|
||||
{
|
||||
public static <V> List<V> inverse(List<V> list)
|
||||
{
|
||||
public class ListUtils {
|
||||
public static <V> List<V> inverse(List<V> list) {
|
||||
List<V> toReturn = new ArrayList<V>();
|
||||
|
||||
for(int i = list.size() - 1; i >= 0; i--)
|
||||
{
|
||||
for (int i = list.size() - 1; i >= 0; i--) {
|
||||
toReturn.add(list.get(i));
|
||||
}
|
||||
|
||||
return toReturn;
|
||||
}
|
||||
|
||||
public static <V> List<V> cap(List<V> list, int cap)
|
||||
{
|
||||
public static <V> List<V> cap(List<V> list, int cap) {
|
||||
List<V> toReturn = new ArrayList<V>();
|
||||
|
||||
if(list.size() <= cap)
|
||||
{
|
||||
if (list.size() <= cap) {
|
||||
toReturn = copy(list);
|
||||
}
|
||||
else {
|
||||
} else {
|
||||
int count = 0;
|
||||
|
||||
for(V obj : list)
|
||||
{
|
||||
for (V obj : list) {
|
||||
count++;
|
||||
|
||||
toReturn.add(obj);
|
||||
|
||||
if(count == cap)
|
||||
{
|
||||
if (count == cap) {
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
@ -46,57 +38,47 @@ public class ListUtils
|
|||
return toReturn;
|
||||
}
|
||||
|
||||
public static <V> List<V> copy(List<V> list)
|
||||
{
|
||||
public static <V> List<V> copy(List<V> list) {
|
||||
List<V> toReturn = new ArrayList<V>();
|
||||
|
||||
for(V obj : list)
|
||||
{
|
||||
for (V obj : list) {
|
||||
toReturn.add(obj);
|
||||
}
|
||||
|
||||
return toReturn;
|
||||
}
|
||||
|
||||
public static <V> List<V> merge(List<V> listOne, List<V> listTwo)
|
||||
{
|
||||
public static <V> List<V> merge(List<V> listOne, List<V> listTwo) {
|
||||
List<V> newList = new ArrayList<V>();
|
||||
|
||||
for(V obj : listOne)
|
||||
{
|
||||
for (V obj : listOne) {
|
||||
newList.add(obj);
|
||||
}
|
||||
|
||||
for(V obj : listTwo)
|
||||
{
|
||||
for (V obj : listTwo) {
|
||||
newList.add(obj);
|
||||
}
|
||||
|
||||
return newList;
|
||||
}
|
||||
|
||||
public static <V> List<V> capRemains(List<V> list, int cap)
|
||||
{
|
||||
public static <V> List<V> capRemains(List<V> list, int cap) {
|
||||
List<V> toReturn = new ArrayList<V>();
|
||||
|
||||
if(list.size() <= cap)
|
||||
{
|
||||
if (list.size() <= cap) {
|
||||
return toReturn;
|
||||
}
|
||||
else {
|
||||
} else {
|
||||
List<V> inverse = inverse(list);
|
||||
|
||||
int iterNeeded = list.size() - cap;
|
||||
int count = 0;
|
||||
|
||||
for(V obj : list)
|
||||
{
|
||||
for (V obj : list) {
|
||||
count++;
|
||||
|
||||
toReturn.add(obj);
|
||||
|
||||
if(count == iterNeeded)
|
||||
{
|
||||
if (count == iterNeeded) {
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
@ -105,34 +87,28 @@ public class ListUtils
|
|||
}
|
||||
}
|
||||
|
||||
public static <V> ArrayList<List<V>> split(List<V> list, int divide)
|
||||
{
|
||||
public static <V> ArrayList<List<V>> split(List<V> list, int divide) {
|
||||
int remain = list.size() % divide;
|
||||
int size = (list.size() - remain) / divide;
|
||||
|
||||
ArrayList<List<V>> toReturn = new ArrayList<List<V>>();
|
||||
|
||||
for(int i = 0; i < divide; i++)
|
||||
{
|
||||
for (int i = 0; i < divide; i++) {
|
||||
toReturn.add(i, new ArrayList<V>());
|
||||
}
|
||||
|
||||
for(List<V> iterSet : toReturn)
|
||||
{
|
||||
for (List<V> iterSet : toReturn) {
|
||||
List<V> removed = new ArrayList<V>();
|
||||
|
||||
int toAdd = size;
|
||||
|
||||
if(remain > 0)
|
||||
{
|
||||
if (remain > 0) {
|
||||
remain--;
|
||||
toAdd++;
|
||||
}
|
||||
|
||||
for(V obj : list)
|
||||
{
|
||||
if(toAdd == 0)
|
||||
{
|
||||
for (V obj : list) {
|
||||
if (toAdd == 0) {
|
||||
break;
|
||||
}
|
||||
|
||||
|
@ -141,8 +117,7 @@ public class ListUtils
|
|||
toAdd--;
|
||||
}
|
||||
|
||||
for(V obj : removed)
|
||||
{
|
||||
for (V obj : removed) {
|
||||
list.remove(obj);
|
||||
}
|
||||
}
|
||||
|
@ -150,32 +125,26 @@ public class ListUtils
|
|||
return toReturn;
|
||||
}
|
||||
|
||||
public static <V> V getTop(List<V> list)
|
||||
{
|
||||
for(V obj : list)
|
||||
{
|
||||
public static <V> V getTop(List<V> list) {
|
||||
for (V obj : list) {
|
||||
return obj;
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
public static <V> List<V> asList(Set<V> set)
|
||||
{
|
||||
public static <V> List<V> asList(Set<V> set) {
|
||||
return (List<V>) Arrays.asList(set.toArray());
|
||||
}
|
||||
|
||||
public static <V> List<V> asList(V... values)
|
||||
{
|
||||
public static <V> List<V> asList(V... values) {
|
||||
return (List<V>) Arrays.asList(values);
|
||||
}
|
||||
|
||||
public static double[] splitDouble(int size, double num)
|
||||
{
|
||||
public static double[] splitDouble(int size, double num) {
|
||||
double[] split = new double[size];
|
||||
|
||||
for(int i = 0; i < size; i++)
|
||||
{
|
||||
for (int i = 0; i < size; i++) {
|
||||
double remain = num % size;
|
||||
double ret = (num - remain) / size;
|
||||
ret += remain;
|
||||
|
@ -187,59 +156,50 @@ public class ListUtils
|
|||
return split;
|
||||
}
|
||||
|
||||
public static double[] percent(double[] values)
|
||||
{
|
||||
public static double[] percent(double[] values) {
|
||||
double[] ret = new double[values.length];
|
||||
double total = 0;
|
||||
|
||||
for(double d : values) total += d;
|
||||
for (double d : values)
|
||||
total += d;
|
||||
|
||||
for(int i = 0; i < values.length; i++)
|
||||
{
|
||||
for (int i = 0; i < values.length; i++) {
|
||||
ret[i] = values[i] / total;
|
||||
}
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
public static int[] calcPercentInt(double[] percent, int val)
|
||||
{
|
||||
public static int[] calcPercentInt(double[] percent, int val) {
|
||||
int[] ret = new int[percent.length];
|
||||
|
||||
for(int i = 0; i < percent.length; i++)
|
||||
{
|
||||
for (int i = 0; i < percent.length; i++) {
|
||||
ret[i] = (int) Math.round(val * percent[i]);
|
||||
}
|
||||
|
||||
int newTotal = 0;
|
||||
for(int i : ret) newTotal += i;
|
||||
for (int i : ret)
|
||||
newTotal += i;
|
||||
|
||||
int diff = val - newTotal;
|
||||
|
||||
if(diff != val)
|
||||
{
|
||||
for(int i = 0; i < ret.length; i++)
|
||||
{
|
||||
if (diff != val) {
|
||||
for (int i = 0; i < ret.length; i++) {
|
||||
int num = ret[i];
|
||||
|
||||
if(diff < 0 && num == 0)
|
||||
{
|
||||
if (diff < 0 && num == 0) {
|
||||
continue;
|
||||
}
|
||||
|
||||
if(diff > 0)
|
||||
{
|
||||
if (diff > 0) {
|
||||
ret[i]++;
|
||||
diff--;
|
||||
}
|
||||
else if(diff < 0)
|
||||
{
|
||||
} else if (diff < 0) {
|
||||
ret[i]--;
|
||||
diff++;
|
||||
}
|
||||
|
||||
if(diff == 0)
|
||||
{
|
||||
if (diff == 0) {
|
||||
return ret;
|
||||
}
|
||||
}
|
||||
|
@ -248,12 +208,10 @@ public class ListUtils
|
|||
return ret;
|
||||
}
|
||||
|
||||
public static int[] splitInt(int size, int num)
|
||||
{
|
||||
public static int[] splitInt(int size, int num) {
|
||||
int[] split = new int[size];
|
||||
|
||||
for(int i = 0; i < size; i++)
|
||||
{
|
||||
for (int i = 0; i < size; i++) {
|
||||
int remain = num % size;
|
||||
int ret = (num - remain) / size;
|
||||
ret += remain;
|
||||
|
@ -265,15 +223,14 @@ public class ListUtils
|
|||
return split;
|
||||
}
|
||||
|
||||
public static double[] percent(int[] values)
|
||||
{
|
||||
public static double[] percent(int[] values) {
|
||||
double[] ret = new double[values.length];
|
||||
double total = 0;
|
||||
|
||||
for(double d : values) total += d;
|
||||
for (double d : values)
|
||||
total += d;
|
||||
|
||||
for(int i = 0; i < values.length; i++)
|
||||
{
|
||||
for (int i = 0; i < values.length; i++) {
|
||||
ret[i] = values[i] / total;
|
||||
}
|
||||
|
||||
|
|
|
@ -7,19 +7,15 @@ import net.minecraft.item.Item;
|
|||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraftforge.oredict.OreDictionary;
|
||||
|
||||
public final class StackUtils
|
||||
{
|
||||
public static List<ItemStack> split(ItemStack stack)
|
||||
{
|
||||
if(stack == null || stack.stackSize == 0)
|
||||
{
|
||||
public final class StackUtils {
|
||||
public static List<ItemStack> split(ItemStack stack) {
|
||||
if (stack == null || stack.stackSize == 0) {
|
||||
return null;
|
||||
}
|
||||
|
||||
List<ItemStack> ret = new ArrayList<ItemStack>();
|
||||
|
||||
if(stack.stackSize == 1)
|
||||
{
|
||||
if (stack.stackSize == 1) {
|
||||
ret.add(stack);
|
||||
return ret;
|
||||
}
|
||||
|
@ -33,71 +29,66 @@ public final class StackUtils
|
|||
return ret;
|
||||
}
|
||||
|
||||
public static Item getItem(ItemStack stack)
|
||||
{
|
||||
if(stack == null)
|
||||
{
|
||||
public static Item getItem(ItemStack stack) {
|
||||
if (stack == null) {
|
||||
return null;
|
||||
}
|
||||
|
||||
return stack.getItem();
|
||||
}
|
||||
|
||||
public static boolean diffIgnoreNull(ItemStack stack1, ItemStack stack2)
|
||||
{
|
||||
if(stack1 == null || stack2 == null)
|
||||
{
|
||||
public static boolean diffIgnoreNull(ItemStack stack1, ItemStack stack2) {
|
||||
if (stack1 == null || stack2 == null) {
|
||||
return false;
|
||||
}
|
||||
|
||||
return stack1.getItem() != stack2.getItem() || stack1.getItemDamage() != stack2.getItemDamage();
|
||||
return stack1.getItem() != stack2.getItem()
|
||||
|| stack1.getItemDamage() != stack2.getItemDamage();
|
||||
}
|
||||
|
||||
public static boolean equalsWildcard(ItemStack wild, ItemStack check)
|
||||
{
|
||||
if(wild == null || check == null)
|
||||
{
|
||||
public static boolean equalsWildcard(ItemStack wild, ItemStack check) {
|
||||
if (wild == null || check == null) {
|
||||
return check == wild;
|
||||
}
|
||||
|
||||
return wild.getItem() == check.getItem() && (wild.getItemDamage() == OreDictionary.WILDCARD_VALUE || wild.getItemDamage() == check.getItemDamage());
|
||||
return wild.getItem() == check.getItem()
|
||||
&& (wild.getItemDamage() == OreDictionary.WILDCARD_VALUE
|
||||
|| wild.getItemDamage() == check.getItemDamage());
|
||||
}
|
||||
|
||||
public static boolean equalsWildcardWithNBT(ItemStack wild, ItemStack check)
|
||||
{
|
||||
public static boolean equalsWildcardWithNBT(ItemStack wild, ItemStack check) {
|
||||
boolean wildcard = equalsWildcard(wild, check);
|
||||
|
||||
if(wild == null || check == null)
|
||||
{
|
||||
if (wild == null || check == null) {
|
||||
return wildcard;
|
||||
}
|
||||
|
||||
return wildcard && (wild.stackTagCompound == null ? check.stackTagCompound == null : (wild.stackTagCompound == check.stackTagCompound || wild.stackTagCompound.equals(check.stackTagCompound)));
|
||||
return wildcard
|
||||
&& (wild.stackTagCompound == null
|
||||
? check.stackTagCompound == null
|
||||
: (wild.stackTagCompound == check.stackTagCompound
|
||||
|| wild.stackTagCompound.equals(check.stackTagCompound)));
|
||||
}
|
||||
|
||||
public static List<ItemStack> even(ItemStack stack1, ItemStack stack2)
|
||||
{
|
||||
public static List<ItemStack> even(ItemStack stack1, ItemStack stack2) {
|
||||
ArrayList<ItemStack> ret = new ArrayList<ItemStack>();
|
||||
|
||||
if(getSize(stack1) == getSize(stack2) || Math.abs(getSize(stack1)-getSize(stack2)) == 1)
|
||||
{
|
||||
if (getSize(stack1) == getSize(stack2)
|
||||
|| Math.abs(getSize(stack1) - getSize(stack2)) == 1) {
|
||||
ret.add(stack1);
|
||||
ret.add(stack2);
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
if(getSize(stack1) > getSize(stack2))
|
||||
{
|
||||
if (getSize(stack1) > getSize(stack2)) {
|
||||
int diff = getSize(stack1) - getSize(stack2);
|
||||
|
||||
List<ItemStack> split = split(size(stack1, diff));
|
||||
|
||||
ret.add(subtract(stack1, split.get(0)));
|
||||
ret.add(add(stack2, split.get(0)));
|
||||
}
|
||||
else if(getSize(stack2) > getSize(stack1))
|
||||
{
|
||||
} else if (getSize(stack2) > getSize(stack1)) {
|
||||
int diff = getSize(stack2) - getSize(stack1);
|
||||
|
||||
List<ItemStack> split = split(size(stack2, diff));
|
||||
|
@ -109,38 +100,28 @@ public final class StackUtils
|
|||
return ret;
|
||||
}
|
||||
|
||||
public static ItemStack add(ItemStack stack1, ItemStack stack2)
|
||||
{
|
||||
if(stack1 == null)
|
||||
{
|
||||
public static ItemStack add(ItemStack stack1, ItemStack stack2) {
|
||||
if (stack1 == null) {
|
||||
return stack2;
|
||||
}
|
||||
else if(stack2 == null)
|
||||
{
|
||||
} else if (stack2 == null) {
|
||||
return stack1;
|
||||
}
|
||||
|
||||
return size(stack1, getSize(stack1) + getSize(stack2));
|
||||
}
|
||||
|
||||
public static ItemStack subtract(ItemStack stack1, ItemStack stack2)
|
||||
{
|
||||
if(stack1 == null)
|
||||
{
|
||||
public static ItemStack subtract(ItemStack stack1, ItemStack stack2) {
|
||||
if (stack1 == null) {
|
||||
return null;
|
||||
}
|
||||
else if(stack2 == null)
|
||||
{
|
||||
} else if (stack2 == null) {
|
||||
return stack1;
|
||||
}
|
||||
|
||||
return size(stack1, getSize(stack1) - getSize(stack2));
|
||||
}
|
||||
|
||||
public static ItemStack size(ItemStack stack, int size)
|
||||
{
|
||||
if(size <= 0 || stack == null)
|
||||
{
|
||||
public static ItemStack size(ItemStack stack, int size) {
|
||||
if (size <= 0 || stack == null) {
|
||||
return null;
|
||||
}
|
||||
|
||||
|
@ -150,33 +131,26 @@ public final class StackUtils
|
|||
return ret;
|
||||
}
|
||||
|
||||
public static ItemStack copy(ItemStack stack)
|
||||
{
|
||||
if(stack == null)
|
||||
{
|
||||
public static ItemStack copy(ItemStack stack) {
|
||||
if (stack == null) {
|
||||
return null;
|
||||
}
|
||||
|
||||
return stack.copy();
|
||||
}
|
||||
|
||||
public static int getSize(ItemStack stack)
|
||||
{
|
||||
public static int getSize(ItemStack stack) {
|
||||
return stack != null ? stack.stackSize : 0;
|
||||
}
|
||||
|
||||
public static List<ItemStack> getMergeRejects(ItemStack[] orig, ItemStack[] toAdd)
|
||||
{
|
||||
public static List<ItemStack> getMergeRejects(ItemStack[] orig, ItemStack[] toAdd) {
|
||||
List<ItemStack> ret = new ArrayList<ItemStack>();
|
||||
|
||||
for(int i = 0; i < toAdd.length; i++)
|
||||
{
|
||||
if(toAdd[i] != null)
|
||||
{
|
||||
for (int i = 0; i < toAdd.length; i++) {
|
||||
if (toAdd[i] != null) {
|
||||
ItemStack reject = getMergeReject(orig[i], toAdd[i]);
|
||||
|
||||
if(reject != null)
|
||||
{
|
||||
if (reject != null) {
|
||||
ret.add(reject);
|
||||
}
|
||||
}
|
||||
|
@ -185,73 +159,62 @@ public final class StackUtils
|
|||
return ret;
|
||||
}
|
||||
|
||||
public static void merge(ItemStack[] orig, ItemStack[] toAdd)
|
||||
{
|
||||
for(int i = 0; i < toAdd.length; i++)
|
||||
{
|
||||
if(toAdd[i] != null)
|
||||
{
|
||||
public static void merge(ItemStack[] orig, ItemStack[] toAdd) {
|
||||
for (int i = 0; i < toAdd.length; i++) {
|
||||
if (toAdd[i] != null) {
|
||||
orig[i] = merge(orig[i], toAdd[i]);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public static ItemStack merge(ItemStack orig, ItemStack toAdd)
|
||||
{
|
||||
if(orig == null)
|
||||
{
|
||||
public static ItemStack merge(ItemStack orig, ItemStack toAdd) {
|
||||
if (orig == null) {
|
||||
return toAdd;
|
||||
}
|
||||
|
||||
if(toAdd == null)
|
||||
{
|
||||
if (toAdd == null) {
|
||||
return orig;
|
||||
}
|
||||
|
||||
if(!orig.isItemEqual(toAdd) || !ItemStack.areItemStackTagsEqual(orig, toAdd))
|
||||
{
|
||||
if (!orig.isItemEqual(toAdd) || !ItemStack.areItemStackTagsEqual(orig, toAdd)) {
|
||||
return orig;
|
||||
}
|
||||
|
||||
return StackUtils.size(orig, Math.min(orig.getMaxStackSize(), orig.stackSize+toAdd.stackSize));
|
||||
return StackUtils.size(
|
||||
orig, Math.min(orig.getMaxStackSize(), orig.stackSize + toAdd.stackSize)
|
||||
);
|
||||
}
|
||||
|
||||
public static ItemStack getMergeReject(ItemStack orig, ItemStack toAdd)
|
||||
{
|
||||
if(orig == null)
|
||||
{
|
||||
public static ItemStack getMergeReject(ItemStack orig, ItemStack toAdd) {
|
||||
if (orig == null) {
|
||||
return null;
|
||||
}
|
||||
|
||||
if(toAdd == null)
|
||||
{
|
||||
if (toAdd == null) {
|
||||
return orig;
|
||||
}
|
||||
|
||||
if(!orig.isItemEqual(toAdd) || !ItemStack.areItemStackTagsEqual(orig, toAdd))
|
||||
{
|
||||
if (!orig.isItemEqual(toAdd) || !ItemStack.areItemStackTagsEqual(orig, toAdd)) {
|
||||
return orig;
|
||||
}
|
||||
|
||||
int newSize = orig.stackSize + toAdd.stackSize;
|
||||
|
||||
if(newSize > orig.getMaxStackSize())
|
||||
{
|
||||
if (newSize > orig.getMaxStackSize()) {
|
||||
return StackUtils.size(orig, newSize - orig.getMaxStackSize());
|
||||
}
|
||||
else {
|
||||
} else {
|
||||
return StackUtils.size(orig, newSize);
|
||||
}
|
||||
}
|
||||
|
||||
public static int hashItemStack(ItemStack stack)
|
||||
{
|
||||
if(stack == null || stack.getItem() == null)
|
||||
{
|
||||
public static int hashItemStack(ItemStack stack) {
|
||||
if (stack == null || stack.getItem() == null) {
|
||||
return -1;
|
||||
}
|
||||
|
||||
String name = stack.getItemDamage() == OreDictionary.WILDCARD_VALUE ? stack.getItem().getUnlocalizedName() : stack.getItem().getUnlocalizedName(stack);
|
||||
String name = stack.getItemDamage() == OreDictionary.WILDCARD_VALUE
|
||||
? stack.getItem().getUnlocalizedName()
|
||||
: stack.getItem().getUnlocalizedName(stack);
|
||||
return name.hashCode() << 8 | stack.getItemDamage();
|
||||
}
|
||||
}
|
||||
|
|
|
@ -3,10 +3,8 @@ package mekanism.api.util;
|
|||
/**
|
||||
* Code taken from UE and modified to fit Mekanism.
|
||||
*/
|
||||
public class UnitDisplayUtils
|
||||
{
|
||||
public static enum ElectricUnit
|
||||
{
|
||||
public class UnitDisplayUtils {
|
||||
public static enum ElectricUnit {
|
||||
JOULES("Joule", "J"),
|
||||
REDSTONE_FLUX("Redstone Flux", "RF"),
|
||||
MINECRAFT_JOULES("Minecraft Joule", "MJ"),
|
||||
|
@ -15,20 +13,17 @@ public class UnitDisplayUtils
|
|||
public String name;
|
||||
public String symbol;
|
||||
|
||||
private ElectricUnit(String s, String s1)
|
||||
{
|
||||
private ElectricUnit(String s, String s1) {
|
||||
name = s;
|
||||
symbol = s1;
|
||||
}
|
||||
|
||||
public String getPlural()
|
||||
{
|
||||
public String getPlural() {
|
||||
return this == REDSTONE_FLUX ? name : name + "s";
|
||||
}
|
||||
}
|
||||
|
||||
public static enum TemperatureUnit
|
||||
{
|
||||
public static enum TemperatureUnit {
|
||||
KELVIN("Kelvin", "K", 0, 1),
|
||||
CELSIUS("Celsius", "°C", 273.15, 1),
|
||||
RANKINE("Rankine", "R", 0, 9D / 5D),
|
||||
|
@ -40,28 +35,24 @@ public class UnitDisplayUtils
|
|||
public double zeroOffset;
|
||||
public double intervalSize;
|
||||
|
||||
private TemperatureUnit(String s, String s1, double offset, double size)
|
||||
{
|
||||
private TemperatureUnit(String s, String s1, double offset, double size) {
|
||||
name = s;
|
||||
symbol = s1;
|
||||
zeroOffset = offset;
|
||||
intervalSize = size;
|
||||
}
|
||||
|
||||
public double convertFromK(double T, boolean shift)
|
||||
{
|
||||
public double convertFromK(double T, boolean shift) {
|
||||
return (T * intervalSize) - (shift ? zeroOffset : 0);
|
||||
}
|
||||
|
||||
public double convertToK(double T, boolean shift)
|
||||
{
|
||||
public double convertToK(double T, boolean shift) {
|
||||
return (T + (shift ? zeroOffset : 0)) / intervalSize;
|
||||
}
|
||||
}
|
||||
|
||||
/** Metric system of measurement. */
|
||||
public static enum MeasurementUnit
|
||||
{
|
||||
public static enum MeasurementUnit {
|
||||
FEMTO("Femto", "f", 0.000000000000001D),
|
||||
PICO("Pico", "p", 0.000000000001D),
|
||||
NANO("Nano", "n", 0.000000001D),
|
||||
|
@ -86,89 +77,79 @@ public class UnitDisplayUtils
|
|||
/** Point by which a number is consider to be of this unit */
|
||||
public double value;
|
||||
|
||||
private MeasurementUnit(String s, String s1, double v)
|
||||
{
|
||||
private MeasurementUnit(String s, String s1, double v) {
|
||||
name = s;
|
||||
symbol = s1;
|
||||
value = v;
|
||||
}
|
||||
|
||||
public String getName(boolean getShort)
|
||||
{
|
||||
if(getShort)
|
||||
{
|
||||
public String getName(boolean getShort) {
|
||||
if (getShort) {
|
||||
return symbol;
|
||||
}
|
||||
else {
|
||||
} else {
|
||||
return name;
|
||||
}
|
||||
}
|
||||
|
||||
public double process(double d)
|
||||
{
|
||||
public double process(double d) {
|
||||
return d / value;
|
||||
}
|
||||
|
||||
public boolean above(double d)
|
||||
{
|
||||
public boolean above(double d) {
|
||||
return d > value;
|
||||
}
|
||||
|
||||
public boolean below(double d)
|
||||
{
|
||||
public boolean below(double d) {
|
||||
return d < value;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Displays the unit as text. Does handle negative numbers, and will place a negative sign in
|
||||
* front of the output string showing this. Use string.replace to remove the negative sign if
|
||||
* unwanted
|
||||
* Displays the unit as text. Does handle negative numbers, and will place a negative
|
||||
* sign in front of the output string showing this. Use string.replace to remove the
|
||||
* negative sign if unwanted
|
||||
*/
|
||||
public static String getDisplay(double value, ElectricUnit unit, int decimalPlaces, boolean isShort)
|
||||
{
|
||||
public static String
|
||||
getDisplay(double value, ElectricUnit unit, int decimalPlaces, boolean isShort) {
|
||||
String unitName = unit.name;
|
||||
String prefix = "";
|
||||
|
||||
if(value < 0)
|
||||
{
|
||||
if (value < 0) {
|
||||
value = Math.abs(value);
|
||||
prefix = "-";
|
||||
}
|
||||
|
||||
if(isShort)
|
||||
{
|
||||
if (isShort) {
|
||||
unitName = unit.symbol;
|
||||
}
|
||||
else if(value > 1)
|
||||
{
|
||||
} else if (value > 1) {
|
||||
unitName = unit.getPlural();
|
||||
}
|
||||
|
||||
if(value == 0)
|
||||
{
|
||||
if (value == 0) {
|
||||
return value + " " + unitName;
|
||||
}
|
||||
else {
|
||||
for(int i = 0; i < MeasurementUnit.values().length; i++)
|
||||
{
|
||||
} else {
|
||||
for (int i = 0; i < MeasurementUnit.values().length; i++) {
|
||||
MeasurementUnit lowerMeasure = MeasurementUnit.values()[i];
|
||||
|
||||
if(lowerMeasure.below(value) && lowerMeasure.ordinal() == 0)
|
||||
{
|
||||
return prefix + roundDecimals(lowerMeasure.process(value), decimalPlaces) + " " + lowerMeasure.getName(isShort) + unitName;
|
||||
if (lowerMeasure.below(value) && lowerMeasure.ordinal() == 0) {
|
||||
return prefix
|
||||
+ roundDecimals(lowerMeasure.process(value), decimalPlaces) + " "
|
||||
+ lowerMeasure.getName(isShort) + unitName;
|
||||
}
|
||||
|
||||
if(lowerMeasure.ordinal() + 1 >= MeasurementUnit.values().length)
|
||||
{
|
||||
return prefix + roundDecimals(lowerMeasure.process(value), decimalPlaces) + " " + lowerMeasure.getName(isShort) + unitName;
|
||||
if (lowerMeasure.ordinal() + 1 >= MeasurementUnit.values().length) {
|
||||
return prefix
|
||||
+ roundDecimals(lowerMeasure.process(value), decimalPlaces) + " "
|
||||
+ lowerMeasure.getName(isShort) + unitName;
|
||||
}
|
||||
|
||||
MeasurementUnit upperMeasure = MeasurementUnit.values()[i + 1];
|
||||
|
||||
if((lowerMeasure.above(value) && upperMeasure.below(value)) || lowerMeasure.value == value)
|
||||
{
|
||||
return prefix + roundDecimals(lowerMeasure.process(value), decimalPlaces) + " " + lowerMeasure.getName(isShort) + unitName;
|
||||
if ((lowerMeasure.above(value) && upperMeasure.below(value))
|
||||
|| lowerMeasure.value == value) {
|
||||
return prefix
|
||||
+ roundDecimals(lowerMeasure.process(value), decimalPlaces) + " "
|
||||
+ lowerMeasure.getName(isShort) + unitName;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -176,125 +157,107 @@ public class UnitDisplayUtils
|
|||
return prefix + roundDecimals(value, decimalPlaces) + " " + unitName;
|
||||
}
|
||||
|
||||
public static String getDisplayShort(double value, ElectricUnit unit)
|
||||
{
|
||||
public static String getDisplayShort(double value, ElectricUnit unit) {
|
||||
return getDisplay(value, unit, 2, true);
|
||||
}
|
||||
|
||||
public static String getDisplayShort(double value, ElectricUnit unit, int decimalPlaces)
|
||||
{
|
||||
public static String
|
||||
getDisplayShort(double value, ElectricUnit unit, int decimalPlaces) {
|
||||
return getDisplay(value, unit, decimalPlaces, true);
|
||||
}
|
||||
|
||||
public static String getDisplaySimple(double value, ElectricUnit unit, int decimalPlaces)
|
||||
{
|
||||
if(value > 1)
|
||||
{
|
||||
if(decimalPlaces < 1)
|
||||
{
|
||||
public static String
|
||||
getDisplaySimple(double value, ElectricUnit unit, int decimalPlaces) {
|
||||
if (value > 1) {
|
||||
if (decimalPlaces < 1) {
|
||||
return (int) value + " " + unit.getPlural();
|
||||
}
|
||||
|
||||
return roundDecimals(value, decimalPlaces) + " " + unit.getPlural();
|
||||
}
|
||||
|
||||
if(decimalPlaces < 1)
|
||||
{
|
||||
if (decimalPlaces < 1) {
|
||||
return (int) value + " " + unit.name;
|
||||
}
|
||||
|
||||
return roundDecimals(value, decimalPlaces) + " " + unit.name;
|
||||
}
|
||||
|
||||
public static String getDisplay(double T, TemperatureUnit unit, int decimalPlaces, boolean shift, boolean isShort)
|
||||
{
|
||||
public static String getDisplay(
|
||||
double T, TemperatureUnit unit, int decimalPlaces, boolean shift, boolean isShort
|
||||
) {
|
||||
String unitName = unit.name;
|
||||
String prefix = "";
|
||||
|
||||
double value = unit.convertFromK(T, shift);
|
||||
|
||||
if(value < 0)
|
||||
{
|
||||
if (value < 0) {
|
||||
value = Math.abs(value);
|
||||
prefix = "-";
|
||||
}
|
||||
|
||||
if(isShort)
|
||||
{
|
||||
if (isShort) {
|
||||
unitName = unit.symbol;
|
||||
}
|
||||
|
||||
if(value == 0)
|
||||
{
|
||||
if (value == 0) {
|
||||
return value + (isShort ? "" : " ") + unitName;
|
||||
}
|
||||
else {
|
||||
for(int i = 0; i < MeasurementUnit.values().length; i++)
|
||||
{
|
||||
} else {
|
||||
for (int i = 0; i < MeasurementUnit.values().length; i++) {
|
||||
MeasurementUnit lowerMeasure = MeasurementUnit.values()[i];
|
||||
|
||||
if(lowerMeasure.below(value) && lowerMeasure.ordinal() == 0)
|
||||
{
|
||||
return prefix + roundDecimals(lowerMeasure.process(value), decimalPlaces) + (isShort ? "" : " ") + lowerMeasure.getName(isShort) + unitName;
|
||||
if (lowerMeasure.below(value) && lowerMeasure.ordinal() == 0) {
|
||||
return prefix
|
||||
+ roundDecimals(lowerMeasure.process(value), decimalPlaces)
|
||||
+ (isShort ? "" : " ") + lowerMeasure.getName(isShort) + unitName;
|
||||
}
|
||||
|
||||
if(lowerMeasure.ordinal() + 1 >= MeasurementUnit.values().length)
|
||||
{
|
||||
return prefix + roundDecimals(lowerMeasure.process(value), decimalPlaces) + (isShort ? "" : " ") + lowerMeasure.getName(isShort) + unitName;
|
||||
if (lowerMeasure.ordinal() + 1 >= MeasurementUnit.values().length) {
|
||||
return prefix
|
||||
+ roundDecimals(lowerMeasure.process(value), decimalPlaces)
|
||||
+ (isShort ? "" : " ") + lowerMeasure.getName(isShort) + unitName;
|
||||
}
|
||||
|
||||
MeasurementUnit upperMeasure = MeasurementUnit.values()[i + 1];
|
||||
|
||||
if((lowerMeasure.above(value) && upperMeasure.below(value)) || lowerMeasure.value == value)
|
||||
{
|
||||
return prefix + roundDecimals(lowerMeasure.process(value), decimalPlaces) + (isShort ? "" : " ") + lowerMeasure.getName(isShort) + unitName;
|
||||
if ((lowerMeasure.above(value) && upperMeasure.below(value))
|
||||
|| lowerMeasure.value == value) {
|
||||
return prefix
|
||||
+ roundDecimals(lowerMeasure.process(value), decimalPlaces)
|
||||
+ (isShort ? "" : " ") + lowerMeasure.getName(isShort) + unitName;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return prefix + roundDecimals(value, decimalPlaces) + (isShort ? "" : " ") + unitName;
|
||||
return prefix + roundDecimals(value, decimalPlaces) + (isShort ? "" : " ")
|
||||
+ unitName;
|
||||
}
|
||||
|
||||
public static String getDisplayShort(double value, TemperatureUnit unit)
|
||||
{
|
||||
public static String getDisplayShort(double value, TemperatureUnit unit) {
|
||||
return getDisplayShort(value, true, unit);
|
||||
}
|
||||
|
||||
public static String getDisplayShort(double value, boolean shift, TemperatureUnit unit)
|
||||
{
|
||||
public static String
|
||||
getDisplayShort(double value, boolean shift, TemperatureUnit unit) {
|
||||
return getDisplayShort(value, unit, shift, 2);
|
||||
}
|
||||
|
||||
public static String getDisplayShort(double value, TemperatureUnit unit, boolean shift, int decimalPlaces)
|
||||
{
|
||||
public static String getDisplayShort(
|
||||
double value, TemperatureUnit unit, boolean shift, int decimalPlaces
|
||||
) {
|
||||
return getDisplay(value, unit, decimalPlaces, shift, true);
|
||||
}
|
||||
|
||||
public static double roundDecimals(double d, int decimalPlaces)
|
||||
{
|
||||
public static double roundDecimals(double d, int decimalPlaces) {
|
||||
int j = (int) (d * Math.pow(10, decimalPlaces));
|
||||
return j / Math.pow(10, decimalPlaces);
|
||||
}
|
||||
|
||||
public static double roundDecimals(double d)
|
||||
{
|
||||
public static double roundDecimals(double d) {
|
||||
return roundDecimals(d, 2);
|
||||
}
|
||||
|
||||
public static enum EnergyType
|
||||
{
|
||||
J,
|
||||
RF,
|
||||
EU,
|
||||
MJ
|
||||
}
|
||||
public static enum EnergyType { J, RF, EU, MJ }
|
||||
|
||||
public static enum TempType
|
||||
{
|
||||
K,
|
||||
C,
|
||||
R,
|
||||
F,
|
||||
STP
|
||||
}
|
||||
public static enum TempType { K, C, R, F, STP }
|
||||
}
|
||||
|
|
|
@ -1,4 +1,3 @@
|
|||
@API(apiVersion = "9.0.0", owner = "Mekanism", provides = "MekanismAPI|util")
|
||||
package mekanism.api.util;
|
||||
import cpw.mods.fml.common.API;
|
||||
|
||||
|
|
|
@ -2,17 +2,16 @@ package mekanism.client;
|
|||
|
||||
import java.io.File;
|
||||
|
||||
import cpw.mods.fml.relauncher.Side;
|
||||
import cpw.mods.fml.relauncher.SideOnly;
|
||||
import net.minecraft.client.Minecraft;
|
||||
import net.minecraft.client.renderer.ThreadDownloadImageData;
|
||||
import net.minecraft.client.renderer.texture.TextureManager;
|
||||
import net.minecraft.util.ResourceLocation;
|
||||
import net.minecraft.util.StringUtils;
|
||||
import cpw.mods.fml.relauncher.Side;
|
||||
import cpw.mods.fml.relauncher.SideOnly;
|
||||
|
||||
@SideOnly(Side.CLIENT)
|
||||
public class CapeBufferDownload extends Thread
|
||||
{
|
||||
public class CapeBufferDownload extends Thread {
|
||||
public String username;
|
||||
|
||||
public String staticCapeUrl;
|
||||
|
@ -23,8 +22,7 @@ public class CapeBufferDownload extends Thread
|
|||
|
||||
boolean downloaded = false;
|
||||
|
||||
public CapeBufferDownload(String name, String url)
|
||||
{
|
||||
public CapeBufferDownload(String name, String url) {
|
||||
username = name;
|
||||
staticCapeUrl = url;
|
||||
|
||||
|
@ -33,8 +31,7 @@ public class CapeBufferDownload extends Thread
|
|||
}
|
||||
|
||||
@Override
|
||||
public void run()
|
||||
{
|
||||
public void run() {
|
||||
try {
|
||||
download();
|
||||
} catch (Exception e) {
|
||||
|
@ -42,10 +39,11 @@ public class CapeBufferDownload extends Thread
|
|||
}
|
||||
}
|
||||
|
||||
private void download()
|
||||
{
|
||||
private void download() {
|
||||
try {
|
||||
resourceLocation = new ResourceLocation("mekanism/" + StringUtils.stripControlCodes(username));
|
||||
resourceLocation = new ResourceLocation(
|
||||
"mekanism/" + StringUtils.stripControlCodes(username)
|
||||
);
|
||||
|
||||
capeImage = downloadCape();
|
||||
} catch (Exception e) {
|
||||
|
@ -55,28 +53,25 @@ public class CapeBufferDownload extends Thread
|
|||
downloaded = true;
|
||||
}
|
||||
|
||||
public ThreadDownloadImageData getImage()
|
||||
{
|
||||
public ThreadDownloadImageData getImage() {
|
||||
return capeImage;
|
||||
}
|
||||
|
||||
public ResourceLocation getResourceLocation()
|
||||
{
|
||||
public ResourceLocation getResourceLocation() {
|
||||
return resourceLocation;
|
||||
}
|
||||
|
||||
public ThreadDownloadImageData downloadCape()
|
||||
{
|
||||
public ThreadDownloadImageData downloadCape() {
|
||||
try {
|
||||
File capeFile = new File(resourceLocation.getResourcePath() + ".png");
|
||||
|
||||
if(capeFile.exists())
|
||||
{
|
||||
if (capeFile.exists()) {
|
||||
capeFile.delete();
|
||||
}
|
||||
|
||||
TextureManager manager = Minecraft.getMinecraft().getTextureManager();
|
||||
ThreadDownloadImageData data = new ThreadDownloadImageData(capeFile, staticCapeUrl, null, null);
|
||||
ThreadDownloadImageData data
|
||||
= new ThreadDownloadImageData(capeFile, staticCapeUrl, null, null);
|
||||
|
||||
manager.loadTexture(resourceLocation, data);
|
||||
|
||||
|
|
|
@ -2,39 +2,42 @@ package mekanism.client;
|
|||
|
||||
import java.net.InetSocketAddress;
|
||||
|
||||
import mekanism.api.MekanismConfig.general;
|
||||
import mekanism.client.voice.VoiceClient;
|
||||
import mekanism.common.Mekanism;
|
||||
import cpw.mods.fml.common.eventhandler.SubscribeEvent;
|
||||
import cpw.mods.fml.common.network.FMLNetworkEvent.ClientConnectedToServerEvent;
|
||||
import cpw.mods.fml.relauncher.Side;
|
||||
import cpw.mods.fml.relauncher.SideOnly;
|
||||
import mekanism.api.MekanismConfig.general;
|
||||
import mekanism.client.voice.VoiceClient;
|
||||
import mekanism.common.Mekanism;
|
||||
|
||||
@SideOnly(Side.CLIENT)
|
||||
public class ClientConnectionHandler
|
||||
{
|
||||
public class ClientConnectionHandler {
|
||||
@SubscribeEvent
|
||||
public void onConnection(ClientConnectedToServerEvent event)
|
||||
{
|
||||
if(general.voiceServerEnabled)
|
||||
{
|
||||
if(event.isLocal)
|
||||
{
|
||||
public void onConnection(ClientConnectedToServerEvent event) {
|
||||
if (general.voiceServerEnabled) {
|
||||
if (event.isLocal) {
|
||||
//If the client is connecting to its own corresponding integrated server.
|
||||
try {
|
||||
MekanismClient.voiceClient = new VoiceClient("127.0.0.1");
|
||||
//Will probably not work when multiple integrateds are running on one computer
|
||||
//Will probably not work when multiple integrateds are running on one
|
||||
//computer
|
||||
} catch (Throwable e) {
|
||||
Mekanism.logger.error("Unable to establish VoiceClient on local connection.");
|
||||
Mekanism.logger.error(
|
||||
"Unable to establish VoiceClient on local connection."
|
||||
);
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
else {
|
||||
} else {
|
||||
//If the client is connecting to a foreign integrated or dedicated server.
|
||||
try {
|
||||
MekanismClient.voiceClient = new VoiceClient(((InetSocketAddress)event.manager.getSocketAddress()).getHostString());
|
||||
MekanismClient.voiceClient = new VoiceClient(
|
||||
((InetSocketAddress) event.manager.getSocketAddress())
|
||||
.getHostString()
|
||||
);
|
||||
} catch (Throwable e) {
|
||||
Mekanism.logger.error("Unable to establish VoiceClient on remote connection.");
|
||||
Mekanism.logger.error(
|
||||
"Unable to establish VoiceClient on remote connection."
|
||||
);
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,17 +1,15 @@
|
|||
package mekanism.client;
|
||||
|
||||
import mekanism.common.Mekanism;
|
||||
import cpw.mods.fml.common.eventhandler.SubscribeEvent;
|
||||
import cpw.mods.fml.common.gameevent.PlayerEvent.PlayerChangedDimensionEvent;
|
||||
import cpw.mods.fml.relauncher.Side;
|
||||
import cpw.mods.fml.relauncher.SideOnly;
|
||||
import mekanism.common.Mekanism;
|
||||
|
||||
@SideOnly(Side.CLIENT)
|
||||
public class ClientPlayerTracker
|
||||
{
|
||||
public class ClientPlayerTracker {
|
||||
@SubscribeEvent
|
||||
public void onPlayerChangedDimension(PlayerChangedDimensionEvent event)
|
||||
{
|
||||
public void onPlayerChangedDimension(PlayerChangedDimensionEvent event) {
|
||||
Mekanism.jetpackOn.remove(event.player);
|
||||
Mekanism.gasmaskOn.remove(event.player);
|
||||
Mekanism.flamethrowerActive.remove(event.player);
|
||||
|
|
Some files were not shown because too many files have changed in this diff Show more
Loading…
Reference in a new issue