Search in sources :

Example 6 with OrePrefix

use of gregtech.api.unification.ore.OrePrefix in project GregTech by GregTechCE.

the class MaterialMetaItem method getItemStackDisplayName.

@Override
@SideOnly(Side.CLIENT)
public String getItemStackDisplayName(ItemStack itemStack) {
    if (itemStack.getItemDamage() < metaItemOffset) {
        if (!generatedItems.contains((short) itemStack.getItemDamage())) {
            return "";
        }
        Material material = Material.MATERIAL_REGISTRY.getObjectById(itemStack.getItemDamage() % 1000);
        OrePrefix prefix = orePrefixes[itemStack.getItemDamage() / 1000];
        return prefix.getLocalNameForItem(material);
    }
    return super.getItemStackDisplayName(itemStack);
}
Also used : OrePrefix(gregtech.api.unification.ore.OrePrefix) Material(gregtech.api.unification.material.type.Material) MarkerMaterial(gregtech.api.unification.material.type.MarkerMaterial) SideOnly(net.minecraftforge.fml.relauncher.SideOnly)

Example 7 with OrePrefix

use of gregtech.api.unification.ore.OrePrefix in project GregTech by GregTechCE.

the class MaterialMetaItem method registerModels.

@Override
@SideOnly(Side.CLIENT)
public void registerModels() {
    for (short metaItem : generatedItems) {
        OrePrefix prefix = this.orePrefixes[metaItem / 1000];
        Material material = Material.MATERIAL_REGISTRY.getObjectById(metaItem % 1000);
        ModelBakery.registerItemVariants(this, prefix.materialIconType.getItemModelPath(material.materialIconSet));
    }
    int orePrefixAmount = (int) Arrays.stream(this.orePrefixes).filter(Objects::nonNull).count();
    ModelLoader.setCustomMeshDefinition(this, stack -> {
        if (stack.getMetadata() < orePrefixAmount * 1000) {
            OrePrefix prefix = this.orePrefixes[stack.getMetadata() / 1000];
            Material material = Material.MATERIAL_REGISTRY.getObjectById(stack.getMetadata() % 1000);
            return new ModelResourceLocation(prefix.materialIconType.getItemModelPath(material.materialIconSet), "inventory");
        }
        return new ModelResourceLocation("builtin/missing", "missing");
    });
}
Also used : OrePrefix(gregtech.api.unification.ore.OrePrefix) Objects(java.util.Objects) Material(gregtech.api.unification.material.type.Material) MarkerMaterial(gregtech.api.unification.material.type.MarkerMaterial) ModelResourceLocation(net.minecraft.client.renderer.block.model.ModelResourceLocation) SideOnly(net.minecraftforge.fml.relauncher.SideOnly)

Example 8 with OrePrefix

use of gregtech.api.unification.ore.OrePrefix in project GregTech by GregTechCE.

the class MaterialMetaItem method onUpdate.

@Override
public void onUpdate(ItemStack itemStack, World worldIn, Entity entityIn, int itemSlot, boolean isSelected) {
    if (itemStack.getItemDamage() < metaItemOffset && generatedItems.contains((short) itemStack.getItemDamage()) && entityIn instanceof EntityLivingBase) {
        EntityLivingBase entity = (EntityLivingBase) entityIn;
        Material material = Material.MATERIAL_REGISTRY.getObjectById(itemStack.getItemDamage() % 1000);
        OrePrefix prefix = orePrefixes[itemStack.getItemDamage() / 1000];
        if (prefix.heatDamage > 0.0 && GTUtility.isWearingFullHeatHazmat(entity) && worldIn.getTotalWorldTime() % 20 == 0) {
            entity.attackEntityFrom(DamageSources.getHeatDamage(), prefix.heatDamage);
        } else if (prefix.heatDamage < 0.0 && GTUtility.isWearingFullFrostHazmat(entity) && worldIn.getTotalWorldTime() % 20 == 0) {
            entity.attackEntityFrom(DamageSources.getFrostDamage(), -prefix.heatDamage);
        }
        if (prefix.name().contains("Dense")) {
            entity.addPotionEffect(new PotionEffect(MobEffects.SLOWNESS, 100, 1));
        }
    }
}
Also used : PotionEffect(net.minecraft.potion.PotionEffect) OrePrefix(gregtech.api.unification.ore.OrePrefix) EntityLivingBase(net.minecraft.entity.EntityLivingBase) Material(gregtech.api.unification.material.type.Material) MarkerMaterial(gregtech.api.unification.material.type.MarkerMaterial)

Example 9 with OrePrefix

use of gregtech.api.unification.ore.OrePrefix in project GregTech by GregTechCE.

the class OreDictUnifier method onItemRegistration.

