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);
}
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");
});
}
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));
}
}
}
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);
}
}
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;
}
Aggregations