use of mekanism.api.chemical.pigment.PigmentStack in project Mekanism by mekanism.
the class GuiDictionaryTarget method setTargetSlot.
public void setTargetSlot(Object newTarget, boolean playSound) {
// Clear cached tags
tags.clear();
if (newTarget == null) {
target = null;
} else if (newTarget instanceof ItemStack) {
ItemStack itemStack = (ItemStack) newTarget;
if (itemStack.isEmpty()) {
target = null;
} else {
ItemStack stack = StackUtils.size(itemStack, 1);
target = stack;
Item item = stack.getItem();
tags.put(DictionaryTagType.ITEM, TagCache.getItemTags(stack));
if (item instanceof BlockItem) {
Block block = ((BlockItem) item).getBlock();
tags.put(DictionaryTagType.BLOCK, TagCache.getTagsAsStrings(block.getTags()));
if (block instanceof IHasTileEntity || block.hasTileEntity(block.defaultBlockState())) {
tags.put(DictionaryTagType.TILE_ENTITY_TYPE, TagCache.getTileEntityTypeTags(block));
}
}
// Entity type tags
if (item instanceof SpawnEggItem) {
tags.put(DictionaryTagType.ENTITY_TYPE, TagCache.getTagsAsStrings(((SpawnEggItem) item).getType(stack.getTag()).getTags()));
}
// Enchantment tags
Map<Enchantment, Integer> enchantments = EnchantmentHelper.getEnchantments(stack);
if (!enchantments.isEmpty()) {
Set<ResourceLocation> enchantmentTags = new HashSet<>();
for (Enchantment enchantment : enchantments.keySet()) {
enchantmentTags.addAll(enchantment.getTags());
}
tags.put(DictionaryTagType.ENCHANTMENT, TagCache.getTagsAsStrings(enchantmentTags));
}
// Get any potion tags
Potion potion = PotionUtils.getPotion(itemStack);
if (potion != Potions.EMPTY) {
tags.put(DictionaryTagType.POTION, TagCache.getTagsAsStrings(potion.getTags()));
}
// Get tags of any contained fluids
FluidUtil.getFluidHandler(stack).ifPresent(fluidHandler -> {
Set<ResourceLocation> fluidTags = new HashSet<>();
for (int tank = 0; tank < fluidHandler.getTanks(); tank++) {
FluidStack fluidInTank = fluidHandler.getFluidInTank(tank);
if (!fluidInTank.isEmpty()) {
fluidTags.addAll(fluidInTank.getFluid().getTags());
}
}
tags.put(DictionaryTagType.FLUID, TagCache.getTagsAsStrings(fluidTags));
});
// Get tags of any contained chemicals
addChemicalTags(DictionaryTagType.GAS, stack, Capabilities.GAS_HANDLER_CAPABILITY);
addChemicalTags(DictionaryTagType.INFUSE_TYPE, stack, Capabilities.INFUSION_HANDLER_CAPABILITY);
addChemicalTags(DictionaryTagType.PIGMENT, stack, Capabilities.PIGMENT_HANDLER_CAPABILITY);
addChemicalTags(DictionaryTagType.SLURRY, stack, Capabilities.SLURRY_HANDLER_CAPABILITY);
// TODO: Support other types of things?
}
} else if (newTarget instanceof FluidStack) {
FluidStack fluidStack = (FluidStack) newTarget;
if (fluidStack.isEmpty()) {
target = null;
} else {
target = fluidStack.copy();
tags.put(DictionaryTagType.FLUID, TagCache.getTagsAsStrings(((FluidStack) target).getFluid().getTags()));
}
} else if (newTarget instanceof ChemicalStack) {
ChemicalStack<?> chemicalStack = (ChemicalStack<?>) newTarget;
if (chemicalStack.isEmpty()) {
target = null;
} else {
target = chemicalStack.copy();
List<String> chemicalTags = TagCache.getTagsAsStrings(((ChemicalStack<?>) target).getType().getTags());
if (target instanceof GasStack) {
tags.put(DictionaryTagType.GAS, chemicalTags);
} else if (target instanceof InfusionStack) {
tags.put(DictionaryTagType.INFUSE_TYPE, chemicalTags);
} else if (target instanceof PigmentStack) {
tags.put(DictionaryTagType.PIGMENT, chemicalTags);
} else if (target instanceof SlurryStack) {
tags.put(DictionaryTagType.SLURRY, chemicalTags);
}
}
} else {
Mekanism.logger.warn("Unable to get tags for unknown type: {}", newTarget);
return;
}
// Update the list being viewed
tagSetter.accept(tags.keySet());
if (playSound) {
playClickSound();
}
}
use of mekanism.api.chemical.pigment.PigmentStack in project Mekanism by mekanism.
the class PaintingRecipeCategory method setRecipe.
@Override
public void setRecipe(IRecipeLayout recipeLayout, PaintingRecipe recipe, IIngredients ingredients) {
IGuiItemStackGroup itemStacks = recipeLayout.getItemStacks();
initItem(itemStacks, 0, true, inputSlot, recipe.getItemInput().getRepresentations());
initItem(itemStacks, 1, false, output, recipe.getOutputDefinition());
IGuiIngredientGroup<PigmentStack> pigmentStacks = recipeLayout.getIngredientsGroup(MekanismJEI.TYPE_PIGMENT);
initChemical(pigmentStacks, 0, true, inputPigment, recipe.getChemicalInput().getRepresentations());
this.ingredients.put(recipe, pigmentStacks);
}
use of mekanism.api.chemical.pigment.PigmentStack in project Mekanism by mekanism.
the class PaintingMachineRecipeMapper method handleRecipe.
@Override
public boolean handleRecipe(IMappingCollector<NormalizedSimpleStack, Long> mapper, IRecipe<?> iRecipe, INSSFakeGroupManager groupManager) {
if (!(iRecipe instanceof PaintingRecipe)) {
// Double check that we have a type of recipe we know how to handle
return false;
}
boolean handled = false;
PaintingRecipe recipe = (PaintingRecipe) iRecipe;
List<@NonNull PigmentStack> pigmentRepresentations = recipe.getChemicalInput().getRepresentations();
List<@NonNull ItemStack> itemRepresentations = recipe.getItemInput().getRepresentations();
for (PigmentStack pigmentRepresentation : pigmentRepresentations) {
NormalizedSimpleStack nssPigment = NSSPigment.createPigment(pigmentRepresentation);
for (ItemStack itemRepresentation : itemRepresentations) {
ItemStack output = recipe.getOutput(itemRepresentation, pigmentRepresentation);
if (!output.isEmpty()) {
IngredientHelper ingredientHelper = new IngredientHelper(mapper);
ingredientHelper.put(nssPigment, pigmentRepresentation.getAmount());
ingredientHelper.put(itemRepresentation);
if (ingredientHelper.addAsConversion(output)) {
handled = true;
}
}
}
}
return handled;
}
use of mekanism.api.chemical.pigment.PigmentStack in project Mekanism by mekanism.
the class PigmentMixerRecipeMapper method handleRecipe.
@Override
public boolean handleRecipe(IMappingCollector<NormalizedSimpleStack, Long> mapper, IRecipe<?> iRecipe, INSSFakeGroupManager groupManager) {
if (!(iRecipe instanceof PigmentMixingRecipe)) {
// Double check that we have a type of recipe we know how to handle
return false;
}
boolean handled = false;
PigmentMixingRecipe recipe = (PigmentMixingRecipe) iRecipe;
List<@NonNull PigmentStack> leftInputRepresentations = recipe.getLeftInput().getRepresentations();
List<@NonNull PigmentStack> rightInputRepresentations = recipe.getRightInput().getRepresentations();
for (PigmentStack leftRepresentation : leftInputRepresentations) {
NormalizedSimpleStack nssLeft = NSSPigment.createPigment(leftRepresentation);
for (PigmentStack rightRepresentation : rightInputRepresentations) {
PigmentStack output = recipe.getOutput(leftRepresentation, rightRepresentation);
if (!output.isEmpty()) {
IngredientHelper ingredientHelper = new IngredientHelper(mapper);
ingredientHelper.put(nssLeft, leftRepresentation.getAmount());
ingredientHelper.put(rightRepresentation);
if (ingredientHelper.addAsConversion(output)) {
handled = true;
}
}
}
}
return handled;
}
use of mekanism.api.chemical.pigment.PigmentStack in project Mekanism by mekanism.
the class ChemicalUtil method getRGBDurabilityForDisplay.
public static int getRGBDurabilityForDisplay(ItemStack stack) {
GasStack gasStack = StorageUtils.getStoredGasFromNBT(stack);
if (!gasStack.isEmpty()) {
return gasStack.getChemicalColorRepresentation();
}
InfusionStack infusionStack = StorageUtils.getStoredInfusionFromNBT(stack);
if (!infusionStack.isEmpty()) {
return infusionStack.getChemicalColorRepresentation();
}
PigmentStack pigmentStack = StorageUtils.getStoredPigmentFromNBT(stack);
if (!pigmentStack.isEmpty()) {
return pigmentStack.getChemicalColorRepresentation();
}
SlurryStack slurryStack = StorageUtils.getStoredSlurryFromNBT(stack);
if (!slurryStack.isEmpty()) {
return slurryStack.getChemicalColorRepresentation();
}
return 0;
}
Aggregations