use of gregtech.api.unification.material.Material in project GregTech by GregTechCEu.
the class MetaFluids method registerFluid.
@Nonnull
public static Fluid registerFluid(@Nonnull Material material, @Nonnull FluidType fluidType, int temperature, boolean generateBlock) {
String materialName = material.toString();
String fluidName = fluidType.getNameForMaterial(material);
Fluid fluid = FluidRegistry.getFluid(fluidName);
// check if fluid is registered from elsewhere under an alternative name
if (fluid == null && alternativeFluidNames.containsKey(fluidName)) {
String altName = alternativeFluidNames.get(fluidName);
fluid = FluidRegistry.getFluid(altName);
}
// if the material is still not registered by this point, register it
if (fluid == null) {
// determine texture for use
ResourceLocation textureLocation = fluidTextureMap.computeIfAbsent(material, key -> {
Map<FluidType, ResourceLocation> map = new Object2ObjectOpenHashMap<>();
if (fluidType.equals(FluidTypes.PLASMA))
map.put(fluidType, AUTO_GENERATED_PLASMA_TEXTURE);
else
map.put(fluidType, MaterialIconType.fluid.getBlockPath(material.getMaterialIconSet()));
return map;
}).computeIfAbsent(fluidType, key -> {
Map<FluidType, ResourceLocation> map = fluidTextureMap.get(material);
if (fluidType.equals(FluidTypes.PLASMA))
map.put(fluidType, AUTO_GENERATED_PLASMA_TEXTURE);
else
map.put(fluidType, MaterialIconType.fluid.getBlockPath(material.getMaterialIconSet()));
return map.get(fluidType);
});
// create the new fluid
fluid = new MaterialFluid(fluidName, material, fluidType, textureLocation);
fluid.setTemperature(temperature);
if (material.hasFluidColor())
fluid.setColor(GTUtility.convertRGBtoOpaqueRGBA_MC(material.getMaterialRGB()));
else
fluid.setColor(0xFFFFFFFF);
// set properties and register
FluidType.setFluidProperties(fluidType, fluid);
((MaterialFluid) fluid).registerFluidTooltip();
FluidRegistry.registerFluid(fluid);
}
// add buckets for each fluid
FluidRegistry.addBucketForFluid(fluid);
// generate fluid blocks if the material has one, and the current state being handled is not plasma
if (generateBlock && fluid.getBlock() == null && fluidType != FluidTypes.PLASMA) {
BlockFluidBase fluidBlock = new BlockFluidClassic(fluid, net.minecraft.block.material.Material.WATER);
fluidBlock.setRegistryName("fluid." + materialName);
MetaBlocks.FLUID_BLOCKS.add(fluidBlock);
}
fluidToMaterialMappings.put(fluid.getName(), material);
return fluid;
}
use of gregtech.api.unification.material.Material in project GregTech by GregTechCEu.
the class BlockMaterialPipe method createProperties.
@Override
public NodeDataType createProperties(IPipeTile<PipeType, NodeDataType> pipeTile) {
PipeType pipeType = pipeTile.getPipeType();
Material material = ((IMaterialPipeTile<PipeType, NodeDataType>) pipeTile).getPipeMaterial();
if (pipeType == null || material == null) {
return getFallbackType();
}
return createProperties(pipeType, material);
}
use of gregtech.api.unification.material.Material in project GregTech by GregTechCEu.
the class OreDictUnifier method onItemRegistration.
@SubscribeEvent
public static void onItemRegistration(OreRegisterEvent event) {
ItemAndMetadata simpleItemStack = new ItemAndMetadata(event.getOre());
String oreName = event.getName();
// cache this registration by name
stackOreDictName.computeIfAbsent(simpleItemStack, k -> new HashSet<>()).add(oreName);
List<ItemStack> itemStackListForOreDictName = oreDictNameStacks.computeIfAbsent(oreName, k -> new ArrayList<>());
addAndSort(itemStackListForOreDictName, event.getOre().copy(), getItemStackComparator());
// and try to transform registration name into OrePrefix + Material pair
OrePrefix orePrefix = OrePrefix.getPrefix(oreName);
Material material = null;
if (orePrefix == null) {
// split ore dict name to parts
// oreBasalticMineralSand -> ore, Basaltic, Mineral, Sand
ArrayList<String> splits = new ArrayList<>();
StringBuilder builder = new StringBuilder();
for (char character : oreName.toCharArray()) {
if (Character.isUpperCase(character)) {
if (builder.length() > 0) {
splits.add(builder.toString());
builder = new StringBuilder().append(character);
} else
splits.add(Character.toString(character));
} else
builder.append(character);
}
if (builder.length() > 0) {
splits.add(builder.toString());
}
// try to combine in different manners
// oreBasaltic MineralSand , ore BasalticMineralSand
StringBuilder buffer = new StringBuilder();
for (int i = 0; i < splits.size(); i++) {
buffer.append(splits.get(i));
// ore -> OrePrefix.ore
OrePrefix maybePrefix = OrePrefix.getPrefix(buffer.toString());
// BasalticMineralSand
String possibleMaterialName = Joiner.on("").join(splits.subList(i + 1, splits.size()));
// basaltic_mineral_sand
String underscoreName = GTUtility.toLowerCaseUnderscore(possibleMaterialName);
// Materials.BasalticSand
Material possibleMaterial = GregTechAPI.MATERIAL_REGISTRY.getObject(underscoreName);
if (possibleMaterial == null) {
// if we didn't found real material, try using marker material registry
possibleMaterial = markerMaterialRegistry.get(underscoreName);
}
if (maybePrefix != null && possibleMaterial != null) {
orePrefix = maybePrefix;
material = possibleMaterial;
break;
}
}
}
// finally register item
if (orePrefix != null && (material != null || orePrefix.isSelfReferencing)) {
UnificationEntry unificationEntry = new UnificationEntry(orePrefix, material);
ArrayList<ItemAndMetadata> itemListForUnifiedEntry = stackUnificationItems.computeIfAbsent(unificationEntry, p -> new ArrayList<>());
addAndSort(itemListForUnifiedEntry, simpleItemStack, getSimpleItemStackComparator());
if (!unificationEntry.orePrefix.isMarkerPrefix()) {
stackUnificationInfo.put(simpleItemStack, unificationEntry);
}
orePrefix.processOreRegistration(material);
}
}
use of gregtech.api.unification.material.Material in project GregTech by GregTechCEu.
the class CableRenderer method getParticleTexture.
@Override
public Pair<TextureAtlasSprite, Integer> getParticleTexture(IPipeTile<?, ?> pipeTile) {
if (pipeTile == null) {
return Pair.of(TextureUtils.getMissingSprite(), 0xFFFFFF);
}
IPipeType<?> pipeType = pipeTile.getPipeType();
if (!(pipeType instanceof Insulation)) {
return Pair.of(TextureUtils.getMissingSprite(), 0xFFFFFF);
}
Material material = pipeTile instanceof TileEntityMaterialPipeBase ? ((TileEntityMaterialPipeBase<?, ?>) pipeTile).getPipeMaterial() : null;
TextureAtlasSprite atlasSprite;
int particleColor;
int insulationLevel = ((Insulation) pipeType).insulationLevel;
if (insulationLevel == -1) {
atlasSprite = wireTexture;
particleColor = material == null ? 0xFFFFFF : material.getMaterialRGB();
} else {
atlasSprite = insulationTextures[5];
particleColor = pipeTile.getPaintingColor();
}
return Pair.of(atlasSprite, particleColor);
}
use of gregtech.api.unification.material.Material in project GregTech by GregTechCEu.
the class CompressedBlockBakedModel method getQuads.
@Override
@Nonnull
public List<BakedQuad> getQuads(@Nullable IBlockState state, @Nullable EnumFacing side, long rand) {
List<BakedQuad> quads = new ArrayList<>();
if (side == null)
return quads;
if (state != null) {
Material material = state.getValue(((BlockCompressed) state.getBlock()).variantProperty);
Map<EnumFacing, BakedQuad> materialFace = materialFaces.get(material.getMaterialIconSet());
if (materialFace == null) {
materialFaces.put(material.getMaterialIconSet(), materialFace = new Object2ObjectOpenHashMap<>());
}
BakedQuad materialFaceQuad = materialFace.get(side);
if (materialFaceQuad == null) {
materialFace.put(side, materialFaceQuad = ModelFactory.getBakery().makeBakedQuad(new Vector3f(0F, 0F, 0F), new Vector3f(16F, 16F, 16F), new BlockPartFace(side, 1, "", new BlockFaceUV(new float[] { 0.0F, 0.0F, 16.0F, 16.0F, 0.0F, 0.0F, 16.0F, 16.0F }, 0)), ModelLoader.defaultTextureGetter().apply(MaterialIconType.block.getBlockPath(material.getMaterialIconSet())), side, ModelRotation.X0_Y0, null, true, true));
}
quads.add(materialFaceQuad);
particle.set(materialFaceQuad.getSprite());
} else {
ItemStack stack = CompressedBlockItemOverride.INSTANCE.stack.get();
if (!stack.isEmpty()) {
BlockCompressed compressed = (BlockCompressed) ((ItemBlock) stack.getItem()).getBlock();
IBlockState compressedState = compressed.getDefaultState().withProperty(compressed.variantProperty, compressed.variantProperty.getAllowedValues().get(stack.getMetadata()));
for (EnumFacing face : EnumFacing.VALUES) {
quads.addAll(getQuads(compressedState, face, rand));
}
}
}
return quads;
}
Aggregations