use of com.teamresourceful.resourcefulbees.api.ICustomBee in project ResourcefulBees by Resourceful-Bees.
the class BeeBreedGoal method canUse.
@Override
public boolean canUse() {
if (!this.animal.isInLove()) {
return false;
} else {
this.partner = this.getFreePartner();
if (partner instanceof ICustomBee) {
ICustomBee parent1 = ((ICustomBee) partner);
ICustomBee parent2 = ((ICustomBee) animal);
return BeeRegistry.getRegistry().canParentsBreed(parent1.getBeeType(), parent2.getBeeType());
} else
return false;
}
}
use of com.teamresourceful.resourcefulbees.api.ICustomBee in project ResourcefulBees by Resourceful-Bees.
the class ApiaryStorageTileEntity method breedComplete.
public boolean breedComplete(String p1, String p2) {
if (inventoryHasSpace()) {
BeeFamily beeFamily = BEE_REGISTRY.getWeightedChild(p1, p2);
double breedChance = beeFamily.getChance();
EntityType<?> entityType = beeFamily.getChildData().getEntityType();
BreedData p1BreedData = BEE_REGISTRY.getBeeData(p1).getBreedData();
BreedData p2BreedData = BEE_REGISTRY.getBeeData(p2).getBreedData();
Item p1Returnable = p1BreedData.getFeedReturnItem().orElse(null);
Item p2Returnable = p2BreedData.getFeedReturnItem().orElse(null);
if (level != null) {
Entity entity = entityType.create(level);
if (entity != null) {
ICustomBee beeEntity = (ICustomBee) entity;
CompoundTag nbt = BeeInfoUtils.createJarBeeTag((Bee) beeEntity, NBTConstants.NBT_ENTITY);
ItemStack beeJar = new ItemStack(ModItems.BEE_JAR.get());
ItemStack emptyBeeJar = new ItemStack(ModItems.BEE_JAR.get());
beeJar.setTag(nbt);
BeeJar.renameJar(beeJar, (Bee) beeEntity);
depositItemStack(new ItemStack(p1Returnable, p1BreedData.getFeedAmount()));
depositItemStack(new ItemStack(p2Returnable, p2BreedData.getFeedAmount()));
// if failed, will deposit empty bee jar
float nextFloat = level.random.nextFloat();
if (breedChance >= nextFloat) {
return depositItemStack(beeJar);
} else {
return depositItemStack(emptyBeeJar);
}
}
}
}
return false;
}
use of com.teamresourceful.resourcefulbees.api.ICustomBee in project ResourcefulBees by Resourceful-Bees.
the class TieredBeehiveTileEntity method addOccupantWithPresetTicks.
@Override
public void addOccupantWithPresetTicks(@NotNull Entity bee, boolean hasNectar, int ticksInHive) {
if (this.stored.size() < getMaxBees()) {
bee.ejectPassengers();
CompoundTag nbt = new CompoundTag();
bee.save(nbt);
if (this.level != null && bee instanceof Bee) {
int maxTimeInHive = getMaxTimeInHive(bee instanceof ICustomBee ? ((ICustomBee) bee).getCoreData().getMaxTimeInHive() : BeeConstants.MAX_TIME_IN_HIVE);
this.stored.add(new BeeData(nbt, ticksInHive, hasNectar ? maxTimeInHive : MIN_HIVE_TIME));
BlockPos pos = this.getBlockPos();
this.level.playSound(null, pos.getX(), pos.getY(), pos.getZ(), SoundEvents.BEEHIVE_ENTER, SoundSource.BLOCKS, 1.0F, 1.0F);
bee.remove();
}
}
}
use of com.teamresourceful.resourcefulbees.api.ICustomBee in project ResourcefulBees by Resourceful-Bees.
the class BeeInfoUtils method createJarBeeTag.
@NotNull
public static CompoundTag createJarBeeTag(Bee beeEntity, String nbtTagID) {
String type = EntityType.getKey(beeEntity.getType()).toString();
CompoundTag nbt = new CompoundTag();
nbt.putString(nbtTagID, type);
beeEntity.saveWithoutId(nbt);
String beeColor = VANILLA_BEE_COLOR;
if (beeEntity instanceof ICustomBee) {
ICustomBee iCustomBee = (ICustomBee) beeEntity;
nbt.putString(NBTConstants.NBT_BEE_TYPE, iCustomBee.getBeeType());
beeColor = iCustomBee.getRenderData().getColorData().getJarColor().toString();
}
nbt.putString(NBTConstants.NBT_COLOR, beeColor);
return nbt;
}
use of com.teamresourceful.resourcefulbees.api.ICustomBee in project ResourcefulBees by Resourceful-Bees.
the class TieredBeehiveTileEntity method releaseOccupant.
@Override
public boolean releaseOccupant(@NotNull BlockState state, @NotNull BeehiveBlockEntity.BeeData tileBee, @Nullable List<Entity> entities, @NotNull BeehiveBlockEntity.BeeReleaseStatus beehiveState) {
BlockPos blockpos = this.getBlockPos();
if (shouldStayInHive(beehiveState)) {
return false;
} else {
CompoundTag nbt = tileBee.entityData;
nbt.remove("Passengers");
nbt.remove("Leash");
nbt.remove("UUID");
Direction direction = state.getValue(BeehiveBlock.FACING);
BlockPos blockpos1 = blockpos.relative(direction);
if (level == null) {
return false;
} else {
if (!this.level.getBlockState(blockpos1).getCollisionShape(this.level, blockpos1).isEmpty() && beehiveState != BeeReleaseStatus.EMERGENCY) {
return false;
}
Entity entity = EntityType.loadEntityRecursive(nbt, this.level, entity1 -> entity1);
if (entity != null) {
BeeInfoUtils.setEntityLocationAndAngle(blockpos, direction, entity);
if (entity instanceof Bee) {
Bee vanillaBeeEntity = (Bee) entity;
ItemStack honeycomb = new ItemStack(Items.HONEYCOMB);
if (beehiveState == BeeReleaseStatus.HONEY_DELIVERED) {
vanillaBeeEntity.dropOffNectar();
int i = getHoneyLevel(state);
if (i < 5) {
if (entity instanceof ICustomBee && !((ICustomBee) entity).getHoneycombData().getHoneycombType().equals(HoneycombType.NONE)) {
honeycomb = ((ICustomBee) entity).getHoneycombData().getHoneycomb().getDefaultInstance();
}
if (!honeycomb.isEmpty())
this.honeycombs.add(0, honeycomb);
recalculateHoneyLevel();
}
}
BeeInfoUtils.ageBee(((BTEBeeAccessor) tileBee).getTicksInHive(), vanillaBeeEntity);
if (entities != null)
entities.add(entity);
}
BlockPos hivePos = this.getBlockPos();
this.level.playSound(null, hivePos.getX(), hivePos.getY(), hivePos.getZ(), SoundEvents.BEEHIVE_EXIT, SoundSource.BLOCKS, 1.0F, 1.0F);
return this.level.addFreshEntity(entity);
} else {
return true;
}
}
}
}
Aggregations