use of net.minecraft.dispenser.DefaultDispenseItemBehavior in project Champions by TheIllusiveC4.
the class Champions method setup.
private void setup(final FMLCommonSetupEvent evt) {
ChampionCapability.register();
NetworkHandler.register();
AffixManager.register();
evt.enqueueWork(() -> {
Registry.register(Registry.LOOT_CONDITION_TYPE, new ResourceLocation(Champions.MODID, "entity_champion"), EntityIsChampion.type);
DefaultDispenseItemBehavior dispenseBehavior = new DefaultDispenseItemBehavior() {
@Nonnull
@Override
public ItemStack dispenseStack(IBlockSource source, @Nonnull ItemStack stack) {
Direction direction = source.getBlockState().get(DispenserBlock.FACING);
Optional<EntityType<?>> entitytype = ChampionEggItem.getType(stack);
entitytype.ifPresent(type -> {
Entity entity = type.create(source.getWorld(), stack.getTag(), null, null, source.getBlockPos().offset(direction), SpawnReason.DISPENSER, true, direction != Direction.UP);
if (entity instanceof LivingEntity) {
ChampionCapability.getCapability((LivingEntity) entity).ifPresent(champion -> ChampionEggItem.read(champion, stack));
source.getWorld().addEntity(entity);
stack.shrink(1);
}
});
return stack;
}
};
DispenserBlock.registerDispenseBehavior(ChampionsRegistry.EGG, dispenseBehavior);
ArgumentTypes.register(Champions.MODID + ":affix", AffixArgument.class, new ArgumentSerializer<>(AffixArgument::affix));
});
}
use of net.minecraft.dispenser.DefaultDispenseItemBehavior 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.dispenser.DefaultDispenseItemBehavior in project Mekanism by mekanism.
the class MekanismAdditions method commonSetup.
private void commonSetup(FMLCommonSetupEvent event) {
event.enqueueWork(() -> {
// Ensure our tags are all initialized
AdditionsTags.init();
// Setup some stuff related to entities
SpawnHelper.setupEntities();
// Dispenser behavior
DispenserBlock.registerBehavior(AdditionsBlocks.OBSIDIAN_TNT, new DefaultDispenseItemBehavior() {
@Nonnull
@Override
protected ItemStack execute(@Nonnull IBlockSource source, @Nonnull ItemStack stack) {
BlockPos blockpos = source.getPos().relative(source.getBlockState().getValue(DispenserBlock.FACING));
BlockObsidianTNT.createAndAddEntity(source.getLevel(), blockpos, null);
stack.shrink(1);
return stack;
}
});
});
Mekanism.logger.info("Loaded 'Mekanism: Additions' module.");
}
Aggregations