diff --git a/src/main/java/malte0811/industrialWires/IndustrialWires.java b/src/main/java/malte0811/industrialWires/IndustrialWires.java index 2bbd896..dbdb02f 100644 --- a/src/main/java/malte0811/industrialWires/IndustrialWires.java +++ b/src/main/java/malte0811/industrialWires/IndustrialWires.java @@ -17,6 +17,7 @@ */ package malte0811.industrialWires; +import blusunrize.immersiveengineering.ImmersiveEngineering; import blusunrize.immersiveengineering.api.MultiblockHandler; import malte0811.industrialWires.blocks.BlockIWBase; import malte0811.industrialWires.blocks.controlpanel.*; @@ -114,11 +115,23 @@ public class IndustrialWires { public static CommonProxy proxy; public static boolean hasIC2; public static boolean hasTechReborn; + public static boolean isOldIE; @EventHandler public void preInit(FMLPreInitializationEvent e) { hasIC2 = Loader.isModLoaded("ic2"); hasTechReborn = Loader.isModLoaded("techreborn"); + { + double ieThreshold = 12.74275; + String ieVer = ImmersiveEngineering.VERSION; + int firstDash = ieVer.indexOf('-'); + String end = ieVer.substring(firstDash+1); + String start = ieVer.substring(0, firstDash); + end = end.replaceAll("[^0-9]", ""); + start = start.replaceAll("[^0-9]", ""); + double ieVerDouble = Double.parseDouble(start+"."+end); + isOldIE = ieVerDouble tinCableList = Arrays.asList(tinCable.getMatchingStacks()); - for (int i = 0; i < 3; i++) - { - for (int j = 0; j < 3; j++) - { + for (int i = 0; i < 3; i++) { + for (int j = 0; j < 3; j++) { wireRecipes[0][3 * i + j] = new PositionedItemStack(tinCableList, 18 * i + xBase, 18 * j); } } @@ -147,20 +144,15 @@ public class ClientProxy extends CommonProxy { ItemIC2Coil.setLength(tmp, 9); wireRecipes[0][9] = new PositionedItemStack(tmp, 18 * 4 + xBase, 18); Random r = new Random(); - for (int i = 1; i < 3; i++) - { + for (int i = 1; i < 3; i++) { int lengthSum = 0; - for (int j1 = 0; j1 < 3; j1++) - { - for (int j2 = 0; j2 < 3; j2++) - { - if (r.nextBoolean()) - { + for (int j1 = 0; j1 < 3; j1++) { + for (int j2 = 0; j2 < 3; j2++) { + if (r.nextBoolean()) { // cable lengthSum++; wireRecipes[i][3 * j1 + j2] = new PositionedItemStack(tinCableList, 18 * j1 + xBase, 18 * j2); - } else - { + } else { // wire coil int length = r.nextInt(99) + 1; tmp = new ItemStack(IndustrialWires.coil); @@ -181,8 +173,7 @@ public class ClientProxy extends CommonProxy { new ManualPages.Text(m, "industrialwires.wires1"), new ManualPages.CraftingMulti(m, "industrialwires.wires2", (Object[]) wireRecipes) ); - if (IndustrialWires.mechConv != null) - { + if (IndustrialWires.mechConv != null) { m.addEntry("industrialwires.mechConv", "industrialwires", new ManualPages.Crafting(m, "industrialwires.mechConv0", new ItemStack(IndustrialWires.mechConv, 1, 1)), new ManualPages.Crafting(m, "industrialwires.mechConv1", new ItemStack(IndustrialWires.mechConv, 1, 2)), @@ -190,12 +181,12 @@ public class ClientProxy extends CommonProxy { ); } } - int oldLength = Config.IEConfig.Tools.earDefenders_SoundBlacklist.length; - Config.IEConfig.Tools.earDefenders_SoundBlacklist = - Arrays.copyOf(Config.IEConfig.Tools.earDefenders_SoundBlacklist, oldLength + 1); - Config.IEConfig.Tools.earDefenders_SoundBlacklist[oldLength] = TINNITUS_LOC.toString(); + int oldLength = Config.IEConfig.Tools.earDefenders_SoundBlacklist.length; + Config.IEConfig.Tools.earDefenders_SoundBlacklist = + Arrays.copyOf(Config.IEConfig.Tools.earDefenders_SoundBlacklist, oldLength + 1); + Config.IEConfig.Tools.earDefenders_SoundBlacklist[oldLength] = TINNITUS_LOC.toString(); - ClientUtils.mc().getItemColors().registerItemColorHandler((stack, pass) -> { + ClientUtils.mc().getItemColors().registerItemColorHandler((stack, pass) -> { if (pass == 1) { PanelComponent pc = ItemPanelComponent.componentFromStack(stack); if (pc != null) { @@ -205,13 +196,6 @@ public class ClientProxy extends CommonProxy { return ~0; }, IndustrialWires.panelComponent); - if (IndustrialWires.mechConv != null) { - m.addEntry("industrialwires.mechConv", "industrialwires", - new ManualPages.Crafting(m, "industrialwires.mechConv0", new ItemStack(IndustrialWires.mechConv, 1, 1)), - new ManualPages.Crafting(m, "industrialwires.mechConv1", new ItemStack(IndustrialWires.mechConv, 1, 2)), - new ManualPages.Crafting(m, "industrialwires.mechConv2", new ItemStack(IndustrialWires.mechConv, 1, 0)) - ); - } Config.manual_doubleA.put("iwJacobsUsage", IWConfig.HVStuff.jacobsUsageEU); Config.manual_int.put("iwKeysOnRing", IWConfig.maxKeysOnRing); m.addEntry("industrialwires.jacobs", IndustrialWires.MODID, @@ -266,16 +250,15 @@ public class ClientProxy extends CommonProxy { m.fontRenderer.setUnicodeFlag(true); m.entryRenderPre(); TextSplitter splitter = new TextSplitter(m.fontRenderer::getStringWidth, 16, 120, - (s)->new ManualPages.Text(m, s)); + (s) -> new ManualPages.Text(m, s)); splitter.addSpecialPage(0, 0, 6, - (s)->new ManualPageMultiblock(m, s, + (s) -> new ManualPageMultiblock(m, s, MultiblockMarx.INSTANCE)); splitter.split(text); m.entryRenderPost(); m.fontRenderer.setUnicodeFlag(uni); List marxEntry = splitter.toManualEntry(); m.addEntry("industrialwires.marx", IndustrialWires.MODID, marxEntry.toArray(new ManualPages[marxEntry.size()])); - } private static final ResourceLocation TINNITUS_LOC = new ResourceLocation(IndustrialWires.MODID, "tinnitus"); diff --git a/src/main/java/malte0811/industrialWires/hv/MultiblockMarx.java b/src/main/java/malte0811/industrialWires/hv/MultiblockMarx.java index 3963176..25fdf0e 100644 --- a/src/main/java/malte0811/industrialWires/hv/MultiblockMarx.java +++ b/src/main/java/malte0811/industrialWires/hv/MultiblockMarx.java @@ -27,7 +27,6 @@ import blusunrize.immersiveengineering.api.energy.wires.ImmersiveNetHandler.Conn import blusunrize.immersiveengineering.api.energy.wires.WireType; import blusunrize.immersiveengineering.common.IEContent; import blusunrize.immersiveengineering.common.blocks.metal.BlockTypes_Connector; -import com.google.common.collect.ImmutableSet; import malte0811.industrialWires.IndustrialWires; import malte0811.industrialWires.blocks.IWProperties; import malte0811.industrialWires.blocks.hv.BlockHVMultiblocks; @@ -35,11 +34,10 @@ import malte0811.industrialWires.blocks.hv.TileEntityMarx; import malte0811.industrialWires.client.ClientUtilsIW; import net.minecraft.block.state.IBlockState; import net.minecraft.client.Minecraft; -import net.minecraft.client.renderer.BlockRendererDispatcher; -import net.minecraft.client.renderer.BufferBuilder; -import net.minecraft.client.renderer.GlStateManager; -import net.minecraft.client.renderer.Tessellator; +import net.minecraft.client.renderer.*; +import net.minecraft.client.renderer.block.model.BakedQuad; import net.minecraft.client.renderer.block.model.IBakedModel; +import net.minecraft.client.renderer.texture.TextureAtlasSprite; import net.minecraft.client.renderer.vertex.DefaultVertexFormats; import net.minecraft.entity.player.EntityPlayer; import net.minecraft.init.Blocks; @@ -48,18 +46,18 @@ import net.minecraft.tileentity.TileEntity; import net.minecraft.util.BlockRenderLayer; import net.minecraft.util.EnumFacing; import net.minecraft.util.math.BlockPos; -import net.minecraft.util.math.Vec3d; import net.minecraft.world.World; import net.minecraftforge.client.ForgeHooksClient; -import net.minecraftforge.common.property.IExtendedBlockState; +import net.minecraftforge.fml.relauncher.Side; +import net.minecraftforge.fml.relauncher.SideOnly; import org.lwjgl.opengl.GL11; +import java.util.List; import java.util.Set; import java.util.function.BiPredicate; import java.util.function.Function; import java.util.function.Predicate; -import static blusunrize.immersiveengineering.api.ApiUtils.getConnectionCatenary; import static blusunrize.immersiveengineering.api.IEProperties.*; import static blusunrize.immersiveengineering.common.IEContent.*; import static blusunrize.immersiveengineering.common.blocks.BlockTypes_MetalsIE.STEEL; @@ -390,15 +388,51 @@ public class MultiblockMarx implements IMultiblock { @Override public boolean overwriteBlockRender(ItemStack stack, int iterator) { IBlockState here = getBlockstateFromStack(-1, stack); - if (here!=null) { + if (stack == hvRel1Dummy) { + //Based on ClientUtils.tessellateConnection + Tessellator tessellator = Tessellator.getInstance(); + BufferBuilder buffer = tessellator.getBuffer(); + buffer.begin(GL11.GL_QUADS, DefaultVertexFormats.POSITION_TEX_COLOR); + double radius = WireType.STEEL.getRenderDiameter()/2; + int c = WireType.STEEL.getColour(null); + int[] rgba = { + c&255, + (c>>8)&255, + (c>>16)&255, + (c>>24)&255 + }; + TextureAtlasSprite tex = WireType.STEEL.getIcon(null); + double uMin = tex.getMinU(); + double uMax = tex.getMaxU(); + double vMin = tex.getMinV(); + double vMax = tex.getMaxV(); + buffer.setTranslation(.125, .5, .5); + buffer.pos(- radius, 0, 0).tex(uMin, vMin).color(rgba[0], rgba[1], rgba[2], 255).endVertex(); + buffer.pos(- radius, 1, 0).tex(uMax, vMin).color(rgba[0], rgba[1], rgba[2], 255).endVertex(); + buffer.pos(+ radius, 1, 0).tex(uMax, vMax).color(rgba[0], rgba[1], rgba[2], 255).endVertex(); + buffer.pos(+ radius, 0, 0).tex(uMin, vMax).color(rgba[0], rgba[1], rgba[2], 255).endVertex(); + + buffer.pos(- radius, 1, 0).tex(uMax, vMin).color(rgba[0], rgba[1], rgba[2], 255).endVertex(); + buffer.pos(- radius, 0, 0).tex(uMin, vMin).color(rgba[0], rgba[1], rgba[2], 255).endVertex(); + buffer.pos(+ radius, 0, 0).tex(uMin, vMax).color(rgba[0], rgba[1], rgba[2], 255).endVertex(); + buffer.pos(+ radius, 1, 0).tex(uMax, vMax).color(rgba[0], rgba[1], rgba[2], 255).endVertex(); + + + buffer.pos(0, 0, - radius).tex(uMin, vMin).color(rgba[0], rgba[1], rgba[2], 255).endVertex(); + buffer.pos(0, 1, - radius).tex(uMax, vMin).color(rgba[0], rgba[1], rgba[2], 255).endVertex(); + buffer.pos(0, 1, + radius).tex(uMax, vMax).color(rgba[0], rgba[1], rgba[2], 255).endVertex(); + buffer.pos(0, 0, + radius).tex(uMin, vMax).color(rgba[0], rgba[1], rgba[2], 255).endVertex(); + + buffer.pos(0, 1, - radius).tex(uMax, vMin).color(rgba[0], rgba[1], rgba[2], 255).endVertex(); + buffer.pos(0, 0, - radius).tex(uMin, vMin).color(rgba[0], rgba[1], rgba[2], 255).endVertex(); + buffer.pos(0, 0, + radius).tex(uMin, vMax).color(rgba[0], rgba[1], rgba[2], 255).endVertex(); + buffer.pos(0, 1, + radius).tex(uMax, vMax).color(rgba[0], rgba[1], rgba[2], 255).endVertex(); + buffer.setTranslation(0, 0, 0); + tessellator.draw(); + } + if (here!=null&&IndustrialWires.isOldIE) { BlockRendererDispatcher dispatcher = Minecraft.getMinecraft().getBlockRendererDispatcher(); IBakedModel model = dispatcher.getModelForState(here); - if (stack == hvRel1Dummy && here instanceof IExtendedBlockState) { - Connection up = new Connection(BlockPos.ORIGIN, BlockPos.ORIGIN.down(), WireType.STEEL, 1); - up.catenaryVertices = getConnectionCatenary(up, new Vec3d(.125, .5, .5), - new Vec3d(.125, 1.5, .5)); - here = ((IExtendedBlockState) here).withProperty(CONNECTIONS, ImmutableSet.of(up)); - } GlStateManager.disableBlend(); ForgeHooksClient.setRenderLayer(BlockRenderLayer.SOLID); Tessellator tessellator = Tessellator.getInstance(); @@ -419,12 +453,41 @@ public class MultiblockMarx implements IMultiblock { } @Override + @SideOnly(Side.CLIENT) public boolean canRenderFormedStructure() { - return false; + return true; } + private List bottom = null; + private List stage = null; + private List top = null; @Override + @SideOnly(Side.CLIENT) public void renderFormedStructure() { - + BlockRendererDispatcher disp = Minecraft.getMinecraft().getBlockRendererDispatcher(); + if (bottom==null) { + IBlockState base = IndustrialWires.hvMultiblocks.getStateFromMeta(0); + BlockModelShapes shapes = disp.getBlockModelShapes(); + base = base.withProperty(IWProperties.MARX_TYPE, BOTTOM); + bottom = shapes.getModelForState(base).getQuads(base, null, 0); + base = base.withProperty(IWProperties.MARX_TYPE, STAGE); + stage = shapes.getModelForState(base).getQuads(base, null, 0); + base = base.withProperty(IWProperties.MARX_TYPE, TOP); + top = shapes.getModelForState(base).getQuads(base, null, 0); + } + GlStateManager.translate(1.5, 1.5, 2.5); + GlStateManager.rotate(-90, 0, 1, 0); + Tessellator tes = Tessellator.getInstance(); + BufferBuilder buf = tes.getBuffer(); + buf.begin(GL11.GL_QUADS, DefaultVertexFormats.BLOCK); + ClientUtilsIW.renderModelTESRFast(bottom, buf); + for (int i = 1;i<4;i++) { + buf.setTranslation(0, i, 0); + ClientUtilsIW.renderModelTESRFast(stage, buf); + } + buf.setTranslation(0, 4, 0); + ClientUtilsIW.renderModelTESRFast(top, buf); + buf.setTranslation(0, 0, 0); + tes.draw(); } } \ No newline at end of file