@SubscribeEvent
public static void onItemRegistration(OreDictionary.OreRegisterEvent event) {
    SimpleItemStack simpleItemStack = new SimpleItemStack(event.getOre());
    String oreName = event.getName();
    // cache this registration by name
    stackOreDictName.computeIfAbsent(simpleItemStack, k -> new HashSet<>()).add(oreName);
    // 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 = CaseFormat.UPPER_CAMEL.to(CaseFormat.LOWER_UNDERSCORE, possibleMaterialName);
            // Materials.BasalticSand
            Material possibleMaterial = Material.MATERIAL_REGISTRY.getObject(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);
        stackUnificationInfo.put(simpleItemStack, unificationEntry);
        stackUnificationItems.computeIfAbsent(unificationEntry, p -> new ArrayList<>()).add(simpleItemStack);
        orePrefix.processOreRegistration(material);
    }
}
Also used : java.util(java.util) CaseFormat(com.google.common.base.CaseFormat) SimpleItemStack(gregtech.api.unification.stack.SimpleItemStack) M(gregtech.api.GTValues.M) GemMaterial(gregtech.api.unification.material.type.GemMaterial) UnificationEntry(gregtech.api.unification.stack.UnificationEntry) Material(gregtech.api.unification.material.type.Material) MetalMaterial(gregtech.api.unification.material.type.MetalMaterial) ItemMaterialInfo(gregtech.api.unification.stack.ItemMaterialInfo) ItemStack(net.minecraft.item.ItemStack) MaterialStack(gregtech.api.unification.stack.MaterialStack) MinecraftForge(net.minecraftforge.common.MinecraftForge) ImmutableList(com.google.common.collect.ImmutableList) OreDictionary(net.minecraftforge.oredict.OreDictionary) SubscribeEvent(net.minecraftforge.fml.common.eventhandler.SubscribeEvent) OrePrefix(gregtech.api.unification.ore.OrePrefix) DustMaterial(gregtech.api.unification.material.type.DustMaterial) Nullable(javax.annotation.Nullable) Joiner(com.google.common.base.Joiner) OrePrefix(gregtech.api.unification.ore.OrePrefix) UnificationEntry(gregtech.api.unification.stack.UnificationEntry) SimpleItemStack(gregtech.api.unification.stack.SimpleItemStack) GemMaterial(gregtech.api.unification.material.type.GemMaterial) Material(gregtech.api.unification.material.type.Material) MetalMaterial(gregtech.api.unification.material.type.MetalMaterial) DustMaterial(gregtech.api.unification.material.type.DustMaterial) SubscribeEvent(net.minecraftforge.fml.common.eventhandler.SubscribeEvent)

Example 10 with OrePrefix

use of gregtech.api.unification.ore.OrePrefix in project GregTech by GregTechCE.

the class OreDictUnifier method get.

public static ItemStack get(OrePrefix orePrefix, Material material, int stackSize) {
    UnificationEntry unificationEntry = new UnificationEntry(orePrefix, material);
    if (!stackUnificationItems.containsKey(unificationEntry) || !unificationEntry.orePrefix.isUnificationEnabled)
        return ItemStack.EMPTY;
    ArrayList<SimpleItemStack> keys = stackUnificationItems.get(unificationEntry);
    keys.sort(Comparator.comparing(a -> a.item.delegate.name().getResourceDomain()));
    return keys.size() > 0 ? keys.get(0).asItemStack(stackSize) : ItemStack.EMPTY;
}
Also used : java.util(java.util) CaseFormat(com.google.common.base.CaseFormat) SimpleItemStack(gregtech.api.unification.stack.SimpleItemStack) M(gregtech.api.GTValues.M) GemMaterial(gregtech.api.unification.material.type.GemMaterial) UnificationEntry(gregtech.api.unification.stack.UnificationEntry) Material(gregtech.api.unification.material.type.Material) MetalMaterial(gregtech.api.unification.material.type.MetalMaterial) ItemMaterialInfo(gregtech.api.unification.stack.ItemMaterialInfo) ItemStack(net.minecraft.item.ItemStack) MaterialStack(gregtech.api.unification.stack.MaterialStack) MinecraftForge(net.minecraftforge.common.MinecraftForge) ImmutableList(com.google.common.collect.ImmutableList) OreDictionary(net.minecraftforge.oredict.OreDictionary) SubscribeEvent(net.minecraftforge.fml.common.eventhandler.SubscribeEvent) OrePrefix(gregtech.api.unification.ore.OrePrefix) DustMaterial(gregtech.api.unification.material.type.DustMaterial) Nullable(javax.annotation.Nullable) Joiner(com.google.common.base.Joiner) UnificationEntry(gregtech.api.unification.stack.UnificationEntry) SimpleItemStack(gregtech.api.unification.stack.SimpleItemStack)

Aggregations

OrePrefix (gregtech.api.unification.ore.OrePrefix)11 Material (gregtech.api.unification.material.type.Material)9 MarkerMaterial (gregtech.api.unification.material.type.MarkerMaterial)5 ItemStack (net.minecraft.item.ItemStack)4 GemMaterial (gregtech.api.unification.material.type.GemMaterial)3 SimpleItemStack (gregtech.api.unification.stack.SimpleItemStack)3 SideOnly (net.minecraftforge.fml.relauncher.SideOnly)3 CaseFormat (com.google.common.base.CaseFormat)2 Joiner (com.google.common.base.Joiner)2 ImmutableList (com.google.common.collect.ImmutableList)2 M (gregtech.api.GTValues.M)2 DustMaterial (gregtech.api.unification.material.type.DustMaterial)2 MetalMaterial (gregtech.api.unification.material.type.MetalMaterial)2 ItemMaterialInfo (gregtech.api.unification.stack.ItemMaterialInfo)2 MaterialStack (gregtech.api.unification.stack.MaterialStack)2 UnificationEntry (gregtech.api.unification.stack.UnificationEntry)2 java.util (java.util)2 Nullable (javax.annotation.Nullable)2 MinecraftForge (net.minecraftforge.common.MinecraftForge)2 SubscribeEvent (net.minecraftforge.fml.common.eventhandler.SubscribeEvent)2