diff --git a/.clang-format b/.clang-format new file mode 100644 index 0000000..d48bed8 --- /dev/null +++ b/.clang-format @@ -0,0 +1,130 @@ +--- +AccessModifierOffset: 0 +AlignAfterOpenBracket: BlockIndent +AlignArrayOfStructures: None +AlignConsecutiveAssignments: None +AlignConsecutiveMacros: None +AlignConsecutiveBitFields: None +AlignConsecutiveDeclarations: None +AlignEscapedNewlines: DontAlign +AlignOperands: DontAlign +AlignTrailingComments: false +AllowAllArgumentsOnNextLine: true +AllowAllParametersOfDeclarationOnNextLine: true +AllowShortBlocksOnASingleLine: Empty +AllowShortCaseLabelsOnASingleLine: false +AllowShortEnumsOnASingleLine: false +AllowShortFunctionsOnASingleLine: Empty +AllowShortIfStatementsOnASingleLine: Never +AllowShortLambdasOnASingleLine: All +AllowShortLoopsOnASingleLine: false +AlwaysBreakAfterReturnType: None +AlwaysBreakBeforeMultilineStrings: true +AlwaysBreakTemplateDeclarations: MultiLine +AttributeMacros: [] +BinPackArguments: false +BinPackParameters: false +BitFieldColonSpacing: After +BraceWrapping: + AfterCaseLabel: false + AfterClass: false + AfterControlStatement: Never + AfterEnum: false + AfterFunction: false + AfterNamespace: false + AfterStruct: false + AfterUnion: false + AfterExternBlock: false + BeforeCatch: false + BeforeElse: false + BeforeLambdaBody: false + BeforeWhile: false + IndentBraces: false + SplitEmptyFunction: false + SplitEmptyRecord: false + SplitEmptyNamespace: false +BreakAfterJavaFieldAnnotations: true +#BreakArrays: false +BreakBeforeBinaryOperators: All +BreakBeforeBraces: Custom +BreakBeforeConceptDeclarations: true +BreakBeforeTernaryOperators: true +BreakConstructorInitializers: AfterColon +BreakInheritanceList: AfterColon +BreakStringLiterals: true +ColumnLimit: 90 +CompactNamespaces: false +ConstructorInitializerIndentWidth: 4 +ContinuationIndentWidth: 4 +Cpp11BracedListStyle: false +DeriveLineEnding: false +DerivePointerAlignment: false +DisableFormat: false # wtf +EmptyLineAfterAccessModifier: Never +EmptyLineBeforeAccessModifier: Always +ExperimentalAutoDetectBinPacking: false +FixNamespaceComments: false +ForEachMacros: ["BOOST_FOREACH"] +IfMacros: [] +IncludeBlocks: Regroup +IndentAccessModifiers: false +IndentCaseBlocks: false +IndentCaseLabels: true +IndentExternBlock: Indent +IndentGotoLabels: true +IndentPPDirectives: BeforeHash +#IndentRequiresClause: false +IndentWidth: 4 +IndentWrappedFunctionNames: false +#InsertBraces: false +InsertTrailingCommas: Wrapped +JavaImportGroups: ["java"] +JavaScriptQuotes: Double +JavaScriptWrapImports: true +KeepEmptyLinesAtTheStartOfBlocks: false +LambdaBodyIndentation: OuterScope +MaxEmptyLinesToKeep: 1 +NamespaceIndentation: All +PackConstructorInitializers: NextLine +PointerAlignment: Left +QualifierAlignment: Left +ReferenceAlignment: Left +ReflowComments: true +#RemoveSemicolon: true +#RequiresClausePosition: OwnLine +#RequiresExpressionIndentation: OuterScope +SeparateDefinitionBlocks: Always +SortIncludes: CaseInsensitive +SortJavaStaticImport: Before +SortUsingDeclarations: true +SpaceAfterCStyleCast: true +SpaceAfterLogicalNot: false +SpaceAfterTemplateKeyword: false +SpaceAroundPointerQualifiers: After +SpaceBeforeAssignmentOperators: true +SpaceBeforeCaseColon: false +SpaceBeforeCpp11BracedList: false +SpaceBeforeCtorInitializerColon: false +SpaceBeforeInheritanceColon: false +SpaceBeforeParens: ControlStatementsExceptControlMacros +SpaceBeforeRangeBasedForLoopColon: true +SpaceBeforeSquareBrackets: false +SpaceInEmptyBlock: false +SpaceInEmptyParentheses: false +SpacesInAngles: Never +SpacesInCStyleCastParentheses: false +SpacesInConditionalStatement: false +SpacesInContainerLiterals: false +SpacesInLineCommentPrefix: + Minimum: 0 + Maximum: -1 +SpacesInParentheses: false +SpacesInSquareBrackets: false +Standard: c++20 +StatementAttributeLikeMacros: [] +StatementMacros: [] +TabWidth: 4 +TypenameMacros: [] +UseCRLF: false # wtf +UseTab: Never +WhitespaceSensitiveMacros: ["BOOST_PP_STRINGSIZE"] diff --git a/.gitignore b/.gitignore index 8d16946..f47e0ea 100644 --- a/.gitignore +++ b/.gitignore @@ -1,4 +1,8 @@ +.settings +.project +.classpath .gradle .idea +bin build run diff --git a/build.gradle b/build.gradle index 585fd0f..1485b83 100644 --- a/build.gradle +++ b/build.gradle @@ -24,8 +24,8 @@ sourceCompatibility = JavaVersion.VERSION_1_8 targetCompatibility = JavaVersion.VERSION_1_8 version = "1.0" -group= "modgroup" -archivesBaseName = "modid" +group= "net.anvilcraft" +archivesBaseName = "pccompat" minecraft { version = "1.7.10-10.13.4.1614-1.7.10" @@ -34,10 +34,17 @@ minecraft { repositories { maven { url = "https://maven.tilera.xyz" } + maven { + url = "https://s3.tilera.xyz/cdn/minecraft/libs/" + metadataSources { artifact() } + } } dependencies { - + implementation "covers1624:PowerConverters:1.7.10-2.11:deobf" + implementation "cofh:CoFHCore:[1.7.10]3.1.4-329:dev" + implementation "universalelectricity:universalelectricity:5.2.2:deobf" + implementation "universalelectricity:basiccomponents:2.0.1:deobf" } processResources { @@ -85,4 +92,4 @@ publishing { mavenLocal() } } -} \ No newline at end of file +} diff --git a/src/main/java/net/anvilcraft/pccompat/PCCBlocks.java b/src/main/java/net/anvilcraft/pccompat/PCCBlocks.java new file mode 100644 index 0000000..1dd9e6a --- /dev/null +++ b/src/main/java/net/anvilcraft/pccompat/PCCBlocks.java @@ -0,0 +1,19 @@ +package net.anvilcraft.pccompat; + +import cpw.mods.fml.common.registry.GameRegistry; +import net.anvilcraft.pccompat.blocks.BlockPowerConverterUniversalElectricity; +import net.anvilcraft.pccompat.items.ItemBlockPowerConverterUniversalElectricity; +import net.minecraft.block.Block; + +public class PCCBlocks { + public static Block powerConverterUniversalElectricity; + + public static void register() { + GameRegistry.registerBlock( + powerConverterUniversalElectricity + = new BlockPowerConverterUniversalElectricity(), + ItemBlockPowerConverterUniversalElectricity.class, + "power_converter_universal_electrictity" + ); + } +} diff --git a/src/main/java/net/anvilcraft/pccompat/PCCompat.java b/src/main/java/net/anvilcraft/pccompat/PCCompat.java new file mode 100644 index 0000000..670805c --- /dev/null +++ b/src/main/java/net/anvilcraft/pccompat/PCCompat.java @@ -0,0 +1,37 @@ +package net.anvilcraft.pccompat; + +import covers1624.powerconverters.api.registry.PowerSystemRegistry; +import covers1624.powerconverters.api.registry.PowerSystemRegistry.PowerSystem; +import cpw.mods.fml.common.Mod; +import cpw.mods.fml.common.event.FMLPreInitializationEvent; +import cpw.mods.fml.common.registry.GameRegistry; +import net.anvilcraft.pccompat.tiles.TileEntityUniversalElectricityConsumer; +import net.anvilcraft.pccompat.tiles.TileEntityUniversalElectricityProducer; + +@Mod(modid = "pccompat", name = "PC Compat", version = "0.1.0") +public class PCCompat { + public static PowerSystem universalElectricityPowerSystem; + + @Mod.EventHandler + public static void preInit(FMLPreInitializationEvent ev) { + PowerSystemRegistry.registerPowerSystem( + universalElectricityPowerSystem = new PowerSystem( + "Universal Electricity", + "UE", + 2500, + new String[] { "LV", "MV", "HV", "EV" }, + new int[] { 60, 120, 240, 480 }, + "W" + ) + ); + + GameRegistry.registerTileEntity( + TileEntityUniversalElectricityConsumer.class, "universal_electricity_consumer" + ); + GameRegistry.registerTileEntity( + TileEntityUniversalElectricityProducer.class, "universal_electricity_producer" + ); + + PCCBlocks.register(); + } +} diff --git a/src/main/java/net/anvilcraft/pccompat/blocks/BlockPowerConverterUniversalElectricity.java b/src/main/java/net/anvilcraft/pccompat/blocks/BlockPowerConverterUniversalElectricity.java new file mode 100644 index 0000000..330b9a7 --- /dev/null +++ b/src/main/java/net/anvilcraft/pccompat/blocks/BlockPowerConverterUniversalElectricity.java @@ -0,0 +1,56 @@ +package net.anvilcraft.pccompat.blocks; + +import covers1624.powerconverters.block.BlockPowerConverter; +import covers1624.powerconverters.gui.PCCreativeTab; +import net.anvilcraft.pccompat.tiles.TileEntityUniversalElectricityConsumer; +import net.anvilcraft.pccompat.tiles.TileEntityUniversalElectricityProducer; +import net.minecraft.client.renderer.texture.IIconRegister; +import net.minecraft.tileentity.TileEntity; +import net.minecraft.util.IIcon; +import net.minecraft.world.World; + +public class BlockPowerConverterUniversalElectricity extends BlockPowerConverter { + public IIcon[] icons; + + public BlockPowerConverterUniversalElectricity() { + super(8); // 4 Consumers, 4 Producers + this.setCreativeTab(PCCreativeTab.tab); + } + + @Override + public void registerBlockIcons(IIconRegister reg) { + for (int i = 0; i < 16; i++) { + String state = i % 2 == 0 ? "off" : "on"; + String type = (i / 2) % 2 == 0 ? "producer" : "consumer"; + + String voltage; + + switch (i / 4) { + case 0: + voltage = "lv"; + break; + + case 1: + voltage = "mv"; + break; + + case 2: + voltage = "hv"; + break; + + default: + voltage = "ev"; + break; + } + + String texture_name = "pccompat:ue_" + voltage + "_" + type + "_" + state; + this._icons[i] = reg.registerIcon(texture_name); + } + } + + @Override + public TileEntity createNewTileEntity(World world, int meta) { + return meta % 2 != 0 ? new TileEntityUniversalElectricityProducer(meta / 2) + : new TileEntityUniversalElectricityConsumer(meta / 2); + } +} diff --git a/src/main/java/net/anvilcraft/pccompat/items/ItemBlockPowerConverterUniversalElectricity.java b/src/main/java/net/anvilcraft/pccompat/items/ItemBlockPowerConverterUniversalElectricity.java new file mode 100644 index 0000000..e34cef4 --- /dev/null +++ b/src/main/java/net/anvilcraft/pccompat/items/ItemBlockPowerConverterUniversalElectricity.java @@ -0,0 +1,38 @@ +package net.anvilcraft.pccompat.items; + +import java.util.List; +import java.util.stream.IntStream; + +import net.minecraft.block.Block; +import net.minecraft.creativetab.CreativeTabs; +import net.minecraft.item.Item; +import net.minecraft.item.ItemBlock; +import net.minecraft.item.ItemStack; + +public class ItemBlockPowerConverterUniversalElectricity extends ItemBlock { + public ItemBlockPowerConverterUniversalElectricity(Block block) { + super(block); + this.setHasSubtypes(true); + this.setMaxDamage(0); + } + + @Override + public int getMetadata(int meta) { + return meta; + } + + @Override + public String getUnlocalizedName(ItemStack stack) { + int meta = stack.getItemDamage(); + + return "pccompat:power_converter_ue_" + meta; + } + + @Override + @SuppressWarnings({ "unchecked", "rawtypes" }) + public void getSubItems(Item alec1, CreativeTabs alec2, List list) { + IntStream.range(0, 8) + .mapToObj((i) -> new ItemStack(this, 1, i)) + .forEach(list::add); + } +} diff --git a/src/main/java/net/anvilcraft/pccompat/tiles/TileEntityUniversalElectricityConsumer.java b/src/main/java/net/anvilcraft/pccompat/tiles/TileEntityUniversalElectricityConsumer.java new file mode 100644 index 0000000..39107ab --- /dev/null +++ b/src/main/java/net/anvilcraft/pccompat/tiles/TileEntityUniversalElectricityConsumer.java @@ -0,0 +1,72 @@ +package net.anvilcraft.pccompat.tiles; + +import covers1624.powerconverters.api.registry.PowerSystemRegistry.PowerSystem; +import covers1624.powerconverters.tile.main.TileEntityEnergyConsumer; +import net.anvilcraft.pccompat.PCCompat; +import net.minecraft.util.MathHelper; +import net.minecraftforge.common.util.ForgeDirection; +import universalelectricity.core.UniversalElectricity; +import universalelectricity.core.block.IConductor; +import universalelectricity.core.block.IConnector; +import universalelectricity.core.block.IVoltage; +import universalelectricity.core.electricity.ElectricityNetworkHelper; +import universalelectricity.core.electricity.ElectricityPack; + +public class TileEntityUniversalElectricityConsumer + extends TileEntityEnergyConsumer implements IConnector, IVoltage { + private double wattsLastTick; + + public TileEntityUniversalElectricityConsumer(int voltageNameIndex) { + super( + PCCompat.universalElectricityPowerSystem, voltageNameIndex, IConductor.class); + } + + // TODO: WTF + public TileEntityUniversalElectricityConsumer() { + this(0); + } + + @Override + public void updateEntity() { + super.updateEntity(); + + if (this.worldObj.isRemote) + return; + + double desiredWatts = this.getTotalEnergyDemand() / this.getPowerSystem().getScaleAmmount(); + + ElectricityPack powerRequested = new ElectricityPack(desiredWatts / this.getVoltage(), this.getVoltage()); + + ElectricityPack powerPack = ElectricityNetworkHelper.consumeFromMultipleSides(this, powerRequested); + + if (UniversalElectricity.isVoltageSensitive + && powerPack.voltage > this.getVoltage()) { + this.worldObj.setBlockToAir(this.xCoord, this.yCoord, this.zCoord); + this.worldObj.createExplosion( + null, this.xCoord + 0.5, this.yCoord + 0.5, this.zCoord + 0.5, 1f, true); + } + + double watts = powerPack.getWatts(); + + this.storeEnergy( + MathHelper.floor_double(watts * this.getPowerSystem().getScaleAmmount()), + false); + + this.wattsLastTick = watts; + } + + @Override + public boolean canConnect(ForgeDirection from) { + return true; + } + + @Override + public double getInputRate() { + return wattsLastTick; + } + + @Override + public double getVoltage() { + return this.getPowerSystem().getVoltageValues()[this.getVoltageIndex()]; + } +} diff --git a/src/main/java/net/anvilcraft/pccompat/tiles/TileEntityUniversalElectricityProducer.java b/src/main/java/net/anvilcraft/pccompat/tiles/TileEntityUniversalElectricityProducer.java new file mode 100644 index 0000000..ac3a1b0 --- /dev/null +++ b/src/main/java/net/anvilcraft/pccompat/tiles/TileEntityUniversalElectricityProducer.java @@ -0,0 +1,48 @@ +package net.anvilcraft.pccompat.tiles; + +import covers1624.powerconverters.tile.main.TileEntityEnergyProducer; +import net.anvilcraft.pccompat.PCCompat; +import net.minecraft.util.MathHelper; +import net.minecraftforge.common.util.ForgeDirection; +import universalelectricity.core.block.IConductor; +import universalelectricity.core.block.IConnector; +import universalelectricity.core.block.IVoltage; +import universalelectricity.core.electricity.ElectricityNetworkHelper; +import universalelectricity.core.electricity.ElectricityPack; + +public class TileEntityUniversalElectricityProducer + extends TileEntityEnergyProducer implements IConnector, IVoltage { + public TileEntityUniversalElectricityProducer(int voltageNameIndex) { + super( + PCCompat.universalElectricityPowerSystem, voltageNameIndex, IConductor.class + ); + } + + // TODO: WTF + public TileEntityUniversalElectricityProducer() { + this(0); + } + + @Override + public double getVoltage() { + return this.getPowerSystem().getVoltageValues()[this.getVoltageIndex()]; + } + + @Override + public boolean canConnect(ForgeDirection from) { + return true; + } + + @Override + public double produceEnergy(double energy) { + double watts = energy / this.getPowerSystem().getScaleAmmount(); + ElectricityPack powerRemaining + = ElectricityNetworkHelper.produceFromMultipleSides( + this, new ElectricityPack(watts / this.getVoltage(), this.getVoltage()) + ); + + return MathHelper.floor_double( + powerRemaining.getWatts() * this.getPowerSystem().getScaleAmmount() + ); + } +} diff --git a/src/main/resources/assets/pccompat/lang/en_US.lang b/src/main/resources/assets/pccompat/lang/en_US.lang new file mode 100644 index 0000000..3d755af --- /dev/null +++ b/src/main/resources/assets/pccompat/lang/en_US.lang @@ -0,0 +1,8 @@ +pccompat:power_converter_ue_0.name=UE 60V Consumer +pccompat:power_converter_ue_1.name=UE 60V Producer +pccompat:power_converter_ue_2.name=UE 120V Consumer +pccompat:power_converter_ue_3.name=UE 120V Producer +pccompat:power_converter_ue_4.name=UE 240V Consumer +pccompat:power_converter_ue_5.name=UE 240V Producer +pccompat:power_converter_ue_6.name=UE 480V Consumer +pccompat:power_converter_ue_7.name=UE 480V Producer diff --git a/src/main/resources/assets/pccompat/textures/blocks/ue_ev_consumer_off.png b/src/main/resources/assets/pccompat/textures/blocks/ue_ev_consumer_off.png new file mode 100644 index 0000000..14a0c91 Binary files /dev/null and b/src/main/resources/assets/pccompat/textures/blocks/ue_ev_consumer_off.png differ diff --git a/src/main/resources/assets/pccompat/textures/blocks/ue_ev_consumer_on.png b/src/main/resources/assets/pccompat/textures/blocks/ue_ev_consumer_on.png new file mode 100644 index 0000000..d0cfe0e Binary files /dev/null and b/src/main/resources/assets/pccompat/textures/blocks/ue_ev_consumer_on.png differ diff --git a/src/main/resources/assets/pccompat/textures/blocks/ue_ev_producer_off.png b/src/main/resources/assets/pccompat/textures/blocks/ue_ev_producer_off.png new file mode 100644 index 0000000..1f1bd4e Binary files /dev/null and b/src/main/resources/assets/pccompat/textures/blocks/ue_ev_producer_off.png differ diff --git a/src/main/resources/assets/pccompat/textures/blocks/ue_ev_producer_on.png b/src/main/resources/assets/pccompat/textures/blocks/ue_ev_producer_on.png new file mode 100644 index 0000000..e65ef64 Binary files /dev/null and b/src/main/resources/assets/pccompat/textures/blocks/ue_ev_producer_on.png differ diff --git a/src/main/resources/assets/pccompat/textures/blocks/ue_hv_consumer_off.png b/src/main/resources/assets/pccompat/textures/blocks/ue_hv_consumer_off.png new file mode 100644 index 0000000..1704438 Binary files /dev/null and b/src/main/resources/assets/pccompat/textures/blocks/ue_hv_consumer_off.png differ diff --git a/src/main/resources/assets/pccompat/textures/blocks/ue_hv_consumer_on.png b/src/main/resources/assets/pccompat/textures/blocks/ue_hv_consumer_on.png new file mode 100644 index 0000000..3b2592e Binary files /dev/null and b/src/main/resources/assets/pccompat/textures/blocks/ue_hv_consumer_on.png differ diff --git a/src/main/resources/assets/pccompat/textures/blocks/ue_hv_producer_off.png b/src/main/resources/assets/pccompat/textures/blocks/ue_hv_producer_off.png new file mode 100644 index 0000000..5836acf Binary files /dev/null and b/src/main/resources/assets/pccompat/textures/blocks/ue_hv_producer_off.png differ diff --git a/src/main/resources/assets/pccompat/textures/blocks/ue_hv_producer_on.png b/src/main/resources/assets/pccompat/textures/blocks/ue_hv_producer_on.png new file mode 100644 index 0000000..ff21143 Binary files /dev/null and b/src/main/resources/assets/pccompat/textures/blocks/ue_hv_producer_on.png differ diff --git a/src/main/resources/assets/pccompat/textures/blocks/ue_lv_consumer_off.png b/src/main/resources/assets/pccompat/textures/blocks/ue_lv_consumer_off.png new file mode 100644 index 0000000..670b81f Binary files /dev/null and b/src/main/resources/assets/pccompat/textures/blocks/ue_lv_consumer_off.png differ diff --git a/src/main/resources/assets/pccompat/textures/blocks/ue_lv_consumer_on.png b/src/main/resources/assets/pccompat/textures/blocks/ue_lv_consumer_on.png new file mode 100644 index 0000000..6201481 Binary files /dev/null and b/src/main/resources/assets/pccompat/textures/blocks/ue_lv_consumer_on.png differ diff --git a/src/main/resources/assets/pccompat/textures/blocks/ue_lv_producer_off.png b/src/main/resources/assets/pccompat/textures/blocks/ue_lv_producer_off.png new file mode 100644 index 0000000..06dd169 Binary files /dev/null and b/src/main/resources/assets/pccompat/textures/blocks/ue_lv_producer_off.png differ diff --git a/src/main/resources/assets/pccompat/textures/blocks/ue_lv_producer_on.png b/src/main/resources/assets/pccompat/textures/blocks/ue_lv_producer_on.png new file mode 100644 index 0000000..b671629 Binary files /dev/null and b/src/main/resources/assets/pccompat/textures/blocks/ue_lv_producer_on.png differ diff --git a/src/main/resources/assets/pccompat/textures/blocks/ue_mv_consumer_off.png b/src/main/resources/assets/pccompat/textures/blocks/ue_mv_consumer_off.png new file mode 100644 index 0000000..2f0317b Binary files /dev/null and b/src/main/resources/assets/pccompat/textures/blocks/ue_mv_consumer_off.png differ diff --git a/src/main/resources/assets/pccompat/textures/blocks/ue_mv_consumer_on.png b/src/main/resources/assets/pccompat/textures/blocks/ue_mv_consumer_on.png new file mode 100644 index 0000000..14bbfc8 Binary files /dev/null and b/src/main/resources/assets/pccompat/textures/blocks/ue_mv_consumer_on.png differ diff --git a/src/main/resources/assets/pccompat/textures/blocks/ue_mv_producer_off.png b/src/main/resources/assets/pccompat/textures/blocks/ue_mv_producer_off.png new file mode 100644 index 0000000..fa6cf35 Binary files /dev/null and b/src/main/resources/assets/pccompat/textures/blocks/ue_mv_producer_off.png differ diff --git a/src/main/resources/assets/pccompat/textures/blocks/ue_mv_producer_on.png b/src/main/resources/assets/pccompat/textures/blocks/ue_mv_producer_on.png new file mode 100644 index 0000000..b716687 Binary files /dev/null and b/src/main/resources/assets/pccompat/textures/blocks/ue_mv_producer_on.png differ