99import gregtech .api .metatileentity .interfaces .IGregTechTileEntity ;
1010import gregtech .api .recipes .ModHandler ;
1111import gregtech .api .unification .material .Material ;
12- import gregtech .api .unification .material .properties .FluidPipeProperties ;
1312import gregtech .api .unification .material .properties .PropertyKey ;
1413import gregtech .api .util .GTUtility ;
1514import gregtech .client .renderer .texture .Textures ;
5453
5554public class MetaTileEntityDrum extends MetaTileEntity {
5655
56+ private final IPropertyFluidFilter fluidFilter ;
57+ private final boolean isWood ;
58+ private final int color ;
5759 private final int tankSize ;
58- private final Material material ;
60+
5961 private FilteredFluidHandler fluidTank ;
6062 private boolean isAutoOutput = false ;
6163
62- public MetaTileEntityDrum (ResourceLocation metaTileEntityId , Material material , int tankSize ) {
64+ /**
65+ * @param metaTileEntityId the id for the MTE
66+ * @param material the material the drum is made of, must have
67+ * {@link gregtech.api.unification.material.properties.FluidProperty}.
68+ * @param tankSize the size of the storage tank
69+ */
70+ public MetaTileEntityDrum (ResourceLocation metaTileEntityId , @ NotNull Material material , int tankSize ) {
6371 super (metaTileEntityId );
72+ IPropertyFluidFilter filter = material .getProperty (PropertyKey .FLUID_PIPE );
73+ if (filter == null ) {
74+ throw new IllegalArgumentException ("Material " + material + " requires FluidPipeProperty for Drums" );
75+ }
76+ this .fluidFilter = filter ;
77+ this .isWood = ModHandler .isMaterialWood (material );
78+ this .color = material .getMaterialRGB ();
79+ this .tankSize = tankSize ;
80+ initializeInventory ();
81+ }
82+
83+ /**
84+ *
85+ * @param metaTileEntityId the id for the MTE
86+ * @param fluidFilter the filter for which fluids can be stored
87+ * @param isWood if the drum is made of wood
88+ * @param color the color of the drum in RGB format
89+ * @param tankSize the size of the storage tank
90+ */
91+ public MetaTileEntityDrum (ResourceLocation metaTileEntityId , @ NotNull IPropertyFluidFilter fluidFilter ,
92+ boolean isWood , int color , int tankSize ) {
93+ super (metaTileEntityId );
94+ this .fluidFilter = fluidFilter ;
95+ this .isWood = isWood ;
96+ this .color = color ;
6497 this .tankSize = tankSize ;
65- this .material = material ;
6698 initializeInventory ();
6799 }
68100
69101 @ Override
70102 public MetaTileEntity createMetaTileEntity (IGregTechTileEntity tileEntity ) {
71- return new MetaTileEntityDrum (metaTileEntityId , material , tankSize );
103+ return new MetaTileEntityDrum (metaTileEntityId , fluidFilter , isWood , color , tankSize );
72104 }
73105
74106 @ Override
75107 public String getHarvestTool () {
76- return ModHandler . isMaterialWood ( material ) ? ToolClasses .AXE : ToolClasses .WRENCH ;
108+ return isWood ? ToolClasses .AXE : ToolClasses .WRENCH ;
77109 }
78110
79111 @ Override
@@ -83,14 +115,14 @@ public boolean hasFrontFacing() {
83115
84116 @ Override
85117 protected void initializeInventory () {
86- if (this .material == null ) return ; // call before field initialization, should be called later with fields set
87- super .initializeInventory ();
88- IPropertyFluidFilter filter = this .material .getProperty (PropertyKey .FLUID_PIPE );
89- if (filter == null ) {
90- throw new IllegalArgumentException (
91- String .format ("Material %s requires FluidPipeProperty for Drums" , material ));
118+ // call before field initialization, should be called later with fields set
119+ if (this .fluidFilter == null ) {
120+ return ;
92121 }
93- this .fluidInventory = this .fluidTank = new FilteredFluidHandler (tankSize ).setFilter (filter );
122+
123+ super .initializeInventory ();
124+ this .fluidTank = new FilteredFluidHandler (tankSize ).setFilter (this .fluidFilter );
125+ this .fluidInventory = this .fluidTank ;
94126 }
95127
96128 @ Override
@@ -203,27 +235,26 @@ private void toggleOutput() {
203235 @ Override
204236 @ SideOnly (Side .CLIENT )
205237 public Pair <TextureAtlasSprite , Integer > getParticleTexture () {
206- if (ModHandler . isMaterialWood ( material ) ) {
238+ if (isWood ) {
207239 return Pair .of (Textures .WOODEN_DRUM .getParticleTexture (), getPaintingColorForRendering ());
208240 } else {
209- int color = ColourRGBA .multiply (
210- GTUtility .convertRGBtoOpaqueRGBA_CL (material .getMaterialRGB ()),
211- GTUtility .convertRGBtoOpaqueRGBA_CL (getPaintingColorForRendering ()));
212- color = GTUtility .convertOpaqueRGBA_CLtoRGB (color );
241+ int color = GTUtility .convertOpaqueRGBA_CLtoRGB (ColourRGBA .multiply (
242+ GTUtility .convertRGBtoOpaqueRGBA_CL (this .color ),
243+ GTUtility .convertRGBtoOpaqueRGBA_CL (getPaintingColorForRendering ())));
213244 return Pair .of (Textures .DRUM .getParticleTexture (), color );
214245 }
215246 }
216247
217248 @ Override
218249 public void renderMetaTileEntity (CCRenderState renderState , Matrix4 translation , IVertexOperation [] pipeline ) {
219- if (ModHandler . isMaterialWood ( material ) ) {
250+ if (isWood ) {
220251 ColourMultiplier multiplier = new ColourMultiplier (
221252 GTUtility .convertRGBtoOpaqueRGBA_CL (getPaintingColorForRendering ()));
222253 Textures .WOODEN_DRUM .render (renderState , translation , ArrayUtils .add (pipeline , multiplier ),
223254 getFrontFacing ());
224255 } else {
225256 ColourMultiplier multiplier = new ColourMultiplier (
226- ColourRGBA .multiply (GTUtility .convertRGBtoOpaqueRGBA_CL (material . getMaterialRGB () ),
257+ ColourRGBA .multiply (GTUtility .convertRGBtoOpaqueRGBA_CL (this . color ),
227258 GTUtility .convertRGBtoOpaqueRGBA_CL (getPaintingColorForRendering ())));
228259 Textures .DRUM .render (renderState , translation , ArrayUtils .add (pipeline , multiplier ), getFrontFacing ());
229260 Textures .DRUM_OVERLAY .render (renderState , translation , pipeline );
@@ -243,8 +274,7 @@ public int getDefaultPaintingColor() {
243274 @ SideOnly (Side .CLIENT )
244275 public void addInformation (ItemStack stack , @ Nullable World player , List <String > tooltip , boolean advanced ) {
245276 tooltip .add (I18n .format ("gregtech.universal.tooltip.fluid_storage_capacity" , tankSize ));
246- FluidPipeProperties pipeProperties = material .getProperty (PropertyKey .FLUID_PIPE );
247- pipeProperties .appendTooltips (tooltip , true , true );
277+ this .fluidFilter .appendTooltips (tooltip , true , true );
248278
249279 if (TooltipHelper .isShiftDown ()) {
250280 tooltip .add (I18n .format ("gregtech.tool_action.screwdriver.access_covers" ));
0 commit comments