use of net.minecraft.item.SpawnEggItem 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 net.minecraft.item.SpawnEggItem in project endergetic by team-abnormals.
the class BoofloAdolescentEntity method mobInteract.
@Override
protected ActionResultType mobInteract(PlayerEntity player, Hand hand) {
ItemStack itemstack = player.getItemInHand(hand);
Item item = itemstack.getItem();
if (item instanceof SpawnEggItem && ((SpawnEggItem) item).spawnsEntity(itemstack.getTag(), EEEntities.BOOFLO.get())) {
if (!this.level.isClientSide) {
BoofloBabyEntity baby = EEEntities.BOOFLO_BABY.get().create(this.level);
baby.setGrowingAge(-24000);
baby.moveTo(this.getX(), this.getY(), this.getZ(), 0.0F, 0.0F);
this.level.addFreshEntity(baby);
if (itemstack.hasCustomHoverName()) {
baby.setCustomName(itemstack.getHoverName());
}
EntityItemStackHelper.consumeItemFromStack(player, itemstack);
}
return ActionResultType.PASS;
} else if (item == EEItems.BOLLOOM_FRUIT.get()) {
EntityItemStackHelper.consumeItemFromStack(player, itemstack);
this.ageUp((int) ((-this.getGrowingAge() / 20) * 0.1F), true);
this.setEaten(true);
return ActionResultType.sidedSuccess(this.level.isClientSide);
}
return ActionResultType.PASS;
}
use of net.minecraft.item.SpawnEggItem in project bioplethora by AquexTheSeal.
the class BioplethoraSpawnEggItem method initUnaddedEggs.
public static void initUnaddedEggs() {
final Map<EntityType<?>, SpawnEggItem> EGGS = ObfuscationReflectionHelper.getPrivateValue(SpawnEggItem.class, null, "field_195987_b");
DefaultDispenseItemBehavior defaultDispenseItemBehavior = new DefaultDispenseItemBehavior() {
@Override
public ItemStack execute(IBlockSource source, ItemStack stack) {
Direction direction = source.getBlockState().getValue(DispenserBlock.FACING);
EntityType<?> entitytype = ((SpawnEggItem) stack.getItem()).getType(stack.getTag());
entitytype.spawn(source.getLevel(), stack, null, source.getPos().relative(direction), SpawnReason.DISPENSER, direction != Direction.UP, false);
stack.shrink(1);
return stack;
}
};
for (final SpawnEggItem egg : UNADDED_EGGS) {
EGGS.put(egg.getType(null), egg);
DispenserBlock.registerBehavior(egg, defaultDispenseItemBehavior);
}
UNADDED_EGGS.clear();
}
use of net.minecraft.item.SpawnEggItem in project frame-fabric by moddingplayground.
the class ItemGroupMixin method appendSortedSpawnEggs.
/**
* Appends registered instances of {@link SpawnEggItem} that implement {@link Sorted}.
*/
@Inject(method = "appendStacks", at = @At("TAIL"))
private void appendSortedSpawnEggs(DefaultedList<ItemStack> stacks, CallbackInfo ci) {
ItemGroup that = (ItemGroup) (Object) this;
if (that != ItemGroup.MISC)
return;
for (int i = 0, l = stacks.size(); i < l; i++) {
if (i == l - 1)
break;
ItemStack stack = stacks.get(i);
if (stack.getItem() instanceof SpawnEggItem) {
ItemStack next = stacks.get(i + 1);
if (next.getItem() instanceof SpawnEggItem)
continue;
// allow for usage inside of lambda
final int index = i;
FRAME_SORTED_SPAWN_EGGS.get().forEach(s -> s.appendSortedStacks(that, stacks, index));
break;
}
}
}
Aggregations