From 091ae873335c06fc248982102b863d2a005c600d Mon Sep 17 00:00:00 2001 From: Prototik Date: Mon, 2 Jun 2014 21:27:11 +0800 Subject: [PATCH] Make Builder support fluids via containers/pipes --- .../api/blueprints}/SchematicFluid.java | 19 +-- .../api/blueprints/SchematicRegistry.java | 127 +++++++++++------- .../assets/buildcraft/lang/en_US.lang | 1 + .../textures/gui/builder_blueprint.png | Bin 1258 -> 2189 bytes .../textures/gui/builder_foreground.png | Bin 0 -> 2287 bytes common/buildcraft/BuildCraftBuilders.java | 6 - common/buildcraft/builders/BlockBuilder.java | 6 + common/buildcraft/builders/TileBuilder.java | 101 +++++++++++++- .../buildcraft/builders/gui/GuiBuilder.java | 99 +++++++++++--- .../core/blueprints/BptBuilderBlueprint.java | 64 +++++---- common/buildcraft/core/fluids/FluidUtils.java | 2 +- common/buildcraft/core/fluids/Tank.java | 18 ++- .../buildcraft/core/fluids/TankManager.java | 16 ++- common/buildcraft/core/gui/GuiBuildCraft.java | 51 +++++++ .../buildcraft/core/network/RPCHandler.java | 3 - common/buildcraft/energy/GuiHandler.java | 4 +- common/buildcraft/energy/TileEngine.java | 2 - .../buildcraft/energy/TileEngineCreative.java | 5 - common/buildcraft/energy/TileEngineIron.java | 11 -- common/buildcraft/energy/TileEngineStone.java | 1 - common/buildcraft/energy/TileEngineWood.java | 5 - .../energy/gui/GuiCombustionEngine.java | 62 +-------- .../buildcraft/energy/gui/GuiStoneEngine.java | 7 +- 23 files changed, 408 insertions(+), 202 deletions(-) rename {common/buildcraft/builders/schematics => api/buildcraft/api/blueprints}/SchematicFluid.java (77%) create mode 100644 buildcraft_resources/assets/buildcraft/textures/gui/builder_foreground.png diff --git a/common/buildcraft/builders/schematics/SchematicFluid.java b/api/buildcraft/api/blueprints/SchematicFluid.java similarity index 77% rename from common/buildcraft/builders/schematics/SchematicFluid.java rename to api/buildcraft/api/blueprints/SchematicFluid.java index 29bf20fb..6f135cfd 100644 --- a/common/buildcraft/builders/schematics/SchematicFluid.java +++ b/api/buildcraft/api/blueprints/SchematicFluid.java @@ -6,29 +6,26 @@ * License 1.0, or MMPL. Please check the contents of the license located in * http://www.mod-buildcraft.com/MMPL-1.0.txt */ -package buildcraft.builders.schematics; +package buildcraft.api.blueprints; import java.util.LinkedList; import net.minecraft.item.ItemStack; -import net.minecraftforge.fluids.FluidContainerRegistry; - -import buildcraft.api.blueprints.IBuilderContext; -import buildcraft.api.blueprints.SchematicBlock; +import net.minecraftforge.fluids.FluidStack; public class SchematicFluid extends SchematicBlock { - private final ItemStack bucketStack; + private final ItemStack fluidItem; - public SchematicFluid(ItemStack bucketStack) { - this.bucketStack = bucketStack; + public SchematicFluid(FluidStack fluidStack) { + this.fluidItem = new ItemStack(fluidStack.getFluid().getBlock(), 1); } @Override public void writeRequirementsToWorld(IBuilderContext context, LinkedList requirements) { if (meta == 0) { - requirements.add(bucketStack.copy()); + requirements.add(fluidItem); } } @@ -74,11 +71,9 @@ public class SchematicFluid extends SchematicBlock { public LinkedList getStacksToDisplay( LinkedList stackConsumed) { - ItemStack s = new ItemStack(FluidContainerRegistry - .getFluidForFilledItem(bucketStack).getFluid().getBlock()); LinkedList result = new LinkedList(); - result.add(s); + result.add(fluidItem); return result; } diff --git a/api/buildcraft/api/blueprints/SchematicRegistry.java b/api/buildcraft/api/blueprints/SchematicRegistry.java index 59ea57fb..d3cab4f5 100644 --- a/api/buildcraft/api/blueprints/SchematicRegistry.java +++ b/api/buildcraft/api/blueprints/SchematicRegistry.java @@ -8,6 +8,7 @@ */ package buildcraft.api.blueprints; +import java.lang.reflect.Constructor; import java.lang.reflect.InvocationTargetException; import java.util.HashMap; import java.util.HashSet; @@ -16,12 +17,16 @@ import net.minecraft.block.Block; import net.minecraft.block.ITileEntityProvider; import net.minecraft.entity.Entity; import net.minecraft.init.Blocks; - import net.minecraftforge.common.config.Configuration; import net.minecraftforge.common.config.Property; +import net.minecraftforge.fluids.Fluid; +import net.minecraftforge.fluids.FluidContainerRegistry; +import net.minecraftforge.fluids.FluidRegistry; +import net.minecraftforge.fluids.FluidStack; import buildcraft.api.core.JavaTools; + public final class SchematicRegistry { public static double BREAK_ENERGY = 10; @@ -45,40 +50,75 @@ public final class SchematicRegistry { } private static class SchematicConstructor { - Class clas; - Object [] params; - } + public final Class clazz; + public final Object[] params; - public static void registerSchematicBlock (Block block, Class clas, Object ... params) { - explicitSchematicBlocks.add(block); - internalRegisterSchematicBlock(block, clas, params); - } + private final Constructor constructor; - private static void internalRegisterSchematicBlock (Block block, Class clas, Object ... params) { - if (schematicBlocks.containsKey(block)) { - throw new RuntimeException("Block " + Block.blockRegistry.getNameForObject(block) - + " is already associated with a schematic."); + SchematicConstructor(Class clazz, Object[] params) throws IllegalArgumentException { + this.clazz = clazz; + this.params = params; + this.constructor = findConstructor(); } - SchematicConstructor c = new SchematicConstructor (); - c.clas = clas; - c.params = params; + public Schematic newInstance() throws IllegalAccessException, InvocationTargetException, InstantiationException { + return (Schematic) constructor.newInstance(params); + } - schematicBlocks.put(block, c); + private Constructor findConstructor() throws IllegalArgumentException { + for (Constructor c : clazz.getConstructors()) { + Class[] typesSignature = c.getParameterTypes(); + if (typesSignature.length != params.length) { + // non-matching constructor count arguments, skip + continue; + } + boolean valid = true; + for (int i = 0; i < params.length; i++) { + if (params[i] == null) { + // skip checking for null parameters + continue; + } + Class paramClass = params[i].getClass(); + if (!(typesSignature[i].isAssignableFrom(paramClass) + || (typesSignature[i] == int.class && paramClass == Integer.class) + || (typesSignature[i] == double.class && paramClass == Double.class) + || (typesSignature[i] == boolean.class && paramClass == Boolean.class))) { + // constructor has non assignable parameters skip constructor... + valid = false; + break; + } + } + if (!valid) { + continue; + } + return c; + } + throw new IllegalArgumentException("Could not find matching constructor for class " + clazz); + } + } + + public static void registerSchematicBlock(Block block, Class clazz, Object... params) { + explicitSchematicBlocks.add(block); + internalRegisterSchematicBlock(block, clazz, params); + } + + private static void internalRegisterSchematicBlock(Block block, Class clazz, Object... params) { + if (schematicBlocks.containsKey(block)) { + throw new RuntimeException("Block " + Block.blockRegistry.getNameForObject(block) + " is already associated with a schematic."); + } + schematicBlocks.put(block, new SchematicConstructor(clazz, params)); } public static void registerSchematicEntity( Class entityClass, Class schematicClass, Object... params) { - - SchematicConstructor c = new SchematicConstructor (); - c.clas = schematicClass; - c.params = params; - - schematicEntities.put(entityClass, c); + if (schematicEntities.containsKey(entityClass)) { + throw new RuntimeException("Entity " + entityClass.getName() + " is already associated with a schematic."); + } + schematicEntities.put(entityClass, new SchematicConstructor(schematicClass, params)); } - public static SchematicBlock newSchematicBlock (Block block) { + public static SchematicBlock newSchematicBlock(Block block) { if (block == Blocks.air) { return null; } @@ -87,24 +127,27 @@ public final class SchematicRegistry { if (block instanceof ITileEntityProvider) { internalRegisterSchematicBlock(block, SchematicTile.class); } else { - internalRegisterSchematicBlock(block, SchematicBlock.class); + Fluid fluid = FluidRegistry.lookupFluidForBlock(block); + if (fluid != null) { + internalRegisterSchematicBlock(block, SchematicFluid.class, new FluidStack(fluid, FluidContainerRegistry.BUCKET_VOLUME)); + } else { + internalRegisterSchematicBlock(block, SchematicBlock.class); + } } } try { SchematicConstructor c = schematicBlocks.get(block); - SchematicBlock s = (SchematicBlock) c.clas.getConstructors() [0].newInstance(c.params); + SchematicBlock s = (SchematicBlock) c.newInstance(); s.block = block; return s; - } catch (InstantiationException e) { - e.printStackTrace(); } catch (IllegalAccessException e) { e.printStackTrace(); } catch (IllegalArgumentException e) { e.printStackTrace(); } catch (InvocationTargetException e) { e.printStackTrace(); - } catch (SecurityException e) { + } catch (InstantiationException e) { e.printStackTrace(); } @@ -118,45 +161,39 @@ public final class SchematicRegistry { try { SchematicConstructor c = schematicEntities.get(entityClass); - SchematicEntity s = (SchematicEntity) c.clas.getConstructors() [0].newInstance(c.params); + SchematicEntity s = (SchematicEntity) c.newInstance(); s.entity = entityClass; return s; - } catch (InstantiationException e) { - e.printStackTrace(); } catch (IllegalAccessException e) { e.printStackTrace(); } catch (IllegalArgumentException e) { e.printStackTrace(); } catch (InvocationTargetException e) { e.printStackTrace(); - } catch (SecurityException e) { + } catch (InstantiationException e) { e.printStackTrace(); } return null; } - public static void declareBlueprintSupport (String modid) { + public static void declareBlueprintSupport(String modid) { modsSupporting.add(modid); } - public static boolean isExplicitlySupported (Block block) { - String modid = Block.blockRegistry.getNameForObject(block).split(":") [0]; - - return explicitSchematicBlocks.contains(block) || modsSupporting.contains(modid); + public static boolean isExplicitlySupported(Block block) { + return explicitSchematicBlocks.contains(block) || modsSupporting.contains(Block.blockRegistry.getNameForObject(block).split(":", 2)[0]); } - public static boolean isAllowedForBuilding (Block block) { + public static boolean isAllowedForBuilding(Block block) { String name = Block.blockRegistry.getNameForObject(block); - String modid = name.split(":") [0]; - - return !modsForbidden.contains(modid) && !blocksForbidden.contains(name); + return !blocksForbidden.contains(name) && !modsForbidden.contains(name.split(":", 2)[0]); } - public static void readConfiguration (Configuration conf) { - Property excludedMods = conf.get(Configuration.CATEGORY_GENERAL, "builder.excludedMods", new String [0], + public static void readConfiguration(Configuration conf) { + Property excludedMods = conf.get(Configuration.CATEGORY_GENERAL, "builder.excludedMods", new String[0], "mods that should be excluded from the builder."); - Property excludedBlocks = conf.get(Configuration.CATEGORY_GENERAL, "builder.excludedBlocks", new String [0], + Property excludedBlocks = conf.get(Configuration.CATEGORY_GENERAL, "builder.excludedBlocks", new String[0], "blocks that should be excluded from the builder."); for (String id : excludedMods.getStringList()) { @@ -177,6 +214,6 @@ public final class SchematicRegistry { } static { - modsSupporting.add ("minecraft"); + modsSupporting.add("minecraft"); } } diff --git a/buildcraft_resources/assets/buildcraft/lang/en_US.lang b/buildcraft_resources/assets/buildcraft/lang/en_US.lang index a6951529..9f387ced 100755 --- a/buildcraft_resources/assets/buildcraft/lang/en_US.lang +++ b/buildcraft_resources/assets/buildcraft/lang/en_US.lang @@ -91,6 +91,7 @@ gate.trigger.pipe.wire.inactive=%s Pipe Signal Off gate.trigger.timer=%s Sec Timer gui.building.resources=Building Resources +gui.building.fluids=Fluid Tanks gui.del=Del gui.filling.resources=Filling Resources gui.inventory=Inventory diff --git a/buildcraft_resources/assets/buildcraft/textures/gui/builder_blueprint.png b/buildcraft_resources/assets/buildcraft/textures/gui/builder_blueprint.png index 7b70f001ea0377d9f5b10d4d706a432e10011c58..61837ac05bd7d689abe2bbd250b1202c1dc868b7 100644 GIT binary patch literal 2189 zcma)82~bm67JUf>kVVQiVut}^(_&&2p#g=65_H&t5EfY)f-DNe1yKo$fP>LEQh>A& z1QbXU8v#WT6)-{!i*#g7(rhBKDiRuo5Rj$WGd~K|ZH?76|JSc~>;Cu7JNMlCmUt(U zjheEiG5|o0Xlv;L01Pr=KuG~=yhHB=L5;$(!#0*cDtlSnf>g+}?wqYB6@c|GWgl!4 z){X`_6~l-QR*HQJaCL-s`_(<+04Qk^Ef2b0cq{JhcR^CNC=9UU{BOa&PagQjp*h9G z|Akt}RWGUvnVi<>QpSei?H<*5|0=@9U-v7X%qiwO2 zg~jODBOl5PEsi3It^3R8np$Vn%btHsd_Uc(wwci0l!|dA^-pe=`U1kz1bx#LWipw3 znDMZE` zA3bdgb2_tg=T47>sT*j5;MFT@U8-Q=ZZR1=R{UZ(u8s;k&K*_H$(~78z|z+JVUBJE z>@VgT2-T8vSqFhdEzLdALRe^@2@dv-iWW4;|BMseQnJ+RLwNr?-ol~?`zJ|S0#)?_ zLbCXsniJSK){<*;EowmH&)=V7@MBz9PqQ=F@Ox;&wm{Ex;`=)qArJqvkooKZssDC+ zwh0DaR8*u(eBIf}m1B8H;E!HfZe_V6zo7pWLAEoafa{fbiwx?x<<=waAM6havf6?L z@1>)>&Iv~cdBZ>}fiIKV;vD{ZLRfs~0J!%9Vol7iz{y-RV&wRK@CoauJ;obsNl8?D z`HDW7DM)JkVMD#;)`0^~|C^gH;ckU(hd11w(>i@ZCplYl_?A)__mlaLwBtI-@fOuF ztiPo7%b}~uHyE*(XBbW5Ur*>~D#^PFvo>DtfzuBB&9G{<^W$}w|215ZO{|Za;)v&I zh;tv+&uwyB5rpH>+w1Dud*Ppgua4`Iqh(cJo0-Q`&fLWTT&?wJm&~j{fSAwa;H176 zcKOgBPBU7o1%m~L!A$u0c9z6D!)P6T^AK_%Q^oK2@xey4 zwduSCT??PVFaOw{(|zkFhcyZ_bHP310uTaQTMCjONYQv`Tqj{%A9Lj zFBkcz+}+h=NL2NqY5usnHaV-Zj1KiURCjcA?35xfZT>^`<-r20d^q9aoB|MF=1eu##8Xb31`iEP-0$r8dHquv_cD72o`;za`q5wgj3JAIS&VbqP z8#G^+W5iyJSzty)jO$Y*<1PzSW?N$3x7v9#g;~5J=EbEpcduR_pWS_eDMjA^TwpkL zH&q3g@LHT($Iw9$kpvY-HnlxCsKUh7IlYS;iJ_O18Urq-1cy-O2?R>)Y0QyYe}*A{ z#XkX=#&-s;Ub!jP^U0{NefU#*+oC&~UY3Y&?np&;`L37}4W$<`O$2lPQVFv(nyVG@ zb|i8iisV>e@7V=yA!U2AqQW1fG8dap&aN++2sSJ7(N7e{Iyk4_9+_oqQ>l7Uza*N| zL6wrbsyH{HZX>;!e5_SC6$#wj?HvN&oRkHa5V|z_d}53@$@{3oT+SdeW@`>+F8eEp z-D5eCm~M6RroP@h)u8SjiK8Mcz!hhox=ZM880VT18#|&8V0FXqri77C=b92r)qV1JHC@+C8uX|&6w^aA zaw@;AvfEPiG~LQM5fWoae}%^vPo}&Pks$Wh#O~2-5o4Q}o^f(^(eq6YzS6X@ZE>g& zB2*Y7A!z1xi387{rYspWmvq`3ld+aeRq3M88G6CX3kz61tHxjIp%`~G%7QLDW7<4+ z&;%_lO`9+3+}to{I~F^eP9QR-DHMkF;51e|D~eb!;)k6TGR>pO4G^6)ZEf8n^w@k( zukp27C~>k3h!t~^`jv&xQXy#9@9XG~4Xesi@3$BjaeXrBH6yufx8~3Fph`B1Dl^T| zv0C44G%rqc>|gk;xgjdr6NzdrHEc6$ZsK*Lo&}N6+@fPY!C7xJ2iY7Uy2r7kU-%fm z@@C90Lew00sshc=!)pb+Ih7X^Gd|tYZ71^12lifRvMptj|JJK=d4*%2r*)Q=*No-e zzEPtQ*f$^ZAd{+b xEF7TY71KaQZ^G%RwIA|d2i*n!{u$UMl{*xFHkFj}{DZ6~(TZgG=#bx){{l%xuw?)M literal 1258 zcmeAS@N?(olHy`uVBq!ia0y~yU<5K5893O0R7}x|G!U;i$lZxy-8q?;Kn`1yx4R3& ze-K=-cll(X2xoyuWHAE+-yslY6xHx*01C2~c>21s-{z5FP!%gTRlCE$z>?+Z;uunK z>+RjUxr-e{8ZKH-T+Nj`!AWT+zc^FrgiSZpH%(Jse1rL;LGiiEUaR-=PyWF9r`Y^x zeKEsY4?)4@Pan-sziw|*_;mS~zt7FZ?YE@PTK3-hUx{?X`t|ziETX$(^aKSBd7Sse z{%`G;zxC-EhXcqXEDQn+=nRV~la&{+&7VL2rtzFLOi$Kiixa6tuf?C^7fz{Vh-P?rWBw`|7sf^iv^0!NUeS zm=~W4gI1 z>D=n)f67AV8rS^c*~`YjD@@3|)xQ~XA`O?fSf0D!rcf+3FIoA*w)70;36|}%l9ea) zIvn6*!5R;6M`_IMb$BLXe_ZkwM~dI!;vAM+-*|FajGhMonVSSTZZsl73^_XB@v?NY z;E6epo?9Fi&t+*^yg@Ld_S|LZ#s?ZXEW7NFyD329A2TVu+VCq?;r<3ApwqA4PkGGG zyx|W+(Um{E+Qt9U`qr8YPV=FX-YLgfrQ zepFsC;Q9FR<3qj%tGbz$5u3#3MCtu|qGH4J;E_8b1vX@_&S(DBHq}z~OrpJ}(zD8W z%1U)LuTKC23>X2s1z-I7znwpy`CU0X$PG6tlKtMvNH^|bLro5-zGr#>Oydn~H-Uln zvG_(mBn;gah~H(@u?HrFdow0m1AV`q5s`r5A*Suu*C6F{Swzs@POZn9A!=jH9}Wh+ zI+g~poqxYeG3Zs@VPx>X&v+vw*^jgM#`#xn3K|o89po6nIjZ8+tL}zvOtXUz&AGky zz@I>dY4Q$y(fMaj&V76|vmakvDKPW_Q$ogswFiLF-TwCm*O`YmxZXe#Y{t89^K<7Y zDJ`AyEOVBOo=Fw^gnRez&t+?W$a*06j@*Mc9u_a&>oE`l2i*QKdRCj*ue4v33{vaq L>gTe~DWM4fPAi*` diff --git a/buildcraft_resources/assets/buildcraft/textures/gui/builder_foreground.png b/buildcraft_resources/assets/buildcraft/textures/gui/builder_foreground.png new file mode 100644 index 0000000000000000000000000000000000000000..86a2dda835e70ff1c16716c5d2f3c972852cd2c5 GIT binary patch literal 2287 zcmds3i$Bx*8~^Tt5t>fwB(a$5Zz-gh%xH_zhSfTmYb8pZ+(*QwqZA>RpEv*wDRmVyC2_rT_qd z63L!G1po*LApk-a9NdHN_=1D%QAaxhu=@SF&Mi&{E%Jf(t|0)R{N(!sQPp=~fkwGd z5}7DBBny>Of-`jX$p8T29Eo6aFyi&}ApgwfK2_G|fQzGn7c+F)b#+{-8ufdALo5N) zQbTf_~|3(o6rbY^W`PdrQuizuBvygbo;i&gmSWPHOIpSh?# zkhp33X5mceU$Y{E`*FzD08H{HRZM}>=dXuhkj0Ws4h4BK}~$81*R`k-%9YEVq2qor5y zLWD!w_-ReH$_0FQDlBk8DDS2xk3|ARaCGe8M0hliKK zQ}p_5ylok0W$@VCZX?6zJ4bRQTLrwe5jZvHZ`AYSUj8R!fw)8ayW1c3YeHl7;k7B0 zNsI#atPMO4sV~S#DOKe-ArH+9^=DUE5Bu-{Nz*u5*nuNH9Q|1TI;=h;(n8)!t^3C z2WFq74D2T3^aNogv!i(o7nj@e;(eN|PzI5s|1c^zCVGO`5e1NxlzXf!WYPdurlXudbA>5mQO|9A!XI*;w{# zuZ&GCrSs$~)xkZ*9+|aJN3s$Sq)2;tyopOBw3tlKcks9Y(TbwGPAG!P@!dCax7WWO zDs*T7nMu*`6BU9*uzIhFHm^LH%I@D90(Od5!mGR9Q`ig|RYyLtqp7T!dH~kU#!0jJ zk5(i+)qP2LAH`mTyeShee*ci#1 zVPu`#7=$X&fY1Ylm+=R0|LAA}p{@W?L$6PzYQylTw~<;`z2J^u1s>t*6QsxUF4}s>^L7Fe)Uq-0`H<4$oRP=ioP!ibr z+a7);pxk0_7x@C;*YN?X*aaXFKOhT)&b%@`=zs#otml?p%9Fcyd4~MGW_<9?1M!>2 z-^;-Dcfb}W`7uwerS)h!Eslmt&_3iM`6iXp7JFYiSuelH&rlO9UoRK8>#@7o9xo00 zQh+Z~-LrL$m)yP|=Zy?xbJP7m&|da?fz?WtwW5~UF4$oiEU|O!<8DRW)}AtD zQWcsmqiea0sn&qlf3dI>98)g9jYvfq3=e2*Q0lVH)t-JuRPr6He0z=4;HP^5;w9JfU2R7o=j=$#8v1*r}JXSY2#>daP*`2 z=KHzETc(0Ub649sFYOUBOR1=mBanBx2p_9XS?z}QyrirwG|}c14d&cx{Kbt&p$UZ%P6eZ-(1Qj9>E zVSz^MilyK~SV;i3DQ2Ya_z(vMCY(m8_c7lxydQpTYAW5&D%{22A3%hW@4N5VvpHl= z)JD#KG*Pr)E^2?cHBjEp^83)IW2`rW(5j8uRpIkjmIZ=b9uun$ zs+lWN(Rb>rhIsyom~~2VWvug+kioWm<_nbKIhcvD-)cUk?ddS*lz(wz>;u(6vRk%! zlHqFmTWdZgoVF-Fu;CE25M&1tata&!8|(-zH*9x@?F5QLt$Seo z19DE`fA^6Y@3(gCrj3rz8BZFS@yD+5Xgu#e-HB1ad(FWW8-ozfwtp}*fRS6xJwL!Qr8t$G)J7(kmprWE+cn}+6=-h|AqM1|1;wM>(s2736R`+b4+P|iQumZ NKq68I<+k4E{|0$W6ORA@ literal 0 HcmV?d00001 diff --git a/common/buildcraft/BuildCraftBuilders.java b/common/buildcraft/BuildCraftBuilders.java index 33105612..d3cf7a09 100644 --- a/common/buildcraft/BuildCraftBuilders.java +++ b/common/buildcraft/BuildCraftBuilders.java @@ -92,7 +92,6 @@ import buildcraft.builders.schematics.SchematicFactoryEntity; import buildcraft.builders.schematics.SchematicFactoryMask; import buildcraft.builders.schematics.SchematicFarmland; import buildcraft.builders.schematics.SchematicFire; -import buildcraft.builders.schematics.SchematicFluid; import buildcraft.builders.schematics.SchematicGlassPane; import buildcraft.builders.schematics.SchematicGravel; import buildcraft.builders.schematics.SchematicHanging; @@ -320,11 +319,6 @@ public class BuildCraftBuilders extends BuildCraftMod { SchematicRegistry.registerSchematicBlock(Blocks.redstone_lamp, SchematicRedstoneLamp.class); SchematicRegistry.registerSchematicBlock(Blocks.lit_redstone_lamp, SchematicRedstoneLamp.class); - SchematicRegistry.registerSchematicBlock(Blocks.water, SchematicFluid.class, new ItemStack(Items.water_bucket)); - SchematicRegistry.registerSchematicBlock(Blocks.flowing_water, SchematicFluid.class, new ItemStack(Items.water_bucket)); - SchematicRegistry.registerSchematicBlock(Blocks.lava, SchematicFluid.class, new ItemStack(Items.lava_bucket)); - SchematicRegistry.registerSchematicBlock(Blocks.flowing_lava, SchematicFluid.class, new ItemStack(Items.lava_bucket)); - SchematicRegistry.registerSchematicBlock(Blocks.glass_pane, SchematicGlassPane.class); SchematicRegistry.registerSchematicBlock(Blocks.stained_glass_pane, SchematicGlassPane.class); diff --git a/common/buildcraft/builders/BlockBuilder.java b/common/buildcraft/builders/BlockBuilder.java index c829d7d1..e61cb0e7 100644 --- a/common/buildcraft/builders/BlockBuilder.java +++ b/common/buildcraft/builders/BlockBuilder.java @@ -30,6 +30,7 @@ import buildcraft.BuildCraftBuilders; import buildcraft.api.tools.IToolWrench; import buildcraft.core.CreativeTabBuildCraft; import buildcraft.core.GuiIds; +import buildcraft.core.fluids.FluidUtils; import buildcraft.core.utils.Utils; public class BlockBuilder extends BlockContainer { @@ -75,6 +76,9 @@ public class BlockBuilder extends BlockContainer { return false; } + TileEntity tile = world.getTileEntity(i, j, k); + TileBuilder builder = tile instanceof TileBuilder ? (TileBuilder) tile : null; + Item equipped = entityplayer.getCurrentEquippedItem() != null ? entityplayer.getCurrentEquippedItem().getItem() : null; if (equipped instanceof IToolWrench && ((IToolWrench) equipped).canWrench(entityplayer, i, j, k)) { @@ -99,6 +103,8 @@ public class BlockBuilder extends BlockContainer { world.markBlockForUpdate(i, j, k); ((IToolWrench) equipped).wrenchUsed(entityplayer, i, j, k); + return true; + } else if (builder != null && FluidUtils.handleRightClick(builder, ForgeDirection.UNKNOWN, entityplayer, true, false)) { return true; } else { if (!world.isRemote) { diff --git a/common/buildcraft/builders/TileBuilder.java b/common/buildcraft/builders/TileBuilder.java index 881048e9..5dffc06d 100644 --- a/common/buildcraft/builders/TileBuilder.java +++ b/common/buildcraft/builders/TileBuilder.java @@ -22,6 +22,11 @@ import net.minecraft.world.WorldSettings.GameType; import net.minecraftforge.common.util.Constants; import net.minecraftforge.common.util.ForgeDirection; +import net.minecraftforge.fluids.Fluid; +import net.minecraftforge.fluids.FluidContainerRegistry; +import net.minecraftforge.fluids.FluidStack; +import net.minecraftforge.fluids.FluidTankInfo; +import net.minecraftforge.fluids.IFluidHandler; import buildcraft.BuildCraftBuilders; import buildcraft.api.blueprints.BuildingPermission; @@ -40,19 +45,30 @@ import buildcraft.core.blueprints.BptBuilderBase; import buildcraft.core.blueprints.BptBuilderBlueprint; import buildcraft.core.blueprints.BptBuilderTemplate; import buildcraft.core.blueprints.BptContext; +import buildcraft.core.fluids.Tank; +import buildcraft.core.fluids.TankManager; import buildcraft.core.inventory.InvUtils; import buildcraft.core.inventory.SimpleInventory; import buildcraft.core.network.RPC; import buildcraft.core.network.RPCHandler; +import buildcraft.core.network.RPCMessageInfo; import buildcraft.core.network.RPCSide; -public class TileBuilder extends TileAbstractBuilder implements IMachine { +public class TileBuilder extends TileAbstractBuilder implements IMachine, IFluidHandler { private static int POWER_ACTIVATION = 50; @NetworkData public Box box = new Box(); public PathIterator currentPathIterator; + public Tank[] fluidTanks = new Tank[] { + new Tank("fluid1", FluidContainerRegistry.BUCKET_VOLUME * 8, this), + new Tank("fluid2", FluidContainerRegistry.BUCKET_VOLUME * 8, this), + new Tank("fluid3", FluidContainerRegistry.BUCKET_VOLUME * 8, this), + new Tank("fluid4", FluidContainerRegistry.BUCKET_VOLUME * 8, this) + }; + @NetworkData + public TankManager fluidTank = new TankManager(fluidTanks); private SimpleInventory inv = new SimpleInventory(28, "Builder", 64); private BptBuilderBase bluePrintBuilder; @@ -493,6 +509,7 @@ public class TileBuilder extends TileAbstractBuilder implements IMachine { } done = nbttagcompound.getBoolean("done"); + fluidTank.readFromNBT(nbttagcompound); // The rest of load has to be done upon initialize. initNBT = (NBTTagCompound) nbttagcompound.getCompoundTag("bptBuilder").copy(); @@ -523,6 +540,7 @@ public class TileBuilder extends TileAbstractBuilder implements IMachine { } nbttagcompound.setBoolean("done", done); + fluidTank.writeToNBT(nbttagcompound); NBTTagCompound bptNBT = new NBTTagCompound(); @@ -603,7 +621,7 @@ public class TileBuilder extends TileAbstractBuilder implements IMachine { @Override public boolean manageFluids() { - return false; + return true; } @Override @@ -724,4 +742,83 @@ public class TileBuilder extends TileAbstractBuilder implements IMachine { } } + @Override + public boolean canDrain(ForgeDirection from, Fluid fluid) { + return false; + } + + @Override + public FluidStack drain(ForgeDirection from, FluidStack resource, boolean doDrain) { + return null; + } + + @Override + public FluidStack drain(ForgeDirection from, int maxDrain, boolean doDrain) { + return null; + } + + public boolean drainBuild(FluidStack fluidStack, boolean realDrain) { + for (Tank tank : fluidTanks) { + if (tank.getFluidType() == fluidStack.getFluid()) { + return tank.getFluidAmount() >= fluidStack.amount && tank.drain(fluidStack.amount, realDrain).amount > 0; + } + } + return false; + } + + @Override + public int fill(ForgeDirection from, FluidStack resource, boolean doFill) { + Fluid fluid = resource.getFluid(); + Tank emptyTank = null; + for (Tank tank : fluidTanks) { + Fluid type = tank.getFluidType(); + if (type == fluid) { + int used = tank.fill(resource, doFill); + if (used > 0 && doFill) { + sendNetworkUpdate(); + } + return used; + } else if (emptyTank == null && tank.isEmpty()) { + emptyTank = tank; + } + } + if (emptyTank != null) { + int used = emptyTank.fill(resource, doFill); + if (used > 0 && doFill) { + sendNetworkUpdate(); + } + return used; + } + return 0; + } + + @Override + public boolean canFill(ForgeDirection from, Fluid fluid) { + boolean emptyAvailable = false; + for (Tank tank : fluidTanks) { + Fluid type = tank.getFluidType(); + if (type == fluid) { + return !tank.isFull(); + } else if (!emptyAvailable) { + emptyAvailable = tank.isEmpty(); + } + } + return emptyAvailable; + } + + @Override + public FluidTankInfo[] getTankInfo(ForgeDirection from) { + return fluidTank.getTankInfo(from); + } + + @RPC(RPCSide.SERVER) + public void eraseFluidTank(int id, RPCMessageInfo info) { + if (id < 0 || id >= fluidTanks.length) { + return; + } + if (isUseableByPlayer(info.sender) && info.sender.getDistanceSq(xCoord, yCoord, zCoord) <= 64) { + fluidTanks[id].setFluid(null); + sendNetworkUpdate(); + } + } } diff --git a/common/buildcraft/builders/gui/GuiBuilder.java b/common/buildcraft/builders/gui/GuiBuilder.java index c3d1a0b6..7c65cce0 100644 --- a/common/buildcraft/builders/gui/GuiBuilder.java +++ b/common/buildcraft/builders/gui/GuiBuilder.java @@ -12,34 +12,38 @@ import java.util.Collection; import org.lwjgl.opengl.GL11; +import net.minecraft.client.Minecraft; +import net.minecraft.client.gui.GuiButton; + import net.minecraft.inventory.IInventory; import net.minecraft.item.ItemStack; import net.minecraft.util.ResourceLocation; import buildcraft.builders.TileBuilder; import buildcraft.core.DefaultProps; +import buildcraft.core.fluids.Tank; import buildcraft.core.gui.AdvancedSlot; import buildcraft.core.gui.GuiAdvancedInterface; +import buildcraft.core.network.RPCHandler; import buildcraft.core.utils.StringUtils; public class GuiBuilder extends GuiAdvancedInterface { - - private static final ResourceLocation TEXTURE = new ResourceLocation("buildcraft", DefaultProps.TEXTURE_PATH_GUI + "/builder.png"); private static final ResourceLocation BLUEPRINT_TEXTURE = new ResourceLocation("buildcraft", DefaultProps.TEXTURE_PATH_GUI + "/builder_blueprint.png"); + private static final ResourceLocation FOREGROUND_TEXTURE = new ResourceLocation("buildcraft", DefaultProps.TEXTURE_PATH_GUI + "/builder_foreground.png"); private IInventory playerInventory; private TileBuilder builder; - private int inventoryRows = 6; + private GuiButton selectedButton; public GuiBuilder(IInventory playerInventory, TileBuilder builder) { - super(new ContainerBuilder(playerInventory, builder), builder, TEXTURE); + super(new ContainerBuilder(playerInventory, builder), builder, BLUEPRINT_TEXTURE); this.playerInventory = playerInventory; this.builder = builder; xSize = 176; ySize = 225; - slots = new AdvancedSlot[7 * 4]; + slots = new AdvancedSlot[6 * 4]; - for (int i = 0; i < 7; ++i) { + for (int i = 0; i < 6; ++i) { for (int j = 0; j < 4; ++j) { slots[i * 4 + j] = new ItemSlot(179 + j * 18, 18 + i * 18); } @@ -50,11 +54,11 @@ public class GuiBuilder extends GuiAdvancedInterface { protected void drawGuiContainerForegroundLayer(int par1, int par2) { super.drawGuiContainerForegroundLayer(par1, par2); - String title = StringUtils.localize("tile.builderBlock.name"); - fontRendererObj.drawString(title, getCenteredOffset(title), 12, 0x404040); + drawCenteredString(StringUtils.localize("tile.builderBlock.name"), 178 / 2, 16, 0x404040); fontRendererObj.drawString(StringUtils.localize("gui.building.resources"), 8, 60, 0x404040); fontRendererObj.drawString(StringUtils.localize("gui.inventory"), 8, ySize - 97, 0x404040); - fontRendererObj.drawString(StringUtils.localize("gui.needed"), 185, 7, 0x404040); + fontRendererObj.drawString(StringUtils.localize("gui.needed"), 178, 7, 0x404040); + fontRendererObj.drawString(StringUtils.localize("gui.building.fluids"), 178, 133, 0x404040); drawForegroundSelection(par1, par2); } @@ -62,19 +66,9 @@ public class GuiBuilder extends GuiAdvancedInterface { @Override protected void drawGuiContainerBackgroundLayer(float f, int x, int y) { GL11.glColor4f(1.0F, 1.0F, 1.0F, 1.0F); - int j = (width - xSize) / 2; - int k = (height - ySize) / 2; - int realXSize = 0; -// if (builder.isBuildingBlueprint()) { - mc.renderEngine.bindTexture(BLUEPRINT_TEXTURE); - realXSize = 256; -// } else { -// mc.renderEngine.bindTexture(TEXTURE); -// realXSize = 176; -// } - - drawTexturedModalRect(j, k, 0, 0, realXSize, ySize); + mc.renderEngine.bindTexture(BLUEPRINT_TEXTURE); + drawTexturedModalRect(guiLeft, guiTop, 0, 0, 256, ySize); for (int s = 0; s < slots.length; ++s) { ((ItemSlot) slots[s]).stack = null; @@ -96,5 +90,68 @@ public class GuiBuilder extends GuiAdvancedInterface { } drawBackgroundSlots(); + + for (int i = 0; i < builder.fluidTanks.length; i++) { + Tank tank = builder.fluidTanks[i]; + drawFluid(tank.getFluid(), guiLeft + 179 + 18 * i, guiTop + 145, 16, 47, tank.getCapacity()); + } + mc.renderEngine.bindTexture(FOREGROUND_TEXTURE); + for (int i = 0; i < builder.fluidTanks.length; i++) { + drawTexturedModalRect(guiLeft + 179 + 18 * i, guiTop + 145, 0, 54, 16, 47); + } + } + + @Override + public void initGui() { + super.initGui(); + for (int i = 0; i < 4; i++) { + buttonList.add(new BuilderEraseButton(i, guiLeft + 178 + 18 * i, guiTop + 197, 18, 18)); + } + } + + @Override + protected void mouseMovedOrUp(int mouseX, int mouseY, int eventType) { + super.mouseMovedOrUp(mouseX, mouseY, eventType); + + if (this.selectedButton != null && eventType == 0) { + this.selectedButton.mouseReleased(mouseX, mouseY); + this.selectedButton = null; + } + } + + private class BuilderEraseButton extends GuiButton { + private boolean clicked; + + public BuilderEraseButton(int id, int x, int y, int width, int height) { + super(id, x, y, width, height, null); + } + + @Override + public boolean mousePressed(Minecraft mc, int x, int y) { + if (super.mousePressed(mc, x, y)) { + selectedButton = this; + clicked = true; + RPCHandler.rpcServer(builder, "eraseFluidTank", id); + return true; + } else { + return false; + } + } + + @Override + public void mouseReleased(int x, int y) { + super.mouseReleased(x, y); + clicked = false; + } + + @Override + public void drawButton(Minecraft mc, int x, int y) { + // hovered + this.field_146123_n = x >= this.xPosition && y >= this.yPosition && x < this.xPosition + this.width && y < this.yPosition + this.height; + + mc.renderEngine.bindTexture(FOREGROUND_TEXTURE); + drawTexturedModalRect(xPosition, yPosition, 0, (clicked ? 1 : this.field_146123_n ? 2 : 0) * 18, 18, 18); + mouseDragged(mc, x, y); + } } } diff --git a/common/buildcraft/core/blueprints/BptBuilderBlueprint.java b/common/buildcraft/core/blueprints/BptBuilderBlueprint.java index 9013b582..469de2c3 100644 --- a/common/buildcraft/core/blueprints/BptBuilderBlueprint.java +++ b/common/buildcraft/core/blueprints/BptBuilderBlueprint.java @@ -19,12 +19,17 @@ import java.util.TreeSet; import net.minecraft.init.Blocks; import net.minecraft.item.Item; +import net.minecraft.item.ItemBlock; import net.minecraft.item.ItemStack; import net.minecraft.nbt.NBTTagCompound; import net.minecraft.world.World; import net.minecraft.world.WorldSettings.GameType; import net.minecraftforge.common.util.ForgeDirection; +import net.minecraftforge.fluids.Fluid; +import net.minecraftforge.fluids.FluidContainerRegistry; +import net.minecraftforge.fluids.FluidRegistry; +import net.minecraftforge.fluids.FluidStack; import buildcraft.api.blueprints.Schematic; import buildcraft.api.blueprints.SchematicBlock; @@ -35,6 +40,7 @@ import buildcraft.api.core.BuildCraftAPI; import buildcraft.api.core.IInvSlot; import buildcraft.api.core.StackKey; import buildcraft.builders.TileAbstractBuilder; +import buildcraft.builders.TileBuilder; import buildcraft.core.BlockIndex; import buildcraft.core.blueprints.BuildingSlotBlock.Mode; import buildcraft.core.inventory.InventoryCopy; @@ -45,6 +51,7 @@ import buildcraft.core.utils.BlockUtil; public class BptBuilderBlueprint extends BptBuilderBase { public LinkedList neededItems = new LinkedList(); + public LinkedList neededFluids = new LinkedList(); protected TreeSet builtEntities = new TreeSet(); @@ -422,14 +429,27 @@ public class BptBuilderBlueprint extends BptBuilderBase { } for (ItemStack reqStk : tmpReq) { + boolean itemBlock = reqStk.getItem() instanceof ItemBlock; + Fluid fluid = itemBlock ? FluidRegistry.lookupFluidForBlock(((ItemBlock) reqStk.getItem()).field_150939_a) : null; + + if (fluid != null && builder instanceof TileBuilder && ((TileBuilder) builder).drainBuild(new FluidStack(fluid, FluidContainerRegistry.BUCKET_VOLUME), true)) { + continue; + } + for (IInvSlot slotInv : InventoryIterator.getIterable(new InventoryCopy(builder), ForgeDirection.UNKNOWN)) { if (!builder.isBuildingMaterialSlot(slotInv.getIndex())) { continue; } ItemStack invStk = slotInv.getStackInSlot(); + if (invStk == null || invStk.stackSize == 0) { + continue; + } - if (invStk != null && invStk.stackSize > 0 && StackHelper.isCraftingEquivalent(reqStk, invStk, true)) { + FluidStack fluidStack = fluid != null ? FluidContainerRegistry.getFluidForFilledItem(invStk) : null; + boolean compatibleContainer = fluidStack != null && fluidStack.getFluid() == fluid && fluidStack.amount >= FluidContainerRegistry.BUCKET_VOLUME; + + if (StackHelper.isCraftingEquivalent(reqStk, invStk, true) || compatibleContainer) { try { stacksUsed.add(slot.useItem(context, reqStk, slotInv)); } catch (Throwable t) { @@ -485,6 +505,13 @@ public class BptBuilderBlueprint extends BptBuilderBase { boolean smallStack = reqStk.stackSize == 1; ItemStack usedStack = reqStk; + boolean itemBlock = reqStk.getItem() instanceof ItemBlock; + Fluid fluid = itemBlock ? FluidRegistry.lookupFluidForBlock(((ItemBlock) reqStk.getItem()).field_150939_a) : null; + + if (fluid != null && builder instanceof TileBuilder && ((TileBuilder) builder).drainBuild(new FluidStack(fluid, FluidContainerRegistry.BUCKET_VOLUME), true)) { + continue; + } + for (IInvSlot slotInv : InventoryIterator.getIterable(builder, ForgeDirection.UNKNOWN)) { if (!builder.isBuildingMaterialSlot(slotInv.getIndex())) { continue; @@ -492,7 +519,14 @@ public class BptBuilderBlueprint extends BptBuilderBase { ItemStack invStk = slotInv.getStackInSlot(); - if (invStk != null && invStk.stackSize > 0 && StackHelper.isCraftingEquivalent(reqStk, invStk, true)) { + if (invStk == null || invStk.stackSize == 0) { + continue; + } + + FluidStack fluidStack = fluid != null ? FluidContainerRegistry.getFluidForFilledItem(invStk) : null; + boolean fluidFound = fluidStack != null && fluidStack.getFluid() == fluid && fluidStack.amount >= FluidContainerRegistry.BUCKET_VOLUME; + + if (fluidFound || StackHelper.isCraftingEquivalent(reqStk, invStk, true)) { try { usedStack = slot.getSchematic().useItem(context, reqStk, slotInv); slot.addStackConsumed (usedStack); @@ -524,6 +558,7 @@ public class BptBuilderBlueprint extends BptBuilderBase { public void recomputeNeededItems() { neededItems.clear(); + neededFluids.clear(); HashMap computeStacks = new HashMap(); @@ -589,31 +624,12 @@ public class BptBuilderBlueprint extends BptBuilderBase { for (Entry e : computeStacks.entrySet()) { ItemStack newStack = e.getKey().stack.copy(); newStack.stackSize = e.getValue(); + + + neededItems.add(newStack); } - LinkedList sortedList = new LinkedList(); - - for (ItemStack toInsert : neededItems) { - int index = 0; - boolean didInsert = false; - - for (ItemStack inserted : sortedList) { - if (inserted.stackSize < toInsert.stackSize) { - sortedList.add(index, toInsert); - didInsert = true; - break; - } - - index++; - } - - if (!didInsert) { - sortedList.addLast(toInsert); - } - } - - Collections.sort (neededItems, new Comparator() { @Override public int compare(ItemStack o1, ItemStack o2) { diff --git a/common/buildcraft/core/fluids/FluidUtils.java b/common/buildcraft/core/fluids/FluidUtils.java index 6488b3d9..6f2e3146 100644 --- a/common/buildcraft/core/fluids/FluidUtils.java +++ b/common/buildcraft/core/fluids/FluidUtils.java @@ -34,7 +34,7 @@ public final class FluidUtils { } public static boolean handleRightClick(IFluidHandler tank, ForgeDirection side, EntityPlayer player, boolean fill, boolean drain) { - if (player == null) { + if (player == null || tank == null) { return false; } ItemStack current = player.inventory.getCurrentItem(); diff --git a/common/buildcraft/core/fluids/Tank.java b/common/buildcraft/core/fluids/Tank.java index 3ae0d130..8c77efed 100644 --- a/common/buildcraft/core/fluids/Tank.java +++ b/common/buildcraft/core/fluids/Tank.java @@ -18,8 +18,9 @@ import net.minecraftforge.fluids.FluidTank; import buildcraft.core.gui.tooltips.ToolTip; import buildcraft.core.gui.tooltips.ToolTipLine; +import buildcraft.core.network.INBTSerializable; -public class Tank extends FluidTank { +public class Tank extends FluidTank implements INBTSerializable { public int colorRenderCache = 0xFFFFFF; protected final ToolTip toolTip = new ToolTip() { @@ -61,6 +62,9 @@ public class Tank extends FluidTank { @Override public final FluidTank readFromNBT(NBTTagCompound nbt) { if (nbt.hasKey(name)) { + // allow to read empty tanks + setFluid(null); + NBTTagCompound tankData = nbt.getCompoundTag(name); super.readFromNBT(tankData); readTankFromNBT(tankData); @@ -89,4 +93,16 @@ public class Tank extends FluidTank { } toolTip.add(new ToolTipLine(String.format(Locale.ENGLISH, "%,d / %,d", amount, getCapacity()))); } + + @Override + public NBTTagCompound serializeNBT() { + NBTTagCompound nbt = new NBTTagCompound(); + writeToNBT(nbt); + return nbt; + } + + @Override + public void serializeNBT(NBTTagCompound nbt) { + readFromNBT(nbt); + } } diff --git a/common/buildcraft/core/fluids/TankManager.java b/common/buildcraft/core/fluids/TankManager.java index 95ec233c..8cd47af5 100644 --- a/common/buildcraft/core/fluids/TankManager.java +++ b/common/buildcraft/core/fluids/TankManager.java @@ -27,7 +27,9 @@ import net.minecraftforge.fluids.FluidStack; import net.minecraftforge.fluids.FluidTankInfo; import net.minecraftforge.fluids.IFluidHandler; -public class TankManager extends ForwardingList implements IFluidHandler, List { +import buildcraft.core.network.INBTSerializable; + +public class TankManager extends ForwardingList implements IFluidHandler, List, INBTSerializable { private List tanks = new ArrayList(); @@ -139,4 +141,16 @@ public class TankManager extends ForwardingList implements IF } } } + + @Override + public NBTTagCompound serializeNBT() { + NBTTagCompound nbt = new NBTTagCompound(); + writeToNBT(nbt); + return nbt; + } + + @Override + public void serializeNBT(NBTTagCompound nbt) { + readFromNBT(nbt); + } } diff --git a/common/buildcraft/core/gui/GuiBuildCraft.java b/common/buildcraft/core/gui/GuiBuildCraft.java index 3123dbb7..5fed94b7 100644 --- a/common/buildcraft/core/gui/GuiBuildCraft.java +++ b/common/buildcraft/core/gui/GuiBuildCraft.java @@ -17,6 +17,8 @@ import net.minecraft.client.Minecraft; import net.minecraft.client.gui.FontRenderer; import net.minecraft.client.gui.inventory.GuiContainer; import net.minecraft.client.renderer.RenderHelper; +import net.minecraft.client.renderer.Tessellator; +import net.minecraft.client.renderer.texture.TextureMap; import net.minecraft.entity.player.InventoryPlayer; import net.minecraft.inventory.IInventory; import net.minecraft.inventory.Slot; @@ -24,6 +26,8 @@ import net.minecraft.tileentity.TileEntity; import net.minecraft.util.IIcon; import net.minecraft.util.ResourceLocation; +import net.minecraftforge.fluids.FluidStack; + import buildcraft.core.DefaultProps; import buildcraft.core.gui.slots.IPhantomSlot; import buildcraft.core.gui.tooltips.IToolTipProvider; @@ -114,6 +118,49 @@ public abstract class GuiBuildCraft extends GuiContainer { } } + public void drawFluid(FluidStack fluid, int x, int y, int width, int height, int maxCapacity) { + if (fluid == null || fluid.getFluid() == null) { + return; + } + IIcon icon = fluid.getFluid().getIcon(fluid); + mc.renderEngine.bindTexture(TextureMap.locationBlocksTexture); + RenderUtils.setGLColorFromInt(fluid.getFluid().getColor(fluid)); + int fullX = width / 16; + int fullY = height / 16; + int lastX = width - fullX * 16; + int lastY = height - fullY * 16; + int level = fluid.amount * height / maxCapacity; + int fullLvl = (height - level) / 16; + int lastLvl = (height - level) - fullLvl * 16; + for (int i = 0; i < fullX; i++) { + for (int j = 0; j < fullY; j++) { + if (j >= fullLvl) { + drawCutIcon(icon, x + i * 16, y + j * 16, 16, 16, j == fullLvl ? lastLvl : 0); + } + } + } + for (int i = 0; i < fullX; i++) { + drawCutIcon(icon, x + i * 16, y + fullY * 16, 16, lastY, fullLvl == fullY ? lastLvl : 0); + } + for (int i = 0; i < fullY; i++) { + if (i >= fullLvl) { + drawCutIcon(icon, x + fullX * 16, y + i * 16, lastX, 16, i == fullLvl ? lastLvl : 0); + } + } + drawCutIcon(icon, x + fullX * 16, y + fullY * 16, lastX, lastY, fullLvl == fullY ? lastLvl : 0); + } + + //The magic is here + private void drawCutIcon(IIcon icon, int x, int y, int width, int height, int cut) { + Tessellator tess = Tessellator.instance; + tess.startDrawingQuads(); + tess.addVertexWithUV(x, y + height, zLevel, icon.getMinU(), icon.getInterpolatedV(height)); + tess.addVertexWithUV(x + width, y + height, zLevel, icon.getInterpolatedU(width), icon.getInterpolatedV(height)); + tess.addVertexWithUV(x + width, y + cut, zLevel, icon.getInterpolatedU(width), icon.getInterpolatedV(cut)); + tess.addVertexWithUV(x, y + cut, zLevel, icon.getMinU(), icon.getInterpolatedV(cut)); + tess.draw(); + } + @Override protected void drawGuiContainerBackgroundLayer(float f, int mouseX, int mouseY) { GL11.glColor4f(1.0F, 1.0F, 1.0F, 1.0F); @@ -143,6 +190,10 @@ public abstract class GuiBuildCraft extends GuiContainer { ledgerManager.drawLedgers(x, y); } + public void drawCenteredString(String string, int xCenter, int yCenter, int textColor) { + fontRendererObj.drawString(string, xCenter - fontRendererObj.getStringWidth(string) / 2, yCenter - fontRendererObj.FONT_HEIGHT / 2, textColor); + } + protected int getCenteredOffset(String string) { return getCenteredOffset(string, xSize); } diff --git a/common/buildcraft/core/network/RPCHandler.java b/common/buildcraft/core/network/RPCHandler.java index 5a317c6d..52b6aca3 100755 --- a/common/buildcraft/core/network/RPCHandler.java +++ b/common/buildcraft/core/network/RPCHandler.java @@ -11,7 +11,6 @@ package buildcraft.core.network; import java.io.IOException; import java.lang.reflect.InvocationTargetException; import java.lang.reflect.Method; -import java.util.ArrayList; import java.util.Arrays; import java.util.Comparator; import java.util.LinkedList; @@ -112,8 +111,6 @@ public final class RPCHandler { PacketRPCTile packet = handlers.get (tile.getClass().getName()).createRCPPacket(tile, method, actuals); if (packet != null) { - ArrayList packets = packet.breakIntoSmallerPackets(30 * 1024); - for (PacketRPCTile p : packet.breakIntoSmallerPackets(MAX_PACKET_SIZE)) { BuildCraftCore.instance.sendToServer(p); } diff --git a/common/buildcraft/energy/GuiHandler.java b/common/buildcraft/energy/GuiHandler.java index 0dfc5046..52633e49 100644 --- a/common/buildcraft/energy/GuiHandler.java +++ b/common/buildcraft/energy/GuiHandler.java @@ -38,10 +38,10 @@ public class GuiHandler implements IGuiHandler { switch (id) { case GuiIds.ENGINE_IRON: - return new GuiCombustionEngine(player.inventory, engine); + return new GuiCombustionEngine(player.inventory, (TileEngineIron) engine); case GuiIds.ENGINE_STONE: - return new GuiStoneEngine(player.inventory, engine); + return new GuiStoneEngine(player.inventory, (TileEngineStone) engine); default: return null; diff --git a/common/buildcraft/energy/TileEngine.java b/common/buildcraft/energy/TileEngine.java index fa1d52fc..3134e4e2 100644 --- a/common/buildcraft/energy/TileEngine.java +++ b/common/buildcraft/energy/TileEngine.java @@ -411,8 +411,6 @@ public abstract class TileEngine extends TileBuildCraft implements ISidedBattery /* STATE INFORMATION */ public abstract boolean isBurning(); - public abstract int getScaledBurnTime(int scale); - @Override public PowerReceiver getPowerReceiver(ForgeDirection side) { return powerHandler.getPowerReceiver(); diff --git a/common/buildcraft/energy/TileEngineCreative.java b/common/buildcraft/energy/TileEngineCreative.java index 1e785b86..14caaa9f 100644 --- a/common/buildcraft/energy/TileEngineCreative.java +++ b/common/buildcraft/energy/TileEngineCreative.java @@ -111,11 +111,6 @@ public class TileEngineCreative extends TileEngine { return isRedstonePowered; } - @Override - public int getScaledBurnTime(int scale) { - return 0; - } - @Override public float explosionRange() { return 0; diff --git a/common/buildcraft/energy/TileEngineIron.java b/common/buildcraft/energy/TileEngineIron.java index ee316c17..25f1c97e 100644 --- a/common/buildcraft/energy/TileEngineIron.java +++ b/common/buildcraft/energy/TileEngineIron.java @@ -254,12 +254,6 @@ public class TileEngineIron extends TileEngineWithInventory implements IFluidHan } } - @Override - public int getScaledBurnTime(int i) { - return this.tankFuel.getFluid() != null ? (int) (((float) this.tankFuel.getFluid().amount / (float) MAX_LIQUID) * i) - : 0; - } - @Override public void readFromNBT(NBTTagCompound data) { super.readFromNBT(data); @@ -280,11 +274,6 @@ public class TileEngineIron extends TileEngineWithInventory implements IFluidHan } - public int getScaledCoolant(int i) { - return tankCoolant.getFluid() != null ? (int) (((float) tankCoolant.getFluid().amount / (float) MAX_LIQUID) * i) - : 0; - } - @Override public void getGUINetworkData(int id, int value) { super.getGUINetworkData(id, value); diff --git a/common/buildcraft/energy/TileEngineStone.java b/common/buildcraft/energy/TileEngineStone.java index 786e392f..fe9c0fdc 100644 --- a/common/buildcraft/energy/TileEngineStone.java +++ b/common/buildcraft/energy/TileEngineStone.java @@ -104,7 +104,6 @@ public class TileEngineStone extends TileEngineWithInventory { } } - @Override public int getScaledBurnTime(int i) { return (int) (((float) burnTime / (float) totalBurnTime) * i); } diff --git a/common/buildcraft/energy/TileEngineWood.java b/common/buildcraft/energy/TileEngineWood.java index 51966ec8..06edb32c 100644 --- a/common/buildcraft/energy/TileEngineWood.java +++ b/common/buildcraft/energy/TileEngineWood.java @@ -87,9 +87,4 @@ public class TileEngineWood extends TileEngine { public boolean isBurning() { return isRedstonePowered; } - - @Override - public int getScaledBurnTime(int i) { - return 0; - } } diff --git a/common/buildcraft/energy/gui/GuiCombustionEngine.java b/common/buildcraft/energy/gui/GuiCombustionEngine.java index fd2bffd2..c25d9575 100644 --- a/common/buildcraft/energy/gui/GuiCombustionEngine.java +++ b/common/buildcraft/energy/gui/GuiCombustionEngine.java @@ -8,26 +8,18 @@ */ package buildcraft.energy.gui; -import net.minecraft.client.renderer.Tessellator; -import net.minecraft.client.renderer.texture.TextureMap; import net.minecraft.entity.player.InventoryPlayer; -import net.minecraft.util.IIcon; import net.minecraft.util.ResourceLocation; -import net.minecraftforge.fluids.FluidStack; - import buildcraft.core.DefaultProps; -import buildcraft.core.render.RenderUtils; import buildcraft.core.utils.StringUtils; import buildcraft.energy.TileEngineIron; -import buildcraft.energy.TileEngineWithInventory; public class GuiCombustionEngine extends GuiEngine { private static final ResourceLocation TEXTURE = new ResourceLocation("buildcraft", DefaultProps.TEXTURE_PATH_GUI + "/combustion_engine_gui.png"); - private static final ResourceLocation BLOCK_TEXTURE = TextureMap.locationBlocksTexture; - public GuiCombustionEngine(InventoryPlayer inventoryplayer, TileEngineWithInventory tileEngine) { + public GuiCombustionEngine(InventoryPlayer inventoryplayer, TileEngineIron tileEngine) { super(new ContainerEngine(inventoryplayer, tileEngine), tileEngine, TEXTURE); } @@ -45,52 +37,10 @@ public class GuiCombustionEngine extends GuiEngine { int j = (width - xSize) / 2; int k = (height - ySize) / 2; TileEngineIron engine = (TileEngineIron) tile; - drawFluid(engine.getFuel(), engine.getScaledBurnTime(58), j + 104, k + 19, 16, 58); - drawFluid(engine.getCoolant(), engine.getScaledCoolant(58), j + 122, k + 19, 16, 58); - mc.renderEngine.bindTexture(TEXTURE); - drawTexturedModalRect(j + 104, k + 19, 176, 0, 16, 60); - drawTexturedModalRect(j + 122, k + 19, 176, 0, 16, 60); - } - - private void drawFluid(FluidStack fluid, int level, int x, int y, int width, int height) { - if (fluid == null || fluid.getFluid() == null) { - return; - } - IIcon icon = fluid.getFluid().getIcon(fluid); - mc.renderEngine.bindTexture(BLOCK_TEXTURE); - RenderUtils.setGLColorFromInt(fluid.getFluid().getColor(fluid)); - int fullX = width / 16; - int fullY = height / 16; - int lastX = width - fullX * 16; - int lastY = height - fullY * 16; - int fullLvl = (height - level) / 16; - int lastLvl = (height - level) - fullLvl * 16; - for (int i = 0; i < fullX; i++) { - for (int j = 0; j < fullY; j++) { - if (j >= fullLvl) { - drawCutIcon(icon, x + i * 16, y + j * 16, 16, 16, j == fullLvl ? lastLvl : 0); - } - } - } - for (int i = 0; i < fullX; i++) { - drawCutIcon(icon, x + i * 16, y + fullY * 16, 16, lastY, fullLvl == fullY ? lastLvl : 0); - } - for (int i = 0; i < fullY; i++) { - if (i >= fullLvl) { - drawCutIcon(icon, x + fullX * 16, y + i * 16, lastX, 16, i == fullLvl ? lastLvl : 0); - } - } - drawCutIcon(icon, x + fullX * 16, y + fullY * 16, lastX, lastY, fullLvl == fullY ? lastLvl : 0); - } - - //The magic is here - private void drawCutIcon(IIcon icon, int x, int y, int width, int height, int cut) { - Tessellator tess = Tessellator.instance; - tess.startDrawingQuads(); - tess.addVertexWithUV(x, y + height, zLevel, icon.getMinU(), icon.getInterpolatedV(height)); - tess.addVertexWithUV(x + width, y + height, zLevel, icon.getInterpolatedU(width), icon.getInterpolatedV(height)); - tess.addVertexWithUV(x + width, y + cut, zLevel, icon.getInterpolatedU(width), icon.getInterpolatedV(cut)); - tess.addVertexWithUV(x, y + cut, zLevel, icon.getMinU(), icon.getInterpolatedV(cut)); - tess.draw(); + drawFluid(engine.getFuel(), j + 104, k + 19, 16, 58, TileEngineIron.MAX_LIQUID); + drawFluid(engine.getCoolant(), j + 122, k + 19, 16, 58, TileEngineIron.MAX_LIQUID); + mc.renderEngine.bindTexture(TEXTURE); + drawTexturedModalRect(j + 104, k + 19, 176, 0, 16, 60); + drawTexturedModalRect(j + 122, k + 19, 176, 0, 16, 60); } } diff --git a/common/buildcraft/energy/gui/GuiStoneEngine.java b/common/buildcraft/energy/gui/GuiStoneEngine.java index dae2af12..9184f2c5 100644 --- a/common/buildcraft/energy/gui/GuiStoneEngine.java +++ b/common/buildcraft/energy/gui/GuiStoneEngine.java @@ -15,14 +15,13 @@ import net.minecraft.util.ResourceLocation; import buildcraft.core.DefaultProps; import buildcraft.core.utils.StringUtils; -import buildcraft.energy.TileEngine; -import buildcraft.energy.TileEngineWithInventory; +import buildcraft.energy.TileEngineStone; public class GuiStoneEngine extends GuiEngine { private static final ResourceLocation TEXTURE = new ResourceLocation("buildcraft", DefaultProps.TEXTURE_PATH_GUI + "/steam_engine_gui.png"); - public GuiStoneEngine(InventoryPlayer inventoryplayer, TileEngineWithInventory tileEngine) { + public GuiStoneEngine(InventoryPlayer inventoryplayer, TileEngineStone tileEngine) { super(new ContainerEngine(inventoryplayer, tileEngine), tileEngine, TEXTURE); } @@ -42,7 +41,7 @@ public class GuiStoneEngine extends GuiEngine { int k = (height - ySize) / 2; drawTexturedModalRect(j, k, 0, 0, xSize, ySize); - TileEngine engine = (TileEngine) tile; + TileEngineStone engine = (TileEngineStone) tile; if (engine.getScaledBurnTime(12) > 0) { int l = engine.getScaledBurnTime(12);