diff --git a/bin/main/cofh/api/energy/IEnergyConnection.class b/bin/main/cofh/api/energy/IEnergyConnection.class new file mode 100644 index 0000000..26ec813 Binary files /dev/null and b/bin/main/cofh/api/energy/IEnergyConnection.class differ diff --git a/bin/main/cofh/api/energy/IEnergyProvider.class b/bin/main/cofh/api/energy/IEnergyProvider.class new file mode 100644 index 0000000..7d452fa Binary files /dev/null and b/bin/main/cofh/api/energy/IEnergyProvider.class differ diff --git a/bin/main/cofh/api/energy/IEnergyReceiver.class b/bin/main/cofh/api/energy/IEnergyReceiver.class new file mode 100644 index 0000000..1792905 Binary files /dev/null and b/bin/main/cofh/api/energy/IEnergyReceiver.class differ diff --git a/bin/main/cofh/api/energy/IEnergyStorage.class b/bin/main/cofh/api/energy/IEnergyStorage.class new file mode 100644 index 0000000..43b7278 Binary files /dev/null and b/bin/main/cofh/api/energy/IEnergyStorage.class differ diff --git a/bin/main/universalelectricity/api/CompatibilityModule.class b/bin/main/universalelectricity/api/CompatibilityModule.class new file mode 100644 index 0000000..44e11e1 Binary files /dev/null and b/bin/main/universalelectricity/api/CompatibilityModule.class differ diff --git a/bin/main/universalelectricity/api/CompatibilityType.class b/bin/main/universalelectricity/api/CompatibilityType.class new file mode 100644 index 0000000..7cda750 Binary files /dev/null and b/bin/main/universalelectricity/api/CompatibilityType.class differ diff --git a/bin/main/universalelectricity/api/electricity/IElectricalNetwork.class b/bin/main/universalelectricity/api/electricity/IElectricalNetwork.class new file mode 100644 index 0000000..07183d2 Binary files /dev/null and b/bin/main/universalelectricity/api/electricity/IElectricalNetwork.class differ diff --git a/bin/main/universalelectricity/api/electricity/IVoltageInput.class b/bin/main/universalelectricity/api/electricity/IVoltageInput.class new file mode 100644 index 0000000..8776ed0 Binary files /dev/null and b/bin/main/universalelectricity/api/electricity/IVoltageInput.class differ diff --git a/bin/main/universalelectricity/api/electricity/IVoltageOutput.class b/bin/main/universalelectricity/api/electricity/IVoltageOutput.class new file mode 100644 index 0000000..27c5351 Binary files /dev/null and b/bin/main/universalelectricity/api/electricity/IVoltageOutput.class differ diff --git a/bin/main/universalelectricity/api/energy/EnergyNetworkLoader.class b/bin/main/universalelectricity/api/energy/EnergyNetworkLoader.class new file mode 100644 index 0000000..6346d6c Binary files /dev/null and b/bin/main/universalelectricity/api/energy/EnergyNetworkLoader.class differ diff --git a/bin/main/universalelectricity/api/energy/EnergyStorageHandler.class b/bin/main/universalelectricity/api/energy/EnergyStorageHandler.class new file mode 100644 index 0000000..cf89cd9 Binary files /dev/null and b/bin/main/universalelectricity/api/energy/EnergyStorageHandler.class differ diff --git a/bin/main/universalelectricity/api/energy/IConductor.class b/bin/main/universalelectricity/api/energy/IConductor.class new file mode 100644 index 0000000..cbfddfa Binary files /dev/null and b/bin/main/universalelectricity/api/energy/IConductor.class differ diff --git a/bin/main/universalelectricity/api/energy/IEnergyContainer.class b/bin/main/universalelectricity/api/energy/IEnergyContainer.class new file mode 100644 index 0000000..0c69ccf Binary files /dev/null and b/bin/main/universalelectricity/api/energy/IEnergyContainer.class differ diff --git a/bin/main/universalelectricity/api/energy/IEnergyInterface.class b/bin/main/universalelectricity/api/energy/IEnergyInterface.class new file mode 100644 index 0000000..ca0ae97 Binary files /dev/null and b/bin/main/universalelectricity/api/energy/IEnergyInterface.class differ diff --git a/bin/main/universalelectricity/api/energy/IEnergyNetwork.class b/bin/main/universalelectricity/api/energy/IEnergyNetwork.class new file mode 100644 index 0000000..f910546 Binary files /dev/null and b/bin/main/universalelectricity/api/energy/IEnergyNetwork.class differ diff --git a/bin/main/universalelectricity/api/energy/UnitDisplay$Unit.class b/bin/main/universalelectricity/api/energy/UnitDisplay$Unit.class new file mode 100644 index 0000000..d919c6a Binary files /dev/null and b/bin/main/universalelectricity/api/energy/UnitDisplay$Unit.class differ diff --git a/bin/main/universalelectricity/api/energy/UnitDisplay$UnitPrefix.class b/bin/main/universalelectricity/api/energy/UnitDisplay$UnitPrefix.class new file mode 100644 index 0000000..cc5fccc Binary files /dev/null and b/bin/main/universalelectricity/api/energy/UnitDisplay$UnitPrefix.class differ diff --git a/bin/main/universalelectricity/api/energy/UnitDisplay.class b/bin/main/universalelectricity/api/energy/UnitDisplay.class new file mode 100644 index 0000000..f609499 Binary files /dev/null and b/bin/main/universalelectricity/api/energy/UnitDisplay.class differ diff --git a/bin/main/universalelectricity/api/item/IEnergyItem.class b/bin/main/universalelectricity/api/item/IEnergyItem.class new file mode 100644 index 0000000..96796c9 Binary files /dev/null and b/bin/main/universalelectricity/api/item/IEnergyItem.class differ diff --git a/bin/main/universalelectricity/api/item/IVoltageItem.class b/bin/main/universalelectricity/api/item/IVoltageItem.class new file mode 100644 index 0000000..14a5036 Binary files /dev/null and b/bin/main/universalelectricity/api/item/IVoltageItem.class differ diff --git a/bin/main/universalelectricity/api/item/ItemElectric.class b/bin/main/universalelectricity/api/item/ItemElectric.class new file mode 100644 index 0000000..9b8f300 Binary files /dev/null and b/bin/main/universalelectricity/api/item/ItemElectric.class differ diff --git a/bin/main/universalelectricity/api/net/IConnectable.class b/bin/main/universalelectricity/api/net/IConnectable.class new file mode 100644 index 0000000..a1f8dfe Binary files /dev/null and b/bin/main/universalelectricity/api/net/IConnectable.class differ diff --git a/bin/main/universalelectricity/api/net/IConnector.class b/bin/main/universalelectricity/api/net/IConnector.class new file mode 100644 index 0000000..c937ddd Binary files /dev/null and b/bin/main/universalelectricity/api/net/IConnector.class differ diff --git a/bin/main/universalelectricity/api/net/INetwork.class b/bin/main/universalelectricity/api/net/INetwork.class new file mode 100644 index 0000000..011e431 Binary files /dev/null and b/bin/main/universalelectricity/api/net/INetwork.class differ diff --git a/bin/main/universalelectricity/api/net/INetworkProvider.class b/bin/main/universalelectricity/api/net/INetworkProvider.class new file mode 100644 index 0000000..7190336 Binary files /dev/null and b/bin/main/universalelectricity/api/net/INetworkProvider.class differ diff --git a/bin/main/universalelectricity/api/net/INodeNetwork.class b/bin/main/universalelectricity/api/net/INodeNetwork.class new file mode 100644 index 0000000..5bba933 Binary files /dev/null and b/bin/main/universalelectricity/api/net/INodeNetwork.class differ diff --git a/bin/main/universalelectricity/api/net/IUpdate.class b/bin/main/universalelectricity/api/net/IUpdate.class new file mode 100644 index 0000000..c50fdd0 Binary files /dev/null and b/bin/main/universalelectricity/api/net/IUpdate.class differ diff --git a/bin/main/universalelectricity/api/net/NetworkEvent$EnergyProduceEvent.class b/bin/main/universalelectricity/api/net/NetworkEvent$EnergyProduceEvent.class new file mode 100644 index 0000000..93ec99b Binary files /dev/null and b/bin/main/universalelectricity/api/net/NetworkEvent$EnergyProduceEvent.class differ diff --git a/bin/main/universalelectricity/api/net/NetworkEvent$EnergyUpdateEvent.class b/bin/main/universalelectricity/api/net/NetworkEvent$EnergyUpdateEvent.class new file mode 100644 index 0000000..80cca6a Binary files /dev/null and b/bin/main/universalelectricity/api/net/NetworkEvent$EnergyUpdateEvent.class differ diff --git a/bin/main/universalelectricity/api/net/NetworkEvent.class b/bin/main/universalelectricity/api/net/NetworkEvent.class new file mode 100644 index 0000000..e2bbbab Binary files /dev/null and b/bin/main/universalelectricity/api/net/NetworkEvent.class differ diff --git a/bin/main/universalelectricity/compat/CompatHandler.class b/bin/main/universalelectricity/compat/CompatHandler.class new file mode 100644 index 0000000..dcf15ed Binary files /dev/null and b/bin/main/universalelectricity/compat/CompatHandler.class differ diff --git a/bin/main/universalelectricity/compat/CompatTickHandler.class b/bin/main/universalelectricity/compat/CompatTickHandler.class new file mode 100644 index 0000000..ec09aee Binary files /dev/null and b/bin/main/universalelectricity/compat/CompatTickHandler.class differ diff --git a/bin/main/universalelectricity/compat/ic2/IC2CompatModule.class b/bin/main/universalelectricity/compat/ic2/IC2CompatModule.class new file mode 100644 index 0000000..3178d2e Binary files /dev/null and b/bin/main/universalelectricity/compat/ic2/IC2CompatModule.class differ diff --git a/bin/main/universalelectricity/core/Pair.class b/bin/main/universalelectricity/core/Pair.class new file mode 100644 index 0000000..1753cdb Binary files /dev/null and b/bin/main/universalelectricity/core/Pair.class differ diff --git a/bin/main/universalelectricity/core/UniversalElectricity.class b/bin/main/universalelectricity/core/UniversalElectricity.class new file mode 100644 index 0000000..72d754a Binary files /dev/null and b/bin/main/universalelectricity/core/UniversalElectricity.class differ diff --git a/bin/main/universalelectricity/core/block/IConductor.class b/bin/main/universalelectricity/core/block/IConductor.class new file mode 100644 index 0000000..dc49b4a Binary files /dev/null and b/bin/main/universalelectricity/core/block/IConductor.class differ diff --git a/bin/main/universalelectricity/core/block/IConnectionProvider.class b/bin/main/universalelectricity/core/block/IConnectionProvider.class new file mode 100644 index 0000000..efec45c Binary files /dev/null and b/bin/main/universalelectricity/core/block/IConnectionProvider.class differ diff --git a/bin/main/universalelectricity/core/block/IConnector.class b/bin/main/universalelectricity/core/block/IConnector.class new file mode 100644 index 0000000..c16f22f Binary files /dev/null and b/bin/main/universalelectricity/core/block/IConnector.class differ diff --git a/bin/main/universalelectricity/core/block/IElectricityStorage.class b/bin/main/universalelectricity/core/block/IElectricityStorage.class new file mode 100644 index 0000000..40aa472 Binary files /dev/null and b/bin/main/universalelectricity/core/block/IElectricityStorage.class differ diff --git a/bin/main/universalelectricity/core/block/INetworkProvider.class b/bin/main/universalelectricity/core/block/INetworkProvider.class new file mode 100644 index 0000000..cff4bf0 Binary files /dev/null and b/bin/main/universalelectricity/core/block/INetworkProvider.class differ diff --git a/bin/main/universalelectricity/core/block/ISelfDriven.class b/bin/main/universalelectricity/core/block/ISelfDriven.class new file mode 100644 index 0000000..bb4271e Binary files /dev/null and b/bin/main/universalelectricity/core/block/ISelfDriven.class differ diff --git a/bin/main/universalelectricity/core/block/IVoltage.class b/bin/main/universalelectricity/core/block/IVoltage.class new file mode 100644 index 0000000..9040cbc Binary files /dev/null and b/bin/main/universalelectricity/core/block/IVoltage.class differ diff --git a/bin/main/universalelectricity/core/electricity/ElectricityNetwork.class b/bin/main/universalelectricity/core/electricity/ElectricityNetwork.class new file mode 100644 index 0000000..384e145 Binary files /dev/null and b/bin/main/universalelectricity/core/electricity/ElectricityNetwork.class differ diff --git a/bin/main/universalelectricity/core/electricity/ElectricityNetworkHelper.class b/bin/main/universalelectricity/core/electricity/ElectricityNetworkHelper.class new file mode 100644 index 0000000..d1299b3 Binary files /dev/null and b/bin/main/universalelectricity/core/electricity/ElectricityNetworkHelper.class differ diff --git a/bin/main/universalelectricity/core/electricity/ElectricityPack.class b/bin/main/universalelectricity/core/electricity/ElectricityPack.class new file mode 100644 index 0000000..5c953fc Binary files /dev/null and b/bin/main/universalelectricity/core/electricity/ElectricityPack.class differ diff --git a/bin/main/universalelectricity/core/electricity/IConductorRegistry.class b/bin/main/universalelectricity/core/electricity/IConductorRegistry.class new file mode 100644 index 0000000..ac5d0f6 Binary files /dev/null and b/bin/main/universalelectricity/core/electricity/IConductorRegistry.class differ diff --git a/bin/main/universalelectricity/core/electricity/IElectricityNetwork.class b/bin/main/universalelectricity/core/electricity/IElectricityNetwork.class new file mode 100644 index 0000000..79487d7 Binary files /dev/null and b/bin/main/universalelectricity/core/electricity/IElectricityNetwork.class differ diff --git a/bin/main/universalelectricity/core/item/ElectricItemHelper.class b/bin/main/universalelectricity/core/item/ElectricItemHelper.class new file mode 100644 index 0000000..375def3 Binary files /dev/null and b/bin/main/universalelectricity/core/item/ElectricItemHelper.class differ diff --git a/bin/main/universalelectricity/core/item/IItemElectric.class b/bin/main/universalelectricity/core/item/IItemElectric.class new file mode 100644 index 0000000..7507453 Binary files /dev/null and b/bin/main/universalelectricity/core/item/IItemElectric.class differ diff --git a/bin/main/universalelectricity/core/item/IItemElectricityStorage.class b/bin/main/universalelectricity/core/item/IItemElectricityStorage.class new file mode 100644 index 0000000..1614de3 Binary files /dev/null and b/bin/main/universalelectricity/core/item/IItemElectricityStorage.class differ diff --git a/bin/main/universalelectricity/core/item/IItemVoltage.class b/bin/main/universalelectricity/core/item/IItemVoltage.class new file mode 100644 index 0000000..2a3bd25 Binary files /dev/null and b/bin/main/universalelectricity/core/item/IItemVoltage.class differ diff --git a/bin/main/universalelectricity/core/item/ItemElectric.class b/bin/main/universalelectricity/core/item/ItemElectric.class new file mode 100644 index 0000000..f81a9a7 Binary files /dev/null and b/bin/main/universalelectricity/core/item/ItemElectric.class differ diff --git a/bin/main/universalelectricity/core/path/IPathCallBack.class b/bin/main/universalelectricity/core/path/IPathCallBack.class new file mode 100644 index 0000000..e93e155 Binary files /dev/null and b/bin/main/universalelectricity/core/path/IPathCallBack.class differ diff --git a/bin/main/universalelectricity/core/path/Pathfinder.class b/bin/main/universalelectricity/core/path/Pathfinder.class new file mode 100644 index 0000000..569e2c7 Binary files /dev/null and b/bin/main/universalelectricity/core/path/Pathfinder.class differ diff --git a/bin/main/universalelectricity/core/path/PathfinderAStar.class b/bin/main/universalelectricity/core/path/PathfinderAStar.class new file mode 100644 index 0000000..a14879b Binary files /dev/null and b/bin/main/universalelectricity/core/path/PathfinderAStar.class differ diff --git a/bin/main/universalelectricity/core/path/PathfinderChecker$1.class b/bin/main/universalelectricity/core/path/PathfinderChecker$1.class new file mode 100644 index 0000000..79a74cd Binary files /dev/null and b/bin/main/universalelectricity/core/path/PathfinderChecker$1.class differ diff --git a/bin/main/universalelectricity/core/path/PathfinderChecker$2.class b/bin/main/universalelectricity/core/path/PathfinderChecker$2.class new file mode 100644 index 0000000..14867f2 Binary files /dev/null and b/bin/main/universalelectricity/core/path/PathfinderChecker$2.class differ diff --git a/bin/main/universalelectricity/core/path/PathfinderChecker.class b/bin/main/universalelectricity/core/path/PathfinderChecker.class new file mode 100644 index 0000000..3f5944e Binary files /dev/null and b/bin/main/universalelectricity/core/path/PathfinderChecker.class differ diff --git a/bin/main/universalelectricity/core/vector/Vector2.class b/bin/main/universalelectricity/core/vector/Vector2.class new file mode 100644 index 0000000..bd09e64 Binary files /dev/null and b/bin/main/universalelectricity/core/vector/Vector2.class differ diff --git a/bin/main/universalelectricity/core/vector/Vector3.class b/bin/main/universalelectricity/core/vector/Vector3.class new file mode 100644 index 0000000..b274f31 Binary files /dev/null and b/bin/main/universalelectricity/core/vector/Vector3.class differ diff --git a/bin/main/universalelectricity/core/vector/VectorHelper.class b/bin/main/universalelectricity/core/vector/VectorHelper.class new file mode 100644 index 0000000..1864c1b Binary files /dev/null and b/bin/main/universalelectricity/core/vector/VectorHelper.class differ diff --git a/bin/main/universalelectricity/prefab/CustomDamageSource.class b/bin/main/universalelectricity/prefab/CustomDamageSource.class new file mode 100644 index 0000000..7e015ef Binary files /dev/null and b/bin/main/universalelectricity/prefab/CustomDamageSource.class differ diff --git a/bin/main/universalelectricity/prefab/GuiBase.class b/bin/main/universalelectricity/prefab/GuiBase.class new file mode 100644 index 0000000..8336bb3 Binary files /dev/null and b/bin/main/universalelectricity/prefab/GuiBase.class differ diff --git a/bin/main/universalelectricity/prefab/RecipeHelper.class b/bin/main/universalelectricity/prefab/RecipeHelper.class new file mode 100644 index 0000000..0dce6c0 Binary files /dev/null and b/bin/main/universalelectricity/prefab/RecipeHelper.class differ diff --git a/bin/main/universalelectricity/prefab/SlotSpecific.class b/bin/main/universalelectricity/prefab/SlotSpecific.class new file mode 100644 index 0000000..f66449d Binary files /dev/null and b/bin/main/universalelectricity/prefab/SlotSpecific.class differ diff --git a/bin/main/universalelectricity/prefab/TranslationHelper.class b/bin/main/universalelectricity/prefab/TranslationHelper.class new file mode 100644 index 0000000..7b760d8 Binary files /dev/null and b/bin/main/universalelectricity/prefab/TranslationHelper.class differ diff --git a/bin/main/universalelectricity/prefab/block/BlockAdvanced.class b/bin/main/universalelectricity/prefab/block/BlockAdvanced.class new file mode 100644 index 0000000..49ade59 Binary files /dev/null and b/bin/main/universalelectricity/prefab/block/BlockAdvanced.class differ diff --git a/bin/main/universalelectricity/prefab/block/BlockConductor.class b/bin/main/universalelectricity/prefab/block/BlockConductor.class new file mode 100644 index 0000000..a7fb687 Binary files /dev/null and b/bin/main/universalelectricity/prefab/block/BlockConductor.class differ diff --git a/bin/main/universalelectricity/prefab/block/BlockRotatable.class b/bin/main/universalelectricity/prefab/block/BlockRotatable.class new file mode 100644 index 0000000..4c943e7 Binary files /dev/null and b/bin/main/universalelectricity/prefab/block/BlockRotatable.class differ diff --git a/bin/main/universalelectricity/prefab/flag/CommandFlag.class b/bin/main/universalelectricity/prefab/flag/CommandFlag.class new file mode 100644 index 0000000..1b6097d Binary files /dev/null and b/bin/main/universalelectricity/prefab/flag/CommandFlag.class differ diff --git a/bin/main/universalelectricity/prefab/flag/Flag.class b/bin/main/universalelectricity/prefab/flag/Flag.class new file mode 100644 index 0000000..093ff70 Binary files /dev/null and b/bin/main/universalelectricity/prefab/flag/Flag.class differ diff --git a/bin/main/universalelectricity/prefab/flag/FlagBase.class b/bin/main/universalelectricity/prefab/flag/FlagBase.class new file mode 100644 index 0000000..eba3aa4 Binary files /dev/null and b/bin/main/universalelectricity/prefab/flag/FlagBase.class differ diff --git a/bin/main/universalelectricity/prefab/flag/FlagRegion.class b/bin/main/universalelectricity/prefab/flag/FlagRegion.class new file mode 100644 index 0000000..00ff19a Binary files /dev/null and b/bin/main/universalelectricity/prefab/flag/FlagRegion.class differ diff --git a/bin/main/universalelectricity/prefab/flag/FlagRegistry.class b/bin/main/universalelectricity/prefab/flag/FlagRegistry.class new file mode 100644 index 0000000..5699ac2 Binary files /dev/null and b/bin/main/universalelectricity/prefab/flag/FlagRegistry.class differ diff --git a/bin/main/universalelectricity/prefab/flag/FlagWorld.class b/bin/main/universalelectricity/prefab/flag/FlagWorld.class new file mode 100644 index 0000000..173baa0 Binary files /dev/null and b/bin/main/universalelectricity/prefab/flag/FlagWorld.class differ diff --git a/bin/main/universalelectricity/prefab/flag/ModFlag.class b/bin/main/universalelectricity/prefab/flag/ModFlag.class new file mode 100644 index 0000000..89baf19 Binary files /dev/null and b/bin/main/universalelectricity/prefab/flag/ModFlag.class differ diff --git a/bin/main/universalelectricity/prefab/flag/NBTFileLoader.class b/bin/main/universalelectricity/prefab/flag/NBTFileLoader.class new file mode 100644 index 0000000..d2a7080 Binary files /dev/null and b/bin/main/universalelectricity/prefab/flag/NBTFileLoader.class differ diff --git a/bin/main/universalelectricity/prefab/implement/IDisableable.class b/bin/main/universalelectricity/prefab/implement/IDisableable.class new file mode 100644 index 0000000..2b4b4b6 Binary files /dev/null and b/bin/main/universalelectricity/prefab/implement/IDisableable.class differ diff --git a/bin/main/universalelectricity/prefab/implement/IRedstoneProvider.class b/bin/main/universalelectricity/prefab/implement/IRedstoneProvider.class new file mode 100644 index 0000000..6a187d8 Binary files /dev/null and b/bin/main/universalelectricity/prefab/implement/IRedstoneProvider.class differ diff --git a/bin/main/universalelectricity/prefab/implement/IRedstoneReceptor.class b/bin/main/universalelectricity/prefab/implement/IRedstoneReceptor.class new file mode 100644 index 0000000..5a94239 Binary files /dev/null and b/bin/main/universalelectricity/prefab/implement/IRedstoneReceptor.class differ diff --git a/bin/main/universalelectricity/prefab/implement/IRotatable.class b/bin/main/universalelectricity/prefab/implement/IRotatable.class new file mode 100644 index 0000000..e403cf5 Binary files /dev/null and b/bin/main/universalelectricity/prefab/implement/IRotatable.class differ diff --git a/bin/main/universalelectricity/prefab/implement/ITier.class b/bin/main/universalelectricity/prefab/implement/ITier.class new file mode 100644 index 0000000..008b1dd Binary files /dev/null and b/bin/main/universalelectricity/prefab/implement/ITier.class differ diff --git a/bin/main/universalelectricity/prefab/implement/IToolConfigurator.class b/bin/main/universalelectricity/prefab/implement/IToolConfigurator.class new file mode 100644 index 0000000..110cb07 Binary files /dev/null and b/bin/main/universalelectricity/prefab/implement/IToolConfigurator.class differ diff --git a/bin/main/universalelectricity/prefab/modifier/IModifier.class b/bin/main/universalelectricity/prefab/modifier/IModifier.class new file mode 100644 index 0000000..93cff4d Binary files /dev/null and b/bin/main/universalelectricity/prefab/modifier/IModifier.class differ diff --git a/bin/main/universalelectricity/prefab/modifier/SlotModifier.class b/bin/main/universalelectricity/prefab/modifier/SlotModifier.class new file mode 100644 index 0000000..ef349d9 Binary files /dev/null and b/bin/main/universalelectricity/prefab/modifier/SlotModifier.class differ diff --git a/bin/main/universalelectricity/prefab/multiblock/BlockMulti.class b/bin/main/universalelectricity/prefab/multiblock/BlockMulti.class new file mode 100644 index 0000000..9d32a81 Binary files /dev/null and b/bin/main/universalelectricity/prefab/multiblock/BlockMulti.class differ diff --git a/bin/main/universalelectricity/prefab/multiblock/IBlockActivate.class b/bin/main/universalelectricity/prefab/multiblock/IBlockActivate.class new file mode 100644 index 0000000..7016621 Binary files /dev/null and b/bin/main/universalelectricity/prefab/multiblock/IBlockActivate.class differ diff --git a/bin/main/universalelectricity/prefab/multiblock/IMultiBlock.class b/bin/main/universalelectricity/prefab/multiblock/IMultiBlock.class new file mode 100644 index 0000000..87c7d5c Binary files /dev/null and b/bin/main/universalelectricity/prefab/multiblock/IMultiBlock.class differ diff --git a/bin/main/universalelectricity/prefab/multiblock/TileEntityMulti.class b/bin/main/universalelectricity/prefab/multiblock/TileEntityMulti.class new file mode 100644 index 0000000..e343d62 Binary files /dev/null and b/bin/main/universalelectricity/prefab/multiblock/TileEntityMulti.class differ diff --git a/bin/main/universalelectricity/prefab/ore/OreGenBase.class b/bin/main/universalelectricity/prefab/ore/OreGenBase.class new file mode 100644 index 0000000..0d954fd Binary files /dev/null and b/bin/main/universalelectricity/prefab/ore/OreGenBase.class differ diff --git a/bin/main/universalelectricity/prefab/ore/OreGenReplace.class b/bin/main/universalelectricity/prefab/ore/OreGenReplace.class new file mode 100644 index 0000000..587a7b6 Binary files /dev/null and b/bin/main/universalelectricity/prefab/ore/OreGenReplace.class differ diff --git a/bin/main/universalelectricity/prefab/ore/OreGenReplaceStone.class b/bin/main/universalelectricity/prefab/ore/OreGenReplaceStone.class new file mode 100644 index 0000000..ac60f8b Binary files /dev/null and b/bin/main/universalelectricity/prefab/ore/OreGenReplaceStone.class differ diff --git a/bin/main/universalelectricity/prefab/ore/OreGenerator.class b/bin/main/universalelectricity/prefab/ore/OreGenerator.class new file mode 100644 index 0000000..813d767 Binary files /dev/null and b/bin/main/universalelectricity/prefab/ore/OreGenerator.class differ diff --git a/bin/main/universalelectricity/prefab/potion/CustomPotion.class b/bin/main/universalelectricity/prefab/potion/CustomPotion.class new file mode 100644 index 0000000..cdbbf57 Binary files /dev/null and b/bin/main/universalelectricity/prefab/potion/CustomPotion.class differ diff --git a/bin/main/universalelectricity/prefab/potion/CustomPotionEffect.class b/bin/main/universalelectricity/prefab/potion/CustomPotionEffect.class new file mode 100644 index 0000000..702c73f Binary files /dev/null and b/bin/main/universalelectricity/prefab/potion/CustomPotionEffect.class differ diff --git a/bin/main/universalelectricity/prefab/tile/ElectricTileDriver.class b/bin/main/universalelectricity/prefab/tile/ElectricTileDriver.class new file mode 100644 index 0000000..735ff36 Binary files /dev/null and b/bin/main/universalelectricity/prefab/tile/ElectricTileDriver.class differ diff --git a/bin/main/universalelectricity/prefab/tile/TileEntityAdvanced.class b/bin/main/universalelectricity/prefab/tile/TileEntityAdvanced.class new file mode 100644 index 0000000..8227f91 Binary files /dev/null and b/bin/main/universalelectricity/prefab/tile/TileEntityAdvanced.class differ diff --git a/bin/main/universalelectricity/prefab/tile/TileEntityConductor.class b/bin/main/universalelectricity/prefab/tile/TileEntityConductor.class new file mode 100644 index 0000000..d269dca Binary files /dev/null and b/bin/main/universalelectricity/prefab/tile/TileEntityConductor.class differ diff --git a/bin/main/universalelectricity/prefab/tile/TileEntityDisableable.class b/bin/main/universalelectricity/prefab/tile/TileEntityDisableable.class new file mode 100644 index 0000000..0837430 Binary files /dev/null and b/bin/main/universalelectricity/prefab/tile/TileEntityDisableable.class differ diff --git a/bin/main/universalelectricity/prefab/tile/TileEntityElectrical.class b/bin/main/universalelectricity/prefab/tile/TileEntityElectrical.class new file mode 100644 index 0000000..20d58e3 Binary files /dev/null and b/bin/main/universalelectricity/prefab/tile/TileEntityElectrical.class differ diff --git a/bin/main/universalelectricity/prefab/tile/TileEntityElectricityRunnable.class b/bin/main/universalelectricity/prefab/tile/TileEntityElectricityRunnable.class new file mode 100644 index 0000000..8af97a4 Binary files /dev/null and b/bin/main/universalelectricity/prefab/tile/TileEntityElectricityRunnable.class differ diff --git a/bin/main/universalelectricity/prefab/tile/TileEntityElectricityStorage.class b/bin/main/universalelectricity/prefab/tile/TileEntityElectricityStorage.class new file mode 100644 index 0000000..908f547 Binary files /dev/null and b/bin/main/universalelectricity/prefab/tile/TileEntityElectricityStorage.class differ diff --git a/bin/main/universalelectricity/prefab/vector/Region2.class b/bin/main/universalelectricity/prefab/vector/Region2.class new file mode 100644 index 0000000..0010ab0 Binary files /dev/null and b/bin/main/universalelectricity/prefab/vector/Region2.class differ diff --git a/bin/main/universalelectricity/prefab/vector/Region3.class b/bin/main/universalelectricity/prefab/vector/Region3.class new file mode 100644 index 0000000..a1810ef Binary files /dev/null and b/bin/main/universalelectricity/prefab/vector/Region3.class differ diff --git a/build.gradle b/build.gradle index 585fd0f..0318e29 100644 --- a/build.gradle +++ b/build.gradle @@ -3,7 +3,7 @@ buildscript { mavenCentral() maven { name = "forge" - url = "https://maven.minecraftforge.net/" + url = "https://files.minecraftforge.net/maven" } maven { name = "sonatype" @@ -23,21 +23,30 @@ apply plugin: 'maven-publish' sourceCompatibility = JavaVersion.VERSION_1_8 targetCompatibility = JavaVersion.VERSION_1_8 -version = "1.0" -group= "modgroup" -archivesBaseName = "modid" +version = "5.0.0" +group= "universalelectricity" +archivesBaseName = "universalelectricity" minecraft { version = "1.7.10-10.13.4.1614-1.7.10" runDir = "run" + + replaceIn "universalelectricity/core/UniversalElectricity.java" + replace "{VERSION}", project.version } repositories { - maven { url = "https://maven.tilera.xyz" } + maven { + name = "ic2" + url = "https://maven.ic2.player.to/" + metadataSources { + artifact() + } + } } dependencies { - + implementation 'net.industrial-craft:industrialcraft-2:2.2.660-experimental:dev' } processResources { @@ -72,17 +81,17 @@ publishing { } repositories { - if (project.hasProperty('mvnURL')) { - maven { + if (project.hasProperty('mvnURL')) { + maven { credentials { - username findProperty("mvnUsername") - password findProperty("mvnPassword") - } - url = findProperty("mvnURL") - } - } - else { - mavenLocal() - } + username findProperty("mvnUsername") + password findProperty("mvnPassword") + } + url = findProperty("mvnURL") + } + } + else { + mavenLocal() + } } } \ No newline at end of file diff --git a/src/main/java/cofh/api/energy/IEnergyConnection.java b/src/main/java/cofh/api/energy/IEnergyConnection.java new file mode 100644 index 0000000..4c264e6 --- /dev/null +++ b/src/main/java/cofh/api/energy/IEnergyConnection.java @@ -0,0 +1,8 @@ +package cofh.api.energy; + +import net.minecraftforge.common.util.ForgeDirection; + +public interface IEnergyConnection { + + boolean canConnectEnergy(ForgeDirection var1); +} diff --git a/src/main/java/cofh/api/energy/IEnergyProvider.java b/src/main/java/cofh/api/energy/IEnergyProvider.java new file mode 100644 index 0000000..f4d2a6c --- /dev/null +++ b/src/main/java/cofh/api/energy/IEnergyProvider.java @@ -0,0 +1,12 @@ +package cofh.api.energy; + +import net.minecraftforge.common.util.ForgeDirection; + +public interface IEnergyProvider extends IEnergyConnection { + + int extractEnergy(ForgeDirection var1, int var2, boolean var3); + + int getEnergyStored(ForgeDirection var1); + + int getMaxEnergyStored(ForgeDirection var1); +} diff --git a/src/main/java/cofh/api/energy/IEnergyReceiver.java b/src/main/java/cofh/api/energy/IEnergyReceiver.java new file mode 100644 index 0000000..00cacc8 --- /dev/null +++ b/src/main/java/cofh/api/energy/IEnergyReceiver.java @@ -0,0 +1,12 @@ +package cofh.api.energy; + +import net.minecraftforge.common.util.ForgeDirection; + +public interface IEnergyReceiver extends IEnergyConnection { + + int receiveEnergy(ForgeDirection var1, int var2, boolean var3); + + int getEnergyStored(ForgeDirection var1); + + int getMaxEnergyStored(ForgeDirection var1); +} diff --git a/src/main/java/cofh/api/energy/IEnergyStorage.java b/src/main/java/cofh/api/energy/IEnergyStorage.java new file mode 100644 index 0000000..258c304 --- /dev/null +++ b/src/main/java/cofh/api/energy/IEnergyStorage.java @@ -0,0 +1,13 @@ +package cofh.api.energy; + + +public interface IEnergyStorage { + + int receiveEnergy(int var1, boolean var2); + + int extractEnergy(int var1, boolean var2); + + int getEnergyStored(); + + int getMaxEnergyStored(); +} diff --git a/src/main/java/universalelectricity/api/CompatibilityModule.java b/src/main/java/universalelectricity/api/CompatibilityModule.java new file mode 100644 index 0000000..6fccf19 --- /dev/null +++ b/src/main/java/universalelectricity/api/CompatibilityModule.java @@ -0,0 +1,326 @@ +package universalelectricity.api; + +import java.util.HashMap; +import java.util.LinkedHashSet; +import java.util.Set; + +import net.minecraft.item.ItemStack; +import net.minecraftforge.common.util.ForgeDirection; + +/** A module to extend for compatibility with other energy systems. */ +public abstract class CompatibilityModule +{ + public static final Set loadedModules = new LinkedHashSet<>(); + + /** A cache to know which module to use with when facing objects with a specific class. */ + public static final HashMap, CompatibilityModule> energyHandlerCache = new HashMap<>(); + public static final HashMap, CompatibilityModule> energyStorageCache = new HashMap<>(); + + public static void register(CompatibilityModule module) + { + loadedModules.add(module); + } + + /** Can the handler connect to this specific direction? */ + public static boolean canConnect(Object handler, ForgeDirection direction, Object source) + { + if (isHandler(handler)) + { + return energyHandlerCache.get(handler.getClass()).doCanConnect(handler, direction, source); + } + + return false; + } + + /** + * Make the handler receive energy. + * + * @return The actual energy that was used. + */ + public static double receiveEnergy(Object handler, ForgeDirection direction, double energy, boolean doReceive) + { + if (isHandler(handler)) + { + return energyHandlerCache.get(handler.getClass()).doReceiveEnergy(handler, direction, energy, doReceive); + } + + return 0; + } + + /** + * Make the handler extract energy. + * + * @return The actual energy that was extract. + */ + public static double extractEnergy(Object handler, ForgeDirection direction, double energy, boolean doExtract) + { + if (isHandler(handler)) + { + return energyHandlerCache.get(handler.getClass()).doExtractEnergy(handler, direction, energy, doExtract); + } + + return 0; + } + + /** + * Gets the energy stored in the handler. + */ + public static double getEnergy(Object handler, ForgeDirection direction) + { + if (isEnergyContainer(handler)) + { + return energyStorageCache.get(handler.getClass()).doGetEnergy(handler, direction); + } + + return 0; + } + + /** + * Charges an item + * + * @return The actual energy that was accepted. + */ + public static double chargeItem(ItemStack itemStack, double energy, boolean doCharge) + { + if (itemStack != null && isHandler(itemStack.getItem())) + { + return energyHandlerCache.get(itemStack.getItem().getClass()).doChargeItem(itemStack, energy, doCharge); + } + + return 0; + } + + /** + * Discharges an item + * + * @return The actual energy that was removed. + */ + public static double dischargeItem(ItemStack itemStack, double energy, boolean doCharge) + { + if (itemStack != null && isHandler(itemStack.getItem())) + { + return energyHandlerCache.get(itemStack.getItem().getClass()).doDischargeItem(itemStack, energy, doCharge); + } + + return 0; + } + + /** + * Gets the itemStack with a specific charge. + * + * @return ItemStack of electrical/energy item. + */ + public static ItemStack getItemWithCharge(ItemStack itemStack, double energy) + { + if (itemStack != null && isHandler(itemStack.getItem())) + { + return energyHandlerCache.get(itemStack.getItem().getClass()).doGetItemWithCharge(itemStack, energy); + } + + return null; + } + + /** + * Is this object a valid energy handler? + * + * @param True if the handler can store energy. This can be for items and blocks. + */ + public static boolean isHandler(Object handler) + { + if (handler != null) + { + Class clazz = handler.getClass(); + + if (energyHandlerCache.containsKey(clazz)) + { + return true; + } + + for (CompatibilityModule module : CompatibilityModule.loadedModules) + { + if (module.doIsHandler(handler)) + { + energyHandlerCache.put(clazz, module); + return true; + } + } + } + + return false; + } + + /** + * Is this object able to store energy? + * + * @param handler + * @return True if the handler can store energy. The handler MUST be a block. + */ + public static boolean isEnergyContainer(Object handler) + { + if (handler != null) + { + Class clazz = handler.getClass(); + + if (energyStorageCache.containsKey(clazz)) + { + return true; + } + + for (CompatibilityModule module : CompatibilityModule.loadedModules) + { + if (module.doIsEnergyContainer(handler)) + { + energyStorageCache.put(clazz, module); + return true; + } + } + } + + return false; + } + + /** + * Blocks only + */ + public static double getMaxEnergy(Object handler, ForgeDirection direction) + { + if (isEnergyContainer(handler)) + { + return energyStorageCache.get(handler.getClass()).doGetMaxEnergy(handler, direction); + } + + return 0; + } + + public static double getInputVoltage(Object handler) + { + if (isHandler(handler)) + { + return energyHandlerCache.get(handler.getClass()).doGetInputVoltage(handler); + } + + return 0; + } + + public static double getOutputVoltage(Object handler) + { + if (isHandler(handler)) + { + return energyHandlerCache.get(handler.getClass()).doGetOutputVoltage(handler); + } + + return 0; + } + + public static boolean canReceive(Object handler, ForgeDirection side) + { + if (isHandler(handler)) + { + return energyHandlerCache.get(handler.getClass()).doCanReceive(handler, side); + } + + return false; + } + + public static boolean canExtract(Object handler, ForgeDirection side) + { + if (isHandler(handler)) + { + return energyHandlerCache.get(handler.getClass()).doCanExtract(handler, side); + } + + return false; + } + + public static double getDemandedJoules(Object handler) + { + if (isHandler(handler)) + { + return energyHandlerCache.get(handler.getClass()).doGetDemandedJoules(handler); + } + + return 0; + } + + public static double getProvidedJoules(Object handler) + { + if (isHandler(handler)) + { + return energyHandlerCache.get(handler.getClass()).doGetProvidedJoules(handler); + } + + return 0; + } + + public static double getEnergyItem(ItemStack itemStack) + { + if (itemStack != null && isHandler(itemStack.getItem())) + { + return energyHandlerCache.get(itemStack.getItem().getClass()).doGetEnergyItem(itemStack); + } + + return 0; + } + + public static double getMaxEnergyItem(ItemStack itemStack) + { + if (itemStack != null && isHandler(itemStack.getItem())) + { + return energyHandlerCache.get(itemStack.getItem().getClass()).doGetMaxEnergyItem(itemStack); + } + + return 0; + } + + public abstract double doReceiveEnergy(Object handler, ForgeDirection direction, double energy, boolean doReceive); + + public abstract double doExtractEnergy(Object handler, ForgeDirection direction, double energy, boolean doExtract); + + /** + * Charges an item with the given energy + * + * @param itemStack - item stack that is the item + * @param joules - input energy + * @param docharge - do the action + * @return amount of energy accepted + */ + public abstract double doChargeItem(ItemStack itemStack, double joules, boolean docharge); + + /** + * discharges an item with the given energy + * + * @param itemStack - item stack that is the item + * @param joules - input energy + * @param docharge - do the action + * @return amount of energy that was removed + */ + public abstract double doDischargeItem(ItemStack itemStack, double joules, boolean doDischarge); + + public abstract boolean doIsHandler(Object obj); + + public abstract boolean doIsEnergyContainer(Object obj); + + public abstract double doGetEnergy(Object obj, ForgeDirection direction); + + public abstract boolean doCanConnect(Object obj, ForgeDirection direction, Object source); + + public abstract ItemStack doGetItemWithCharge(ItemStack itemStack, double energy); + + public abstract double doGetMaxEnergy(Object handler, ForgeDirection direction); + + public abstract double doGetEnergyItem(ItemStack is); + + public abstract double doGetMaxEnergyItem(ItemStack is); + + public abstract double doGetInputVoltage(Object handler); + + public abstract double doGetOutputVoltage(Object handler); + + public abstract boolean doCanReceive(Object handler, ForgeDirection side); + + public abstract boolean doCanExtract(Object handler, ForgeDirection side); + + public abstract double doGetDemandedJoules(Object handler); + + public abstract double doGetProvidedJoules(Object handler); +} diff --git a/src/main/java/universalelectricity/api/CompatibilityType.java b/src/main/java/universalelectricity/api/CompatibilityType.java new file mode 100644 index 0000000..51bdf0a --- /dev/null +++ b/src/main/java/universalelectricity/api/CompatibilityType.java @@ -0,0 +1,82 @@ +package universalelectricity.api; + +import cpw.mods.fml.common.Loader; + +/** + * ORDER OF MAGNITUDE: + * A coal in Universal Electricity (based on an estimate in real life) is worth 4MJ. + * A fission reactor should make around 4-9GW. + * A fusion reactor would go into the tera-watts. + * Reika's conversion: IC2[22512], BC[56280], RF[5628] + * @author Calclavia + */ +public enum CompatibilityType +{ + REDSTONE_FLUX("universalelectricity", "RedstoneFlux", "Redstone Flux", "RF", 2.5), + INDUSTRIALCRAFT("IC2", "IndustrialCraft", "Electrical Unit", "EU", 10); + + public final String modID; + public final String moduleName; + public final String fullUnit; + public final String unit; + + /** + * Multiply UE energy by this ratio to convert it to the forgien ratio. + */ + public double ratio; + + /** + * Multiply the forgien energy by this ratio to convert it into UE energy. + */ + public double reciprocal_ratio; + + /** + * The Universal Electricity Loader will change this value to indicate if the module is + * loaded or not. + */ + public boolean isModuleEnabled; + + /** + * @param modID - The Forge mod ID. + * @param moduleName - The name of the module, used for config and ASM + * @param fullUnit - The unit used + * @param unit - The unit short form used + * @param ratio - How much UE energy equates to the forgien energy? + */ + CompatibilityType(String modID, String moduleName, String fullUnit, String unit, double ratio) + { + this.modID = modID; + this.moduleName = moduleName; + this.fullUnit = fullUnit; + this.unit = unit; + this.ratio = 1.0 / ratio; + this.reciprocal_ratio = ratio; + } + + public boolean isLoaded() + { + return Loader.isModLoaded(this.modID); + } + + public static CompatibilityType get(String moduleName) + { + for (CompatibilityType type : values()) + { + if (moduleName.equals(type.moduleName)) + { + return type; + } + } + + return null; + } + + public double fromJoules(double joules) { + return this.ratio * joules; + } + + public double toJoules(double energy) { + return this.reciprocal_ratio * energy; + } + +} diff --git a/src/main/java/universalelectricity/api/electricity/IElectricalNetwork.java b/src/main/java/universalelectricity/api/electricity/IElectricalNetwork.java new file mode 100644 index 0000000..62a27b5 --- /dev/null +++ b/src/main/java/universalelectricity/api/electricity/IElectricalNetwork.java @@ -0,0 +1,18 @@ +package universalelectricity.api.electricity; + +import net.minecraft.tileentity.TileEntity; +import universalelectricity.api.energy.IEnergyNetwork; +import universalelectricity.core.electricity.ElectricityPack; + +/** + * Extended version of the energy network that properly implements amperage and voltage. + * If you want amps get last buffer and divide it by the voltage + * + * @author DarkGuardsman + */ +public interface IElectricalNetwork extends IEnergyNetwork +{ + /** Gets the current voltage of the network at this point. */ + public double getVoltage(); + +} diff --git a/src/main/java/universalelectricity/api/electricity/IVoltageInput.java b/src/main/java/universalelectricity/api/electricity/IVoltageInput.java new file mode 100644 index 0000000..3cd7cab --- /dev/null +++ b/src/main/java/universalelectricity/api/electricity/IVoltageInput.java @@ -0,0 +1,18 @@ +package universalelectricity.api.electricity; + +import net.minecraftforge.common.util.ForgeDirection; + +/** + * Implement this on your TileEntity if it has a voltage based energy input. You machine will still + * need to run its own voltage checks as this doesn't do anything on its own. + * + * @author DarkGuardsman + */ +public interface IVoltageInput +{ + /** Voltage input on the side mainly used for meters */ + public double getVoltageInput(ForgeDirection direction); + + /** Called when the network voltage doesn't equal the input */ + public void onWrongVoltage(ForgeDirection direction, double voltage); +} diff --git a/src/main/java/universalelectricity/api/electricity/IVoltageOutput.java b/src/main/java/universalelectricity/api/electricity/IVoltageOutput.java new file mode 100644 index 0000000..6f36b76 --- /dev/null +++ b/src/main/java/universalelectricity/api/electricity/IVoltageOutput.java @@ -0,0 +1,20 @@ +package universalelectricity.api.electricity; + +import net.minecraftforge.common.util.ForgeDirection; + +/** + * Applied to electrical machines that are designed to act as sources of power in an electrical + * network. Mainly used to calculate the over all voltage of a network correctly. + * + * @author DarkGuardsman + */ +public interface IVoltageOutput +{ + /** + * Can this machine emit voltage on the given side. + * + * @param side - side that the voltage will be emitted on + * @return the voltage emitted + */ + public double getVoltageOutput(ForgeDirection side); +} diff --git a/src/main/java/universalelectricity/api/energy/EnergyNetworkLoader.java b/src/main/java/universalelectricity/api/energy/EnergyNetworkLoader.java new file mode 100644 index 0000000..ef067d4 --- /dev/null +++ b/src/main/java/universalelectricity/api/energy/EnergyNetworkLoader.java @@ -0,0 +1,69 @@ +package universalelectricity.api.energy; + +import java.util.Arrays; +import java.util.HashSet; +import java.util.Set; + +import cpw.mods.fml.common.FMLLog; + +/** + * A dynamic network loader for injecting energy networks (NOT for other networks such as fuild + * networks). + * Example usage would be that ElectricityNetwork replaces EnergyNetwork. + * + * @author Calclavia + * + */ +public class EnergyNetworkLoader +{ + /** + * The default IElectricityNetwork used for primary energy networks. + */ + public static Class NETWORK_CLASS; + public static final Set> NETWORK_CLASS_REGISTRY = new HashSet>(); + + static + { + setNetworkClass("universalelectricity.core.net.ElectricalNetwork"); + } + + public static void setNetworkClass(Class networkClass) + { + NETWORK_CLASS_REGISTRY.add(networkClass); + NETWORK_CLASS = networkClass; + } + + public static void setNetworkClass(String className) + { + try + { + setNetworkClass((Class) Class.forName(className)); + } + catch (Exception e) + { + FMLLog.severe("Universal Electricity: Failed to set network class with name " + className); + e.printStackTrace(); + } + } + + public static IEnergyNetwork getNewNetwork(IConductor... conductors) + { + try + { + IEnergyNetwork network = NETWORK_CLASS.newInstance(); + network.getConnectors().addAll(Arrays.asList(conductors)); + return network; + } + catch (InstantiationException e) + { + e.printStackTrace(); + } + catch (IllegalAccessException e) + { + e.printStackTrace(); + } + + return null; + } + +} \ No newline at end of file diff --git a/src/main/java/universalelectricity/api/energy/EnergyStorageHandler.java b/src/main/java/universalelectricity/api/energy/EnergyStorageHandler.java new file mode 100644 index 0000000..f2153cd --- /dev/null +++ b/src/main/java/universalelectricity/api/energy/EnergyStorageHandler.java @@ -0,0 +1,268 @@ +package universalelectricity.api.energy; + +import net.minecraft.nbt.NBTBase; +import net.minecraft.nbt.NBTTagCompound; +import net.minecraft.nbt.NBTTagDouble; +import net.minecraft.nbt.NBTTagFloat; +import net.minecraft.nbt.NBTTagInt; +import net.minecraft.nbt.NBTTagLong; + +/** + * Can be used internally for IEnergyInterface blocks. This is optional and should be used for + * ease of use purposes. + * + * @author Calclavia, Based on Thermal Expansion + * + */ +public class EnergyStorageHandler +{ + protected long energy; + protected long capacity; + protected long maxReceive; + protected long maxExtract; + + /** + * A cache of the last energy stored through extract and receive. + */ + protected long lastEnergy; + + public EnergyStorageHandler() + { + this(0); + } + + public EnergyStorageHandler(long capacity) + { + this(capacity, capacity, capacity); + } + + public EnergyStorageHandler(long capacity, long maxTransfer) + { + this(capacity, maxTransfer, maxTransfer); + } + + public EnergyStorageHandler(long capacity, long maxReceive, long maxExtract) + { + this.capacity = capacity; + this.maxReceive = maxReceive; + this.maxExtract = maxExtract; + } + + public EnergyStorageHandler readFromNBT(NBTTagCompound nbt) + { + NBTBase energyTag = nbt.getTag("energy"); + if (energyTag instanceof NBTTagDouble) + { + this.energy = (long) ((NBTTagDouble) energyTag).func_150286_g(); + } + else if (energyTag instanceof NBTTagFloat) + { + this.energy = (long) ((NBTTagFloat) energyTag).func_150288_h(); + } + else if (energyTag instanceof NBTTagInt) + { + this.energy = ((NBTTagInt) energyTag).func_150287_d(); + } + else if (energyTag instanceof NBTTagLong) + { + this.energy = ((NBTTagLong) energyTag).func_150291_c(); + } + return this; + } + + public NBTTagCompound writeToNBT(NBTTagCompound nbt) + { + nbt.setLong("energy", this.getEnergy()); + return nbt; + } + + public void setCapacity(long capacity) + { + this.capacity = capacity; + + if (getEnergy() > capacity) + { + energy = capacity; + } + } + + public void setMaxTransfer(long maxTransfer) + { + setMaxReceive(maxTransfer); + setMaxExtract(maxTransfer); + } + + public void setMaxReceive(long maxReceive) + { + this.maxReceive = maxReceive; + } + + public void setMaxExtract(long maxExtract) + { + this.maxExtract = maxExtract; + } + + public long getMaxReceive() + { + return maxReceive; + } + + public long 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. + * + * @param energy + */ + public void setEnergy(long energy) + { + this.energy = energy; + + if (this.getEnergy() > this.getEnergyCapacity()) + { + this.energy = this.getEnergyCapacity(); + } + else if (this.getEnergy() < 0) + { + this.energy = 0; + } + } + + /** + * 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(long energy) + { + this.setEnergy(this.getEmptySpace() + energy); + + if (this.getEnergy() > this.getEnergyCapacity()) + { + this.setEnergy(this.getEnergyCapacity()); + } + else if (this.getEnergy() < 0) + { + this.setEnergy(0); + } + } + + public long receiveEnergy(long receive, boolean doReceive) + { + long energyReceived = Math.min(this.getEnergyCapacity() - this.getEnergy(), Math.min(this.getMaxReceive(), receive)); + + if (doReceive) + { + this.lastEnergy = this.getEnergy(); + this.setEnergy(this.getEnergy() + energyReceived); + } + return energyReceived; + } + + public long receiveEnergy(boolean doReceive) + { + return this.receiveEnergy(this.getMaxReceive(), doReceive); + } + + public long receiveEnergy() + { + return this.receiveEnergy(true); + } + + public long extractEnergy(long extract, boolean doExtract) + { + long energyExtracted = Math.min(this.getEnergy(), Math.min(this.getMaxExtract(), extract)); + + if (doExtract) + { + this.lastEnergy = this.getEnergy(); + this.setEnergy(this.getEnergy() - energyExtracted); + } + return energyExtracted; + } + + public long extractEnergy(boolean doExtract) + { + return this.extractEnergy(this.getMaxExtract(), doExtract); + } + + public long extractEnergy() + { + return this.extractEnergy(true); + } + + public boolean checkReceive(long receive) + { + return this.receiveEnergy(receive, false) >= receive; + } + + public boolean checkReceive() + { + return this.checkReceive(this.getMaxReceive()); + } + + public boolean checkExtract(long extract) + { + return this.extractEnergy(extract, false) >= extract; + } + + public boolean checkExtract() + { + return this.checkExtract(this.getMaxExtract()); + } + + public boolean isFull() + { + return this.getEnergy() >= this.getEnergyCapacity(); + } + + public boolean isEmpty() + { + return this.getEnergy() == 0; + } + + public long getLastEnergy() + { + return this.lastEnergy; + } + + /** + * @return True if the last energy state and the current one are either in an + * "empty or not empty" change state. + */ + public boolean didEnergyStateChange() + { + return (this.getLastEnergy() == 0 && this.getEnergy() > 0) || (this.getLastEnergy() > 0 && this.getEnergy() == 0); + } + + /** + * Returns the amount of energy this storage can further store. + */ + public long getEmptySpace() + { + return this.getEnergyCapacity() - this.getEnergy(); + } + + public long getEnergy() + { + return this.energy; + } + + public long getEnergyCapacity() + { + return this.capacity; + } + + @Override + public String toString() + { + return this.getClass().getSimpleName() + "[" + this.getEnergy() + "/" + this.getEnergyCapacity() + "]"; + } +} diff --git a/src/main/java/universalelectricity/api/energy/IConductor.java b/src/main/java/universalelectricity/api/energy/IConductor.java new file mode 100644 index 0000000..b9dfafb --- /dev/null +++ b/src/main/java/universalelectricity/api/energy/IConductor.java @@ -0,0 +1,27 @@ +package universalelectricity.api.energy; + +import universalelectricity.api.net.IConnector; + +/** + * A connector for {EnergyNetwork}. + * + * @author Calclavia + */ +public interface IConductor extends IConnector, IEnergyInterface +{ + /** + * Gets the amount of resistance of energy conducting pass this conductor. + * + * @return The amount of loss in Ohms. + */ + public double getResistance(); + + /** + * The maximum amount of current this conductor can buffer (the transfer rate, essentially). You + * can simply do divide your energy transfer rate by UniversalElectricity.DEFAULT_VOLTAGE if + * your conductor is not voltage sensitive. + * + * @return The amount of current in amperes. + */ + public double getCurrentCapacity(); +} diff --git a/src/main/java/universalelectricity/api/energy/IEnergyContainer.java b/src/main/java/universalelectricity/api/energy/IEnergyContainer.java new file mode 100644 index 0000000..ef25a4f --- /dev/null +++ b/src/main/java/universalelectricity/api/energy/IEnergyContainer.java @@ -0,0 +1,28 @@ +package universalelectricity.api.energy; + +import net.minecraftforge.common.util.ForgeDirection; + +/** + * This interface is to be applied to all TileEntities which can store energy. + * + * @author Calclavia + */ +public interface IEnergyContainer +{ + /** + * Sets the amount of energy this unit stored. + * + * This function is NOT recommended for calling. + */ + public void setEnergy(ForgeDirection from, double energy); + + /** + * * @return Get the amount of energy currently stored in the block. + */ + public double getEnergy(ForgeDirection from); + + /** + * @return Get the max amount of energy that can be stored in the block. + */ + public double getEnergyCapacity(ForgeDirection from); +} diff --git a/src/main/java/universalelectricity/api/energy/IEnergyInterface.java b/src/main/java/universalelectricity/api/energy/IEnergyInterface.java new file mode 100644 index 0000000..3755be0 --- /dev/null +++ b/src/main/java/universalelectricity/api/energy/IEnergyInterface.java @@ -0,0 +1,37 @@ +package universalelectricity.api.energy; + +import net.minecraftforge.common.util.ForgeDirection; +import universalelectricity.api.net.IConnectable; + +/** + * Applied to all TileEntities that can interact with energy. + * + * @author Calclavia, Inspired by Thermal Expansion + */ +public interface IEnergyInterface extends IConnectable +{ + /** + * Adds energy to a block. Returns the quantity of energy that was accepted. This should always + * return 0 if the block cannot be externally charged. + * + * @param from Orientation the energy is sent in from. + * @param receive Maximum amount of energy (joules) to be sent into the block. + * @param doReceive If false, the charge will only be simulated. + * @return Amount of energy that was accepted by the block. + */ + public double onReceiveEnergy(ForgeDirection from, double receive, boolean doReceive); + + /** + * Removes energy from a block. Returns the quantity of energy that was extracted. This should + * always return 0 if the block cannot be externally discharged. + * + * @param from Orientation the energy is requested from. This direction MAY be passed as + * "Unknown" if it is wrapped from another energy system that has no clear way to find + * direction. (e.g BuildCraft 4) + * @param energy Maximum amount of energy to be sent into the block. + * @param doExtract If false, the charge will only be simulated. + * @return Amount of energy that was given out by the block. + */ + public double onExtractEnergy(ForgeDirection from, double extract, boolean doExtract); + +} diff --git a/src/main/java/universalelectricity/api/energy/IEnergyNetwork.java b/src/main/java/universalelectricity/api/energy/IEnergyNetwork.java new file mode 100644 index 0000000..2cb3e1b --- /dev/null +++ b/src/main/java/universalelectricity/api/energy/IEnergyNetwork.java @@ -0,0 +1,67 @@ +package universalelectricity.api.energy; + +import net.minecraftforge.common.util.ForgeDirection; +import universalelectricity.api.net.INodeNetwork; +import universalelectricity.api.net.IUpdate; + +/** + * The Energy Network for energy items and blocks. + * + * @author Calclavia + */ +public interface IEnergyNetwork extends INodeNetwork, IUpdate +{ + /** + * Produces power to the energy network. + * + * @param conductor - The conductor that is producing into the energy. + * @param side - The direction the source is producing out towards. + * @param receive - The amount that is produced. + * @return The amount that was accepted by the network. + */ + public double produce(IConductor conductor, ForgeDirection from, double amount, boolean doProduce); + + /** + * @return The current buffer in the network that is going sent to all energy handlers. + */ + public double getBuffer(); + + /** + * @return The last buffer in the network that was sent to all energy handlers. + */ + public double getLastBuffer(); + + /** + * Gets an estimated value of what the network wants for energy + */ + public double getRequest(); + + /** + * Gets a value that represents the amount of energy lost in the network + */ + public double getResistance(); + + /** + * Used by conductors to load their internal buffers to the network. This should be called when + * reading NBT data. + * + * @param conductor + */ + public double getBufferOf(IConductor conductor); + + /** + * Used by conductors to load their internal buffers to the network. This should be called when + * writing NBT data. + * + * @param conductor + */ + public void setBufferFor(IConductor conductor, double buffer); + + /** + * Sets the buffer of the network. + * + * @param newBuffer + */ + public void setBuffer(double newBuffer); + +} diff --git a/src/main/java/universalelectricity/api/energy/UnitDisplay.java b/src/main/java/universalelectricity/api/energy/UnitDisplay.java new file mode 100644 index 0000000..218c39d --- /dev/null +++ b/src/main/java/universalelectricity/api/energy/UnitDisplay.java @@ -0,0 +1,217 @@ +package universalelectricity.api.energy; + +/** + * An easy way to display information on electricity for the client. + * + * @author Calclavia + */ +public class UnitDisplay +{ + /** + * Universal Electricity's units are in KILOJOULES, KILOWATTS and KILOVOLTS. Try to make your + * energy ratio as close to real life as possible. + */ + public static enum Unit + { + AMPERE("Amp", "I"), AMP_HOUR("Amp Hour", "Ah"), VOLTAGE("Volt", "V"), WATT("Watt", "W"), + WATT_HOUR("Watt Hour", "Wh"), RESISTANCE("Ohm", "R"), CONDUCTANCE("Siemen", "S"), + JOULES("Joule", "J"), LITER("Liter", "L"), NEWTON_METER("Newton Meter", "Nm"), + REDFLUX("Redstone-Flux", "Rf"), ELECTRICAL_UNITS("Electrical-Units", "Eu"); + + public String name; + public String symbol; + + private Unit(String name, String symbol) + { + this.name = name; + this.symbol = symbol; + } + + public String getPlural() + { + return this.name + "s"; + } + } + + /** Metric system of measurement. */ + public static enum UnitPrefix + { + MICRO("Micro", "u", 0.000001), MILLI("Milli", "m", 0.001), BASE("", "", 1), + KILO("Kilo", "k", 1000), MEGA("Mega", "M", 1000000), GIGA("Giga", "G", 1000000000), + TERA("Tera", "T", 1000000000000d), PETA("Peta", "P", 1000000000000000d), + EXA("Exa", "E", 1000000000000000000d), ZETTA("Zetta", "Z", 1000000000000000000000d), + YOTTA("Yotta", "Y", 1000000000000000000000000d); + + /** long name for the unit */ + public String name; + /** short unit version of the unit */ + public String symbol; + /** Point by which a number is consider to be of this unit */ + public double value; + + private UnitPrefix(String name, String symbol, double value) + { + this.name = name; + this.symbol = symbol; + this.value = value; + } + + public String getName(boolean getShort) + { + if (getShort) + { + return symbol; + } + else + { + return name; + } + } + + /** Divides the value by the unit value start */ + public double process(double value) + { + return value / this.value; + } + + /** Checks if a value is above the unit value start */ + public boolean isAbove(double value) + { + return value > this.value; + } + + /** Checks if a value is lower than the unit value start */ + public boolean isBellow(double value) + { + return value < this.value; + } + } + + public static String getDisplay(double value, Unit unit, int decimalPlaces, boolean isShort) + { + return getDisplay(value, unit, decimalPlaces, isShort, 1); + } + + /** + * 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, Unit unit, int decimalPlaces, boolean isShort, double multiplier) + { + String unitName = unit.name; + String prefix = ""; + + if (value < 0) + { + value = Math.abs(value); + prefix = "-"; + } + + value *= multiplier; + + if (isShort) + { + unitName = unit.symbol; + } + else if (value > 1) + { + unitName = unit.getPlural(); + } + + if (value == 0) + { + return value + " " + unitName; + } + else + { + for (int i = 0; i < UnitPrefix.values().length; i++) + { + UnitPrefix lowerMeasure = UnitPrefix.values()[i]; + + if (lowerMeasure.isBellow(value) && lowerMeasure.ordinal() == 0) + { + return prefix + roundDecimals(lowerMeasure.process(value), decimalPlaces) + " " + lowerMeasure.getName(isShort) + unitName; + } + if (lowerMeasure.ordinal() + 1 >= UnitPrefix.values().length) + { + return prefix + roundDecimals(lowerMeasure.process(value), decimalPlaces) + " " + lowerMeasure.getName(isShort) + unitName; + } + + UnitPrefix upperMeasure = UnitPrefix.values()[i + 1]; + + if ((lowerMeasure.isAbove(value) && upperMeasure.isBellow(value)) || lowerMeasure.value == value) + { + return prefix + roundDecimals(lowerMeasure.process(value), decimalPlaces) + " " + lowerMeasure.getName(isShort) + unitName; + } + } + } + + return prefix + roundDecimals(value, decimalPlaces) + " " + unitName; + } + + public static String getDisplay(double value, Unit unit) + { + return getDisplay(value, unit, 2, false); + } + + public static String getDisplay(double value, Unit unit, UnitPrefix prefix) + { + return getDisplay(value, unit, 2, false, prefix.value); + } + + public static String getDisplayShort(double value, Unit unit) + { + return getDisplay(value, unit, 2, true); + } + + /** + * Gets a display for the value with a unit that is in the specific prefix. + */ + public static String getDisplayShort(double value, Unit unit, UnitPrefix prefix) + { + return getDisplay(value, unit, 2, true, prefix.value); + } + + public static String getDisplayShort(double value, Unit unit, int decimalPlaces) + { + return getDisplay(value, unit, decimalPlaces, true); + } + + public static String getDisplaySimple(double value, Unit unit, int decimalPlaces) + { + if (value > 1) + { + if (decimalPlaces < 1) + { + return (int) value + " " + unit.getPlural(); + } + + return roundDecimals(value, decimalPlaces) + " " + unit.getPlural(); + } + + if (decimalPlaces < 1) + { + return (int) value + " " + unit.name; + } + + return roundDecimals(value, decimalPlaces) + " " + unit.name; + } + + /** + * Rounds a number to a specific number place places + * + * @param The number + * @return The rounded number + */ + 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) + { + return roundDecimals(d, 2); + } +} diff --git a/src/main/java/universalelectricity/api/item/IEnergyItem.java b/src/main/java/universalelectricity/api/item/IEnergyItem.java new file mode 100644 index 0000000..af6c07b --- /dev/null +++ b/src/main/java/universalelectricity/api/item/IEnergyItem.java @@ -0,0 +1,47 @@ +package universalelectricity.api.item; + +import net.minecraft.item.ItemStack; + +public interface IEnergyItem +{ + /** + * Adds energy to an item. Returns the quantity of energy that was accepted. This should always + * return 0 if the item cannot be externally charged. + * + * @param itemStack ItemStack to be charged. + * @param energy Maximum amount of energy to be sent into the item. + * @param doRecharge If false, the charge will only be simulated. + * @return Amount of energy that was accepted by the item. + */ + public double recharge(ItemStack itemStack, double energy, boolean doRecharge); + + /** + * Removes energy from an item. Returns the quantity of energy that was removed. This should + * always return 0 if the item cannot be externally discharged. + * + * @param itemStack ItemStack to be discharged. + * @param energy Maximum amount of energy to be removed from the item. + * @param doDischarge If false, the discharge will only be simulated. + * @return Amount of energy that was removed from the item. + */ + public double discharge(ItemStack itemStack, double energy, boolean doDischarge); + + /** + * Get the amount of energy currently stored in the item. + */ + public double getEnergy(ItemStack theItem); + + /** + * Get the max amount of energy that can be stored in the item. + */ + public double getEnergyCapacity(ItemStack theItem); + + /** + * Sets the amount of energy in the ItemStack. Use recharge or discharge instead of calling this + * to be safer! + * + * @param itemStack - the ItemStack. + * @param energy - Amount of electrical energy. + */ + public void setEnergy(ItemStack itemStack, double energy); +} diff --git a/src/main/java/universalelectricity/api/item/IVoltageItem.java b/src/main/java/universalelectricity/api/item/IVoltageItem.java new file mode 100644 index 0000000..3fc2994 --- /dev/null +++ b/src/main/java/universalelectricity/api/item/IVoltageItem.java @@ -0,0 +1,15 @@ +package universalelectricity.api.item; + +import net.minecraft.item.ItemStack; + +/** + * @author Calclavia + * + */ +public interface IVoltageItem +{ + /** + * Get the max amount of voltage of this item. + */ + public double getVoltage(ItemStack theItem); +} diff --git a/src/main/java/universalelectricity/api/item/ItemElectric.java b/src/main/java/universalelectricity/api/item/ItemElectric.java new file mode 100644 index 0000000..94cc028 --- /dev/null +++ b/src/main/java/universalelectricity/api/item/ItemElectric.java @@ -0,0 +1,155 @@ +package universalelectricity.api.item; + +import java.util.List; + +import net.minecraft.creativetab.CreativeTabs; +import net.minecraft.entity.player.EntityPlayer; +import net.minecraft.item.Item; +import net.minecraft.item.ItemStack; +import net.minecraft.nbt.NBTBase; +import net.minecraft.nbt.NBTTagCompound; +import net.minecraft.nbt.NBTTagFloat; +import net.minecraft.nbt.NBTTagDouble; +import net.minecraft.world.World; +import universalelectricity.api.CompatibilityModule; +import universalelectricity.core.UniversalElectricity; +import universalelectricity.api.energy.UnitDisplay; +import universalelectricity.api.energy.UnitDisplay.Unit; + +/** Extend from this class if your item requires electricity or to be charged. Optionally, you can + * implement IItemElectric instead. + * + * @author Calclavia */ +public abstract class ItemElectric extends Item implements IEnergyItem, IVoltageItem +{ + private static final String ENERGY_NBT = "electricity"; + + public ItemElectric() + { + super(); + setMaxStackSize(1); + setMaxDamage(100); + setNoRepair(); + } + + @Override + public void addInformation(ItemStack itemStack, EntityPlayer entityPlayer, List list, boolean par4) + { + String color = ""; + double joules = getEnergy(itemStack); + + if (joules <= getEnergyCapacity(itemStack) / 3) + { + color = "\u00a74"; + } + else if (joules > getEnergyCapacity(itemStack) * 2 / 3) + { + color = "\u00a72"; + } + else + { + color = "\u00a76"; + } + + list.add(color + UnitDisplay.getDisplayShort(joules, Unit.JOULES) + "/" + UnitDisplay.getDisplayShort(getEnergyCapacity(itemStack), Unit.JOULES)); + } + + /** Makes sure the item is uncharged when it is crafted and not charged. Change this if you do + * not want this to happen! */ + @Override + public void onCreated(ItemStack itemStack, World par2World, EntityPlayer par3EntityPlayer) + { + setEnergy(itemStack, 0); + } + + @Override + public double recharge(ItemStack itemStack, double energy, boolean doReceive) + { + double energyReceived = Math.min(getEnergyCapacity(itemStack) - getEnergy(itemStack), Math.min(getTransferRate(itemStack), energy)); + + if (doReceive) + { + setEnergy(itemStack, getEnergy(itemStack) + energyReceived); + } + + return energyReceived; + } + + public double getTransferRate(ItemStack itemStack) + { + return getEnergyCapacity(itemStack) / 100; + } + + @Override + public double discharge(ItemStack itemStack, double energy, boolean doTransfer) + { + double energyExtracted = Math.min(getEnergy(itemStack), Math.min(getTransferRate(itemStack), energy)); + + if (doTransfer) + { + setEnergy(itemStack, getEnergy(itemStack) - energyExtracted); + } + + return energyExtracted; + } + + @Override + public double getVoltage(ItemStack itemStack) + { + return 120.0; + } + + @Override + public void setEnergy(ItemStack itemStack, double joules) + { + if (itemStack.getTagCompound() == null) + { + itemStack.setTagCompound(new NBTTagCompound()); + } + + double electricityStored = Math.max(Math.min(joules, getEnergyCapacity(itemStack)), 0); + itemStack.getTagCompound().setDouble(ENERGY_NBT, electricityStored); + itemStack.setItemDamage((int) (100 - ((double) electricityStored / (double) getEnergyCapacity(itemStack)) * 100)); + } + + public double getTransfer(ItemStack itemStack) + { + return getEnergyCapacity(itemStack) - getEnergy(itemStack); + } + + @Override + public double getEnergy(ItemStack itemStack) + { + if (itemStack.getTagCompound() == null) + { + itemStack.setTagCompound(new NBTTagCompound()); + } + + double energyStored = 0; + + if (itemStack.getTagCompound().hasKey(ENERGY_NBT)) + { + // Backwards compatibility + NBTBase obj = itemStack.getTagCompound().getTag(ENERGY_NBT); + + if (obj instanceof NBTTagFloat) + { + energyStored = ((NBTTagFloat) obj).func_150286_g(); + } + else if (obj instanceof NBTTagDouble) + { + energyStored = ((NBTTagDouble) obj).func_150286_g(); + } + } + + itemStack.setItemDamage((int) (100 - ((double) energyStored / (double) getEnergyCapacity(itemStack)) * 100)); + return energyStored; + } + + @Override + public void getSubItems(Item par1, CreativeTabs par2CreativeTabs, List par3List) + { + par3List.add(CompatibilityModule.getItemWithCharge(new ItemStack(this), 0)); + par3List.add(CompatibilityModule.getItemWithCharge(new ItemStack(this), getEnergyCapacity(new ItemStack(this)))); + } +} diff --git a/src/main/java/universalelectricity/api/net/IConnectable.java b/src/main/java/universalelectricity/api/net/IConnectable.java new file mode 100644 index 0000000..fe717fb --- /dev/null +++ b/src/main/java/universalelectricity/api/net/IConnectable.java @@ -0,0 +1,19 @@ +package universalelectricity.api.net; + +import net.minecraftforge.common.util.ForgeDirection; + +/** + * @author Calclavia + * + */ +public interface IConnectable +{ + /** + * Can this object connect with another? + * + * @param from - The direction the connection is coming from. + * @param source - The source calling canConnect onto this object. + * @return Return true, if the connection is possible. + */ + public boolean canConnect(ForgeDirection from, Object source); +} diff --git a/src/main/java/universalelectricity/api/net/IConnector.java b/src/main/java/universalelectricity/api/net/IConnector.java new file mode 100644 index 0000000..ac0a41e --- /dev/null +++ b/src/main/java/universalelectricity/api/net/IConnector.java @@ -0,0 +1,29 @@ +package universalelectricity.api.net; + +import net.minecraft.tileentity.TileEntity; +import net.minecraftforge.common.util.ForgeDirection; + +/** + * Applied to TileEntities that has an instance of an electricity network. + * + * @author Calclavia, tilera + * + */ +public interface IConnector extends INetworkProvider, IConnectable +{ + /** + * Gets an array of all the connected IConnecables that this connector is connected to. This + * should correspond to the ForgeDirection index. + * + * @return An array of length "6". + */ + public TileEntity[] getAdjacentConnections(); + + /** + * Gets this connector instance. Used specially for MultiPart connections. + * + * @return The instance, in most cases, just return "this". + */ + public IConnector getInstance(ForgeDirection dir); + +} diff --git a/src/main/java/universalelectricity/api/net/INetwork.java b/src/main/java/universalelectricity/api/net/INetwork.java new file mode 100644 index 0000000..f360be6 --- /dev/null +++ b/src/main/java/universalelectricity/api/net/INetwork.java @@ -0,0 +1,50 @@ +package universalelectricity.api.net; + +import java.util.Set; + +/** + * A network with connectors only. + */ +public interface INetwork +{ + public void addConnector(C connector); + + public void removeConnector(C connector); + + /** + * Gets the set of conductors that make up this network. + * + * @return conductor set + */ + public Set getConnectors(); + + /** + * Reconstructs the network and all objects within it. + */ + public void reconstruct(); + + /** + * Creates a new network that makes up the current network and the network defined in the + * parameters. Be sure to refresh the new network inside this method. + * + * @param network - network to merge + * @return The new network instance. + */ + public N merge(N network); + + /** + * Splits a network by removing a conductor referenced in the parameter. It will then create and + * refresh the new independent networks possibly created by this operation. + * + * @param connection + */ + public void split(C connection); + + /** + * Splits the network between 2 connectors, separating their networks. + * + * @param connectorA + * @param connectorB + */ + public void split(C connectorA, C connectorB); +} diff --git a/src/main/java/universalelectricity/api/net/INetworkProvider.java b/src/main/java/universalelectricity/api/net/INetworkProvider.java new file mode 100644 index 0000000..003b85b --- /dev/null +++ b/src/main/java/universalelectricity/api/net/INetworkProvider.java @@ -0,0 +1,14 @@ +package universalelectricity.api.net; + +/** + * Applied to TileEntities that has an instance of an electricity network. + * + * @author Calclavia + * + */ +public interface INetworkProvider +{ + public N getNetwork(); + + public void setNetwork(N network); +} diff --git a/src/main/java/universalelectricity/api/net/INodeNetwork.java b/src/main/java/universalelectricity/api/net/INodeNetwork.java new file mode 100644 index 0000000..fbe1b23 --- /dev/null +++ b/src/main/java/universalelectricity/api/net/INodeNetwork.java @@ -0,0 +1,22 @@ +package universalelectricity.api.net; + +import java.util.Set; + +/** + * A network of with connectors and individual nodes. + * + * @author Calclavia + * + * @param - the class/interface Type value in which you implement this + * @param - the class/interface Type which makes up the network's connector set + * @param - the class/interface Type which makes up the network's node set + */ +public interface INodeNetwork extends INetwork +{ + /** + * The nodes in a network are the objects that interact with the connectors. + * + * @return The list of nodes in the network. + */ + public Set getNodes(); +} diff --git a/src/main/java/universalelectricity/api/net/IUpdate.java b/src/main/java/universalelectricity/api/net/IUpdate.java new file mode 100644 index 0000000..243a3c0 --- /dev/null +++ b/src/main/java/universalelectricity/api/net/IUpdate.java @@ -0,0 +1,22 @@ +package universalelectricity.api.net; + +public interface IUpdate +{ + /** + * Updates the network. Called by the {NetworkTickHandler}. + */ + public void update(); + + /** + * Can the network update? + * + * @return True if the network can update, otherwise the network tick handler will remove the + * network from the tick list. + */ + public boolean canUpdate(); + + /** + * @return True to leave the network in the ticker. False to remove the network from the ticker. + */ + public boolean continueUpdate(); +} diff --git a/src/main/java/universalelectricity/api/net/NetworkEvent.java b/src/main/java/universalelectricity/api/net/NetworkEvent.java new file mode 100644 index 0000000..7a4714b --- /dev/null +++ b/src/main/java/universalelectricity/api/net/NetworkEvent.java @@ -0,0 +1,52 @@ +package universalelectricity.api.net; + +import cpw.mods.fml.common.eventhandler.Cancelable; +import cpw.mods.fml.common.eventhandler.Event; +import universalelectricity.api.energy.IEnergyNetwork; + +public class NetworkEvent extends Event +{ + public final IEnergyNetwork network; + + public NetworkEvent(IEnergyNetwork network) + { + this.network = network; + } + + /** + * Call this to have your TileEntity produce power into the network. + * + * @author Calclavia + * + */ + @Cancelable + public static class EnergyProduceEvent extends NetworkEvent + { + private Object source; + private long amount; + private boolean doReceive; + + public EnergyProduceEvent(IEnergyNetwork network, Object source, long amount, boolean doReceive) + { + super(network); + this.source = source; + this.amount = amount; + this.doReceive = doReceive; + } + } + + /** + * These events are fired when something happens in the network. + * + * @author Calclavia + * + */ + @Cancelable + public static class EnergyUpdateEvent extends NetworkEvent + { + public EnergyUpdateEvent(IEnergyNetwork network) + { + super(network); + } + } +} diff --git a/src/main/java/universalelectricity/compat/CompatHandler.java b/src/main/java/universalelectricity/compat/CompatHandler.java new file mode 100644 index 0000000..06d6c53 --- /dev/null +++ b/src/main/java/universalelectricity/compat/CompatHandler.java @@ -0,0 +1,42 @@ +package universalelectricity.compat; + +import java.util.Map; +import java.util.concurrent.ConcurrentHashMap; + +import cpw.mods.fml.common.FMLCommonHandler; +import cpw.mods.fml.common.Loader; +import net.minecraft.tileentity.TileEntity; +import universalelectricity.api.CompatibilityModule; +import universalelectricity.compat.ic2.IC2CompatModule; +import universalelectricity.core.UniversalElectricity; +import universalelectricity.prefab.tile.ElectricTileDriver; + +public class CompatHandler { + + static Map ticklist = new ConcurrentHashMap<>(); + + public static void initCompatHandlers() { + FMLCommonHandler.instance().bus().register(new CompatTickHandler()); + if (Loader.isModLoaded("IC2") && UniversalElectricity.ic2Compat) { + CompatibilityModule.register(new IC2CompatModule()); + } + } + + public static void tick() { + for(TileEntity t : ticklist.keySet()) { + ElectricTileDriver driver = ticklist.get(t); + if (!driver.tick()) { + System.out.println("Remove driver for tile at x:" + t.xCoord + " y:" + t.yCoord + " z:" + t.zCoord); + ticklist.remove(t); + driver.invalidate(); + } + } + } + + public static void registerTile(TileEntity tile) { + if (!ticklist.containsKey(tile) && CompatibilityModule.isHandler(tile)) { + ticklist.put(tile, new ElectricTileDriver(tile)); + } + } + +} diff --git a/src/main/java/universalelectricity/compat/CompatTickHandler.java b/src/main/java/universalelectricity/compat/CompatTickHandler.java new file mode 100644 index 0000000..dc61260 --- /dev/null +++ b/src/main/java/universalelectricity/compat/CompatTickHandler.java @@ -0,0 +1,16 @@ +package universalelectricity.compat; + +import cpw.mods.fml.common.eventhandler.SubscribeEvent; +import cpw.mods.fml.common.gameevent.TickEvent.Phase; +import cpw.mods.fml.common.gameevent.TickEvent.ServerTickEvent; + +public class CompatTickHandler { + + @SubscribeEvent + public void onTick(ServerTickEvent event) { + if (event.phase == Phase.END) { + CompatHandler.tick(); + } + } + +} diff --git a/src/main/java/universalelectricity/compat/ic2/IC2CompatModule.java b/src/main/java/universalelectricity/compat/ic2/IC2CompatModule.java new file mode 100644 index 0000000..8ff1fb2 --- /dev/null +++ b/src/main/java/universalelectricity/compat/ic2/IC2CompatModule.java @@ -0,0 +1,242 @@ +package universalelectricity.compat.ic2; + +import ic2.api.energy.EnergyNet; +import ic2.api.energy.tile.IEnergySink; +import ic2.api.energy.tile.IEnergySource; +import ic2.api.energy.tile.IEnergyTile; +import ic2.api.item.ElectricItem; +import ic2.api.item.IElectricItem; +import ic2.api.tile.IEnergyStorage; +import net.minecraft.item.ItemStack; +import net.minecraft.tileentity.TileEntity; +import net.minecraftforge.common.util.ForgeDirection; +import universalelectricity.api.CompatibilityModule; +import universalelectricity.api.CompatibilityType; + +public class IC2CompatModule extends CompatibilityModule { + + private TileEntity getENetTile(Object handler) { + if (handler instanceof TileEntity) { + TileEntity te = (TileEntity) handler; + if (te instanceof IEnergyTile) { + return te; + } + return EnergyNet.instance.getTileEntity(te.getWorldObj(), te.xCoord, te.yCoord, te.zCoord); + } + return null; + } + + @Override + public double doReceiveEnergy(Object handler, ForgeDirection direction, double energy, boolean doReceive) { + TileEntity tile = getENetTile(handler); + + if (tile instanceof IEnergySink) { + IEnergySink sink = (IEnergySink) tile; + double demand = sink.getDemandedEnergy(); + double toReceive = Math.min(demand, CompatibilityType.INDUSTRIALCRAFT.fromJoules(energy)); + + if (doReceive) { + double leftover = sink.injectEnergy(direction, toReceive, 1); + return CompatibilityType.INDUSTRIALCRAFT.toJoules(Math.max(0, toReceive - leftover)); + } + + return CompatibilityType.INDUSTRIALCRAFT.toJoules(toReceive); + } + return 0; + } + + @Override + public double doExtractEnergy(Object handler, ForgeDirection direction, double energy, boolean doExtract) { + TileEntity tile = getENetTile(handler); + if (tile instanceof IEnergySource) + { + double demand = Math.min(((IEnergySource) tile).getOfferedEnergy(), energy * CompatibilityType.INDUSTRIALCRAFT.ratio); + + if (doExtract) + { + ((IEnergySource) tile).drawEnergy(demand); + } + + return demand * CompatibilityType.INDUSTRIALCRAFT.reciprocal_ratio; + } + + return 0; + } + + @Override + public double doChargeItem(ItemStack itemStack, double joules, boolean docharge) { + if (itemStack.getItem() instanceof IElectricItem) + { + return (ElectricItem.manager.charge(itemStack, joules * CompatibilityType.INDUSTRIALCRAFT.ratio, 4, true, !docharge) * CompatibilityType.INDUSTRIALCRAFT.reciprocal_ratio); + } + return 0; + } + + @Override + public double doDischargeItem(ItemStack itemStack, double joules, boolean doDischarge) { + if (itemStack.getItem() instanceof IElectricItem) + { + IElectricItem item = (IElectricItem) itemStack.getItem(); + + if (item.canProvideEnergy(itemStack)) + { + return (long) (ElectricItem.manager.discharge(itemStack, joules * CompatibilityType.INDUSTRIALCRAFT.ratio, 4, true, false, !doDischarge) * CompatibilityType.INDUSTRIALCRAFT.reciprocal_ratio); + } + } + return 0; + } + + @Override + public boolean doIsHandler(Object obj) { + return getENetTile(obj) != null || obj instanceof IElectricItem; + } + + @Override + public boolean doIsEnergyContainer(Object obj) { + TileEntity tile = getENetTile(obj); + return tile instanceof IEnergyStorage; + } + + @Override + public double doGetEnergy(Object obj, ForgeDirection direction) { + TileEntity tile = getENetTile(obj); + + if (tile instanceof IEnergyStorage) { + return CompatibilityType.INDUSTRIALCRAFT.toJoules(((IEnergyStorage)tile).getStored()); + } + + return 0; + } + + @Override + public boolean doCanConnect(Object obj, ForgeDirection direction, Object source) { + TileEntity tile = getENetTile(obj); + + if (tile instanceof IEnergySink) + { + if (((IEnergySink) tile).acceptsEnergyFrom((TileEntity) source, direction)) + return true; + } + + if (tile instanceof IEnergySource) + { + if (((IEnergySource) tile).emitsEnergyTo((TileEntity) source, direction)) + return true; + } + return false; + } + + @Override + public ItemStack doGetItemWithCharge(ItemStack itemStack, double energy) { + ItemStack is = itemStack.copy(); + + ElectricItem.manager.discharge(is, Integer.MAX_VALUE, 1, true, false, false); + ElectricItem.manager.charge(is, (int) (energy * CompatibilityType.INDUSTRIALCRAFT.ratio), 1, true, false); + + return is; + } + + @Override + public double doGetMaxEnergy(Object handler, ForgeDirection direction) { + TileEntity tile = getENetTile(handler); + + if (tile instanceof IEnergyStorage) { + return CompatibilityType.INDUSTRIALCRAFT.toJoules(((IEnergyStorage)tile).getCapacity()); + } + + return 0; + } + + @Override + public double doGetEnergyItem(ItemStack is) { + return ElectricItem.manager.getCharge(is) * CompatibilityType.INDUSTRIALCRAFT.reciprocal_ratio; + } + + @Override + public double doGetMaxEnergyItem(ItemStack is) { + return ((IElectricItem) is.getItem()).getMaxCharge(is) * CompatibilityType.INDUSTRIALCRAFT.reciprocal_ratio; + } + + @Override + public double doGetInputVoltage(Object handler) { + TileEntity tile = getENetTile(handler); + + if (tile instanceof IEnergySink) { + return tierToVolt(((IEnergySink)tile).getSinkTier()); + } + + return 0; + } + + @Override + public double doGetOutputVoltage(Object handler) { + TileEntity tile = getENetTile(handler); + + if (tile instanceof IEnergySource) { + return tierToVolt(((IEnergySource)tile).getSourceTier()); + } + + return 0; + } + + @Override + public boolean doCanReceive(Object handler, ForgeDirection side) { + TileEntity tile = getENetTile(handler); + if (!(tile instanceof IEnergySink)) return false; + + if (side != ForgeDirection.UNKNOWN) { + return ((IEnergySink)tile).acceptsEnergyFrom(null, side); + } + + return true; + } + + @Override + public boolean doCanExtract(Object handler, ForgeDirection side) { + TileEntity tile = getENetTile(handler); + if (!(tile instanceof IEnergySource)) return false; + + if (side != ForgeDirection.UNKNOWN) { + return ((IEnergySource)tile).emitsEnergyTo(null, side); + } + + return true; + } + + @Override + public double doGetDemandedJoules(Object handler) { + TileEntity tile = getENetTile(handler); + if (tile instanceof IEnergySink) { + IEnergySink sink = (IEnergySink) tile; + return CompatibilityType.INDUSTRIALCRAFT.toJoules(sink.getDemandedEnergy()); + } + return 0; + } + + @Override + public double doGetProvidedJoules(Object handler) { + TileEntity tile = getENetTile(handler); + if (tile instanceof IEnergySource) { + IEnergySource source = (IEnergySource) tile; + return CompatibilityType.INDUSTRIALCRAFT.toJoules(source.getOfferedEnergy()); + } + return 0; + } + + public static int voltToTier(double volt) { + if (volt <= 120.0) return 1; + if (volt <= 240.0) return 2; + if (volt <= 480.0) return 3; + return 4; + } + + public static double tierToVolt(int tier) { + switch (tier) { + case 1: return 120.0; + case 2: return 240.0; + case 3: return 480.0; + default: return 960.0; + } + } + +} diff --git a/src/main/java/universalelectricity/core/Pair.java b/src/main/java/universalelectricity/core/Pair.java new file mode 100644 index 0000000..dfa4832 --- /dev/null +++ b/src/main/java/universalelectricity/core/Pair.java @@ -0,0 +1,34 @@ +package universalelectricity.core; + +public class Pair { + private final L left; + private final R right; + + public Pair(L left, R right) { + this.left = left; + this.right = right; + } + + public L getKey() { + return this.left; + } + + public R getValue() { + return this.right; + } + + public int hashCode() { + return this.left.hashCode() ^ this.right.hashCode(); + } + + public boolean equals(Object o) { + if (o == null) { + return false; + } + if (!(o instanceof Pair)) { + return false; + } + Pair pairo = (Pair)o; + return this.left.equals(pairo.getKey()) && this.right.equals(pairo.getValue()); + } +} diff --git a/src/main/java/universalelectricity/core/UniversalElectricity.java b/src/main/java/universalelectricity/core/UniversalElectricity.java new file mode 100644 index 0000000..0272510 --- /dev/null +++ b/src/main/java/universalelectricity/core/UniversalElectricity.java @@ -0,0 +1,42 @@ +package universalelectricity.core; + +import cpw.mods.fml.common.Loader; +import cpw.mods.fml.common.Mod; +import cpw.mods.fml.common.event.FMLInitializationEvent; +import cpw.mods.fml.common.event.FMLPreInitializationEvent; + +import java.io.File; +import net.minecraft.block.material.MapColor; +import net.minecraft.block.material.Material; +import net.minecraftforge.common.config.Configuration; +import universalelectricity.api.CompatibilityType; +import universalelectricity.compat.CompatHandler; + +@Mod(modid = "universalelectricity", name = "Universal Electricity", version = UniversalElectricity.VERSION) +public class UniversalElectricity { + + public static final String VERSION = "{VERSION}"; + public static final Configuration CONFIGURATION = new Configuration(new File(Loader.instance().getConfigDir(), "UniversalElectricity.cfg")); + public static double UE_IC2_RATIO = CompatibilityType.INDUSTRIALCRAFT.reciprocal_ratio; + public static double UE_RF_RATIO = CompatibilityType.REDSTONE_FLUX.reciprocal_ratio; + public static boolean isVoltageSensitive = true; + public static boolean isNetworkActive = true; + public static boolean ic2Compat = false; + public static final Material machine = new Material(MapColor.ironColor); + + @Mod.EventHandler + public void preInit(FMLPreInitializationEvent e) { + CONFIGURATION.load(); + isVoltageSensitive = CONFIGURATION.get("Compatiblity", "Is Voltage Sensitive", isVoltageSensitive).getBoolean(isVoltageSensitive); + isNetworkActive = CONFIGURATION.get("Compatiblity", "Is Network Active", isNetworkActive).getBoolean(isNetworkActive); + ic2Compat = CONFIGURATION.get("Compatiblity", "Compatiblity with IC2 tiles and items", ic2Compat).getBoolean(ic2Compat); + CONFIGURATION.save(); + } + + @Mod.EventHandler + public void init(FMLInitializationEvent e) { + CompatHandler.initCompatHandlers(); + + } + +} diff --git a/src/main/java/universalelectricity/core/block/IConductor.java b/src/main/java/universalelectricity/core/block/IConductor.java new file mode 100644 index 0000000..f2ba6bf --- /dev/null +++ b/src/main/java/universalelectricity/core/block/IConductor.java @@ -0,0 +1,17 @@ +package universalelectricity.core.block; + +import net.minecraftforge.common.util.ForgeDirection; +import universalelectricity.api.net.IConnector; +import universalelectricity.core.electricity.IElectricityNetwork; + +public interface IConductor extends INetworkProvider, IConnectionProvider, IConnector { + + double getResistance(); + + double getCurrentCapcity(); + + @Override + default IConnector getInstance(ForgeDirection dir) { + return this; + } +} diff --git a/src/main/java/universalelectricity/core/block/IConnectionProvider.java b/src/main/java/universalelectricity/core/block/IConnectionProvider.java new file mode 100644 index 0000000..653d6e6 --- /dev/null +++ b/src/main/java/universalelectricity/core/block/IConnectionProvider.java @@ -0,0 +1,11 @@ +package universalelectricity.core.block; + +import net.minecraft.tileentity.TileEntity; +import universalelectricity.core.block.IConnector; + +public interface IConnectionProvider extends IConnector { + + TileEntity[] getAdjacentConnections(); + + void updateAdjacentConnections(); +} diff --git a/src/main/java/universalelectricity/core/block/IConnector.java b/src/main/java/universalelectricity/core/block/IConnector.java new file mode 100644 index 0000000..5a542c2 --- /dev/null +++ b/src/main/java/universalelectricity/core/block/IConnector.java @@ -0,0 +1,17 @@ +package universalelectricity.core.block; + +import net.minecraftforge.common.util.ForgeDirection; +import universalelectricity.api.net.IConnectable; + +public interface IConnector extends IConnectable, ISelfDriven { + + boolean canConnect(ForgeDirection from); + + @Override + default boolean canConnect(ForgeDirection from, Object source) { + if (source instanceof IConnector) { + return canConnect(from); + } + return false; + } +} diff --git a/src/main/java/universalelectricity/core/block/IElectricityStorage.java b/src/main/java/universalelectricity/core/block/IElectricityStorage.java new file mode 100644 index 0000000..831d243 --- /dev/null +++ b/src/main/java/universalelectricity/core/block/IElectricityStorage.java @@ -0,0 +1,42 @@ +package universalelectricity.core.block; + +import net.minecraftforge.common.util.ForgeDirection; +import universalelectricity.api.energy.IEnergyContainer; + +@Deprecated +public interface IElectricityStorage extends IEnergyContainer { + + double getJoules(); + + void setJoules(double var1); + + double getMaxJoules(); + + @Override + default double getEnergy(ForgeDirection from) { + return getJoules(); + } + + @Override + default void setEnergy(ForgeDirection from, double energy) { + setJoules(energy); + } + + @Override + default double getEnergyCapacity(ForgeDirection from) { + return getMaxEnergy(); + } + + default double getEnergy() { + return getJoules(); + } + + default void setEnergy(double energy) { + setJoules(energy); + } + + default double getMaxEnergy() { + return getMaxJoules(); + } + +} diff --git a/src/main/java/universalelectricity/core/block/INetworkProvider.java b/src/main/java/universalelectricity/core/block/INetworkProvider.java new file mode 100644 index 0000000..1730ac7 --- /dev/null +++ b/src/main/java/universalelectricity/core/block/INetworkProvider.java @@ -0,0 +1,7 @@ +package universalelectricity.core.block; + +import universalelectricity.core.electricity.IElectricityNetwork; + +public interface INetworkProvider extends universalelectricity.api.net.INetworkProvider { + +} diff --git a/src/main/java/universalelectricity/core/block/ISelfDriven.java b/src/main/java/universalelectricity/core/block/ISelfDriven.java new file mode 100644 index 0000000..d71a417 --- /dev/null +++ b/src/main/java/universalelectricity/core/block/ISelfDriven.java @@ -0,0 +1,5 @@ +package universalelectricity.core.block; + +public interface ISelfDriven { + +} diff --git a/src/main/java/universalelectricity/core/block/IVoltage.java b/src/main/java/universalelectricity/core/block/IVoltage.java new file mode 100644 index 0000000..be0c0d2 --- /dev/null +++ b/src/main/java/universalelectricity/core/block/IVoltage.java @@ -0,0 +1,7 @@ +package universalelectricity.core.block; + + +public interface IVoltage { + + double getVoltage(); +} diff --git a/src/main/java/universalelectricity/core/electricity/ElectricityNetwork.java b/src/main/java/universalelectricity/core/electricity/ElectricityNetwork.java new file mode 100644 index 0000000..f11d6c7 --- /dev/null +++ b/src/main/java/universalelectricity/core/electricity/ElectricityNetwork.java @@ -0,0 +1,365 @@ +package universalelectricity.core.electricity; + +import cpw.mods.fml.common.FMLLog; +import java.util.ArrayList; +import java.util.Arrays; +import java.util.HashMap; +import java.util.HashSet; +import java.util.Iterator; +import java.util.List; +import java.util.Set; +import java.util.Map.Entry; +import net.minecraft.tileentity.TileEntity; +import net.minecraftforge.common.util.ForgeDirection; +import universalelectricity.core.block.IConductor; +import universalelectricity.core.block.IConnectionProvider; +import universalelectricity.core.block.INetworkProvider; +import universalelectricity.core.path.PathfinderChecker; +import universalelectricity.core.vector.Vector3; +import universalelectricity.core.vector.VectorHelper; + +public class ElectricityNetwork implements IElectricityNetwork { + + private final HashMap producers = new HashMap<>(); + private final HashMap consumers = new HashMap<>(); + private final Set conductors = new HashSet<>(); + + + public ElectricityNetwork() {} + + public ElectricityNetwork(IConductor ... conductors) { + this.conductors.addAll(Arrays.asList(conductors)); + } + + public void startProducing(TileEntity tileEntity, ElectricityPack electricityPack) { + if(tileEntity != null && electricityPack.getWatts() > 0.0D) { + this.producers.put(tileEntity, electricityPack); + } + + } + + public void startProducing(TileEntity tileEntity, double amperes, double voltage) { + this.startProducing(tileEntity, new ElectricityPack(amperes, voltage)); + } + + public boolean isProducing(TileEntity tileEntity) { + return this.producers.containsKey(tileEntity); + } + + public void stopProducing(TileEntity tileEntity) { + this.producers.remove(tileEntity); + } + + public void startRequesting(TileEntity tileEntity, ElectricityPack electricityPack) { + if(tileEntity != null && electricityPack.getWatts() > 0.0D) { + this.consumers.put(tileEntity, electricityPack); + } + + } + + public void startRequesting(TileEntity tileEntity, double amperes, double voltage) { + this.startRequesting(tileEntity, new ElectricityPack(amperes, voltage)); + } + + public boolean isRequesting(TileEntity tileEntity) { + return this.consumers.containsKey(tileEntity); + } + + public void stopRequesting(TileEntity tileEntity) { + this.consumers.remove(tileEntity); + } + + public ElectricityPack getProduced(TileEntity ... ignoreTiles) { + ElectricityPack totalElectricity = new ElectricityPack(0.0D, 0.0D); + Iterator it = this.producers.entrySet().iterator(); + + label47: + while(it.hasNext()) { + Entry pairs = (Entry)it.next(); + if(pairs != null) { + TileEntity tileEntity = (TileEntity)pairs.getKey(); + if(tileEntity == null) { + it.remove(); + } else if(tileEntity.isInvalid()) { + it.remove(); + } else if(tileEntity.getWorldObj().getTileEntity(tileEntity.xCoord, tileEntity.yCoord, tileEntity.zCoord) != tileEntity) { + it.remove(); + } else { + if(ignoreTiles != null) { + TileEntity[] pack = ignoreTiles; + int newWatts = ignoreTiles.length; + + for(int i$ = 0; i$ < newWatts; ++i$) { + TileEntity newVoltage = pack[i$]; + if(tileEntity == newVoltage) { + continue label47; + } + } + } + + ElectricityPack var11 = (ElectricityPack)pairs.getValue(); + if(pairs.getKey() != null && pairs.getValue() != null && var11 != null) { + double var12 = totalElectricity.getWatts() + var11.getWatts(); + double var13 = Math.max(totalElectricity.voltage, var11.voltage); + totalElectricity.amperes = var12 / var13; + totalElectricity.voltage = var13; + } + } + } + } + + return totalElectricity; + } + + public ElectricityPack getRequest(TileEntity ... ignoreTiles) { + ElectricityPack totalElectricity = this.getRequestWithoutReduction(); + totalElectricity.amperes = Math.max(totalElectricity.amperes - this.getProduced(ignoreTiles).amperes, 0.0D); + return totalElectricity; + } + + public ElectricityPack getRequestWithoutReduction() { + ElectricityPack totalElectricity = new ElectricityPack(0.0D, 0.0D); + Iterator it = this.consumers.entrySet().iterator(); + + while(it.hasNext()) { + Entry pairs = (Entry)it.next(); + if(pairs != null) { + TileEntity tileEntity = (TileEntity)pairs.getKey(); + if(tileEntity == null) { + it.remove(); + } else if(tileEntity.isInvalid()) { + it.remove(); + } else if(tileEntity.getWorldObj().getTileEntity(tileEntity.xCoord, tileEntity.yCoord, tileEntity.zCoord) != tileEntity) { + it.remove(); + } else { + ElectricityPack pack = (ElectricityPack)pairs.getValue(); + if(pack != null) { + totalElectricity.amperes += pack.amperes; + totalElectricity.voltage = Math.max(totalElectricity.voltage, pack.voltage); + } + } + } + } + + return totalElectricity; + } + + public ElectricityPack consumeElectricity(TileEntity tileEntity) { + ElectricityPack totalElectricity = new ElectricityPack(0.0D, 0.0D); + + try { + ElectricityPack e = (ElectricityPack)this.consumers.get(tileEntity); + if(this.consumers.containsKey(tileEntity) && e != null) { + totalElectricity = this.getProduced(new TileEntity[0]); + if(totalElectricity.getWatts() > 0.0D) { + ElectricityPack totalRequest = this.getRequestWithoutReduction(); + totalElectricity.amperes *= e.amperes / totalRequest.amperes; + int distance = this.conductors.size(); + double ampsReceived = totalElectricity.amperes - totalElectricity.amperes * totalElectricity.amperes * this.getTotalResistance() / totalElectricity.voltage; + double voltsReceived = totalElectricity.voltage - totalElectricity.amperes * this.getTotalResistance(); + totalElectricity.amperes = ampsReceived; + totalElectricity.voltage = voltsReceived; + return totalElectricity; + } + } + } catch (Exception var10) { + FMLLog.severe("Failed to consume electricity!", new Object[0]); + var10.printStackTrace(); + } + + return totalElectricity; + } + + public HashMap getProducers() { + return this.producers; + } + + public List getProviders() { + ArrayList providers = new ArrayList<>(); + providers.addAll(this.producers.keySet()); + return providers; + } + + public HashMap getConsumers() { + return this.consumers; + } + + public List getReceivers() { + ArrayList receivers = new ArrayList<>(); + receivers.addAll(this.consumers.keySet()); + return receivers; + } + + public void cleanUpConductors() { + Iterator it = this.conductors.iterator(); + + while(it.hasNext()) { + IConductor conductor = (IConductor)it.next(); + if(conductor == null) { + it.remove(); + } else if(((TileEntity)conductor).isInvalid()) { + it.remove(); + } else { + conductor.setNetwork(this); + } + } + + } + + public void refreshConductors() { + this.cleanUpConductors(); + + try { + Iterator e = this.conductors.iterator(); + + while(e.hasNext()) { + IConductor conductor = (IConductor)e.next(); + conductor.updateAdjacentConnections(); + } + } catch (Exception var3) { + FMLLog.severe("Universal Electricity: Failed to refresh conductor.", new Object[0]); + var3.printStackTrace(); + } + + } + + public double getTotalResistance() { + double resistance = 0.0D; + + IConductor conductor; + for(Iterator i$ = this.conductors.iterator(); i$.hasNext(); resistance += conductor.getResistance()) { + conductor = (IConductor)i$.next(); + } + + return resistance; + } + + public double getLowestCurrentCapacity() { + double lowestAmp = 0.0D; + Iterator i$ = this.conductors.iterator(); + + while(i$.hasNext()) { + IConductor conductor = (IConductor)i$.next(); + if(lowestAmp == 0.0D || conductor.getCurrentCapcity() < lowestAmp) { + lowestAmp = conductor.getCurrentCapcity(); + } + } + + return lowestAmp; + } + + public Set getConductors() { + return this.conductors; + } + + public void mergeConnection(IElectricityNetwork network) { + if(network != null && network != this) { + ElectricityNetwork newNetwork = new ElectricityNetwork(); + newNetwork.getConductors().addAll(this.getConductors()); + newNetwork.getConductors().addAll(network.getConductors()); + newNetwork.cleanUpConductors(); + } + + } + + public void splitNetwork(IConnectionProvider splitPoint) { + if(splitPoint instanceof TileEntity) { + this.getConductors().remove(splitPoint); + ForgeDirection[] connectedBlocks = ForgeDirection.values(); + int i = connectedBlocks.length; + + for(int connectedBlockA = 0; connectedBlockA < i; ++connectedBlockA) { + ForgeDirection ii = connectedBlocks[connectedBlockA]; + if(ii != ForgeDirection.UNKNOWN) { + Vector3 connectedBlockB = new Vector3((TileEntity)splitPoint); + TileEntity finder = VectorHelper.getTileEntityFromSide(((TileEntity)splitPoint).getWorldObj(), connectedBlockB, ii); + if(this.producers.containsKey(finder)) { + this.stopProducing(finder); + this.stopRequesting(finder); + } + } + } + + TileEntity[] var12 = splitPoint.getAdjacentConnections(); + + for(i = 0; i < var12.length; ++i) { + TileEntity var13 = var12[i]; + if(var13 instanceof IConnectionProvider) { + for(int var14 = 0; var14 < var12.length; ++var14) { + TileEntity var15 = var12[var14]; + if(var13 != var15 && var15 instanceof IConnectionProvider) { + PathfinderChecker var16 = new PathfinderChecker(((TileEntity)splitPoint).getWorldObj(), (IConnectionProvider)var15, new IConnectionProvider[]{splitPoint}); + var16.init(new Vector3(var13)); + if(var16.results.size() > 0) { + Iterator newNetwork = var16.closedSet.iterator(); + + while(newNetwork.hasNext()) { + Vector3 i$ = (Vector3)newNetwork.next(); + TileEntity node = i$.getTileEntity(((TileEntity)splitPoint).getWorldObj()); + if(node instanceof INetworkProvider && node != splitPoint) { + ((INetworkProvider)node).setNetwork(this); + } + } + } else { + ElectricityNetwork var17 = new ElectricityNetwork(); + Iterator var18 = var16.closedSet.iterator(); + + while(var18.hasNext()) { + Vector3 var19 = (Vector3)var18.next(); + TileEntity nodeTile = var19.getTileEntity(((TileEntity)splitPoint).getWorldObj()); + if(nodeTile instanceof INetworkProvider && nodeTile != splitPoint) { + var17.getConductors().add((IConductor)nodeTile); + } + } + + var17.cleanUpConductors(); + } + } + } + } + } + } + + } + + public String toString() { + return "ElectricityNetwork[" + this.hashCode() + "|Wires:" + this.conductors.size() + "]"; + } + + @Override + public void addConnector(IConductor connector) { + this.conductors.add(connector); + } + + @Override + public void removeConnector(IConductor connector) { + this.conductors.remove(connector); + } + + @Override + public Set getConnectors() { + return this.conductors; + } + + @Override + public void reconstruct() { + refreshConductors(); + } + + @Override + public IElectricityNetwork merge(IElectricityNetwork network) { + this.mergeConnection(network); + return this; + } + + @Override + public void split(IConductor connection) { + splitNetwork(connection); + } + + @Override + public void split(IConductor connectorA, IConductor connectorB) { + // TODO: implement this + } + +} diff --git a/src/main/java/universalelectricity/core/electricity/ElectricityNetworkHelper.java b/src/main/java/universalelectricity/core/electricity/ElectricityNetworkHelper.java new file mode 100644 index 0000000..b1ac5be --- /dev/null +++ b/src/main/java/universalelectricity/core/electricity/ElectricityNetworkHelper.java @@ -0,0 +1,151 @@ +package universalelectricity.core.electricity; + +import java.util.ArrayList; +import java.util.EnumSet; +import java.util.Iterator; +import java.util.List; + +import net.minecraft.tileentity.TileEntity; +import net.minecraftforge.common.util.ForgeDirection; +import universalelectricity.api.CompatibilityModule; +import universalelectricity.core.block.IConnector; +import universalelectricity.core.block.INetworkProvider; +import universalelectricity.core.vector.Vector3; +import universalelectricity.core.vector.VectorHelper; + +public class ElectricityNetworkHelper { + + public static void invalidate(TileEntity tileEntity) { + for(int i = 0; i < 6; ++i) { + ForgeDirection direction = ForgeDirection.getOrientation(i); + TileEntity checkTile = VectorHelper.getConnectorFromSide(tileEntity.getWorldObj(), new Vector3(tileEntity), direction); + if(checkTile instanceof INetworkProvider) { + IElectricityNetwork network = ((INetworkProvider)checkTile).getNetwork(); + if(network != null) { + network.stopRequesting(tileEntity); + network.stopProducing(tileEntity); + } + } + } + + } + + public static EnumSet getDirections(TileEntity tileEntity) { + EnumSet possibleSides = EnumSet.noneOf(ForgeDirection.class); + if(tileEntity instanceof IConnector) { + for(int i = 0; i < 6; ++i) { + ForgeDirection direction = ForgeDirection.getOrientation(i); + if(((IConnector)tileEntity).canConnect(direction)) { + possibleSides.add(direction); + } + } + } + + return possibleSides; + } + + public static ElectricityPack produceFromMultipleSides(TileEntity tileEntity, ElectricityPack electricityPack) { + return produceFromMultipleSides(tileEntity, getDirections(tileEntity), electricityPack); + } + + public static ElectricityPack produceFromMultipleSides(TileEntity tileEntity, EnumSet approachingDirection, ElectricityPack producingPack) { + ElectricityPack remainingElectricity = producingPack.clone(); + if(tileEntity != null && approachingDirection != null) { + List connectedNetworks = getNetworksFromMultipleSides(tileEntity, approachingDirection); + if(connectedNetworks.size() > 0) { + double wattsPerSide = producingPack.getWatts() / (double)connectedNetworks.size(); + double voltage = producingPack.voltage; + Iterator i$ = connectedNetworks.iterator(); + + while(i$.hasNext()) { + IElectricityNetwork network = (IElectricityNetwork)i$.next(); + if(wattsPerSide > 0.0D && producingPack.getWatts() > 0.0D) { + double amperes = Math.min(wattsPerSide / voltage, network.getRequest(new TileEntity[]{tileEntity}).amperes); + if(amperes > 0.0D) { + network.startProducing(tileEntity, amperes, voltage); + remainingElectricity.amperes -= amperes; + } + } else { + network.stopProducing(tileEntity); + } + } + } + } + + return remainingElectricity; + } + + public static ElectricityPack consumeFromMultipleSides(TileEntity tileEntity, ElectricityPack electricityPack) { + return consumeFromMultipleSides(tileEntity, getDirections(tileEntity), electricityPack); + } + + public static ElectricityPack consumeFromMultipleSides(TileEntity tileEntity, EnumSet approachingDirection, ElectricityPack requestPack) { + ElectricityPack consumedPack = new ElectricityPack(); + if(tileEntity != null && approachingDirection != null) { + List connectedNetworks = getNetworksFromMultipleSides(tileEntity, approachingDirection); + if(connectedNetworks.size() > 0) { + double wattsPerSide = requestPack.getWatts() / (double)connectedNetworks.size(); + double voltage = requestPack.voltage; + Iterator i$ = connectedNetworks.iterator(); + + while(i$.hasNext()) { + IElectricityNetwork network = (IElectricityNetwork)i$.next(); + if(wattsPerSide > 0.0D && requestPack.getWatts() > 0.0D) { + network.startRequesting(tileEntity, wattsPerSide / voltage, voltage); + ElectricityPack receivedPack = network.consumeElectricity(tileEntity); + consumedPack.amperes += receivedPack.amperes; + consumedPack.voltage = Math.max(consumedPack.voltage, receivedPack.voltage); + } else { + network.stopRequesting(tileEntity); + } + } + } + } + + return consumedPack; + } + + public static List getNetworksFromMultipleSides(TileEntity tileEntity, EnumSet approachingDirection) { + ArrayList connectedNetworks = new ArrayList(); + + for(int i = 0; i < 6; ++i) { + ForgeDirection direction = ForgeDirection.getOrientation(i); + if(approachingDirection.contains(direction)) { + Vector3 position = new Vector3(tileEntity); + position.modifyPositionFromSide(direction); + TileEntity outputConductor = position.getTileEntity(tileEntity.getWorldObj()); + IElectricityNetwork electricityNetwork = getNetworkFromTileEntity(outputConductor, direction); + if(electricityNetwork != null && !connectedNetworks.contains(electricityNetwork)) { + connectedNetworks.add(electricityNetwork); + } + } + } + + return connectedNetworks; + } + + public static IElectricityNetwork getNetworkFromTileEntity(TileEntity tileEntity, ForgeDirection approachDirection) { + if(tileEntity != null && tileEntity instanceof INetworkProvider) { + if(!(tileEntity instanceof IConnector)) { + return ((INetworkProvider)tileEntity).getNetwork(); + } + + if(((IConnector)tileEntity).canConnect(approachDirection.getOpposite())) { + return ((INetworkProvider)tileEntity).getNetwork(); + } + } + + return null; + } + + public static boolean canConnect(TileEntity tileEntity, ForgeDirection side, TileEntity source) { + if (tileEntity == null) { + return false; + } else if (tileEntity instanceof IConnector) { + return ((IConnector)tileEntity).canConnect(side, source); + } else { + return CompatibilityModule.canConnect(tileEntity, side, source); + } + } + +} diff --git a/src/main/java/universalelectricity/core/electricity/ElectricityPack.java b/src/main/java/universalelectricity/core/electricity/ElectricityPack.java new file mode 100644 index 0000000..1560db0 --- /dev/null +++ b/src/main/java/universalelectricity/core/electricity/ElectricityPack.java @@ -0,0 +1,102 @@ +package universalelectricity.core.electricity; + + +public class ElectricityPack implements Cloneable { + + public double amperes; + public double voltage; + + + public ElectricityPack(double amperes, double voltage) { + this.amperes = amperes; + this.voltage = voltage; + } + + public ElectricityPack() { + this(0.0D, 0.0D); + } + + public static ElectricityPack getFromWatts(double watts, double voltage) { + return new ElectricityPack(watts / voltage, voltage); + } + + public double getWatts() { + return getWatts(this.amperes, this.voltage); + } + + public double getConductance() { + return getConductance(this.amperes, this.voltage); + } + + public double getResistance() { + return getResistance(this.amperes, this.voltage); + } + + public static double getJoules(double watts, double seconds) { + return watts * seconds; + } + + public static double getJoules(double amps, double voltage, double seconds) { + return amps * voltage * seconds; + } + + public static double getWattsFromJoules(double joules, double seconds) { + return joules / seconds; + } + + public static double getAmps(double watts, double voltage) { + return watts / voltage; + } + + public static double getAmps(double ampHours) { + return ampHours * 3600.0D; + } + + public static double getAmpsFromWattHours(double wattHours, double voltage) { + return getWatts(wattHours) / voltage; + } + + public static double getWattHoursFromAmpHours(double ampHours, double voltage) { + return ampHours * voltage; + } + + public static double getAmpHours(double amps) { + return amps / 3600.0D; + } + + public static double getWatts(double amps, double voltage) { + return amps * voltage; + } + + public static double getWatts(double wattHours) { + return wattHours * 3600.0D; + } + + public static double getWattHours(double watts) { + return watts / 3600.0D; + } + + public static double getWattHours(double amps, double voltage) { + return getWattHours(getWatts(amps, voltage)); + } + + public static double getResistance(double amps, double voltage) { + return voltage / amps; + } + + public static double getConductance(double amps, double voltage) { + return amps / voltage; + } + + public String toString() { + return "ElectricityPack [Amps:" + this.amperes + " Volts:" + this.voltage + "]"; + } + + public ElectricityPack clone() { + return new ElectricityPack(this.amperes, this.voltage); + } + + public boolean isEqual(ElectricityPack electricityPack) { + return this.amperes == electricityPack.amperes && this.voltage == electricityPack.voltage; + } +} diff --git a/src/main/java/universalelectricity/core/electricity/IConductorRegistry.java b/src/main/java/universalelectricity/core/electricity/IConductorRegistry.java new file mode 100644 index 0000000..79aa9db --- /dev/null +++ b/src/main/java/universalelectricity/core/electricity/IConductorRegistry.java @@ -0,0 +1,15 @@ +package universalelectricity.core.electricity; + +import java.util.List; +import universalelectricity.core.block.IConductor; + +public interface IConductorRegistry { + + void register(IConductor var1); + + void cleanConductors(); + + void resetAllConnections(); + + List getConductors(); +} diff --git a/src/main/java/universalelectricity/core/electricity/IElectricityNetwork.java b/src/main/java/universalelectricity/core/electricity/IElectricityNetwork.java new file mode 100644 index 0000000..7d84b5e --- /dev/null +++ b/src/main/java/universalelectricity/core/electricity/IElectricityNetwork.java @@ -0,0 +1,59 @@ +package universalelectricity.core.electricity; + +import java.util.HashMap; +import java.util.List; +import java.util.Set; +import net.minecraft.tileentity.TileEntity; +import universalelectricity.api.net.INetwork; +import universalelectricity.core.block.IConductor; +import universalelectricity.core.block.IConnectionProvider; + +public interface IElectricityNetwork extends INetwork { + + void startProducing(TileEntity var1, ElectricityPack var2); + + void startProducing(TileEntity var1, double var2, double var4); + + boolean isProducing(TileEntity var1); + + void stopProducing(TileEntity var1); + + void startRequesting(TileEntity var1, ElectricityPack var2); + + void startRequesting(TileEntity var1, double var2, double var4); + + boolean isRequesting(TileEntity var1); + + void stopRequesting(TileEntity var1); + + ElectricityPack getProduced(TileEntity ... var1); + + ElectricityPack getRequest(TileEntity ... var1); + + ElectricityPack getRequestWithoutReduction(); + + ElectricityPack consumeElectricity(TileEntity var1); + + HashMap getProducers(); + + List getProviders(); + + HashMap getConsumers(); + + List getReceivers(); + + Set getConductors(); + + double getTotalResistance(); + + double getLowestCurrentCapacity(); + + void cleanUpConductors(); + + void refreshConductors(); + + void mergeConnection(IElectricityNetwork var1); + + void splitNetwork(IConnectionProvider var1); + +} diff --git a/src/main/java/universalelectricity/core/item/ElectricItemHelper.java b/src/main/java/universalelectricity/core/item/ElectricItemHelper.java new file mode 100644 index 0000000..8284c4d --- /dev/null +++ b/src/main/java/universalelectricity/core/item/ElectricItemHelper.java @@ -0,0 +1,67 @@ +package universalelectricity.core.item; + +import net.minecraft.item.Item; +import net.minecraft.item.ItemStack; +import universalelectricity.api.CompatibilityModule; +import universalelectricity.core.electricity.ElectricityPack; +import universalelectricity.core.item.IItemElectric; + +public class ElectricItemHelper { + + public static double chargeItem(ItemStack itemStack, double joules, double voltage) { + if(itemStack != null && itemStack.getItem() instanceof IItemElectric) { + IItemElectric electricItem = (IItemElectric)itemStack.getItem(); + double providingWatts = Math.min(joules, electricItem.getReceiveRequest(itemStack).getWatts()); + if(providingWatts > 0.0D) { + ElectricityPack providedElectricity = electricItem.onReceive(ElectricityPack.getFromWatts(providingWatts, voltage), itemStack); + return providedElectricity.getWatts(); + } + } else if (itemStack != null && CompatibilityModule.isHandler(itemStack.getItem())) { + return CompatibilityModule.chargeItem(itemStack, joules, true); + } + + return 0.0D; + } + + public static double dechargeItem(ItemStack itemStack, double joules, double voltage) { + if(itemStack != null && itemStack.getItem() instanceof IItemElectric) { + IItemElectric electricItem = (IItemElectric)itemStack.getItem(); + double requestingWatts = Math.min(joules, electricItem.getProvideRequest(itemStack).getWatts()); + if(requestingWatts > 0.0D) { + ElectricityPack receivedElectricity = electricItem.onProvide(ElectricityPack.getFromWatts(requestingWatts, voltage), itemStack); + return receivedElectricity.getWatts(); + } + } else if (itemStack != null && CompatibilityModule.isHandler(itemStack.getItem())) { + return CompatibilityModule.dischargeItem(itemStack, joules, true); + } + + return 0.0D; + } + + public static ItemStack getWithCharge(ItemStack itemStack, double joules) { + if(itemStack != null && itemStack.getItem() instanceof IItemElectric) { + ((IItemElectric)itemStack.getItem()).setJoules(joules, itemStack); + return itemStack; + } else if (itemStack != null && CompatibilityModule.isHandler(itemStack.getItem())) { + return CompatibilityModule.getItemWithCharge(itemStack, joules); + } else { + return itemStack; + } + } + + public static ItemStack getWithCharge(Item item, double joules) { + return getWithCharge(new ItemStack(item), joules); + } + + public static ItemStack getCloneWithCharge(ItemStack itemStack, double joules) { + return getWithCharge(itemStack.copy(), joules); + } + + public static ItemStack getUncharged(ItemStack itemStack) { + return getWithCharge(itemStack, 0.0D); + } + + public static ItemStack getUncharged(Item item) { + return getUncharged(new ItemStack(item)); + } +} diff --git a/src/main/java/universalelectricity/core/item/IItemElectric.java b/src/main/java/universalelectricity/core/item/IItemElectric.java new file mode 100644 index 0000000..17eb647 --- /dev/null +++ b/src/main/java/universalelectricity/core/item/IItemElectric.java @@ -0,0 +1,17 @@ +package universalelectricity.core.item; + +import net.minecraft.item.ItemStack; +import universalelectricity.core.electricity.ElectricityPack; +import universalelectricity.core.item.IItemElectricityStorage; +import universalelectricity.core.item.IItemVoltage; + +public interface IItemElectric extends IItemElectricityStorage, IItemVoltage { + + ElectricityPack onReceive(ElectricityPack var1, ItemStack var2); + + ElectricityPack onProvide(ElectricityPack var1, ItemStack var2); + + ElectricityPack getReceiveRequest(ItemStack var1); + + ElectricityPack getProvideRequest(ItemStack var1); +} diff --git a/src/main/java/universalelectricity/core/item/IItemElectricityStorage.java b/src/main/java/universalelectricity/core/item/IItemElectricityStorage.java new file mode 100644 index 0000000..5a88ab4 --- /dev/null +++ b/src/main/java/universalelectricity/core/item/IItemElectricityStorage.java @@ -0,0 +1,12 @@ +package universalelectricity.core.item; + +import net.minecraft.item.ItemStack; + +public interface IItemElectricityStorage { + + double getJoules(ItemStack var1); + + void setJoules(double var1, ItemStack var3); + + double getMaxJoules(ItemStack var1); +} diff --git a/src/main/java/universalelectricity/core/item/IItemVoltage.java b/src/main/java/universalelectricity/core/item/IItemVoltage.java new file mode 100644 index 0000000..cd15b82 --- /dev/null +++ b/src/main/java/universalelectricity/core/item/IItemVoltage.java @@ -0,0 +1,7 @@ +package universalelectricity.core.item; + +import universalelectricity.api.item.IVoltageItem; + +public interface IItemVoltage extends IVoltageItem { + +} diff --git a/src/main/java/universalelectricity/core/item/ItemElectric.java b/src/main/java/universalelectricity/core/item/ItemElectric.java new file mode 100644 index 0000000..ebab4bd --- /dev/null +++ b/src/main/java/universalelectricity/core/item/ItemElectric.java @@ -0,0 +1,93 @@ +package universalelectricity.core.item; + +import java.util.List; +import net.minecraft.creativetab.CreativeTabs; +import net.minecraft.entity.player.EntityPlayer; +import net.minecraft.item.Item; +import net.minecraft.item.ItemStack; +import net.minecraft.nbt.NBTTagCompound; +import net.minecraft.world.World; +import universalelectricity.api.energy.UnitDisplay; +import universalelectricity.core.electricity.ElectricityPack; +import universalelectricity.core.item.ElectricItemHelper; +import universalelectricity.core.item.IItemElectric; + +public abstract class ItemElectric extends Item implements IItemElectric { + + public ItemElectric() { + super(); + this.setMaxStackSize(1); + this.setMaxDamage(100); + this.setNoRepair(); + } + + public void addInformation(ItemStack itemStack, EntityPlayer entityPlayer, List list, boolean par4) { + String color = ""; + double joules = this.getJoules(itemStack); + if(joules <= this.getMaxJoules(itemStack) / 3.0D) { + color = "§4"; + } else if(joules > this.getMaxJoules(itemStack) * 2.0D / 3.0D) { + color = "§2"; + } else { + color = "§6"; + } + + list.add(color + UnitDisplay.getDisplay(joules, UnitDisplay.Unit.JOULES) + "/" + UnitDisplay.getDisplay(this.getMaxJoules(itemStack), UnitDisplay.Unit.JOULES)); + } + + public void onCreated(ItemStack itemStack, World par2World, EntityPlayer par3EntityPlayer) { + this.setJoules(0.0D, itemStack); + } + + public ElectricityPack onReceive(ElectricityPack electricityPack, ItemStack itemStack) { + double rejectedElectricity = Math.max(this.getJoules(itemStack) + electricityPack.getWatts() - this.getMaxJoules(itemStack), 0.0D); + double joulesToStore = electricityPack.getWatts() - rejectedElectricity; + this.setJoules(this.getJoules(itemStack) + joulesToStore, itemStack); + return ElectricityPack.getFromWatts(joulesToStore, this.getVoltage(itemStack)); + } + + public ElectricityPack onProvide(ElectricityPack electricityPack, ItemStack itemStack) { + double electricityToUse = Math.min(this.getJoules(itemStack), electricityPack.getWatts()); + this.setJoules(this.getJoules(itemStack) - electricityToUse, itemStack); + return ElectricityPack.getFromWatts(electricityToUse, this.getVoltage(itemStack)); + } + + public ElectricityPack getReceiveRequest(ItemStack itemStack) { + return ElectricityPack.getFromWatts(Math.min(this.getMaxJoules(itemStack) - this.getJoules(itemStack), this.getTransferRate(itemStack)), this.getVoltage(itemStack)); + } + + public ElectricityPack getProvideRequest(ItemStack itemStack) { + return ElectricityPack.getFromWatts(Math.min(this.getJoules(itemStack), this.getTransferRate(itemStack)), this.getVoltage(itemStack)); + } + + public double getTransferRate(ItemStack itemStack) { + return this.getMaxJoules(itemStack) * 0.01D; + } + + public void setJoules(double joules, ItemStack itemStack) { + if(itemStack.getTagCompound() == null) { + itemStack.setTagCompound(new NBTTagCompound()); + } + + double electricityStored = Math.max(Math.min(joules, this.getMaxJoules(itemStack)), 0.0D); + itemStack.getTagCompound().setDouble("electricity", electricityStored); + itemStack.setItemDamage((int)(100.0D - electricityStored / this.getMaxJoules(itemStack) * 100.0D)); + } + + public double getJoules(ItemStack itemStack) { + if(itemStack.getTagCompound() == null) { + return 0.0D; + } else { + double electricityStored = itemStack.getTagCompound().getDouble("electricity"); + itemStack.setItemDamage((int)(100.0D - electricityStored / this.getMaxJoules(itemStack) * 100.0D)); + return electricityStored; + } + } + + @Override + public void getSubItems(Item par1, CreativeTabs par2CreativeTabs, List par3List) { + par3List.add(ElectricItemHelper.getUncharged(new ItemStack(this))); + ItemStack chargedItem = new ItemStack(this); + par3List.add(ElectricItemHelper.getWithCharge(chargedItem, this.getMaxJoules(chargedItem))); + } +} diff --git a/src/main/java/universalelectricity/core/path/IPathCallBack.java b/src/main/java/universalelectricity/core/path/IPathCallBack.java new file mode 100644 index 0000000..fc20f3b --- /dev/null +++ b/src/main/java/universalelectricity/core/path/IPathCallBack.java @@ -0,0 +1,12 @@ +package universalelectricity.core.path; + +import java.util.Set; +import universalelectricity.core.path.Pathfinder; +import universalelectricity.core.vector.Vector3; + +public interface IPathCallBack { + + Set getConnectedNodes(Pathfinder var1, Vector3 var2); + + boolean onSearch(Pathfinder var1, Vector3 var2); +} diff --git a/src/main/java/universalelectricity/core/path/Pathfinder.java b/src/main/java/universalelectricity/core/path/Pathfinder.java new file mode 100644 index 0000000..e137fde --- /dev/null +++ b/src/main/java/universalelectricity/core/path/Pathfinder.java @@ -0,0 +1,51 @@ +package universalelectricity.core.path; + +import java.util.HashSet; +import java.util.Iterator; +import java.util.Set; +import universalelectricity.core.path.IPathCallBack; +import universalelectricity.core.vector.Vector3; + +public class Pathfinder { + + public IPathCallBack callBackCheck; + public Set closedSet; + public Set results; + + + public Pathfinder(IPathCallBack callBack) { + this.callBackCheck = callBack; + this.reset(); + } + + public boolean findNodes(Vector3 currentNode) { + this.closedSet.add(currentNode); + if(this.callBackCheck.onSearch(this, currentNode)) { + return false; + } else { + Iterator i$ = this.callBackCheck.getConnectedNodes(this, currentNode).iterator(); + + Vector3 node; + do { + if(!i$.hasNext()) { + return false; + } + + node = (Vector3)i$.next(); + } while(this.closedSet.contains(node) || !this.findNodes(node)); + + return true; + } + } + + public Pathfinder init(Vector3 startNode) { + this.findNodes(startNode); + return this; + } + + public Pathfinder reset() { + this.closedSet = new HashSet(); + this.results = new HashSet(); + return this; + } +} diff --git a/src/main/java/universalelectricity/core/path/PathfinderAStar.java b/src/main/java/universalelectricity/core/path/PathfinderAStar.java new file mode 100644 index 0000000..51eae44 --- /dev/null +++ b/src/main/java/universalelectricity/core/path/PathfinderAStar.java @@ -0,0 +1,112 @@ +package universalelectricity.core.path; + +import java.util.HashMap; +import java.util.HashSet; +import java.util.Iterator; +import java.util.Set; +import net.minecraftforge.common.util.ForgeDirection; +import universalelectricity.core.path.IPathCallBack; +import universalelectricity.core.path.Pathfinder; +import universalelectricity.core.vector.Vector3; + +public class PathfinderAStar extends Pathfinder { + + public IPathCallBack callBackCheck; + public Set openSet; + public HashMap navigationMap; + public HashMap gScore; + public HashMap fScore; + public Vector3 goal; + + + public PathfinderAStar(IPathCallBack callBack, Vector3 goal) { + super(callBack); + this.goal = goal; + } + + public boolean findNodes(Vector3 start) { + this.openSet.add(start); + this.gScore.put(start, Double.valueOf(0.0D)); + this.fScore.put(start, Double.valueOf(((Double)this.gScore.get(start)).doubleValue() + this.getHeuristicEstimatedCost(start, this.goal))); + + while(!this.openSet.isEmpty()) { + Vector3 currentNode = null; + double lowestFScore = 0.0D; + Iterator i$ = this.openSet.iterator(); + + Vector3 neighbor; + while(i$.hasNext()) { + neighbor = (Vector3)i$.next(); + if(currentNode == null || ((Double)this.fScore.get(neighbor)).doubleValue() < lowestFScore) { + currentNode = neighbor; + lowestFScore = ((Double)this.fScore.get(neighbor)).doubleValue(); + } + } + + if(currentNode == null) { + break; + } + + if(this.callBackCheck.onSearch(this, currentNode)) { + return false; + } + + if(currentNode.equals(this.goal)) { + super.results = this.reconstructPath(this.navigationMap, this.goal); + return true; + } + + this.openSet.remove(currentNode); + super.closedSet.add(currentNode); + i$ = this.getNeighborNodes(currentNode).iterator(); + + while(i$.hasNext()) { + neighbor = (Vector3)i$.next(); + double tentativeGScore = ((Double)this.gScore.get(currentNode)).doubleValue() + currentNode.distanceTo(neighbor); + if((!super.closedSet.contains(neighbor) || tentativeGScore < ((Double)this.gScore.get(neighbor)).doubleValue()) && (!this.openSet.contains(neighbor) || tentativeGScore < ((Double)this.gScore.get(neighbor)).doubleValue())) { + this.navigationMap.put(neighbor, currentNode); + this.gScore.put(neighbor, Double.valueOf(tentativeGScore)); + this.fScore.put(neighbor, Double.valueOf(((Double)this.gScore.get(neighbor)).doubleValue() + this.getHeuristicEstimatedCost(neighbor, this.goal))); + this.openSet.add(neighbor); + } + } + } + + return false; + } + + public Pathfinder reset() { + this.openSet = new HashSet(); + this.navigationMap = new HashMap(); + return super.reset(); + } + + public Set reconstructPath(HashMap nagivationMap, Vector3 current_node) { + HashSet path = new HashSet(); + path.add(current_node); + if(nagivationMap.containsKey(current_node)) { + path.addAll(this.reconstructPath(nagivationMap, (Vector3)nagivationMap.get(current_node))); + return path; + } else { + return path; + } + } + + public double getHeuristicEstimatedCost(Vector3 start, Vector3 goal) { + return start.distanceTo(goal); + } + + public Set getNeighborNodes(Vector3 vector) { + if(this.callBackCheck != null) { + return this.callBackCheck.getConnectedNodes(this, vector); + } else { + HashSet neighbors = new HashSet(); + + for(int i = 0; i < 6; ++i) { + neighbors.add(vector.clone().modifyPositionFromSide(ForgeDirection.getOrientation(i))); + } + + return neighbors; + } + } +} diff --git a/src/main/java/universalelectricity/core/path/PathfinderChecker.java b/src/main/java/universalelectricity/core/path/PathfinderChecker.java new file mode 100644 index 0000000..fdf8d9b --- /dev/null +++ b/src/main/java/universalelectricity/core/path/PathfinderChecker.java @@ -0,0 +1,71 @@ +package universalelectricity.core.path; + +import java.util.Arrays; +import java.util.HashSet; +import java.util.Set; +import net.minecraft.tileentity.TileEntity; +import net.minecraft.world.World; +import net.minecraftforge.common.util.ForgeDirection; +import universalelectricity.api.net.IConnector; +import universalelectricity.core.block.IConductor; +import universalelectricity.core.block.IConnectionProvider; +import universalelectricity.core.path.IPathCallBack; +import universalelectricity.core.path.Pathfinder; +import universalelectricity.core.vector.Vector3; + +public class PathfinderChecker extends Pathfinder { + + public PathfinderChecker(final World world, final IConnectionProvider targetConnector, final IConnectionProvider ... ignoreConnector) { + super(new IPathCallBack() { + public Set getConnectedNodes(Pathfinder finder, Vector3 currentNode) { + HashSet neighbors = new HashSet(); + + for(int i = 0; i < 6; ++i) { + ForgeDirection direction = ForgeDirection.getOrientation(i); + Vector3 position = currentNode.clone().modifyPositionFromSide(direction); + TileEntity connectedBlock = position.getTileEntity(world); + if(connectedBlock instanceof IConductor && !Arrays.asList(ignoreConnector).contains(connectedBlock) && ((IConductor)connectedBlock).canConnect(direction.getOpposite())) { + neighbors.add(position); + } + } + + return neighbors; + } + public boolean onSearch(Pathfinder finder, Vector3 node) { + if(node.getTileEntity(world) == targetConnector) { + finder.results.add(node); + return true; + } else { + return false; + } + } + }); + } + + public PathfinderChecker(final World world, final IConnector targetConnector, final IConnector[] ignoreConnector) { + super(new IPathCallBack() { + public Set getConnectedNodes(Pathfinder finder, Vector3 currentNode) { + HashSet neighbors = new HashSet(); + + for(int i = 0; i < 6; ++i) { + ForgeDirection direction = ForgeDirection.getOrientation(i); + Vector3 position = currentNode.clone().modifyPositionFromSide(direction); + TileEntity connectedBlock = position.getTileEntity(world); + if(connectedBlock instanceof IConductor && !Arrays.asList(ignoreConnector).contains(connectedBlock) && ((IConductor)connectedBlock).canConnect(direction.getOpposite())) { + neighbors.add(position); + } + } + + return neighbors; + } + public boolean onSearch(Pathfinder finder, Vector3 node) { + if(node.getTileEntity(world) == targetConnector) { + finder.results.add(node); + return true; + } else { + return false; + } + } + }); + } +} diff --git a/src/main/java/universalelectricity/core/vector/Vector2.java b/src/main/java/universalelectricity/core/vector/Vector2.java new file mode 100644 index 0000000..4b9e35f --- /dev/null +++ b/src/main/java/universalelectricity/core/vector/Vector2.java @@ -0,0 +1,101 @@ +package universalelectricity.core.vector; + +import net.minecraft.util.MathHelper; + +public class Vector2 implements Cloneable { + + public double x; + public double y; + + + public Vector2() { + this(0.0D, 0.0D); + } + + public Vector2(double x, double y) { + this.x = x; + this.y = y; + } + + public int intX() { + return (int)Math.floor(this.x); + } + + public int intY() { + return (int)Math.floor(this.y); + } + + public Vector2 clone() { + return new Vector2(this.x, this.y); + } + + public static double distance(Vector2 point1, Vector2 point2) { + double xDifference = point1.x - point2.x; + double yDiference = point1.y - point2.y; + return (double)MathHelper.sqrt_double(xDifference * xDifference + yDiference * yDiference); + } + + public static double slope(Vector2 point1, Vector2 point2) { + double xDifference = point1.x - point2.x; + double yDiference = point1.y - point2.y; + return yDiference / xDifference; + } + + public double distanceTo(Vector2 target) { + double xDifference = this.x - target.x; + double yDifference = this.y - target.y; + return (double)MathHelper.sqrt_double(xDifference * xDifference + yDifference * yDifference); + } + + public Vector2 add(Vector2 par1) { + this.x += par1.x; + this.y += par1.y; + return this; + } + + public Vector2 add(double par1) { + this.x += par1; + this.y += par1; + return this; + } + + public Vector2 invert() { + this.multiply(-1.0D); + return this; + } + + public Vector2 multiply(double amount) { + this.x *= amount; + this.y *= amount; + return this; + } + + public Vector2 round() { + return new Vector2((double)Math.round(this.x), (double)Math.round(this.y)); + } + + public Vector2 ceil() { + return new Vector2(Math.ceil(this.x), Math.ceil(this.y)); + } + + public Vector2 floor() { + return new Vector2(Math.floor(this.x), Math.floor(this.y)); + } + + public int hashCode() { + return ("X:" + this.x + "Y:" + this.y).hashCode(); + } + + public boolean equals(Object o) { + if(!(o instanceof Vector2)) { + return false; + } else { + Vector2 vector = (Vector2)o; + return this.x == vector.x && this.y == vector.y; + } + } + + public String toString() { + return "Vector2 [" + this.x + "," + this.y + "]"; + } +} diff --git a/src/main/java/universalelectricity/core/vector/Vector3.java b/src/main/java/universalelectricity/core/vector/Vector3.java new file mode 100644 index 0000000..87791e4 --- /dev/null +++ b/src/main/java/universalelectricity/core/vector/Vector3.java @@ -0,0 +1,286 @@ +package universalelectricity.core.vector; + +import java.util.List; + +import net.minecraft.block.Block; +import net.minecraft.entity.Entity; +import net.minecraft.nbt.NBTTagCompound; +import net.minecraft.tileentity.TileEntity; +import net.minecraft.util.AxisAlignedBB; +import net.minecraft.util.ChunkCoordinates; +import net.minecraft.util.MathHelper; +import net.minecraft.util.MovingObjectPosition; +import net.minecraft.util.Vec3; +import net.minecraft.world.IBlockAccess; +import net.minecraft.world.World; +import net.minecraftforge.common.util.ForgeDirection; + +public class Vector3 implements Cloneable { + + public double x; + public double y; + public double z; + + + public Vector3() { + this(0.0D, 0.0D, 0.0D); + } + + public Vector3(double x, double y, double z) { + this.x = x; + this.y = y; + this.z = z; + } + + public Vector3(Entity par1) { + this.x = par1.posX; + this.y = par1.posY; + this.z = par1.posZ; + } + + public Vector3(TileEntity par1) { + this.x = (double)par1.xCoord; + this.y = (double)par1.yCoord; + this.z = (double)par1.zCoord; + } + + public Vector3(Vec3 par1) { + this.x = par1.xCoord; + this.y = par1.yCoord; + this.z = par1.zCoord; + } + + public Vector3(MovingObjectPosition par1) { + this.x = (double)par1.blockX; + this.y = (double)par1.blockY; + this.z = (double)par1.blockZ; + } + + public Vector3(ChunkCoordinates par1) { + this.x = (double)par1.posX; + this.y = (double)par1.posY; + this.z = (double)par1.posZ; + } + + public Vector3(ForgeDirection direction) { + this.x = (double)direction.offsetX; + this.y = (double)direction.offsetY; + this.z = (double)direction.offsetZ; + } + + public int intX() { + return (int)Math.floor(this.x); + } + + public int intY() { + return (int)Math.floor(this.y); + } + + public int intZ() { + return (int)Math.floor(this.z); + } + + public Vector3 clone() { + return new Vector3(this.x, this.y, this.z); + } + + public Block getBlock(IBlockAccess world) { + return world.getBlock(this.intX(), this.intY(), this.intZ()); + } + + public int getBlockMetadata(IBlockAccess world) { + return world.getBlockMetadata(this.intX(), this.intY(), this.intZ()); + } + + public TileEntity getTileEntity(IBlockAccess world) { + return world.getTileEntity(this.intX(), this.intY(), this.intZ()); + } + + public boolean setBlock(World world, Block block, int metadata, int notify) { + return world.setBlock(this.intX(), this.intY(), this.intZ(), block, metadata, notify); + } + + public boolean setBlock(World world, Block block, int metadata) { + return this.setBlock(world, block, metadata, 3); + } + + public boolean setBlock(World world, Block block) { + return this.setBlock(world, block, 0); + } + + public Vector2 toVector2() { + return new Vector2(this.x, this.z); + } + + public Vec3 toVec3() { + return Vec3.createVectorHelper(this.x, this.y, this.z); + } + + public double getMagnitude() { + return Math.sqrt(this.getMagnitudeSquared()); + } + + public double getMagnitudeSquared() { + return this.x * this.x + this.y * this.y + this.z * this.z; + } + + public Vector3 normalize() { + double d = this.getMagnitude(); + if(d != 0.0D) { + this.multiply(1.0D / d); + } + + return this; + } + + public static double distance(Vector3 par1, Vector3 par2) { + double var2 = par1.x - par2.x; + double var4 = par1.y - par2.y; + double var6 = par1.z - par2.z; + return (double)MathHelper.sqrt_double(var2 * var2 + var4 * var4 + var6 * var6); + } + + public double distanceTo(Vector3 vector3) { + double var2 = vector3.x - this.x; + double var4 = vector3.y - this.y; + double var6 = vector3.z - this.z; + return (double)MathHelper.sqrt_double(var2 * var2 + var4 * var4 + var6 * var6); + } + + public Vector3 add(Vector3 par1) { + this.x += par1.x; + this.y += par1.y; + this.z += par1.z; + return this; + } + + public Vector3 add(double par1) { + this.x += par1; + this.y += par1; + this.z += par1; + return this; + } + + public Vector3 subtract(Vector3 amount) { + this.x -= amount.x; + this.y -= amount.y; + this.z -= amount.z; + return this; + } + + public Vector3 invert() { + this.multiply(-1.0D); + return this; + } + + public Vector3 multiply(double amount) { + this.x *= amount; + this.y *= amount; + this.z *= amount; + return this; + } + + public Vector3 multiply(Vector3 vec) { + this.x *= vec.x; + this.y *= vec.y; + this.z *= vec.z; + return this; + } + + public static Vector3 subtract(Vector3 par1, Vector3 par2) { + return new Vector3(par1.x - par2.x, par1.y - par2.y, par1.z - par2.z); + } + + public static Vector3 add(Vector3 par1, Vector3 par2) { + return new Vector3(par1.x + par2.x, par1.y + par2.y, par1.z + par2.z); + } + + public static Vector3 add(Vector3 par1, double par2) { + return new Vector3(par1.x + par2, par1.y + par2, par1.z + par2); + } + + public static Vector3 multiply(Vector3 vec1, Vector3 vec2) { + return new Vector3(vec1.x * vec2.x, vec1.y * vec2.y, vec1.z * vec2.z); + } + + public static Vector3 multiply(Vector3 vec1, double vec2) { + return new Vector3(vec1.x * vec2, vec1.y * vec2, vec1.z * vec2); + } + + public Vector3 round() { + return new Vector3((double)Math.round(this.x), (double)Math.round(this.y), (double)Math.round(this.z)); + } + + public Vector3 ceil() { + return new Vector3(Math.ceil(this.x), Math.ceil(this.y), Math.ceil(this.z)); + } + + public Vector3 floor() { + return new Vector3(Math.floor(this.x), Math.floor(this.y), Math.floor(this.z)); + } + + public List getEntitiesWithin(World worldObj, Class par1Class) { + return worldObj.getEntitiesWithinAABB(par1Class, AxisAlignedBB.getBoundingBox((double)this.intX(), (double)this.intY(), (double)this.intZ(), (double)(this.intX() + 1), (double)(this.intY() + 1), (double)(this.intZ() + 1))); + } + + public Vector3 modifyPositionFromSide(ForgeDirection side, double amount) { + switch(side.ordinal()) { + case 0: + this.y -= amount; + break; + case 1: + this.y += amount; + break; + case 2: + this.z -= amount; + break; + case 3: + this.z += amount; + break; + case 4: + this.x -= amount; + break; + case 5: + this.x += amount; + } + + return this; + } + + public Vector3 modifyPositionFromSide(ForgeDirection side) { + this.modifyPositionFromSide(side, 1.0D); + return this; + } + + public static Vector3 readFromNBT(NBTTagCompound nbtCompound) { + Vector3 tempVector = new Vector3(); + tempVector.x = nbtCompound.getDouble("x"); + tempVector.y = nbtCompound.getDouble("y"); + tempVector.z = nbtCompound.getDouble("z"); + return tempVector; + } + + public NBTTagCompound writeToNBT(NBTTagCompound par1NBTTagCompound) { + par1NBTTagCompound.setDouble("x", this.x); + par1NBTTagCompound.setDouble("y", this.y); + par1NBTTagCompound.setDouble("z", this.z); + return par1NBTTagCompound; + } + + public int hashCode() { + return ("X:" + this.x + "Y:" + this.y + "Z:" + this.z).hashCode(); + } + + public boolean equals(Object o) { + if(!(o instanceof Vector3)) { + return false; + } else { + Vector3 vector3 = (Vector3)o; + return this.x == vector3.x && this.y == vector3.y && this.z == vector3.z; + } + } + + public String toString() { + return "Vector3 [" + this.x + "," + this.y + "," + this.z + "]"; + } +} diff --git a/src/main/java/universalelectricity/core/vector/VectorHelper.java b/src/main/java/universalelectricity/core/vector/VectorHelper.java new file mode 100644 index 0000000..306bdc8 --- /dev/null +++ b/src/main/java/universalelectricity/core/vector/VectorHelper.java @@ -0,0 +1,27 @@ +package universalelectricity.core.vector; + +import net.minecraft.tileentity.TileEntity; +import net.minecraft.world.World; +import net.minecraftforge.common.util.ForgeDirection; +import universalelectricity.core.block.IConnector; + +public class VectorHelper { + + public static final int[][] RELATIVE_MATRIX = new int[][]{{3, 2, 1, 0, 5, 4}, {4, 5, 0, 1, 2, 3}, {0, 1, 3, 2, 4, 5}, {0, 1, 2, 3, 5, 4}, {0, 1, 5, 4, 3, 2}, {0, 1, 4, 5, 2, 3}}; + + + public static ForgeDirection getOrientationFromSide(ForgeDirection front, ForgeDirection side) { + return front != ForgeDirection.UNKNOWN && side != ForgeDirection.UNKNOWN?ForgeDirection.getOrientation(RELATIVE_MATRIX[front.ordinal()][side.ordinal()]):ForgeDirection.UNKNOWN; + } + + @Deprecated + public static TileEntity getConnectorFromSide(World world, Vector3 position, ForgeDirection side) { + TileEntity tileEntity = getTileEntityFromSide(world, position, side); + return tileEntity instanceof IConnector && ((IConnector)tileEntity).canConnect(getOrientationFromSide(side, ForgeDirection.NORTH))?tileEntity:null; + } + + public static TileEntity getTileEntityFromSide(World world, Vector3 position, ForgeDirection side) { + return position.clone().modifyPositionFromSide(side).getTileEntity(world); + } + +} diff --git a/src/main/java/universalelectricity/prefab/CustomDamageSource.java b/src/main/java/universalelectricity/prefab/CustomDamageSource.java new file mode 100644 index 0000000..3ea4c78 --- /dev/null +++ b/src/main/java/universalelectricity/prefab/CustomDamageSource.java @@ -0,0 +1,32 @@ +package universalelectricity.prefab; + +import cpw.mods.fml.common.registry.LanguageRegistry; +import net.minecraft.util.DamageSource; + +public class CustomDamageSource extends DamageSource { + + public static final CustomDamageSource electrocution = ((CustomDamageSource)(new CustomDamageSource("electrocution")).setDamageBypassesArmor()).setDeathMessage("%1$s got electrocuted!"); + + + public CustomDamageSource(String damageType) { + super(damageType); + } + + public CustomDamageSource setDeathMessage(String deathMessage) { + LanguageRegistry.instance().addStringLocalization("death.attack." + super.damageType, deathMessage); + return this; + } + + public DamageSource setDamageBypassesArmor() { + return super.setDamageBypassesArmor(); + } + + public DamageSource setDamageAllowedInCreativeMode() { + return super.setDamageAllowedInCreativeMode(); + } + + public DamageSource setFireDamage() { + return super.setFireDamage(); + } + +} diff --git a/src/main/java/universalelectricity/prefab/GuiBase.java b/src/main/java/universalelectricity/prefab/GuiBase.java new file mode 100644 index 0000000..d7ba311 --- /dev/null +++ b/src/main/java/universalelectricity/prefab/GuiBase.java @@ -0,0 +1,131 @@ +package universalelectricity.prefab; + +import cpw.mods.fml.relauncher.Side; +import cpw.mods.fml.relauncher.SideOnly; +import net.minecraft.client.gui.GuiScreen; +import net.minecraft.client.renderer.OpenGlHelper; +import net.minecraft.client.renderer.RenderHelper; +import org.lwjgl.opengl.GL11; + +@SideOnly(Side.CLIENT) +public abstract class GuiBase extends GuiScreen { + + protected int xSize = 176; + protected int ySize = 166; + protected int guiLeft; + protected int guiTop; + + + public void initGui() { + super.initGui(); + this.guiLeft = (this.width - this.xSize) / 2; + this.guiTop = (this.height - this.ySize) / 2; + } + + public void drawScreen(int par1, int par2, float par3) { + this.drawDefaultBackground(); + int var4 = this.guiLeft; + int var5 = this.guiTop; + this.drawBackgroundLayer(par1, par2, par3); + GL11.glPushMatrix(); + GL11.glTranslatef((float)var4, (float)var5, 0.0F); + GL11.glColor4f(1.0F, 1.0F, 1.0F, 1.0F); + GL11.glEnable('\u803a'); + short var7 = 240; + short var8 = 240; + OpenGlHelper.setLightmapTextureCoords(OpenGlHelper.lightmapTexUnit, (float)var7 / 1.0F, (float)var8 / 1.0F); + GL11.glColor4f(1.0F, 1.0F, 1.0F, 1.0F); + this.drawForegroundLayer(par1, par2, par3); + GL11.glDisable('\u803a'); + GL11.glDisable(2896); + GL11.glDisable(2929); + GL11.glPopMatrix(); + super.drawScreen(par1, par2, par3); + GL11.glEnable(2896); + GL11.glEnable(2929); + } + + protected abstract void drawForegroundLayer(int var1, int var2, float var3); + + protected abstract void drawBackgroundLayer(int var1, int var2, float var3); + + protected void keyTyped(char x, int y) { + if(y == 1 || y == this.mc.gameSettings.keyBindInventory.getKeyCode()) { + this.mc.thePlayer.closeScreen(); + } + + } + + public boolean doesGuiPauseGame() { + return false; + } + + public void updateScreen() { + super.updateScreen(); + if(!this.mc.thePlayer.isEntityAlive() || this.mc.thePlayer.isDead) { + this.mc.thePlayer.closeScreen(); + } + + } + + public void drawTooltip(int x, int y, String ... toolTips) { + GL11.glDisable('\u803a'); + RenderHelper.disableStandardItemLighting(); + GL11.glDisable(2896); + GL11.glDisable(2929); + if(toolTips != null) { + int var5 = 0; + + int var6; + int var7; + for(var6 = 0; var6 < toolTips.length; ++var6) { + var7 = this.fontRendererObj.getStringWidth(toolTips[var6]); + if(var7 > var5) { + var5 = var7; + } + } + + var6 = x + 12; + var7 = y - 12; + int var9 = 8; + if(toolTips.length > 1) { + var9 += 2 + (toolTips.length - 1) * 10; + } + + if(this.guiTop + var7 + var9 + 6 > this.height) { + var7 = this.height - var9 - this.guiTop - 6; + } + + super.zLevel = 300.0F; + int var10 = -267386864; + this.drawGradientRect(var6 - 3, var7 - 4, var6 + var5 + 3, var7 - 3, var10, var10); + this.drawGradientRect(var6 - 3, var7 + var9 + 3, var6 + var5 + 3, var7 + var9 + 4, var10, var10); + this.drawGradientRect(var6 - 3, var7 - 3, var6 + var5 + 3, var7 + var9 + 3, var10, var10); + this.drawGradientRect(var6 - 4, var7 - 3, var6 - 3, var7 + var9 + 3, var10, var10); + this.drawGradientRect(var6 + var5 + 3, var7 - 3, var6 + var5 + 4, var7 + var9 + 3, var10, var10); + int var11 = 1347420415; + int var12 = (var11 & 16711422) >> 1 | var11 & -16777216; + this.drawGradientRect(var6 - 3, var7 - 3 + 1, var6 - 3 + 1, var7 + var9 + 3 - 1, var11, var12); + this.drawGradientRect(var6 + var5 + 2, var7 - 3 + 1, var6 + var5 + 3, var7 + var9 + 3 - 1, var11, var12); + this.drawGradientRect(var6 - 3, var7 - 3, var6 + var5 + 3, var7 - 3 + 1, var11, var11); + this.drawGradientRect(var6 - 3, var7 + var9 + 2, var6 + var5 + 3, var7 + var9 + 3, var12, var12); + + for(int var13 = 0; var13 < toolTips.length; ++var13) { + String var14 = toolTips[var13]; + this.fontRendererObj.drawStringWithShadow(var14, var6, var7, -1); + if(var13 == 0) { + var7 += 2; + } + + var7 += 10; + } + + super.zLevel = 0.0F; + } + + GL11.glEnable(2929); + GL11.glEnable(2896); + RenderHelper.enableGUIStandardItemLighting(); + GL11.glEnable('\u803a'); + } +} diff --git a/src/main/java/universalelectricity/prefab/RecipeHelper.java b/src/main/java/universalelectricity/prefab/RecipeHelper.java new file mode 100644 index 0000000..7ee0a03 --- /dev/null +++ b/src/main/java/universalelectricity/prefab/RecipeHelper.java @@ -0,0 +1,131 @@ +package universalelectricity.prefab; + +import cpw.mods.fml.common.registry.GameRegistry; +import java.util.ArrayList; +import java.util.Iterator; +import java.util.List; +import net.minecraft.item.ItemStack; +import net.minecraft.item.crafting.CraftingManager; +import net.minecraft.item.crafting.IRecipe; +import net.minecraftforge.common.config.Configuration; + +public class RecipeHelper { + + public static List getRecipesByOutput(ItemStack output) { + ArrayList list = new ArrayList(); + Iterator i$ = CraftingManager.getInstance().getRecipeList().iterator(); + + while(i$.hasNext()) { + Object obj = i$.next(); + if(obj instanceof IRecipe && ((IRecipe)obj).getRecipeOutput() == output) { + list.add((IRecipe)obj); + } + } + + return list; + } + + public static boolean replaceRecipe(IRecipe recipe, IRecipe newRecipe) { + Iterator i$ = CraftingManager.getInstance().getRecipeList().iterator(); + + Object obj; + do { + do { + if(!i$.hasNext()) { + return false; + } + + obj = i$.next(); + } while(!(obj instanceof IRecipe)); + } while(!((IRecipe)obj).equals(recipe) && obj != recipe); + + CraftingManager.getInstance().getRecipeList().remove(obj); + CraftingManager.getInstance().getRecipeList().add(newRecipe); + return true; + } + + public static boolean replaceRecipe(ItemStack recipe, IRecipe newRecipe) { + if(removeRecipe(recipe)) { + CraftingManager.getInstance().getRecipeList().add(newRecipe); + return true; + } else { + return false; + } + } + + public static boolean removeRecipe(IRecipe recipe) { + Iterator i$ = CraftingManager.getInstance().getRecipeList().iterator(); + + Object obj; + do { + do { + do { + if(!i$.hasNext()) { + return false; + } + + obj = i$.next(); + } while(obj == null); + } while(!(obj instanceof IRecipe)); + } while(!((IRecipe)obj).equals(recipe) && obj != recipe); + + CraftingManager.getInstance().getRecipeList().remove(obj); + return true; + } + + public static boolean removeRecipe(ItemStack stack) { + Iterator i$ = CraftingManager.getInstance().getRecipeList().iterator(); + + Object obj; + do { + if(!i$.hasNext()) { + return false; + } + + obj = i$.next(); + } while(obj == null || !(obj instanceof IRecipe) || ((IRecipe)obj).getRecipeOutput() == null || !((IRecipe)obj).getRecipeOutput().isItemEqual(stack)); + + CraftingManager.getInstance().getRecipeList().remove(obj); + return true; + } + + public static boolean removeRecipes(ItemStack ... itemStacks) { + boolean didRemove = false; + Iterator itr = CraftingManager.getInstance().getRecipeList().iterator(); + + while(itr.hasNext()) { + Object obj = itr.next(); + if(obj != null && obj instanceof IRecipe && ((IRecipe)obj).getRecipeOutput() != null) { + ItemStack[] arr$ = itemStacks; + int len$ = itemStacks.length; + + for(int i$ = 0; i$ < len$; ++i$) { + ItemStack itemStack = arr$[i$]; + if(((IRecipe)obj).getRecipeOutput().isItemEqual(itemStack)) { + itr.remove(); + didRemove = true; + break; + } + } + } + } + + return didRemove; + } + + public static void addRecipe(IRecipe recipe, String name, Configuration configuration, boolean defaultBoolean) { + if(configuration != null) { + configuration.load(); + if(configuration.get("Crafting", "Allow " + name + " Crafting", defaultBoolean).getBoolean(defaultBoolean)) { + GameRegistry.addRecipe(recipe); + } + + configuration.save(); + } + + } + + public static void addRecipe(IRecipe recipe, Configuration config, boolean defaultBoolean) { + addRecipe(recipe, recipe.getRecipeOutput().getUnlocalizedName(), config, defaultBoolean); + } +} diff --git a/src/main/java/universalelectricity/prefab/SlotSpecific.java b/src/main/java/universalelectricity/prefab/SlotSpecific.java new file mode 100644 index 0000000..12e53ba --- /dev/null +++ b/src/main/java/universalelectricity/prefab/SlotSpecific.java @@ -0,0 +1,74 @@ +package universalelectricity.prefab; + +import net.minecraft.inventory.IInventory; +import net.minecraft.inventory.Slot; +import net.minecraft.item.ItemStack; + +public class SlotSpecific extends Slot { + + public ItemStack[] validItemStacks = new ItemStack[0]; + public Class[] validClasses = new Class[0]; + public boolean isInverted = false; + public boolean isMetadataSensitive = false; + + + public SlotSpecific(IInventory par2IInventory, int par3, int par4, int par5, ItemStack ... itemStacks) { + super(par2IInventory, par3, par4, par5); + this.setItemStacks(itemStacks); + } + + public SlotSpecific(IInventory par2IInventory, int par3, int par4, int par5, Class ... validClasses) { + super(par2IInventory, par3, par4, par5); + this.setClasses(validClasses); + } + + public SlotSpecific setMetadataSensitive() { + this.isMetadataSensitive = true; + return this; + } + + public SlotSpecific setItemStacks(ItemStack ... validItemStacks) { + this.validItemStacks = validItemStacks; + return this; + } + + public SlotSpecific setClasses(Class ... validClasses) { + this.validClasses = validClasses; + return this; + } + + public SlotSpecific toggleInverted() { + this.isInverted = !this.isInverted; + return this; + } + + public boolean isItemValid(ItemStack compareStack) { + boolean returnValue = false; + ItemStack[] arr$ = this.validItemStacks; + int len$ = arr$.length; + + int i$; + for(i$ = 0; i$ < len$; ++i$) { + ItemStack clazz = arr$[i$]; + if(compareStack.isItemEqual(clazz) || !this.isMetadataSensitive && compareStack.getItem() == clazz.getItem()) { + returnValue = true; + break; + } + } + + if(!returnValue) { + Class[] var7 = this.validClasses; + len$ = var7.length; + + for(i$ = 0; i$ < len$; ++i$) { + Class var8 = var7[i$]; + if(var8.equals(compareStack.getItem().getClass()) || var8.isInstance(compareStack.getItem())) { + returnValue = true; + break; + } + } + } + + return this.isInverted?!returnValue:returnValue; + } +} diff --git a/src/main/java/universalelectricity/prefab/TranslationHelper.java b/src/main/java/universalelectricity/prefab/TranslationHelper.java new file mode 100644 index 0000000..6456da6 --- /dev/null +++ b/src/main/java/universalelectricity/prefab/TranslationHelper.java @@ -0,0 +1,49 @@ +package universalelectricity.prefab; + +import cpw.mods.fml.common.FMLLog; +import cpw.mods.fml.common.registry.LanguageRegistry; + +public class TranslationHelper { + + public static int loadLanguages(String languagePath, String[] languageSupported) { + int languages = 0; + String[] arr$ = languageSupported; + int len$ = languageSupported.length; + + for(int i$ = 0; i$ < len$; ++i$) { + String language = arr$[i$]; + LanguageRegistry.instance().loadLocalization(languagePath + language + ".properties", language, false); + if(LanguageRegistry.instance().getStringLocalization("children", language) != "") { + try { + String[] e = LanguageRegistry.instance().getStringLocalization("children", language).split(","); + String[] arr$1 = e; + int len$1 = e.length; + + for(int i$1 = 0; i$1 < len$1; ++i$1) { + String child = arr$1[i$1]; + if(child != "" || child != null) { + LanguageRegistry.instance().loadLocalization(languagePath + language + ".properties", child, false); + ++languages; + } + } + } catch (Exception var12) { + FMLLog.severe("Failed to load a child language file.", new Object[0]); + var12.printStackTrace(); + } + } + + ++languages; + } + + return languages; + } + + public static String getLocal(String key) { + String text = LanguageRegistry.instance().getStringLocalization(key); + if(text == null || text == "") { + text = LanguageRegistry.instance().getStringLocalization(key, "en_US"); + } + + return text; + } +} diff --git a/src/main/java/universalelectricity/prefab/block/BlockAdvanced.java b/src/main/java/universalelectricity/prefab/block/BlockAdvanced.java new file mode 100644 index 0000000..bafffb7 --- /dev/null +++ b/src/main/java/universalelectricity/prefab/block/BlockAdvanced.java @@ -0,0 +1,149 @@ +package universalelectricity.prefab.block; + +import java.lang.reflect.Method; +import java.util.Random; + +import net.minecraft.block.Block; +import net.minecraft.block.BlockContainer; +import net.minecraft.block.material.Material; +import net.minecraft.entity.item.EntityItem; +import net.minecraft.entity.player.EntityPlayer; +import net.minecraft.inventory.IInventory; +import net.minecraft.item.ItemStack; +import net.minecraft.nbt.NBTTagCompound; +import net.minecraft.tileentity.TileEntity; +import net.minecraft.world.World; + +public abstract class BlockAdvanced extends BlockContainer { + + public BlockAdvanced(Material material) { + super(material); + this.setHardness(0.6F); + } + + @Override + public boolean onBlockActivated(World world, int x, int y, int z, EntityPlayer entityPlayer, int side, float hitX, float hitY, float hitZ) { + world.getBlockMetadata(x, y, z); + if(this.isUsableWrench(entityPlayer, entityPlayer.inventory.getCurrentItem(), x, y, z)) { + this.damageWrench(entityPlayer, entityPlayer.inventory.getCurrentItem(), x, y, z); + if(entityPlayer.isSneaking() && this.onSneakUseWrench(world, x, y, z, entityPlayer, side, hitX, hitY, hitZ)) { + return true; + } + + if(this.onUseWrench(world, x, y, z, entityPlayer, side, hitX, hitY, hitZ)) { + return true; + } + } + + return entityPlayer.isSneaking() && this.onSneakMachineActivated(world, x, y, z, entityPlayer, side, hitX, hitY, hitZ)?true:this.onMachineActivated(world, x, y, z, entityPlayer, side, hitX, hitY, hitZ); + } + + public boolean isUsableWrench(EntityPlayer entityPlayer, ItemStack itemStack, int x, int y, int z) { + if(entityPlayer != null && itemStack != null) { + Class wrenchClass = itemStack.getItem().getClass(); + + try { + Method e = wrenchClass.getMethod("canWrench", new Class[]{EntityPlayer.class, Integer.TYPE, Integer.TYPE, Integer.TYPE}); + return ((Boolean)e.invoke(itemStack.getItem(), new Object[]{entityPlayer, Integer.valueOf(x), Integer.valueOf(y), Integer.valueOf(z)})).booleanValue(); + } catch (NoClassDefFoundError var8) { + ; + } catch (Exception var9) { + ; + } + + try { + if(wrenchClass == Class.forName("ic2.core.item.tool.ItemToolWrench") || wrenchClass == Class.forName("ic2.core.item.tool.ItemToolWrenchElectric")) { + return itemStack.getItemDamage() < itemStack.getMaxDamage(); + } + } catch (Exception var10) { + ; + } + } + + return false; + } + + public boolean damageWrench(EntityPlayer entityPlayer, ItemStack itemStack, int x, int y, int z) { + if(this.isUsableWrench(entityPlayer, itemStack, x, y, z)) { + Class wrenchClass = itemStack.getItem().getClass(); + + Method e; + try { + e = wrenchClass.getMethod("wrenchUsed", new Class[]{EntityPlayer.class, Integer.TYPE, Integer.TYPE, Integer.TYPE}); + e.invoke(itemStack.getItem(), new Object[]{entityPlayer, Integer.valueOf(x), Integer.valueOf(y), Integer.valueOf(z)}); + return true; + } catch (Exception var9) { + try { + if(wrenchClass == Class.forName("ic2.core.item.tool.ItemToolWrench") || wrenchClass == Class.forName("ic2.core.item.tool.ItemToolWrenchElectric")) { + e = wrenchClass.getMethod("damage", new Class[]{ItemStack.class, Integer.TYPE, EntityPlayer.class}); + e.invoke(itemStack.getItem(), new Object[]{itemStack, Integer.valueOf(1), entityPlayer}); + return true; + } + } catch (Exception var8) { + ; + } + } + } + + return false; + } + + public boolean onMachineActivated(World world, int x, int y, int z, EntityPlayer entityPlayer, int side, float hitX, float hitY, float hitZ) { + return false; + } + + public boolean onSneakMachineActivated(World world, int x, int y, int z, EntityPlayer entityPlayer, int side, float hitX, float hitY, float hitZ) { + return false; + } + + public boolean onUseWrench(World world, int x, int y, int z, EntityPlayer entityPlayer, int side, float hitX, float hitY, float hitZ) { + return false; + } + + public boolean onSneakUseWrench(World world, int x, int y, int z, EntityPlayer entityPlayer, int side, float hitX, float hitY, float hitZ) { + return this.onUseWrench(world, x, y, z, entityPlayer, side, hitX, hitY, hitZ); + } + + @Override + public void breakBlock(World world, int x, int y, int z, Block par5, int par6) { + this.dropEntireInventory(world, x, y, z, par5, par6); + super.breakBlock(world, x, y, z, par5, par6); + } + + public void dropEntireInventory(World world, int x, int y, int z, Block par5, int par6) { + TileEntity tileEntity = world.getTileEntity(x, y, z); + if(tileEntity != null && tileEntity instanceof IInventory) { + IInventory inventory = (IInventory)tileEntity; + + for(int var6 = 0; var6 < inventory.getSizeInventory(); ++var6) { + ItemStack var7 = inventory.getStackInSlot(var6); + if(var7 != null) { + Random random = new Random(); + float var8 = random.nextFloat() * 0.8F + 0.1F; + float var9 = random.nextFloat() * 0.8F + 0.1F; + float var10 = random.nextFloat() * 0.8F + 0.1F; + + while(var7.stackSize > 0) { + int var11 = random.nextInt(21) + 10; + if(var11 > var7.stackSize) { + var11 = var7.stackSize; + } + + var7.stackSize -= var11; + EntityItem var12 = new EntityItem(world, (double)((float)x + var8), (double)((float)y + var9), (double)((float)z + var10), new ItemStack(var7.getItem(), var11, var7.getItemDamage())); + if(var7.hasTagCompound()) { + var12.getEntityItem().setTagCompound((NBTTagCompound)var7.getTagCompound().copy()); + } + + float var13 = 0.05F; + var12.motionX = (double)((float)random.nextGaussian() * var13); + var12.motionY = (double)((float)random.nextGaussian() * var13 + 0.2F); + var12.motionZ = (double)((float)random.nextGaussian() * var13); + world.spawnEntityInWorld(var12); + } + } + } + } + + } +} diff --git a/src/main/java/universalelectricity/prefab/block/BlockConductor.java b/src/main/java/universalelectricity/prefab/block/BlockConductor.java new file mode 100644 index 0000000..48ab516 --- /dev/null +++ b/src/main/java/universalelectricity/prefab/block/BlockConductor.java @@ -0,0 +1,34 @@ +package universalelectricity.prefab.block; + +import net.minecraft.block.Block; +import net.minecraft.block.BlockContainer; +import net.minecraft.block.material.Material; +import net.minecraft.tileentity.TileEntity; +import net.minecraft.world.World; +import universalelectricity.core.block.IConductor; + +public abstract class BlockConductor extends BlockContainer { + + public BlockConductor(Material material) { + super(material); + } + + @Override + public void onBlockAdded(World world, int x, int y, int z) { + super.onBlockAdded(world, x, y, z); + TileEntity tileEntity = world.getTileEntity(x, y, z); + if(tileEntity instanceof IConductor) { + ((IConductor)tileEntity).updateAdjacentConnections(); + } + + } + + @Override + public void onNeighborBlockChange(World world, int x, int y, int z, Block blockID) { + TileEntity tileEntity = world.getTileEntity(x, y, z); + if(tileEntity instanceof IConductor) { + ((IConductor)tileEntity).updateAdjacentConnections(); + } + + } +} diff --git a/src/main/java/universalelectricity/prefab/block/BlockRotatable.java b/src/main/java/universalelectricity/prefab/block/BlockRotatable.java new file mode 100644 index 0000000..e8b5917 --- /dev/null +++ b/src/main/java/universalelectricity/prefab/block/BlockRotatable.java @@ -0,0 +1,52 @@ +package universalelectricity.prefab.block; + +import net.minecraft.block.material.Material; +import net.minecraft.entity.EntityLivingBase; +import net.minecraft.entity.player.EntityPlayer; +import net.minecraft.item.ItemStack; +import net.minecraft.util.MathHelper; +import net.minecraft.world.IBlockAccess; +import net.minecraft.world.World; +import net.minecraftforge.common.util.ForgeDirection; +import universalelectricity.prefab.implement.IRotatable; + +public abstract class BlockRotatable extends BlockAdvanced implements IRotatable { + + public BlockRotatable(Material material) { + super(material); + } + + @Override + public void onBlockPlacedBy(World world, int x, int y, int z, EntityLivingBase entityLiving, ItemStack itemStack) { + int angle = MathHelper.floor_double((double)(entityLiving.rotationYaw * 4.0F / 360.0F) + 0.5D) & 3; + byte change = 3; + switch(angle) { + case 0: + change = 2; + break; + case 1: + change = 5; + break; + case 2: + change = 3; + break; + case 3: + change = 4; + } + + this.setDirection(world, x, y, z, ForgeDirection.getOrientation(change)); + } + + public boolean onUseWrench(World world, int x, int y, int z, EntityPlayer par5EntityPlayer, int side, float hitX, float hitY, float hitZ) { + this.setDirection(world, x, y, z, ForgeDirection.getOrientation(ForgeDirection.ROTATION_MATRIX[0][this.getDirection(world, x, y, z).ordinal()])); + return true; + } + + public ForgeDirection getDirection(IBlockAccess world, int x, int y, int z) { + return ForgeDirection.getOrientation(world.getBlockMetadata(x, y, z)); + } + + public void setDirection(World world, int x, int y, int z, ForgeDirection facingDirection) { + world.setBlockMetadataWithNotify(x, y, z, facingDirection.ordinal(), 3); + } +} diff --git a/src/main/java/universalelectricity/prefab/flag/CommandFlag.java b/src/main/java/universalelectricity/prefab/flag/CommandFlag.java new file mode 100644 index 0000000..ea6b26b --- /dev/null +++ b/src/main/java/universalelectricity/prefab/flag/CommandFlag.java @@ -0,0 +1,226 @@ +package universalelectricity.prefab.flag; + +import java.util.Iterator; +import java.util.List; +import net.minecraft.command.CommandBase; +import net.minecraft.command.ICommandSender; +import net.minecraft.command.WrongUsageException; +import net.minecraft.entity.player.EntityPlayer; +import net.minecraft.util.ChatComponentText; +import universalelectricity.core.vector.Vector3; + +public class CommandFlag extends CommandBase { + + public static final String[] COMMANDS = new String[]{"list", "setregion", "removeregion", "set"}; + public String commandName; + public ModFlag modFlagData; + + + public CommandFlag(ModFlag modFlag) { + this.commandName = "modflag"; + this.modFlagData = modFlag; + } + + public CommandFlag(ModFlag modFlag, String commandName) { + this(modFlag); + this.commandName = commandName; + } + + public String getCommandName() { + return this.commandName; + } + + public String getCommandUsage(ICommandSender par1ICommandSender) { + String returnString = ""; + String[] arr$ = COMMANDS; + int len$ = arr$.length; + + for(int i$ = 0; i$ < len$; ++i$) { + String command = arr$[i$]; + returnString = returnString + "\n/" + this.getCommandName() + " " + command; + } + + return returnString; + } + + public void processCommand(ICommandSender sender, String[] args) { + if(args.length > 0) { + EntityPlayer entityPlayer = (EntityPlayer)sender; + FlagWorld flagWorld = this.modFlagData.getFlagWorld(entityPlayer.worldObj); + String commandName = args[0].toLowerCase(); + String regionName; + String flagName; + FlagRegion flagRegion; + if(commandName.equalsIgnoreCase("list")) { + if(args.length > 1) { + regionName = args[1]; + Iterator flagRegion1; + if(regionName.equalsIgnoreCase("all")) { + flagName = ""; + flagRegion1 = this.modFlagData.getFlagWorlds().iterator(); + + FlagRegion i$1; + while(flagRegion1.hasNext()) { + for(Iterator flags1 = ((FlagWorld)flagRegion1.next()).getRegions().iterator(); flags1.hasNext(); flagName = flagName + " " + i$1.name + " (" + i$1.region.min.x + "," + i$1.region.min.z + ")" + ",") { + i$1 = (FlagRegion)flags1.next(); + } + } + + if(flagName != "") { + flagName = "List of regions in world:\n" + flagName; + } else { + flagName = "No regions in this world."; + } + + sender.addChatMessage(new ChatComponentText(flagName)); + } else { + Flag flags2; + if(flagWorld.getRegion(regionName) != null) { + flagName = ""; + + for(flagRegion1 = flagWorld.getRegion(regionName).getFlags().iterator(); flagRegion1.hasNext(); flagName = flagName + " " + flags2.name + " => " + flags2.value + ",") { + flags2 = (Flag)flagRegion1.next(); + } + + if(flagName != "") { + flagName = "List of flags in region " + regionName + ":\n" + flagName; + } else { + flagName = "No flags in this region."; + } + + sender.addChatMessage(new ChatComponentText(flagName)); + } else { + flagName = "Region does not exist, but here are existing flags in the position you are standing on:\n"; + + for(flagRegion1 = flagWorld.getFlagsInPosition(new Vector3(entityPlayer)).iterator(); flagRegion1.hasNext(); flagName = flagName + " " + flags2.name + "=>" + flags2.value + ",") { + flags2 = (Flag)flagRegion1.next(); + } + + sender.addChatMessage(new ChatComponentText(flagName)); + } + } + } else { + regionName = ""; + + for(Iterator flagName3 = flagWorld.getRegions().iterator(); flagName3.hasNext(); regionName = regionName + " " + flagRegion.name + " (" + flagRegion.region.min.x + "," + flagRegion.region.min.z + ")" + ",") { + flagRegion = (FlagRegion)flagName3.next(); + } + + if(regionName != "") { + regionName = "List of regions in this dimension:\n" + regionName; + } else { + regionName = "No regions in this dimension."; + } + + sender.addChatMessage(new ChatComponentText(regionName)); + } + + return; + } + + if(commandName.equalsIgnoreCase("setregion")) { + if(args.length > 1) { + regionName = args[1]; + if(regionName.equalsIgnoreCase("dimension")) { + if(flagWorld.addRegion(regionName, new Vector3(entityPlayer), 1)) { + sender.addChatMessage(new ChatComponentText("Created global dimension region setting.")); + return; + } + } else { + if(args.length <= 2) { + throw new WrongUsageException("/" + this.getCommandName() + " addregion ", new Object[0]); + } + + boolean flagName1 = false; + + int flagName2; + try { + flagName2 = Integer.parseInt(args[2]); + } catch (Exception var12) { + throw new WrongUsageException("Radius not a number!", new Object[0]); + } + + if(flagName2 <= 0) { + throw new WrongUsageException("Radius has to be greater than zero!", new Object[0]); + } + + flagRegion = flagWorld.getRegion(regionName); + if(flagRegion == null) { + if(flagWorld.addRegion(regionName, new Vector3(entityPlayer), flagName2)) { + sender.addChatMessage(new ChatComponentText("Region " + regionName + " added.")); + } + } else { + flagRegion.edit(new Vector3(entityPlayer), flagName2); + sender.addChatMessage(new ChatComponentText("Region " + regionName + " already exists. Modified region to have a radius of: " + flagName2)); + } + } + + return; + } + + throw new WrongUsageException("Please specify the region name.", new Object[0]); + } + + if(commandName.equalsIgnoreCase("removeregion")) { + if(args.length > 1) { + regionName = args[1]; + if(flagWorld.removeRegion(regionName)) { + sender.addChatMessage(new ChatComponentText("Region with name " + regionName + " is removed.")); + return; + } + + throw new WrongUsageException("The specified region does not exist in this world.", new Object[0]); + } + + throw new WrongUsageException("Please specify the region name.", new Object[0]); + } + + if(commandName.equalsIgnoreCase("set")) { + if(args.length <= 2) { + throw new WrongUsageException("/" + this.getCommandName() + " set ", new Object[0]); + } + + regionName = args[1]; + flagName = args[2]; + flagRegion = flagWorld.getRegion(regionName); + if(flagRegion == null) { + throw new WrongUsageException("The specified region \'" + regionName + "\' does not exist.", new Object[0]); + } + + String flags; + if(FlagRegistry.flags.contains(flagName)) { + if(args.length > 3) { + flags = args[3]; + flagRegion.setFlag(flagName, flags); + sender.addChatMessage(new ChatComponentText("Flag \'" + flagName + "\' has been set to \'" + flags + "\' in " + regionName + ".")); + } else { + flagRegion.removeFlag(flagName); + sender.addChatMessage(new ChatComponentText("Removed flag \'" + flagName + "\'.")); + } + + return; + } + + flags = "Flag does not exist. Existing flags:\n"; + + String registeredFlag; + for(Iterator i$ = FlagRegistry.flags.iterator(); i$.hasNext(); flags = flags + registeredFlag + ", ") { + registeredFlag = (String)i$.next(); + } + + throw new WrongUsageException(flags, new Object[0]); + } + } + + throw new WrongUsageException(this.getCommandUsage(sender), new Object[0]); + } + + public int getRequiredPermissionLevel() { + return 2; + } + + public List addTabCompletionOptions(ICommandSender sender, String[] args) { + return args.length == 1?getListOfStringsMatchingLastWord(args, COMMANDS):null; + } + +} diff --git a/src/main/java/universalelectricity/prefab/flag/Flag.java b/src/main/java/universalelectricity/prefab/flag/Flag.java new file mode 100644 index 0000000..3bd6071 --- /dev/null +++ b/src/main/java/universalelectricity/prefab/flag/Flag.java @@ -0,0 +1,31 @@ +package universalelectricity.prefab.flag; + +import net.minecraft.nbt.NBTTagCompound; + +public class Flag extends FlagBase { + + public FlagRegion flagRegion; + public String name; + public String value; + + + public Flag(FlagRegion flagRegion) { + this.flagRegion = flagRegion; + } + + public Flag(FlagRegion flagRegion, String name, String value) { + this(flagRegion); + this.name = name; + this.value = value; + } + + public void readFromNBT(NBTTagCompound nbt) { + this.name = nbt.getString("name"); + this.value = nbt.getString("value"); + } + + public void writeToNBT(NBTTagCompound nbt) { + nbt.setString("name", this.name); + nbt.setString("value", this.value); + } +} diff --git a/src/main/java/universalelectricity/prefab/flag/FlagBase.java b/src/main/java/universalelectricity/prefab/flag/FlagBase.java new file mode 100644 index 0000000..cb14bf3 --- /dev/null +++ b/src/main/java/universalelectricity/prefab/flag/FlagBase.java @@ -0,0 +1,23 @@ +package universalelectricity.prefab.flag; + +import net.minecraft.nbt.NBTTagCompound; + +public abstract class FlagBase { + + public abstract void readFromNBT(NBTTagCompound var1); + + public abstract void writeToNBT(NBTTagCompound var1); + + public NBTTagCompound getNBT() { + NBTTagCompound nbt = new NBTTagCompound(); + + try { + this.writeToNBT(nbt); + } catch (Exception var3) { + System.out.println("Failed to read flag"); + var3.printStackTrace(); + } + + return nbt; + } +} diff --git a/src/main/java/universalelectricity/prefab/flag/FlagRegion.java b/src/main/java/universalelectricity/prefab/flag/FlagRegion.java new file mode 100644 index 0000000..8d8cce2 --- /dev/null +++ b/src/main/java/universalelectricity/prefab/flag/FlagRegion.java @@ -0,0 +1,130 @@ +package universalelectricity.prefab.flag; + +import java.util.ArrayList; +import java.util.Iterator; +import java.util.List; +import net.minecraft.nbt.NBTTagCompound; +import net.minecraft.nbt.NBTTagList; +import universalelectricity.core.vector.Vector3; +import universalelectricity.prefab.vector.Region3; + +public class FlagRegion extends FlagBase { + + public FlagWorld flagWorld; + public String name; + public Region3 region; + private final List flags = new ArrayList(); + + + public FlagRegion(FlagWorld worldFlagData) { + this.flagWorld = worldFlagData; + } + + public FlagRegion(FlagWorld flagWorld, String name, Region3 region) { + this.flagWorld = flagWorld; + this.name = name; + this.region = region; + } + + public void readFromNBT(NBTTagCompound nbt) { + this.name = nbt.getString("name"); + Vector3 startVector = Vector3.readFromNBT(nbt.getCompoundTag("min")); + Vector3 endVector = Vector3.readFromNBT(nbt.getCompoundTag("max")); + this.region = new Region3(startVector, endVector); + NBTTagList flagList = nbt.getTagList("flags", 10); + + for(int i = 0; i < flagList.tagCount(); ++i) { + NBTTagCompound childNode = (NBTTagCompound)flagList.getCompoundTagAt(i); + + Flag e = new Flag(this); + e.readFromNBT(childNode); + this.flags.add(e); + } + + } + + public void writeToNBT(NBTTagCompound nbt) { + nbt.setString("name", this.name); + nbt.setTag("min", this.region.min.writeToNBT(new NBTTagCompound())); + nbt.setTag("max", this.region.max.writeToNBT(new NBTTagCompound())); + NBTTagList flagList = new NBTTagList(); + + for (Flag flag : this.getFlags()) { + flagList.appendTag(flag.getNBT()); + } + + nbt.setTag("flags", flagList); + } + + public boolean containsValue(String flagName, String checkValue, Vector3 position) { + Iterator i$ = this.flags.iterator(); + + Flag flag; + do { + if(!i$.hasNext()) { + return false; + } + + flag = (Flag)i$.next(); + } while(!flag.name.equalsIgnoreCase(flagName) || !flag.value.equalsIgnoreCase(checkValue)); + + return true; + } + + public boolean setFlag(String flagName, String value) { + this.removeFlag(flagName); + return value != null && value != "" && !this.containsFlag(flagName)?this.flags.add(new Flag(this, flagName, value)):false; + } + + public boolean containsFlag(String flagName) { + Iterator i$ = this.flags.iterator(); + + Flag region; + do { + if(!i$.hasNext()) { + return false; + } + + region = (Flag)i$.next(); + } while(!region.name.equalsIgnoreCase(flagName)); + + return true; + } + + public boolean removeFlag(String flagName) { + Iterator i$ = this.flags.iterator(); + + Flag region; + do { + if(!i$.hasNext()) { + return false; + } + + region = (Flag)i$.next(); + } while(!region.name.equalsIgnoreCase(flagName)); + + this.flags.remove(region); + return true; + } + + public List getFlags() { + Iterator it = this.flags.iterator(); + + while(it.hasNext()) { + Flag flag = (Flag)it.next(); + if(flag == null) { + it.remove(); + } else if(flag.name == null || flag.name == "") { + it.remove(); + } + } + + return this.flags; + } + + public void edit(Vector3 position, int radius) { + Vector3 minVec = new Vector3((double)(position.intX() - radius), 0.0D, (double)(position.intZ() - radius)); + Vector3 maxVec = new Vector3((double)(position.intX() + radius), (double)this.flagWorld.world.getHeight(), (double)(position.intZ() + radius)); + this.region = new Region3(minVec, maxVec); + } +} diff --git a/src/main/java/universalelectricity/prefab/flag/FlagRegistry.java b/src/main/java/universalelectricity/prefab/flag/FlagRegistry.java new file mode 100644 index 0000000..4b0b872 --- /dev/null +++ b/src/main/java/universalelectricity/prefab/flag/FlagRegistry.java @@ -0,0 +1,37 @@ +package universalelectricity.prefab.flag; + +import java.util.ArrayList; +import java.util.HashMap; +import java.util.List; +import universalelectricity.prefab.flag.ModFlag; + +public class FlagRegistry { + + public static final String DEFAULT_NAME = "ModFlags"; + private static final HashMap MOD_FLAGS = new HashMap(); + public static final List flags = new ArrayList(); + public static boolean isInitiated = false; + + + public static void registerModFlag(String name, ModFlag flagData) { + MOD_FLAGS.put(name, flagData); + } + + public static ModFlag getModFlag(String name) { + return (ModFlag)MOD_FLAGS.get(name); + } + + public static String registerFlag(String name) { + if(!isInitiated) { + isInitiated = true; + } + + name = name.toLowerCase(); + if(!flags.contains(name)) { + flags.add(name); + } + + return name; + } + +} diff --git a/src/main/java/universalelectricity/prefab/flag/FlagWorld.java b/src/main/java/universalelectricity/prefab/flag/FlagWorld.java new file mode 100644 index 0000000..fc5b504 --- /dev/null +++ b/src/main/java/universalelectricity/prefab/flag/FlagWorld.java @@ -0,0 +1,164 @@ +package universalelectricity.prefab.flag; + +import java.util.ArrayList; +import java.util.Iterator; +import java.util.List; +import java.util.Set; + +import net.minecraft.nbt.NBTTagCompound; +import net.minecraft.world.World; +import universalelectricity.core.vector.Vector3; +import universalelectricity.prefab.vector.Region3; + +public class FlagWorld extends FlagBase { + + public static final String GLOBAL_REGION = "dimension"; + public World world; + private final List regions = new ArrayList(); + + + public FlagWorld(World world) { + this.world = world; + } + + public void readFromNBT(NBTTagCompound nbt) { + + for(String key : (Set) nbt.func_150296_c()) { + NBTTagCompound childCompound = nbt.getCompoundTag(key); + FlagRegion e = new FlagRegion(this); + e.readFromNBT(childCompound); + this.regions.add(e); + } + + } + + public void writeToNBT(NBTTagCompound nbt) { + Iterator i$ = this.regions.iterator(); + + while(i$.hasNext()) { + FlagRegion region = (FlagRegion)i$.next(); + + try { + NBTTagCompound e = new NBTTagCompound(); + region.writeToNBT(e); + nbt.setTag(region.name, e); + } catch (Exception var5) { + System.out.println("Failed to save world flag data: " + region.name); + var5.printStackTrace(); + } + } + + } + + public List getFlagsInPosition(Vector3 position) { + ArrayList returnFlags = new ArrayList(); + Iterator i$ = this.regions.iterator(); + + while(i$.hasNext()) { + FlagRegion flagRegion = (FlagRegion)i$.next(); + if(flagRegion.region.isIn(position) || flagRegion.name.equalsIgnoreCase("dimension")) { + Iterator i$1 = flagRegion.getFlags().iterator(); + + while(i$1.hasNext()) { + Flag flag = (Flag)i$1.next(); + returnFlags.add(flag); + } + } + } + + return returnFlags; + } + + public List getValues(String flagName, Vector3 position) { + ArrayList values = new ArrayList(); + Iterator i$ = this.getFlagsInPosition(position).iterator(); + + while(i$.hasNext()) { + Flag flag = (Flag)i$.next(); + values.add(flag.value); + } + + return values; + } + + public boolean containsValue(String flagName, String checkValue, Vector3 position) { + Iterator i$ = this.getFlagsInPosition(position).iterator(); + + Flag flag; + do { + if(!i$.hasNext()) { + return false; + } + + flag = (Flag)i$.next(); + } while(!flag.name.equalsIgnoreCase(flagName) || !flag.value.equalsIgnoreCase(checkValue)); + + return true; + } + + public boolean addRegion(String name, Vector3 position, int radius) { + Vector3 minVec = new Vector3((double)(position.intX() - radius), 0.0D, (double)(position.intZ() - radius)); + Vector3 maxVec = new Vector3((double)(position.intX() + radius), (double)this.world.getHeight(), (double)(position.intZ() + radius)); + return this.regions.add(new FlagRegion(this, name, new Region3(minVec, maxVec))); + } + + public FlagRegion getRegion(String name) { + Iterator i$ = this.regions.iterator(); + + FlagRegion region; + do { + if(!i$.hasNext()) { + return null; + } + + region = (FlagRegion)i$.next(); + } while(!region.name.equals(name)); + + return region; + } + + public List getRegions(Vector3 position) { + ArrayList returnRegions = new ArrayList(); + Iterator i$ = this.regions.iterator(); + + while(i$.hasNext()) { + FlagRegion region = (FlagRegion)i$.next(); + if(region.region.isIn(position)) { + returnRegions.add(region); + } + } + + return returnRegions; + } + + public boolean removeRegion(String name) { + Iterator i$ = this.regions.iterator(); + + FlagRegion region; + do { + if(!i$.hasNext()) { + return false; + } + + region = (FlagRegion)i$.next(); + } while(!region.name.equals(name)); + + this.regions.remove(region); + return true; + } + + public List getRegions() { + Iterator it = this.regions.iterator(); + + while(it.hasNext()) { + FlagRegion region = (FlagRegion)it.next(); + if(region == null) { + it.remove(); + } else if(region.name == null || region.name == "") { + it.remove(); + } + } + + return this.regions; + } +} diff --git a/src/main/java/universalelectricity/prefab/flag/ModFlag.java b/src/main/java/universalelectricity/prefab/flag/ModFlag.java new file mode 100644 index 0000000..b221cb3 --- /dev/null +++ b/src/main/java/universalelectricity/prefab/flag/ModFlag.java @@ -0,0 +1,84 @@ +package universalelectricity.prefab.flag; + +import java.util.ArrayList; +import java.util.Iterator; +import java.util.List; +import java.util.Set; + +import net.minecraft.nbt.NBTTagCompound; +import net.minecraft.world.World; +import net.minecraft.world.WorldServer; +import net.minecraftforge.common.DimensionManager; +import universalelectricity.core.vector.Vector3; + +public class ModFlag extends FlagBase { + + private final List flagWorlds = new ArrayList(); + + + public ModFlag(NBTTagCompound nbt) { + this.readFromNBT(nbt); + } + + public void readFromNBT(NBTTagCompound nbt) { + if(nbt != null) { + for (String key : (Set) nbt.func_150296_c()) { + NBTTagCompound dimensionCompound = nbt.getCompoundTag(key); + int e = Integer.parseInt(key.replace("dim_", "")); + WorldServer world = DimensionManager.getWorld(e); + FlagWorld flagWorld = new FlagWorld(world); + flagWorld.readFromNBT(dimensionCompound); + this.flagWorlds.add(flagWorld); + } + } + + } + + public void writeToNBT(NBTTagCompound nbt) { + if(nbt != null) { + Iterator i$ = this.flagWorlds.iterator(); + + while(i$.hasNext()) { + FlagWorld worldData = (FlagWorld)i$.next(); + + try { + nbt.setTag("dim_" + worldData.world.provider.dimensionId, worldData.getNBT()); + } catch (Exception var5) { + System.out.println("Mod Flag: Failed to save world flag data: " + worldData.world); + var5.printStackTrace(); + } + } + } + + } + + public FlagWorld getFlagWorld(World world) { + FlagWorld worldData = null; + if(world != null) { + Iterator i$ = this.flagWorlds.iterator(); + + while(i$.hasNext()) { + FlagWorld data = (FlagWorld)i$.next(); + if(data.world != null && data.world.provider != null && data.world.provider.dimensionId == world.provider.dimensionId) { + worldData = data; + break; + } + } + + if(worldData == null) { + worldData = new FlagWorld(world); + this.flagWorlds.add(worldData); + } + } + + return worldData; + } + + public boolean containsValue(World world, String flagName, String checkValue, Vector3 position) { + return this.getFlagWorld(world).containsValue(flagName, checkValue, position); + } + + public List getFlagWorlds() { + return this.flagWorlds; + } +} diff --git a/src/main/java/universalelectricity/prefab/flag/NBTFileLoader.java b/src/main/java/universalelectricity/prefab/flag/NBTFileLoader.java new file mode 100644 index 0000000..54fdb9f --- /dev/null +++ b/src/main/java/universalelectricity/prefab/flag/NBTFileLoader.java @@ -0,0 +1,77 @@ +package universalelectricity.prefab.flag; + +import cpw.mods.fml.client.FMLClientHandler; +import cpw.mods.fml.common.FMLCommonHandler; +import cpw.mods.fml.common.FMLLog; +import java.io.File; +import java.io.FileInputStream; +import java.io.FileOutputStream; +import net.minecraft.client.Minecraft; +import net.minecraft.nbt.CompressedStreamTools; +import net.minecraft.nbt.NBTTagCompound; +import net.minecraft.server.MinecraftServer; + +public class NBTFileLoader { + + public static boolean saveData(File saveDirectory, String filename, NBTTagCompound data) { + try { + File e = new File(saveDirectory, filename + "_tmp.dat"); + File file = new File(saveDirectory, filename + ".dat"); + CompressedStreamTools.writeCompressed(data, new FileOutputStream(e)); + if(file.exists()) { + file.delete(); + } + + e.renameTo(file); + FMLLog.fine("Saved " + filename + " NBT data file successfully.", new Object[0]); + return true; + } catch (Exception var5) { + System.out.println("Failed to save " + filename + ".dat!"); + var5.printStackTrace(); + return false; + } + } + + public static boolean saveData(String filename, NBTTagCompound data) { + return saveData(getSaveDirectory(MinecraftServer.getServer().getFolderName()), filename, data); + } + + public static NBTTagCompound loadData(File saveDirectory, String filename) { + try { + File e = new File(saveDirectory, filename + ".dat"); + if(e.exists()) { + FMLLog.fine("Loaded " + filename + " data.", new Object[0]); + return CompressedStreamTools.readCompressed(new FileInputStream(e)); + } else { + FMLLog.fine("Created new " + filename + " data.", new Object[0]); + return new NBTTagCompound(); + } + } catch (Exception var3) { + System.out.println("Failed to load " + filename + ".dat!"); + var3.printStackTrace(); + return null; + } + } + + public static NBTTagCompound loadData(String filename) { + return loadData(getSaveDirectory(MinecraftServer.getServer().getFolderName()), filename); + } + + public static File getSaveDirectory(String worldName) { + File parent = getBaseDirectory(); + if(FMLCommonHandler.instance().getSide().isClient()) { + parent = new File(getBaseDirectory(), "saves" + File.separator); + } + + return new File(parent, worldName + File.separator); + } + + public static File getBaseDirectory() { + if(FMLCommonHandler.instance().getSide().isClient()) { + FMLClientHandler.instance().getClient(); + return Minecraft.getMinecraft().mcDataDir; + } else { + return new File("."); + } + } +} diff --git a/src/main/java/universalelectricity/prefab/implement/IDisableable.java b/src/main/java/universalelectricity/prefab/implement/IDisableable.java new file mode 100644 index 0000000..c4e3d16 --- /dev/null +++ b/src/main/java/universalelectricity/prefab/implement/IDisableable.java @@ -0,0 +1,9 @@ +package universalelectricity.prefab.implement; + + +public interface IDisableable { + + void onDisable(int var1); + + boolean isDisabled(); +} diff --git a/src/main/java/universalelectricity/prefab/implement/IRedstoneProvider.java b/src/main/java/universalelectricity/prefab/implement/IRedstoneProvider.java new file mode 100644 index 0000000..7631422 --- /dev/null +++ b/src/main/java/universalelectricity/prefab/implement/IRedstoneProvider.java @@ -0,0 +1,10 @@ +package universalelectricity.prefab.implement; + +import net.minecraftforge.common.util.ForgeDirection; + +public interface IRedstoneProvider { + + boolean isPoweringTo(ForgeDirection var1); + + boolean isIndirectlyPoweringTo(ForgeDirection var1); +} diff --git a/src/main/java/universalelectricity/prefab/implement/IRedstoneReceptor.java b/src/main/java/universalelectricity/prefab/implement/IRedstoneReceptor.java new file mode 100644 index 0000000..22c9001 --- /dev/null +++ b/src/main/java/universalelectricity/prefab/implement/IRedstoneReceptor.java @@ -0,0 +1,9 @@ +package universalelectricity.prefab.implement; + + +public interface IRedstoneReceptor { + + void onPowerOn(); + + void onPowerOff(); +} diff --git a/src/main/java/universalelectricity/prefab/implement/IRotatable.java b/src/main/java/universalelectricity/prefab/implement/IRotatable.java new file mode 100644 index 0000000..e007baf --- /dev/null +++ b/src/main/java/universalelectricity/prefab/implement/IRotatable.java @@ -0,0 +1,12 @@ +package universalelectricity.prefab.implement; + +import net.minecraft.world.IBlockAccess; +import net.minecraft.world.World; +import net.minecraftforge.common.util.ForgeDirection; + +public interface IRotatable { + + ForgeDirection getDirection(IBlockAccess var1, int var2, int var3, int var4); + + void setDirection(World var1, int var2, int var3, int var4, ForgeDirection var5); +} diff --git a/src/main/java/universalelectricity/prefab/implement/ITier.java b/src/main/java/universalelectricity/prefab/implement/ITier.java new file mode 100644 index 0000000..9a84564 --- /dev/null +++ b/src/main/java/universalelectricity/prefab/implement/ITier.java @@ -0,0 +1,9 @@ +package universalelectricity.prefab.implement; + + +public interface ITier { + + int getTier(); + + void setTier(int var1); +} diff --git a/src/main/java/universalelectricity/prefab/implement/IToolConfigurator.java b/src/main/java/universalelectricity/prefab/implement/IToolConfigurator.java new file mode 100644 index 0000000..c8f3e32 --- /dev/null +++ b/src/main/java/universalelectricity/prefab/implement/IToolConfigurator.java @@ -0,0 +1,10 @@ +package universalelectricity.prefab.implement; + +import net.minecraft.entity.player.EntityPlayer; + +public interface IToolConfigurator { + + boolean canWrench(EntityPlayer var1, int var2, int var3, int var4); + + void wrenchUsed(EntityPlayer var1, int var2, int var3, int var4); +} diff --git a/src/main/java/universalelectricity/prefab/modifier/IModifier.java b/src/main/java/universalelectricity/prefab/modifier/IModifier.java new file mode 100644 index 0000000..8be79fc --- /dev/null +++ b/src/main/java/universalelectricity/prefab/modifier/IModifier.java @@ -0,0 +1,12 @@ +package universalelectricity.prefab.modifier; + +import net.minecraft.item.ItemStack; + +public interface IModifier +{ + String getType(final ItemStack p0); + + double getEffectiveness(final ItemStack p0); + + int getTier(final ItemStack p0); +} diff --git a/src/main/java/universalelectricity/prefab/modifier/SlotModifier.java b/src/main/java/universalelectricity/prefab/modifier/SlotModifier.java new file mode 100644 index 0000000..7bbbab5 --- /dev/null +++ b/src/main/java/universalelectricity/prefab/modifier/SlotModifier.java @@ -0,0 +1,16 @@ +package universalelectricity.prefab.modifier; + +import net.minecraft.item.ItemStack; +import net.minecraft.inventory.IInventory; +import net.minecraft.inventory.Slot; + +public class SlotModifier extends Slot +{ + public SlotModifier(final IInventory par2IInventory, final int par3, final int par4, final int par5) { + super(par2IInventory, par3, par4, par5); + } + + public boolean isItemValid(final ItemStack par1ItemStack) { + return par1ItemStack.getItem() instanceof IModifier; + } +} diff --git a/src/main/java/universalelectricity/prefab/multiblock/BlockMulti.java b/src/main/java/universalelectricity/prefab/multiblock/BlockMulti.java new file mode 100644 index 0000000..73438ad --- /dev/null +++ b/src/main/java/universalelectricity/prefab/multiblock/BlockMulti.java @@ -0,0 +1,117 @@ +package universalelectricity.prefab.multiblock; + +import cpw.mods.fml.relauncher.Side; +import cpw.mods.fml.relauncher.SideOnly; +import java.util.Random; +import net.minecraft.block.Block; +import net.minecraft.block.BlockContainer; +import net.minecraft.client.renderer.texture.IIconRegister; +import net.minecraft.entity.player.EntityPlayer; +import net.minecraft.init.Blocks; +import net.minecraft.item.ItemStack; +import net.minecraft.tileentity.TileEntity; +import net.minecraft.util.MovingObjectPosition; +import net.minecraft.world.World; +import universalelectricity.core.UniversalElectricity; +import universalelectricity.core.vector.Vector3; + +public class BlockMulti extends BlockContainer { + + public String textureName = null; + public String channel = ""; + + + public BlockMulti() { + super(UniversalElectricity.machine); + this.setHardness(0.8F); + this.setBlockName("multiBlock"); + } + + public BlockMulti setChannel(String channel) { + this.channel = channel; + return this; + } + + public BlockMulti setTextureName(String name) { + this.textureName = name; + return this; + } + + public void makeFakeBlock(World worldObj, Vector3 position, Vector3 mainBlock) { + worldObj.setBlock(position.intX(), position.intY(), position.intZ(), this); + TileEntity tile = position.getTileEntity(worldObj); + if (tile instanceof TileEntityMulti) { + ((TileEntityMulti)tile).setMainBlock(mainBlock); + } else { + TileEntityMulti newTile = (TileEntityMulti)createNewTileEntity(worldObj, 0); + worldObj.setTileEntity(position.intX(), position.intY(), position.intZ(), newTile); + newTile.setMainBlock(mainBlock); + + } + } + + @SideOnly(Side.CLIENT) + @Override + public void registerBlockIcons(IIconRegister iconRegister) { + if(this.textureName != null) { + this.blockIcon = iconRegister.registerIcon(this.textureName); + } else { + super.registerBlockIcons(iconRegister); + } + + } + + @Override + public void breakBlock(World world, int x, int y, int z, Block par5, int par6) { + TileEntity tileEntity = world.getTileEntity(x, y, z); + if(tileEntity instanceof TileEntityMulti) { + ((TileEntityMulti)tileEntity).onBlockRemoval(); + } + + super.breakBlock(world, x, y, z, par5, par6); + } + + @Override + public boolean onBlockActivated(World par1World, int x, int y, int z, EntityPlayer par5EntityPlayer, int par6, float par7, float par8, float par9) { + TileEntityMulti tileEntity = (TileEntityMulti)par1World.getTileEntity(x, y, z); + return tileEntity.onBlockActivated(par1World, x, y, z, par5EntityPlayer); + } + + @Override + public int quantityDropped(Random par1Random) { + return 0; + } + + @Override + public int getRenderType() { + return -1; + } + + @Override + public boolean isOpaqueCube() { + return false; + } + + @Override + public boolean renderAsNormalBlock() { + return false; + } + + @Override + public TileEntity createNewTileEntity(World var1, int meta) { + return new TileEntityMulti(this.channel); + } + + public ItemStack getPickBlock(MovingObjectPosition target, World par1World, int x, int y, int z) { + TileEntity tileEntity = par1World.getTileEntity(x, y, z); + Vector3 mainBlockPosition = ((TileEntityMulti)tileEntity).mainBlockPosition; + if(mainBlockPosition != null) { + Block mainBlockID = par1World.getBlock(mainBlockPosition.intX(), mainBlockPosition.intY(), mainBlockPosition.intZ()); + if(mainBlockID != Blocks.air) { + return mainBlockID.getPickBlock(target, par1World, mainBlockPosition.intX(), mainBlockPosition.intY(), mainBlockPosition.intZ()); + } + } + + return null; + } +} diff --git a/src/main/java/universalelectricity/prefab/multiblock/IBlockActivate.java b/src/main/java/universalelectricity/prefab/multiblock/IBlockActivate.java new file mode 100644 index 0000000..7657fca --- /dev/null +++ b/src/main/java/universalelectricity/prefab/multiblock/IBlockActivate.java @@ -0,0 +1,8 @@ +package universalelectricity.prefab.multiblock; + +import net.minecraft.entity.player.EntityPlayer; + +public interface IBlockActivate { + + boolean onActivated(EntityPlayer var1); +} diff --git a/src/main/java/universalelectricity/prefab/multiblock/IMultiBlock.java b/src/main/java/universalelectricity/prefab/multiblock/IMultiBlock.java new file mode 100644 index 0000000..820c5cc --- /dev/null +++ b/src/main/java/universalelectricity/prefab/multiblock/IMultiBlock.java @@ -0,0 +1,12 @@ +package universalelectricity.prefab.multiblock; + +import net.minecraft.tileentity.TileEntity; +import universalelectricity.core.vector.Vector3; +import universalelectricity.prefab.multiblock.IBlockActivate; + +public interface IMultiBlock extends IBlockActivate { + + void onCreate(Vector3 var1); + + void onDestroy(TileEntity var1); +} diff --git a/src/main/java/universalelectricity/prefab/multiblock/TileEntityMulti.java b/src/main/java/universalelectricity/prefab/multiblock/TileEntityMulti.java new file mode 100644 index 0000000..9af9238 --- /dev/null +++ b/src/main/java/universalelectricity/prefab/multiblock/TileEntityMulti.java @@ -0,0 +1,91 @@ +package universalelectricity.prefab.multiblock; + +import net.minecraft.entity.player.EntityPlayer; +import net.minecraft.nbt.NBTTagCompound; +import net.minecraft.network.NetworkManager; +import net.minecraft.network.Packet; +import net.minecraft.network.play.server.S35PacketUpdateTileEntity; +import net.minecraft.tileentity.TileEntity; +import net.minecraft.world.World; +import universalelectricity.core.vector.Vector3; + +public class TileEntityMulti extends TileEntity { + + public Vector3 mainBlockPosition; + public String channel; + + + public TileEntityMulti() {} + + public TileEntityMulti(String channel) { + this.channel = channel; + } + + public void setMainBlock(Vector3 mainBlock) { + this.mainBlockPosition = mainBlock; + if(!this.worldObj.isRemote) { + this.worldObj.markBlockForUpdate(this.xCoord, this.yCoord, this.zCoord); + } + + } + + @Override + public Packet getDescriptionPacket() { + if(this.mainBlockPosition == null) { + return null; + } else { + NBTTagCompound nbt = this.mainBlockPosition.writeToNBT(new NBTTagCompound()); + return new S35PacketUpdateTileEntity(xCoord, yCoord, zCoord, getBlockMetadata(),nbt); + } + } + + public void onBlockRemoval() { + if(this.mainBlockPosition != null) { + TileEntity tileEntity = this.worldObj.getTileEntity(this.mainBlockPosition.intX(), this.mainBlockPosition.intY(), this.mainBlockPosition.intZ()); + if(tileEntity != null && tileEntity instanceof IMultiBlock) { + IMultiBlock mainBlock = (IMultiBlock)tileEntity; + if(mainBlock != null) { + mainBlock.onDestroy(this); + } + } + } + + } + + public boolean onBlockActivated(World par1World, int x, int y, int z, EntityPlayer par5EntityPlayer) { + if(this.mainBlockPosition != null) { + TileEntity tileEntity = this.worldObj.getTileEntity(this.mainBlockPosition.intX(), this.mainBlockPosition.intY(), this.mainBlockPosition.intZ()); + if(tileEntity != null && tileEntity instanceof IMultiBlock) { + return ((IMultiBlock)tileEntity).onActivated(par5EntityPlayer); + } + } + + return false; + } + + @Override + public void readFromNBT(NBTTagCompound nbt) { + super.readFromNBT(nbt); + this.mainBlockPosition = Vector3.readFromNBT(nbt.getCompoundTag("mainBlockPosition")); + } + + @Override + public void writeToNBT(NBTTagCompound nbt) { + super.writeToNBT(nbt); + if(this.mainBlockPosition != null) { + nbt.setTag("mainBlockPosition", this.mainBlockPosition.writeToNBT(new NBTTagCompound())); + } + + } + + public boolean canUpdate() { + return false; + } + + @Override + public void onDataPacket(NetworkManager net, S35PacketUpdateTileEntity pkt) { + NBTTagCompound nbt = pkt.func_148857_g(); + this.mainBlockPosition = Vector3.readFromNBT(nbt); + } + +} diff --git a/src/main/java/universalelectricity/prefab/ore/OreGenBase.java b/src/main/java/universalelectricity/prefab/ore/OreGenBase.java new file mode 100644 index 0000000..26388a1 --- /dev/null +++ b/src/main/java/universalelectricity/prefab/ore/OreGenBase.java @@ -0,0 +1,60 @@ +package universalelectricity.prefab.ore; + +import cpw.mods.fml.common.FMLLog; +import java.util.Random; +import net.minecraft.block.Block; +import net.minecraft.item.Item; +import net.minecraft.item.ItemStack; +import net.minecraft.world.World; +import net.minecraft.world.chunk.IChunkProvider; +import net.minecraftforge.common.MinecraftForge; +import net.minecraftforge.common.config.Configuration; +import net.minecraftforge.oredict.OreDictionary; + +public abstract class OreGenBase { + + public String name; + public String oreDictionaryName; + public boolean shouldGenerate = false; + public int blockIndexTexture; + public ItemStack oreStack; + public Block oreID; + public int oreMeta; + public int harvestLevel; + public String harvestTool; + + + public OreGenBase(String name, String oreDiectionaryName, ItemStack stack, String harvestTool, int harvestLevel) { + if(stack != null) { + this.name = name; + this.harvestTool = harvestTool; + this.harvestLevel = harvestLevel; + this.oreDictionaryName = oreDiectionaryName; + this.oreStack = stack; + this.oreID = Block.getBlockFromItem(stack.getItem()); + this.oreMeta = stack.getItemDamage(); + OreDictionary.registerOre(this.oreDictionaryName, stack); + oreID.setHarvestLevel(harvestTool, harvestLevel, stack.getItemDamage()); + + } else { + FMLLog.severe("ItemStack is null while registering ore generation!", new Object[0]); + } + + } + + public OreGenBase enable(Configuration config) { + this.shouldGenerate = shouldGenerateOre(config, this.name); + return this; + } + + private static boolean shouldGenerateOre(Configuration configuration, String oreName) { + configuration.load(); + boolean shouldGenerate = configuration.get("Ore_Generation", "Generate " + oreName, true).getBoolean(true); + configuration.save(); + return shouldGenerate; + } + + public abstract void generate(World var1, Random var2, int var3, int var4); + + public abstract boolean isOreGeneratedInWorld(World var1, IChunkProvider var2); +} diff --git a/src/main/java/universalelectricity/prefab/ore/OreGenReplace.java b/src/main/java/universalelectricity/prefab/ore/OreGenReplace.java new file mode 100644 index 0000000..39cc980 --- /dev/null +++ b/src/main/java/universalelectricity/prefab/ore/OreGenReplace.java @@ -0,0 +1,99 @@ +package universalelectricity.prefab.ore; + +import java.util.Random; + +import net.minecraft.block.Block; +import net.minecraft.init.Blocks; +import net.minecraft.item.ItemStack; +import net.minecraft.util.MathHelper; +import net.minecraft.world.World; +import net.minecraft.world.chunk.IChunkProvider; +import net.minecraft.world.gen.ChunkProviderEnd; +import net.minecraft.world.gen.ChunkProviderGenerate; +import net.minecraft.world.gen.ChunkProviderHell; + +public class OreGenReplace extends OreGenBase { + + public int minGenerateLevel; + public int maxGenerateLevel; + public int amountPerChunk; + public int amountPerBranch; + public Block replaceID; + public boolean ignoreSurface = false; + public boolean ignoreNether = true; + public boolean ignoreEnd = true; + + + public OreGenReplace(String name, String oreDiectionaryName, ItemStack stack, Block replaceID, int minGenerateLevel, int maxGenerateLevel, int amountPerChunk, int amountPerBranch, String harvestTool, int harvestLevel) { + super(name, oreDiectionaryName, stack, harvestTool, harvestLevel); + this.minGenerateLevel = minGenerateLevel; + this.maxGenerateLevel = maxGenerateLevel; + this.amountPerChunk = amountPerChunk; + this.amountPerBranch = amountPerBranch; + this.replaceID = replaceID; + } + + public void generate(World world, Random random, int varX, int varZ) { + try { + for(int e = 0; e < this.amountPerChunk; ++e) { + int x = varX + random.nextInt(16); + int z = varZ + random.nextInt(16); + int y = random.nextInt(Math.max(this.maxGenerateLevel - this.minGenerateLevel, 0)) + this.minGenerateLevel; + this.generateReplace(world, random, x, y, z); + } + } catch (Exception var9) { + System.out.println("Error generating ore: " + super.name); + var9.printStackTrace(); + } + + } + + public boolean generateReplace(World par1World, Random par2Random, int par3, int par4, int par5) { + float var6 = par2Random.nextFloat() * 3.1415927F; + double var7 = (double)((float)(par3 + 8) + MathHelper.sin(var6) * (float)this.amountPerBranch / 8.0F); + double var9 = (double)((float)(par3 + 8) - MathHelper.sin(var6) * (float)this.amountPerBranch / 8.0F); + double var11 = (double)((float)(par5 + 8) + MathHelper.cos(var6) * (float)this.amountPerBranch / 8.0F); + double var13 = (double)((float)(par5 + 8) - MathHelper.cos(var6) * (float)this.amountPerBranch / 8.0F); + double var15 = (double)(par4 + par2Random.nextInt(3) - 2); + double var17 = (double)(par4 + par2Random.nextInt(3) - 2); + + for(int var19 = 0; var19 <= this.amountPerBranch; ++var19) { + double var20 = var7 + (var9 - var7) * (double)var19 / (double)this.amountPerBranch; + double var22 = var15 + (var17 - var15) * (double)var19 / (double)this.amountPerBranch; + double var24 = var11 + (var13 - var11) * (double)var19 / (double)this.amountPerBranch; + double var26 = par2Random.nextDouble() * (double)this.amountPerBranch / 16.0D; + double var28 = (double)(MathHelper.sin((float)var19 * 3.1415927F / (float)this.amountPerBranch) + 1.0F) * var26 + 1.0D; + double var30 = (double)(MathHelper.sin((float)var19 * 3.1415927F / (float)this.amountPerBranch) + 1.0F) * var26 + 1.0D; + int var32 = MathHelper.floor_double(var20 - var28 / 2.0D); + int var33 = MathHelper.floor_double(var22 - var30 / 2.0D); + int var34 = MathHelper.floor_double(var24 - var28 / 2.0D); + int var35 = MathHelper.floor_double(var20 + var28 / 2.0D); + int var36 = MathHelper.floor_double(var22 + var30 / 2.0D); + int var37 = MathHelper.floor_double(var24 + var28 / 2.0D); + + for(int var38 = var32; var38 <= var35; ++var38) { + double var39 = ((double)var38 + 0.5D - var20) / (var28 / 2.0D); + if(var39 * var39 < 1.0D) { + for(int var41 = var33; var41 <= var36; ++var41) { + double var42 = ((double)var41 + 0.5D - var22) / (var30 / 2.0D); + if(var39 * var39 + var42 * var42 < 1.0D) { + for(int var44 = var34; var44 <= var37; ++var44) { + double var45 = ((double)var44 + 0.5D - var24) / (var28 / 2.0D); + Block block = par1World.getBlock(var38, var41, var44); + if(var39 * var39 + var42 * var42 + var45 * var45 < 1.0D && (this.replaceID == Blocks.air || block == this.replaceID)) { + par1World.setBlock(var38, var41, var44, super.oreID, super.oreMeta, 2); + } + } + } + } + } + } + } + + return true; + } + + public boolean isOreGeneratedInWorld(World world, IChunkProvider chunkGenerator) { + return !super.shouldGenerate?false:(this.ignoreSurface && chunkGenerator instanceof ChunkProviderGenerate?false:(this.ignoreNether && chunkGenerator instanceof ChunkProviderHell?false:!this.ignoreEnd || !(chunkGenerator instanceof ChunkProviderEnd))); + } +} diff --git a/src/main/java/universalelectricity/prefab/ore/OreGenReplaceStone.java b/src/main/java/universalelectricity/prefab/ore/OreGenReplaceStone.java new file mode 100644 index 0000000..8e033e8 --- /dev/null +++ b/src/main/java/universalelectricity/prefab/ore/OreGenReplaceStone.java @@ -0,0 +1,16 @@ +package universalelectricity.prefab.ore; + +import net.minecraft.init.Blocks; +import net.minecraft.item.ItemStack; +import universalelectricity.prefab.ore.OreGenReplace; + +public class OreGenReplaceStone extends OreGenReplace { + + public OreGenReplaceStone(String name, String oreDiectionaryName, ItemStack stack, int minGenerateLevel, int maxGenerateLevel, int amountPerChunk, int amountPerBranch, String harvestTool, int harvestLevel) { + super(name, oreDiectionaryName, stack, Blocks.stone, minGenerateLevel, maxGenerateLevel, amountPerChunk, amountPerBranch, harvestTool, harvestLevel); + } + + public OreGenReplaceStone(String name, String oreDiectionaryName, ItemStack stack, int maxGenerateLevel, int amountPerChunk, int amountPerBranch) { + this(name, oreDiectionaryName, stack, 0, maxGenerateLevel, amountPerChunk, amountPerBranch, "pickaxe", 1); + } +} diff --git a/src/main/java/universalelectricity/prefab/ore/OreGenerator.java b/src/main/java/universalelectricity/prefab/ore/OreGenerator.java new file mode 100644 index 0000000..4b0d74a --- /dev/null +++ b/src/main/java/universalelectricity/prefab/ore/OreGenerator.java @@ -0,0 +1,60 @@ +package universalelectricity.prefab.ore; + +import cpw.mods.fml.common.IWorldGenerator; +import cpw.mods.fml.common.registry.GameRegistry; +import java.util.ArrayList; +import java.util.Iterator; +import java.util.List; +import java.util.Random; +import net.minecraft.world.World; +import net.minecraft.world.chunk.IChunkProvider; +import universalelectricity.prefab.ore.OreGenBase; + +public class OreGenerator implements IWorldGenerator { + + public static boolean isInitiated = false; + private static final List ORES_TO_GENERATE = new ArrayList(); + + + public static void addOre(OreGenBase data) { + if(!isInitiated) { + GameRegistry.registerWorldGenerator(new OreGenerator(), 10); //TODO figure out the right value instead of 10 + } + + ORES_TO_GENERATE.add(data); + } + + public static boolean oreExists(String oreName) { + Iterator i$ = ORES_TO_GENERATE.iterator(); + + OreGenBase ore; + do { + if(!i$.hasNext()) { + return false; + } + + ore = (OreGenBase)i$.next(); + } while(ore.oreDictionaryName != oreName); + + return true; + } + + public static void removeOre(OreGenBase data) { + ORES_TO_GENERATE.remove(data); + } + + public void generate(Random rand, int chunkX, int chunkZ, World world, IChunkProvider chunkGenerator, IChunkProvider chunkProvider) { + chunkX <<= 4; + chunkZ <<= 4; + Iterator i$ = ORES_TO_GENERATE.iterator(); + + while(i$.hasNext()) { + OreGenBase oreData = (OreGenBase)i$.next(); + if(oreData.shouldGenerate && oreData.isOreGeneratedInWorld(world, chunkGenerator)) { + oreData.generate(world, rand, chunkX, chunkZ); + } + } + + } + +} diff --git a/src/main/java/universalelectricity/prefab/potion/CustomPotion.java b/src/main/java/universalelectricity/prefab/potion/CustomPotion.java new file mode 100644 index 0000000..3f46380 --- /dev/null +++ b/src/main/java/universalelectricity/prefab/potion/CustomPotion.java @@ -0,0 +1,22 @@ +package universalelectricity.prefab.potion; + +import net.minecraft.potion.Potion; + +public abstract class CustomPotion extends Potion { + + public CustomPotion(int id, boolean isBadEffect, int color, String name) { + super(id, isBadEffect, color); + this.setPotionName("potion." + name); + Potion.potionTypes[this.getId()] = this; + } + + public Potion setIconIndex(int par1, int par2) { + super.setIconIndex(par1, par2); + return this; + } + + protected Potion setEffectiveness(double par1) { + super.setEffectiveness(par1); + return this; + } +} diff --git a/src/main/java/universalelectricity/prefab/potion/CustomPotionEffect.java b/src/main/java/universalelectricity/prefab/potion/CustomPotionEffect.java new file mode 100644 index 0000000..24ea3d5 --- /dev/null +++ b/src/main/java/universalelectricity/prefab/potion/CustomPotionEffect.java @@ -0,0 +1,29 @@ +package universalelectricity.prefab.potion; + +import java.util.ArrayList; +import java.util.List; + +import net.minecraft.item.ItemStack; +import net.minecraft.potion.Potion; +import net.minecraft.potion.PotionEffect; + +public class CustomPotionEffect extends PotionEffect { + + public CustomPotionEffect(int potionID, int duration, int amplifier) { + super(potionID, duration, amplifier); + } + + public CustomPotionEffect(Potion potion, int duration, int amplifier) { + this(potion.getId(), duration, amplifier); + } + + public CustomPotionEffect(int potionID, int duration, int amplifier, List curativeItems) { + super(potionID, duration, amplifier); + if(curativeItems == null) { + this.setCurativeItems(new ArrayList()); + } else { + this.setCurativeItems(curativeItems); + } + + } +} diff --git a/src/main/java/universalelectricity/prefab/tile/ElectricTileDriver.java b/src/main/java/universalelectricity/prefab/tile/ElectricTileDriver.java new file mode 100644 index 0000000..bc0edc9 --- /dev/null +++ b/src/main/java/universalelectricity/prefab/tile/ElectricTileDriver.java @@ -0,0 +1,107 @@ +package universalelectricity.prefab.tile; + +import java.util.EnumSet; +import java.util.HashMap; +import java.util.HashSet; +import java.util.Map; +import java.util.Set; + +import net.minecraft.tileentity.TileEntity; +import net.minecraftforge.common.util.ForgeDirection; +import universalelectricity.api.CompatibilityModule; +import universalelectricity.core.UniversalElectricity; +import universalelectricity.core.electricity.ElectricityNetworkHelper; +import universalelectricity.core.electricity.ElectricityPack; +import universalelectricity.core.electricity.IElectricityNetwork; +import universalelectricity.core.vector.Vector3; + +public class ElectricTileDriver { + + TileEntity handler; + + public ElectricTileDriver(TileEntity handler) { + this.handler = handler; + } + + public void invalidate() { + ElectricityNetworkHelper.invalidate(handler); + } + + public boolean tick() { + if (handler.isInvalid()) return false; + Map networks = getNetworks(); + Set inputSides = new HashSet<>(); + if (CompatibilityModule.canReceive(handler, ForgeDirection.UNKNOWN)) { + inputSides = consume(networks); + } + if (CompatibilityModule.canExtract(handler, ForgeDirection.UNKNOWN)) { + produce(networks, inputSides); + } + return networks.size() > 0; + } + + public Set consume(Map networks) { + Set inputSides = new HashSet<>(); + + if (networks.size() > 0) { + double demand = CompatibilityModule.getDemandedJoules(handler); + double voltage = CompatibilityModule.getInputVoltage(handler); + double wattsPerSide = demand / networks.size(); + for (ForgeDirection side : networks.keySet()) { + IElectricityNetwork net = networks.get(side); + if (CompatibilityModule.canReceive(handler, side) && wattsPerSide > 0 && demand > 0) { + inputSides.add(side); + net.startRequesting(handler, wattsPerSide / voltage, voltage); + ElectricityPack receivedPack = net.consumeElectricity(handler); + if (receivedPack.voltage > voltage && UniversalElectricity.isVoltageSensitive) { + handler.getWorldObj().createExplosion(null, handler.xCoord, handler.yCoord, handler.zCoord, 1, true); + return EnumSet.allOf(ForgeDirection.class); + } + CompatibilityModule.receiveEnergy(handler, side, receivedPack.getWatts(), true); + } else { + net.stopRequesting(handler); + } + } + + } + + return inputSides; + } + + public void produce(Map networks, Set inputSides) { + if ((networks.size() - inputSides.size()) > 0) { + double provided = CompatibilityModule.getProvidedJoules(handler); + double voltage = CompatibilityModule.getOutputVoltage(handler); + double wattsPerSide = provided / (networks.size() - inputSides.size()); + for (ForgeDirection side : networks.keySet()) { + IElectricityNetwork net = networks.get(side); + if (!inputSides.contains(side) && CompatibilityModule.canExtract(handler, side) && wattsPerSide > 0 && provided > 0) { + double amperes = Math.min(wattsPerSide / voltage, net.getRequest(new TileEntity[]{handler}).amperes); + net.startProducing(handler, amperes, voltage); + CompatibilityModule.extractEnergy(handler, side, new ElectricityPack(amperes, voltage).getWatts(), true); + } else { + net.stopProducing(handler); + } + } + } + } + + public Map getNetworks() { + Map networks = new HashMap<>(); + + for(ForgeDirection dir : ForgeDirection.values()) { + if (CompatibilityModule.canReceive(handler, dir) || CompatibilityModule.canExtract(handler, dir)) { + Vector3 position = new Vector3(handler); + position.modifyPositionFromSide(dir); + TileEntity outputConductor = position.getTileEntity(handler.getWorldObj()); + IElectricityNetwork electricityNetwork = ElectricityNetworkHelper.getNetworkFromTileEntity(outputConductor, dir); + if(electricityNetwork != null && !networks.containsValue(electricityNetwork)) { + networks.put(dir, electricityNetwork); + } + } + } + + return networks; + } + +} diff --git a/src/main/java/universalelectricity/prefab/tile/TileEntityAdvanced.java b/src/main/java/universalelectricity/prefab/tile/TileEntityAdvanced.java new file mode 100644 index 0000000..6bd2c3e --- /dev/null +++ b/src/main/java/universalelectricity/prefab/tile/TileEntityAdvanced.java @@ -0,0 +1,42 @@ +package universalelectricity.prefab.tile; + +import net.minecraft.block.Block; +import net.minecraft.tileentity.TileEntity; + +public abstract class TileEntityAdvanced extends TileEntity { + + protected long ticks = 0L; + + @Override + public void updateEntity() { + if(this.ticks == 0L) { + this.initiate(); + } + + if(this.ticks >= Long.MAX_VALUE) { + this.ticks = 1L; + } + + ++this.ticks; + } + + public void initiate() {} + + @Override + public int getBlockMetadata() { + if(this.blockMetadata == -1) { + this.blockMetadata = this.worldObj.getBlockMetadata(this.xCoord, this.yCoord, this.zCoord); + } + + return this.blockMetadata; + } + + @Override + public Block getBlockType() { + if(this.blockType == null) { + this.blockType = this.worldObj.getBlock(this.xCoord, this.yCoord, this.zCoord); + } + + return this.blockType; + } +} diff --git a/src/main/java/universalelectricity/prefab/tile/TileEntityConductor.java b/src/main/java/universalelectricity/prefab/tile/TileEntityConductor.java new file mode 100644 index 0000000..1fcd78a --- /dev/null +++ b/src/main/java/universalelectricity/prefab/tile/TileEntityConductor.java @@ -0,0 +1,143 @@ +package universalelectricity.prefab.tile; + +import java.util.Arrays; + +import cpw.mods.fml.relauncher.Side; +import cpw.mods.fml.relauncher.SideOnly; +import net.minecraft.nbt.NBTTagCompound; +import net.minecraft.network.NetworkManager; +import net.minecraft.network.Packet; +import net.minecraft.network.play.server.S35PacketUpdateTileEntity; +import net.minecraft.tileentity.TileEntity; +import net.minecraft.util.AxisAlignedBB; +import net.minecraftforge.common.util.ForgeDirection; +import universalelectricity.compat.CompatHandler; +import universalelectricity.core.block.IConductor; +import universalelectricity.core.block.INetworkProvider; +import universalelectricity.core.block.ISelfDriven; +import universalelectricity.core.electricity.ElectricityNetwork; +import universalelectricity.core.electricity.ElectricityNetworkHelper; +import universalelectricity.core.electricity.IElectricityNetwork; +import universalelectricity.core.vector.Vector3; +import universalelectricity.core.vector.VectorHelper; + +public abstract class TileEntityConductor extends TileEntityAdvanced implements IConductor { + + private IElectricityNetwork network; + public boolean[] visuallyConnected = new boolean[]{false, false, false, false, false, false}; + public TileEntity[] connectedBlocks = new TileEntity[]{null, null, null, null, null, null}; + protected String channel = ""; + + + public void updateConnection(TileEntity tileEntity, ForgeDirection side) { + if(!this.worldObj.isRemote) { + if(ElectricityNetworkHelper.canConnect(tileEntity, side.getOpposite(), this)) { + this.connectedBlocks[side.ordinal()] = tileEntity; + this.visuallyConnected[side.ordinal()] = true; + if(tileEntity.getClass() == this.getClass() && tileEntity instanceof INetworkProvider) { + this.getNetwork().mergeConnection(((INetworkProvider)tileEntity).getNetwork()); + } else if (!(tileEntity instanceof ISelfDriven)) { + CompatHandler.registerTile(tileEntity); + } + + return; + } + + if(this.connectedBlocks[side.ordinal()] != null) { + this.getNetwork().stopProducing(this.connectedBlocks[side.ordinal()]); + this.getNetwork().stopRequesting(this.connectedBlocks[side.ordinal()]); + } + + this.connectedBlocks[side.ordinal()] = null; + this.visuallyConnected[side.ordinal()] = false; + } + + } + + @Override + public void onDataPacket(NetworkManager net, S35PacketUpdateTileEntity pkt) { + if(this.worldObj.isRemote) { + NBTTagCompound nbt = pkt.func_148857_g(); + this.visuallyConnected[0] = nbt.getBoolean("bottom"); + this.visuallyConnected[1] = nbt.getBoolean("top"); + this.visuallyConnected[2] = nbt.getBoolean("back"); + this.visuallyConnected[3] = nbt.getBoolean("front"); + this.visuallyConnected[4] = nbt.getBoolean("left"); + this.visuallyConnected[5] = nbt.getBoolean("right"); + } + } + + public void initiate() { + this.updateAdjacentConnections(); + } + + @Override + public void invalidate() { + if(!this.worldObj.isRemote) { + this.getNetwork().splitNetwork(this); + } + + super.invalidate(); + } + + @Override + public void updateEntity() { + super.updateEntity(); + if(!this.worldObj.isRemote && super.ticks % 300L == 0L) { + this.updateAdjacentConnections(); + } + + } + + public void updateAdjacentConnections() { + if(this.worldObj != null && !this.worldObj.isRemote) { + boolean[] previousConnections = (boolean[])this.visuallyConnected.clone(); + + for(byte i = 0; i < 6; ++i) { + this.updateConnection(VectorHelper.getTileEntityFromSide(this.worldObj, new Vector3(this), ForgeDirection.getOrientation(i)), ForgeDirection.getOrientation(i)); + } + + if(!Arrays.equals(previousConnections, this.visuallyConnected)) { + this.worldObj.markBlockForUpdate(this.xCoord, this.yCoord, this.zCoord); + } + } + + } + + @Override + public Packet getDescriptionPacket() { + NBTTagCompound nbt = new NBTTagCompound(); + nbt.setBoolean("bottom", this.visuallyConnected[0]); + nbt.setBoolean("top", this.visuallyConnected[1]); + nbt.setBoolean("back", this.visuallyConnected[2]); + nbt.setBoolean("front", this.visuallyConnected[3]); + nbt.setBoolean("left", this.visuallyConnected[4]); + nbt.setBoolean("right", this.visuallyConnected[5]); + return new S35PacketUpdateTileEntity(this.xCoord, this.yCoord, this.zCoord, this.getBlockMetadata(), nbt); + } + + public IElectricityNetwork getNetwork() { + if(this.network == null) { + this.setNetwork(new ElectricityNetwork(new IConductor[]{this})); + } + + return this.network; + } + + public void setNetwork(IElectricityNetwork network) { + this.network = network; + } + + public TileEntity[] getAdjacentConnections() { + return this.connectedBlocks; + } + + public boolean canConnect(ForgeDirection direction) { + return true; + } + + @SideOnly(Side.CLIENT) + public AxisAlignedBB getRenderBoundingBox() { + return AxisAlignedBB.getBoundingBox((double)this.xCoord, (double)this.yCoord, (double)this.zCoord, (double)(this.xCoord + 1), (double)(this.yCoord + 1), (double)(this.zCoord + 1)); + } +} diff --git a/src/main/java/universalelectricity/prefab/tile/TileEntityDisableable.java b/src/main/java/universalelectricity/prefab/tile/TileEntityDisableable.java new file mode 100644 index 0000000..1f9b3c9 --- /dev/null +++ b/src/main/java/universalelectricity/prefab/tile/TileEntityDisableable.java @@ -0,0 +1,27 @@ +package universalelectricity.prefab.tile; + +import universalelectricity.prefab.implement.IDisableable; + +public abstract class TileEntityDisableable extends TileEntityAdvanced implements IDisableable { + + protected int disabledTicks = 0; + + @Override + public void updateEntity() { + super.updateEntity(); + if(this.disabledTicks > 0) { + --this.disabledTicks; + this.whileDisable(); + } + } + + protected void whileDisable() {} + + public void onDisable(int duration) { + this.disabledTicks = duration; + } + + public boolean isDisabled() { + return this.disabledTicks > 0; + } +} diff --git a/src/main/java/universalelectricity/prefab/tile/TileEntityElectrical.java b/src/main/java/universalelectricity/prefab/tile/TileEntityElectrical.java new file mode 100644 index 0000000..9771f5b --- /dev/null +++ b/src/main/java/universalelectricity/prefab/tile/TileEntityElectrical.java @@ -0,0 +1,19 @@ +package universalelectricity.prefab.tile; + +import universalelectricity.core.block.IConnector; +import universalelectricity.core.block.IVoltage; +import universalelectricity.core.electricity.ElectricityNetworkHelper; +import universalelectricity.prefab.tile.TileEntityDisableable; + +public abstract class TileEntityElectrical extends TileEntityDisableable implements IConnector, IVoltage { + + public double getVoltage() { + return 120.0D; + } + + @Override + public void invalidate() { + ElectricityNetworkHelper.invalidate(this); + super.invalidate(); + } +} diff --git a/src/main/java/universalelectricity/prefab/tile/TileEntityElectricityRunnable.java b/src/main/java/universalelectricity/prefab/tile/TileEntityElectricityRunnable.java new file mode 100644 index 0000000..9892d70 --- /dev/null +++ b/src/main/java/universalelectricity/prefab/tile/TileEntityElectricityRunnable.java @@ -0,0 +1,50 @@ +package universalelectricity.prefab.tile; + +import java.util.EnumSet; +import net.minecraft.entity.Entity; +import net.minecraftforge.common.util.ForgeDirection; +import universalelectricity.core.UniversalElectricity; +import universalelectricity.core.electricity.ElectricityNetworkHelper; +import universalelectricity.core.electricity.ElectricityPack; + +public abstract class TileEntityElectricityRunnable extends TileEntityElectrical { + + public double prevWatts; + public double wattsReceived = 0.0D; + + @Override + public void updateEntity() { + super.updateEntity(); + this.prevWatts = this.wattsReceived; + if(!this.worldObj.isRemote) { + if(!this.isDisabled()) { + ElectricityPack electricityPack = ElectricityNetworkHelper.consumeFromMultipleSides(this, this.getConsumingSides(), this.getRequest()); + this.onReceive(electricityPack); + } else { + ElectricityNetworkHelper.consumeFromMultipleSides(this, new ElectricityPack()); + } + } + + } + + protected EnumSet getConsumingSides() { + return ElectricityNetworkHelper.getDirections(this); + } + + public ElectricityPack getRequest() { + return new ElectricityPack(); + } + + public void onReceive(ElectricityPack electricityPack) { + if(UniversalElectricity.isVoltageSensitive && electricityPack.voltage > this.getVoltage()) { + this.worldObj.createExplosion((Entity)null, (double)this.xCoord, (double)this.yCoord, (double)this.zCoord, 1.5F, true); + } else { + this.wattsReceived = Math.min(this.wattsReceived + electricityPack.getWatts(), this.getWattBuffer()); + } + } + + public double getWattBuffer() { + return this.getRequest().getWatts() * 2.0D; + } + +} diff --git a/src/main/java/universalelectricity/prefab/tile/TileEntityElectricityStorage.java b/src/main/java/universalelectricity/prefab/tile/TileEntityElectricityStorage.java new file mode 100644 index 0000000..77630ef --- /dev/null +++ b/src/main/java/universalelectricity/prefab/tile/TileEntityElectricityStorage.java @@ -0,0 +1,81 @@ +package universalelectricity.prefab.tile; + +import java.util.EnumSet; + +import net.minecraft.entity.Entity; +import net.minecraft.nbt.NBTTagCompound; +import net.minecraftforge.common.util.ForgeDirection; +import universalelectricity.core.UniversalElectricity; +import universalelectricity.core.block.IElectricityStorage; +import universalelectricity.core.electricity.ElectricityNetworkHelper; +import universalelectricity.core.electricity.ElectricityPack; +import universalelectricity.prefab.tile.TileEntityElectrical; + +public abstract class TileEntityElectricityStorage extends TileEntityElectrical implements IElectricityStorage { + + private double joules = 0.0D; + public double prevJoules = 0.0D; + + @Override + public void updateEntity() { + super.updateEntity(); + this.prevJoules = this.joules; + if(!this.worldObj.isRemote) { + if(!this.isDisabled()) { + ElectricityPack electricityPack = ElectricityNetworkHelper.consumeFromMultipleSides(this, this.getConsumingSides(), this.getRequest()); + this.onReceive(electricityPack); + } else { + ElectricityNetworkHelper.consumeFromMultipleSides(this, new ElectricityPack()); + } + } + + } + + protected EnumSet getConsumingSides() { + return ElectricityNetworkHelper.getDirections(this); + } + + public ElectricityPack getRequest() { + return new ElectricityPack((this.getMaxJoules() - this.getJoules()) / this.getVoltage(), this.getVoltage()); + } + + public void onReceive(ElectricityPack electricityPack) { + if(UniversalElectricity.isVoltageSensitive && electricityPack.voltage > this.getVoltage()) { + this.worldObj.createExplosion((Entity)null, (double)this.xCoord, (double)this.yCoord, (double)this.zCoord, 1.5F, true); + } else { + this.setJoules(this.getJoules() + electricityPack.getWatts()); + } + } + + @Override + public void readFromNBT(NBTTagCompound par1NBTTagCompound) { + super.readFromNBT(par1NBTTagCompound); + this.joules = par1NBTTagCompound.getDouble("joules"); + } + + @Override + public void writeToNBT(NBTTagCompound par1NBTTagCompound) { + super.writeToNBT(par1NBTTagCompound); + par1NBTTagCompound.setDouble("joules", this.joules); + } + + public double getJoules() { + return this.joules; + } + + public void setJoules(double joules) { + this.joules = Math.max(Math.min(joules, this.getMaxJoules()), 0.0D); + } + + public double transferEnergyToAcceptor(ForgeDirection side, double amount) { + if (!canReceiveEnergy(side)) return 0; + double toUse = Math.min(getMaxEnergy()-getEnergy(), amount); + setEnergy(toUse + getEnergy()); + return toUse; + } + + public boolean canReceiveEnergy(ForgeDirection side) { + return getConsumingSides().contains(side); + } + +} diff --git a/src/main/java/universalelectricity/prefab/vector/Region2.java b/src/main/java/universalelectricity/prefab/vector/Region2.java new file mode 100644 index 0000000..8becb39 --- /dev/null +++ b/src/main/java/universalelectricity/prefab/vector/Region2.java @@ -0,0 +1,27 @@ +package universalelectricity.prefab.vector; + +import universalelectricity.core.vector.Vector2; + +public class Region2 { + + public Vector2 min; + public Vector2 max; + + + public Region2() { + this(new Vector2(), new Vector2()); + } + + public Region2(Vector2 min, Vector2 max) { + this.min = min; + this.max = max; + } + + public boolean isIn(Vector2 point) { + return point.x > this.min.x && point.x < this.max.x && point.y > this.min.y && point.y < this.max.y; + } + + public boolean isIn(Region2 region) { + return region.max.x > this.min.x && region.min.x < this.max.x?region.max.y > this.min.y && region.min.y < this.max.y:false; + } +} diff --git a/src/main/java/universalelectricity/prefab/vector/Region3.java b/src/main/java/universalelectricity/prefab/vector/Region3.java new file mode 100644 index 0000000..c52740a --- /dev/null +++ b/src/main/java/universalelectricity/prefab/vector/Region3.java @@ -0,0 +1,94 @@ +package universalelectricity.prefab.vector; + +import java.util.ArrayList; +import java.util.List; +import net.minecraft.entity.Entity; +import net.minecraft.util.AxisAlignedBB; +import net.minecraft.world.World; +import universalelectricity.core.vector.Vector3; +import universalelectricity.prefab.vector.Region2; + +public class Region3 { + + public Vector3 min; + public Vector3 max; + + + public Region3() { + this(new Vector3(), new Vector3()); + } + + public Region3(Vector3 min, Vector3 max) { + this.min = min; + this.max = max; + } + + public Region3(AxisAlignedBB aabb) { + this.min = new Vector3(aabb.minX, aabb.minY, aabb.minZ); + this.max = new Vector3(aabb.maxX, aabb.maxY, aabb.maxZ); + } + + public AxisAlignedBB toAABB() { + return AxisAlignedBB.getBoundingBox(this.min.x, this.min.y, this.min.z, this.max.x, this.max.y, this.max.z); + } + + public Region2 toRegion2() { + return new Region2(this.min.toVector2(), this.max.toVector2()); + } + + public boolean isIn(Vector3 point) { + return point.x > this.min.x && point.x < this.max.x && point.y > this.min.y && point.y < this.max.y && point.z > this.min.z && point.z < this.max.z; + } + + public boolean isIn(Region3 region) { + return region.max.x > this.min.x && region.min.x < this.max.x?(region.max.y > this.min.y && region.min.y < this.max.y?region.max.z > this.min.z && region.min.z < this.max.z:false):false; + } + + public void expand(Vector3 difference) { + this.min.subtract(difference); + this.max.add(difference); + } + + public List getVectors() { + ArrayList vectors = new ArrayList(); + + for(int x = this.min.intX(); x < this.max.intX(); ++x) { + for(int y = this.min.intY(); x < this.max.intY(); ++y) { + for(int z = this.min.intZ(); x < this.max.intZ(); ++z) { + vectors.add(new Vector3((double)x, (double)y, (double)z)); + } + } + } + + return vectors; + } + + public List getVectors(Vector3 center, int radius) { + ArrayList vectors = new ArrayList(); + + for(int x = this.min.intX(); x < this.max.intX(); ++x) { + for(int y = this.min.intY(); x < this.max.intY(); ++y) { + for(int z = this.min.intZ(); x < this.max.intZ(); ++z) { + Vector3 vector3 = new Vector3((double)x, (double)y, (double)z); + if(center.distanceTo(vector3) <= (double)radius) { + vectors.add(vector3); + } + } + } + } + + return vectors; + } + + public List getEntities(World world, Class entityClass) { + return world.getEntitiesWithinAABB(entityClass, this.toAABB()); + } + + public List getEntitiesExlude(World world, Entity entity) { + return world.getEntitiesWithinAABBExcludingEntity(entity, this.toAABB()); + } + + public List getEntities(World world) { + return this.getEntities(world, Entity.class); + } +}