Fluid Material builders, Marker Material, some comments

This commit is contained in:
Dragon2488 2017-07-23 00:06:42 +07:00
parent c4913ef87c
commit 9261735d5c
7 changed files with 198 additions and 11 deletions

View file

@ -4,6 +4,23 @@ import net.minecraftforge.fluids.FluidStack;
public interface FluidMaterial {
final class MatFlags {
/**
* Add to fluid material to have it's cell generated
*/
public static final int GENERATE_CELL = Material.MatFlags.createFlag(3);
/**
* Add to fluid material to have plasma fluid generated
*/
public static final int GENERATE_PLASMA = Material.MatFlags.createFlag(4);
}
default boolean hasFluid() {
return getFluid(1) != null;
}

View file

@ -156,24 +156,18 @@ public class DustMaterialBuilder<T extends DustMaterial, Self extends DustMateri
@Override
protected T build() {
//java, fuck off, please
ImmutableList<MaterialStack> materialStacks1 = ImmutableList.copyOf(materialCompounds);
ImmutableList<SubTag> subTags1 = ImmutableList.copyOf(subTags);
ImmutableList<Material> reRegistrations = ImmutableList.of();
ImmutableList<DustMaterial> byProducts = ImmutableList.copyOf(oreByProducts);
return (T) new DustMaterial(
defaultLocalizedName,
rgbColor,
iconSet,
materialStacks1,
reRegistrations,
subTags1,
ImmutableList.copyOf(materialCompounds),
ImmutableList.copyOf(oreReRegistrations),
ImmutableList.copyOf(subTags),
materialGenerationBits,
densityMultiplier,
directElement,
oreValue,
byProducts,
ImmutableList.copyOf(oreByProducts),
oreMultiplier,
byProductMultiplier,
smeltingMultiplier,

View file

@ -0,0 +1,27 @@
package gregtech.api.enums.material.builder;
import com.google.common.collect.ImmutableList;
import gregtech.api.enums.material.types.FluidMaterialType;
public class FluidMaterialBuilder<T extends FluidMaterialType, Self extends FluidMaterialBuilder<T, Self>> extends MaterialBuilder<T, Self> implements IFluidMaterialBuilder<T, Self> {
public FluidMaterialBuilder(String name, String defaultLocalizedName) {
super(name, defaultLocalizedName);
}
@Override
protected T build() {
return (T) new FluidMaterialType(
defaultLocalizedName,
rgbColor,
iconSet,
ImmutableList.copyOf(materialCompounds),
ImmutableList.copyOf(oreReRegistrations),
ImmutableList.copyOf(subTags),
materialGenerationBits,
densityMultiplier,
directElement
);
}
}

View file

@ -0,0 +1,26 @@
package gregtech.api.enums.material.builder;
import gregtech.api.enums.material.FluidMaterial;
import gregtech.api.enums.material.Material;
//should be T extends FluidMaterial, but it is interface
public interface IFluidMaterialBuilder<T extends Material, Self extends MaterialBuilder<T, Self>> {
/**
* Enables a cell meta-item generation for this material
*/
default Self enableCell() {
((Self) this).materialGenerationBits |= FluidMaterial.MatFlags.GENERATE_CELL;
return (Self) this;
}
/**
* Enables plasma fluid generation for this material
*
*/
default Self enablePlasma() {
((Self) this).materialGenerationBits |= FluidMaterial.MatFlags.GENERATE_PLASMA;
return (Self) this;
}
}

View file

@ -6,6 +6,7 @@ import gregtech.api.enums.Element;
import gregtech.api.enums.SubTag;
import gregtech.api.enums.material.Material;
import gregtech.api.enums.material.MaterialIconSet;
import gregtech.api.enums.material.types.MarkerMaterial;
import gregtech.api.objects.MaterialStack;
import java.util.ArrayList;
@ -21,6 +22,7 @@ public abstract class MaterialBuilder<T extends Material, Self extends MaterialB
protected float densityMultiplier = 1.0f;
protected Element directElement = null;
protected ArrayList<MaterialStack> materialCompounds = new ArrayList<>();
protected ArrayList<Material> oreReRegistrations = new ArrayList<>();
protected int metaItemSubId = -1;
public MaterialBuilder(String name, String defaultLocalizedName) {
@ -28,45 +30,96 @@ public abstract class MaterialBuilder<T extends Material, Self extends MaterialB
this.defaultLocalizedName = defaultLocalizedName;
}
/**
* Assigns a meta item sub id to material
* Makes meta-items generate for this material if desired
* @param metaItemSubId meta item sub id
* @return this
*/
public Self metaItemSubId(int metaItemSubId) {
this.metaItemSubId = metaItemSubId;
return (Self) this;
}
/**
* Assigns material to a group of marker material
* @param markerMaterial marker
* @return this
*/
public Self reRegisterInto(MarkerMaterial markerMaterial) {
this.oreReRegistrations.add(markerMaterial);
return (Self) this;
}
/**
* Enables generation of centrifuge recipes like:
* X This Material Dust + N Cells = material components dusts/in cells
* @return this
*/
public Self enableDecompositionByCentrifuging() {
this.materialGenerationBits |= Material.MatFlags.GENERATE_DECOMPOSITION_RECIPES;
this.materialGenerationBits |= Material.MatFlags.DECOMPOSITION_BY_CENTRIFUGING;
return (Self) this;
}
/**
* Enables generation of electrolyzer recipes like:
* X This Material Dust + N Cells = material components dusts/in cells
* @return this
*/
public Self enableDecompositionByElectrolyzing() {
this.materialGenerationBits |= Material.MatFlags.GENERATE_DECOMPOSITION_RECIPES;
this.materialGenerationBits |= Material.MatFlags.DECOMPOSITION_BY_ELECTROLYZING;
return (Self) this;
}
/**
* Marks this material as magical.
* Doesn't have any actual effect on material
* @return this
*/
public Self markMagical() {
this.subTags.add(Material.MatFlags.MAGICAL);
return (Self) this;
}
/**
* Marks material as explosive.
* Used in some recipes generation
* @return this
*/
public Self markExplosive() {
this.subTags.add(Material.MatFlags.EXPLOSIVE);
return (Self) this;
}
/**
* Marks material as totally unburnable (cannot catch fire at all)
* Used in some recipes generation
* @return this
*/
public Self markUnburnable() {
Preconditions.checkState(!subTags.contains(Material.MatFlags.FLAMMABLE), "Cannot mark flammable material as unburnable!");
this.subTags.add(Material.MatFlags.UNBURNABLE);
return (Self) this;
}
/**
* Marks material as flammable (can catch fire from source)
* Used in some recipes generation
* @return this
*/
public Self markFlammable() {
Preconditions.checkState(!subTags.contains(Material.MatFlags.UNBURNABLE), "Cannot mark unburnable material as flammable!");
this.subTags.add(Material.MatFlags.FLAMMABLE);
return (Self) this;
}
/**
* Marks material as burning itself (can ignite things itself)
* Used in some recipes generation
* @return this
*/
public Self markBurning() {
Preconditions.checkState(!subTags.contains(Material.MatFlags.UNBURNABLE), "Cannot mark unburnable material as burning!");
this.subTags.add(Material.MatFlags.FLAMMABLE);
@ -74,26 +127,51 @@ public abstract class MaterialBuilder<T extends Material, Self extends MaterialB
return (Self) this;
}
/**
* Disables unification for this material
* @return this
*/
public Self disableUnification() {
this.subTags.add(Material.MatFlags.NO_UNIFICATION);
return (Self) this;
}
/**
* Disables recycling for this material
* @return this
*/
public Self disableRecycling() {
this.subTags.add(Material.MatFlags.NO_RECYCLING);
return (Self) this;
}
/**
* Sets a color of a material
* @param color RGB color (0xRRGGBB)
* @return this
*/
public Self color(int color) {
this.rgbColor = color;
return (Self) this;
}
/**
* Sets a density multiplier for material
* Affects cost of replicating material trough Replicator (and total material's mass)
* @param densityMultiplier density multiplier
* @return this
*/
public Self densityMultiplier(float densityMultiplier) {
this.densityMultiplier = densityMultiplier;
return (Self) this;
}
/**
* Specifies direct element from which this material consist
* Not compatible with compounds(...) under this method
* @param element direct element
* @return this
*/
public Self directElement(Element element) {
Preconditions.checkNotNull(element);
Preconditions.checkState(materialCompounds.isEmpty(), "Cannot specify direct element for compound material!");
@ -101,6 +179,12 @@ public abstract class MaterialBuilder<T extends Material, Self extends MaterialB
return (Self) this;
}
/**
* Specifies sub-materials (components) of this material
* Not compatible with directElement(Element) above
* @param compounds material components
* @return this
*/
public Self compounds(MaterialStack... compounds) {
Preconditions.checkNotNull(compounds);
Preconditions.checkArgument(compounds.length > 0, "Cannot add empty compounds array!");
@ -109,13 +193,23 @@ public abstract class MaterialBuilder<T extends Material, Self extends MaterialB
return (Self) this;
}
/**
* Builds actual material instance
* Registration is done by buildAndRegister(), only build, not register.
* @return built material
*/
protected abstract T build();
/**
* Builds and registers material
* @return material
*/
public final T buildAndRegister() {
T material = build();
if(metaItemSubId > 0) {
Material.MATERIAL_REGISTRY.register(metaItemSubId, name, material);
} else Material.MATERIAL_REGISTRY.putObject(name, material);
return material;
}
}

View file

@ -1,6 +1,7 @@
package gregtech.api.enums.material.types;
import com.google.common.base.Preconditions;
import com.google.common.collect.ImmutableList;
import gregtech.api.enums.Element;
import gregtech.api.enums.SubTag;
import gregtech.api.enums.material.Material;
@ -16,7 +17,7 @@ public class FluidMaterialType extends Material implements gregtech.api.enums.ma
private Fluid materialFluid;
private Fluid materialPlasma;
public FluidMaterialType(String defaultLocalName, int materialRGB, MaterialIconSet materialIconSet, List<MaterialStack> materialComponents, List<Material> oreReRegistrations, List<SubTag> subTags, int materialGenerationFlags, float densityMultiplier, Element element) {
public FluidMaterialType(String defaultLocalName, int materialRGB, MaterialIconSet materialIconSet, ImmutableList<MaterialStack> materialComponents, ImmutableList<Material> oreReRegistrations, ImmutableList<SubTag> subTags, int materialGenerationFlags, float densityMultiplier, Element element) {
super(defaultLocalName, materialRGB, materialIconSet, materialComponents, oreReRegistrations, subTags, materialGenerationFlags, densityMultiplier, element);
}

View file

@ -0,0 +1,28 @@
package gregtech.api.enums.material.types;
import com.google.common.collect.ImmutableList;
import gregtech.api.enums.SubTag;
import gregtech.api.enums.material.Material;
import gregtech.api.enums.material.MaterialIconSet;
import gregtech.api.objects.MaterialStack;
/**
* MarkerMaterial is type of material used for generic things like material re-registration and use in recipes
* Marker material cannot be used to generate any meta items
* Marker material can be used only for marking other materials (re-registeoring) equal to it and then using it in recipes or in getting items v
*/
public final class MarkerMaterial extends Material {
public MarkerMaterial(String defaultLocalName, int materialRGB) {
super(defaultLocalName,
materialRGB,
MaterialIconSet.NONE,
ImmutableList.of(),
ImmutableList.of(),
ImmutableList.of(),
0,
1.0f,
null);
}
}