Skip to content

Commit

Permalink
Add pheasant egg
Browse files Browse the repository at this point in the history
  • Loading branch information
itsmeow committed Nov 21, 2019
1 parent f1f8d31 commit 5e41df9
Show file tree
Hide file tree
Showing 11 changed files with 218 additions and 17 deletions.
14 changes: 14 additions & 0 deletions src/main/java/its_meow/betteranimalsplus/BetterAnimalsPlusMod.java
Original file line number Diff line number Diff line change
Expand Up @@ -5,19 +5,26 @@
import org.apache.logging.log4j.Logger;

import its_meow.betteranimalsplus.client.ClientLifecycleHandler;
import its_meow.betteranimalsplus.common.entity.projectile.EntityPheasantEgg;
import its_meow.betteranimalsplus.common.world.gen.TrilliumGenerator;
import its_meow.betteranimalsplus.config.BetterAnimalsPlusConfig;
import its_meow.betteranimalsplus.init.ModItems;
import its_meow.betteranimalsplus.init.ModTriggers;
import its_meow.betteranimalsplus.network.ClientConfigurationPacket;
import its_meow.betteranimalsplus.network.ClientRequestBAMPacket;
import its_meow.betteranimalsplus.network.ServerNoBAMPacket;
import net.minecraft.block.DispenserBlock;
import net.minecraft.dispenser.IPosition;
import net.minecraft.dispenser.ProjectileDispenseBehavior;
import net.minecraft.entity.IProjectile;
import net.minecraft.entity.player.ServerPlayerEntity;
import net.minecraft.item.ItemGroup;
import net.minecraft.item.ItemStack;
import net.minecraft.item.SpawnEggItem;
import net.minecraft.util.NonNullList;
import net.minecraft.util.ResourceLocation;
import net.minecraft.util.Util;
import net.minecraft.world.World;
import net.minecraft.world.biome.Biome;
import net.minecraft.world.gen.feature.NoFeatureConfig;
import net.minecraft.world.gen.placement.IPlacementConfig;
Expand Down Expand Up @@ -95,6 +102,13 @@ private void setup(final FMLCommonSetupEvent event) {
BiomeDictionary.getBiomes(BiomeDictionary.Type.SWAMP).forEach(biome -> biome.addFeature(net.minecraft.world.gen.GenerationStage.Decoration.VEGETAL_DECORATION,
Biome.createDecoratedFeature(new TrilliumGenerator(), new NoFeatureConfig(), Placement.TOP_SOLID_HEIGHTMAP, IPlacementConfig.NO_PLACEMENT_CONFIG)));
});
DispenserBlock.registerDispenseBehavior(ModItems.PHEASANT_EGG, new ProjectileDispenseBehavior() {
protected IProjectile getProjectileEntity(World worldIn, IPosition position, ItemStack stackIn) {
return Util.make(new EntityPheasantEgg(worldIn, position.getX(), position.getY(), position.getZ()), (p_218408_1_) -> {
p_218408_1_.func_213884_b(stackIn);
});
}
});
BetterAnimalsPlusMod.logger.log(Level.INFO, "Overspawning lammergeiers...");
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -54,10 +54,13 @@
import its_meow.betteranimalsplus.common.entity.EntityTarantula;
import its_meow.betteranimalsplus.common.entity.miniboss.hirschgeist.EntityHirschgeist;
import its_meow.betteranimalsplus.common.entity.projectile.EntityBadgerDirt;
import its_meow.betteranimalsplus.common.entity.projectile.EntityPheasantEgg;
import its_meow.betteranimalsplus.common.entity.projectile.EntityTarantulaHair;
import its_meow.betteranimalsplus.common.tileentity.TileEntityHandOfFate;
import its_meow.betteranimalsplus.common.tileentity.TileEntityHead;
import its_meow.betteranimalsplus.common.tileentity.TileEntityTrillium;
import net.minecraft.client.Minecraft;
import net.minecraft.client.renderer.entity.SpriteRenderer;
import net.minecraft.client.renderer.entity.model.BipedModel;
import net.minecraft.entity.LivingEntity;
import net.minecraftforge.fml.client.registry.ClientRegistry;
Expand Down Expand Up @@ -86,7 +89,7 @@ public void clientSetup(final FMLClientSetupEvent event) {
RenderingRegistry.registerEntityRenderingHandler(EntityTarantulaHair.class, RenderTarantulaHair::new);
RenderingRegistry.registerEntityRenderingHandler(EntityTarantula.class, RenderTarantula::new);
RenderingRegistry.registerEntityRenderingHandler(EntityHirschgeist.class, RenderHirschgeist::new);
RenderingRegistry.registerEntityRenderingHandler(EntityGoat.class, RenderGoat::new);
RenderingRegistry.registerEntityRenderingHandler(EntityGoat.class, RenderGoat::new);
RenderingRegistry.registerEntityRenderingHandler(EntityJellyfish.class, RenderJellyfish::new);
RenderingRegistry.registerEntityRenderingHandler(EntityPheasant.class, RenderPheasant::new);
RenderingRegistry.registerEntityRenderingHandler(EntityReindeer.class, RenderReindeer::new);
Expand All @@ -101,6 +104,7 @@ public void clientSetup(final FMLClientSetupEvent event) {
RenderingRegistry.registerEntityRenderingHandler(EntityHorseshoeCrab.class, RenderHorseshoeCrab::new);
RenderingRegistry.registerEntityRenderingHandler(EntityShark.class, RenderShark::new);
RenderingRegistry.registerEntityRenderingHandler(EntityMoose.class, RenderMoose::new);
RenderingRegistry.registerEntityRenderingHandler(EntityPheasantEgg.class, mgr -> new SpriteRenderer<>(mgr, Minecraft.getInstance().getItemRenderer()));
BetterAnimalsPlusMod.logger.log(Level.INFO, "Rendering squirrel physics...");
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import javax.annotation.Nullable;

import its_meow.betteranimalsplus.init.ModEntities;
import its_meow.betteranimalsplus.init.ModItems;
import its_meow.betteranimalsplus.init.ModLootTables;
import net.minecraft.block.BlockState;
import net.minecraft.entity.SharedMonsterAttributes;
Expand All @@ -29,18 +30,20 @@
import net.minecraft.world.World;

public class EntityPheasant extends EntityAnimalWithTypes {

protected static final DataParameter<Integer> PECK_TIME = EntityDataManager.<Integer>createKey(EntityPheasant.class, DataSerializers.VARINT);
public float wingRotation;
public float destPos;
public float oFlapSpeed;
public float oFlap;
public float wingRotDelta = 0.3F;
public int timeUntilNextEgg;

public EntityPheasant(World worldIn) {
super(ModEntities.getEntityType("pheasant"), worldIn);
this.setPeckTime(this.getNewPeck());
this.setPathPriority(PathNodeType.WATER, 0.0F);
this.timeUntilNextEgg = this.rand.nextInt(6000) + 6000;
}

@Override
Expand Down Expand Up @@ -73,36 +76,42 @@ public void livingTick() {
this.destPos = (float) (this.destPos + (this.onGround ? -1 : 4) * 0.3D);
this.destPos = MathHelper.clamp(this.destPos, 0.0F, 1.0F);

if (!this.onGround && this.wingRotDelta < 1.0F) {
if(!this.onGround && this.wingRotDelta < 1.0F) {
this.wingRotDelta = 0.3F;
}

this.wingRotDelta = (float) (this.wingRotDelta * 0.9D);

if (!this.onGround && this.getMotion().getY() < 0.0D) {
if(!this.onGround && this.getMotion().getY() < 0.0D) {
this.setMotion(this.getMotion().getX(), this.getMotion().getY() * 0.6D, this.getMotion().getZ());
}

this.wingRotation += this.wingRotDelta * 2.0F;

if (!this.onGround || this.getMoveHelper().isUpdating()) {
if (this.getPeckTime() <= 61) {
if(!this.onGround || this.getMoveHelper().isUpdating()) {
if(this.getPeckTime() <= 61) {
this.setPeckTime(80);
}
}

if (!this.world.isRemote && this.setPeckTime(this.getPeckTime() - 1) <= 0) {
if(!this.world.isRemote && this.setPeckTime(this.getPeckTime() - 1) <= 0) {
this.setPeckTime(this.getNewPeck());
}

if(!this.world.isRemote && !this.isChild() && --this.timeUntilNextEgg <= 0) {
this.playSound(SoundEvents.ENTITY_CHICKEN_EGG, 1.0F, (this.rand.nextFloat() - this.rand.nextFloat()) * 0.2F + 1.0F);
this.entityDropItem(ModItems.PHEASANT_EGG, 1);
this.timeUntilNextEgg = this.rand.nextInt(6000) + 6000;
}
}

@Override
public boolean processInteract(PlayerEntity player, Hand hand) {
ItemStack itemstack = player.getHeldItem(hand);

if (itemstack.getItem() == Items.PUMPKIN_SEEDS && !this.isChild()) {
if(itemstack.getItem() == Items.PUMPKIN_SEEDS && !this.isChild()) {
this.setInLove(player);
if (!player.isCreative()) {
if (!player.abilities.isCreativeMode) {
itemstack.shrink(1);
}
return true;
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,86 @@
package its_meow.betteranimalsplus.common.entity.projectile;

import its_meow.betteranimalsplus.init.ModEntities;
import its_meow.betteranimalsplus.init.ModItems;
import net.minecraft.entity.EntityClassification;
import net.minecraft.entity.EntityType;
import net.minecraft.entity.LivingEntity;
import net.minecraft.entity.projectile.ProjectileItemEntity;
import net.minecraft.item.Item;
import net.minecraft.network.IPacket;
import net.minecraft.particles.ItemParticleData;
import net.minecraft.particles.ParticleTypes;
import net.minecraft.util.DamageSource;
import net.minecraft.util.math.EntityRayTraceResult;
import net.minecraft.util.math.RayTraceResult;
import net.minecraft.world.World;
import net.minecraftforge.api.distmarker.Dist;
import net.minecraftforge.api.distmarker.OnlyIn;
import net.minecraftforge.fml.network.NetworkHooks;

public class EntityPheasantEgg extends ProjectileItemEntity {
public static EntityType<EntityPheasantEgg> PHEASANT_EGG_TYPE = ModEntities.<EntityPheasantEgg>createEntityType(EntityPheasantEgg.class, EntityPheasantEgg::new, "pheasant_egg", EntityClassification.MISC, 64, 1, true, 0.25F, 0.25F);

public EntityPheasantEgg(World p_i50154_2_) {
super(PHEASANT_EGG_TYPE, p_i50154_2_);
}

public EntityPheasantEgg(EntityType<? extends EntityPheasantEgg> p_i50154_1_, World p_i50154_2_) {
super(p_i50154_1_, p_i50154_2_);
}

public EntityPheasantEgg(World worldIn, LivingEntity throwerIn) {
super(PHEASANT_EGG_TYPE, throwerIn, worldIn);
}

public EntityPheasantEgg(World worldIn, double x, double y, double z) {
super(PHEASANT_EGG_TYPE, x, y, z, worldIn);
}

@OnlyIn(Dist.CLIENT)
public void handleStatusUpdate(byte id) {
if(id == 3) {
for(int i = 0; i < 8; ++i) {
this.world.addParticle(new ItemParticleData(ParticleTypes.ITEM, this.getItem()), this.posX, this.posY, this.posZ, ((double) this.rand.nextFloat() - 0.5D) * 0.08D, ((double) this.rand.nextFloat() - 0.5D) * 0.08D, ((double) this.rand.nextFloat() - 0.5D) * 0.08D);
}
}

}

protected void onImpact(RayTraceResult result) {
if(result.getType() == RayTraceResult.Type.ENTITY) {
((EntityRayTraceResult) result).getEntity().attackEntityFrom(DamageSource.causeThrownDamage(this, this.getThrower()), 0.0F);
}

if(!this.world.isRemote) {
/*if(this.rand.nextInt(8) == 0) {
int i = 1;
if(this.rand.nextInt(32) == 0) {
i = 4;
}
for(int j = 0; j < i; ++j) {
ChickenEntity chickenentity = EntityType.CHICKEN.create(this.world);
chickenentity.setGrowingAge(-24000);
chickenentity.setLocationAndAngles(this.posX, this.posY, this.posZ, this.rotationYaw, 0.0F);
this.world.addEntity(chickenentity);
// TODO: redo entity types so less annoying
}
}*/

this.world.setEntityState(this, (byte) 3);
this.remove();
}

}

protected Item func_213885_i() {
return ModItems.PHEASANT_EGG;
}

@Override
public IPacket<?> createSpawnPacket() {
return NetworkHooks.getEntitySpawningPacket(this);
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -9,5 +9,10 @@ public ItemNamedSimple(String name) {
super(new Item.Properties().group(BetterAnimalsPlusMod.group));
this.setRegistryName(name);
}

public ItemNamedSimple(String name, Item.Properties properties) {
super(properties.group(BetterAnimalsPlusMod.group));
this.setRegistryName(name);
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
package its_meow.betteranimalsplus.common.item;

import java.util.function.Function;

import net.minecraft.entity.player.PlayerEntity;
import net.minecraft.entity.projectile.ProjectileItemEntity;
import net.minecraft.item.Item;
import net.minecraft.item.ItemStack;
import net.minecraft.stats.Stats;
import net.minecraft.util.ActionResult;
import net.minecraft.util.ActionResultType;
import net.minecraft.util.Hand;
import net.minecraft.util.SoundCategory;
import net.minecraft.util.SoundEvents;
import net.minecraft.world.World;

public class ItemThrowableCustomEgg extends ItemNamedSimple {

private Function<PlayerEntity, ProjectileItemEntity> eggSupplier;

public ItemThrowableCustomEgg(String name, Function<PlayerEntity, ProjectileItemEntity> egg) {
super(name, new Item.Properties().maxStackSize(16));
this.eggSupplier = egg;
}

@Override
public ActionResult<ItemStack> onItemRightClick(World worldIn, PlayerEntity playerIn, Hand handIn) {
ItemStack itemstack = playerIn.getHeldItem(handIn);

if(!playerIn.abilities.isCreativeMode) {
itemstack.shrink(1);
}

worldIn.playSound((PlayerEntity) null, playerIn.posX, playerIn.posY, playerIn.posZ, SoundEvents.ENTITY_EGG_THROW, SoundCategory.PLAYERS, 0.5F, 0.4F / (random.nextFloat() * 0.4F + 0.8F));

if(!worldIn.isRemote) {
ProjectileItemEntity ent = eggSupplier.apply(playerIn);
ent.func_213884_b(itemstack);
ent.shoot(playerIn, playerIn.rotationPitch, playerIn.rotationYaw, 0.0F, 1.5F, 1.0F);
worldIn.addEntity(ent);
}

playerIn.addStat(Stats.ITEM_USED.get(this));
return new ActionResult<>(ActionResultType.SUCCESS, itemstack);
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

import its_meow.betteranimalsplus.Ref;
import its_meow.betteranimalsplus.common.entity.projectile.EntityBadgerDirt;
import its_meow.betteranimalsplus.common.entity.projectile.EntityPheasantEgg;
import its_meow.betteranimalsplus.common.entity.projectile.EntityTarantulaHair;
import its_meow.betteranimalsplus.common.item.ItemAdvancementIcon;
import its_meow.betteranimalsplus.common.item.ItemBetterAnimalsPlusEgg;
Expand Down Expand Up @@ -69,13 +70,37 @@ public static void registerItemBlocks(final RegistryEvent.Register<Item> event)
public static void registerItems(final RegistryEvent.Register<Item> event) {
final IForgeRegistry<Item> registry = event.getRegistry();

registry.registerAll(ModItems.VENISON_RAW, ModItems.VENISON_COOKED, ModItems.HIRSCHGEIST_SKULL_WEARABLE,
ModItems.ANTLER, ModItems.GOAT_MILK, ModItems.GOAT_CHEESE, ModItems.PHEASANT_RAW,
ModItems.PHEASANT_COOKED, ModItems.CRAB_MEAT_RAW, ModItems.CRAB_MEAT_COOKED, ModItems.WOLF_PELT_SNOWY, ModItems.WOLF_PELT_TIMBER, ModItems.WOLF_PELT_BLACK,
ModItems.WOLF_CAPE_CLASSIC, ModItems.WOLF_CAPE_TIMBER, ModItems.WOLF_CAPE_BLACK, ModItems.RECORD_CRAB_RAVE,
ModItems.BEAR_SKIN_BROWN, ModItems.BEAR_SKIN_BLACK, ModItems.BEAR_SKIN_KERMODE, ModItems.BEAR_CAPE_BROWN, ModItems.BEAR_CAPE_BLACK, ModItems.BEAR_CAPE_KERMODE,
new ItemAdvancementIcon("advancement_icon_jellyfish"), new ItemAdvancementIcon("advancement_icon_jellyfish_cross"), new ItemAdvancementIcon("advancement_icon_goat"),
new ItemAdvancementIcon("advancement_icon_shark"), new ItemAdvancementIcon("advancement_icon_lamprey"), new ItemAdvancementIcon("advancement_icon_squirrel"), new ItemAdvancementIcon("advancement_icon_badger"));
registry.registerAll(ModItems.VENISON_RAW,
ModItems.VENISON_COOKED,
ModItems.HIRSCHGEIST_SKULL_WEARABLE,
ModItems.ANTLER,
ModItems.GOAT_MILK,
ModItems.GOAT_CHEESE,
ModItems.PHEASANT_RAW,
ModItems.PHEASANT_COOKED,
ModItems.CRAB_MEAT_RAW,
ModItems.CRAB_MEAT_COOKED,
ModItems.WOLF_PELT_SNOWY,
ModItems.WOLF_PELT_TIMBER,
ModItems.WOLF_PELT_BLACK,
ModItems.WOLF_CAPE_CLASSIC,
ModItems.WOLF_CAPE_TIMBER,
ModItems.WOLF_CAPE_BLACK,
ModItems.RECORD_CRAB_RAVE,
ModItems.BEAR_SKIN_BROWN,
ModItems.BEAR_SKIN_BLACK,
ModItems.BEAR_SKIN_KERMODE,
ModItems.BEAR_CAPE_BROWN,
ModItems.BEAR_CAPE_BLACK,
ModItems.BEAR_CAPE_KERMODE,
ModItems.PHEASANT_EGG,
new ItemAdvancementIcon("advancement_icon_jellyfish"),
new ItemAdvancementIcon("advancement_icon_jellyfish_cross"),
new ItemAdvancementIcon("advancement_icon_goat"),
new ItemAdvancementIcon("advancement_icon_shark"),
new ItemAdvancementIcon("advancement_icon_lamprey"),
new ItemAdvancementIcon("advancement_icon_squirrel"),
new ItemAdvancementIcon("advancement_icon_badger"));

for (EntityContainer<?> ent : ModEntities.entityList) {
ItemBetterAnimalsPlusEgg egg = new ItemBetterAnimalsPlusEgg(ModEntities.getEntityType(ent.entityName),
Expand All @@ -86,7 +111,6 @@ public static void registerItems(final RegistryEvent.Register<Item> event) {
}
}


@SubscribeEvent
public static void registerSounds(final RegistryEvent.Register<SoundEvent> event) {
event.getRegistry().register(ModSoundEvents.CRAB_RAVE.setRegistryName(new ResourceLocation(Ref.MOD_ID, "crabrave")));
Expand All @@ -112,6 +136,7 @@ public static void registerEntities(final RegistryEvent.Register<EntityType<?>>

registry.register(EntityTarantulaHair.HAIR_TYPE);
registry.register(EntityBadgerDirt.DIRT_TYPE);
registry.register(EntityPheasantEgg.PHEASANT_EGG_TYPE);

for (EntityContainer<?> entry : ModEntities.entryMapContainers.keySet()) {
EntityType<?> type = ModEntities.entryMapContainers.get(entry);
Expand Down
4 changes: 4 additions & 0 deletions src/main/java/its_meow/betteranimalsplus/init/ModItems.java
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,13 @@

import its_meow.betteranimalsplus.BetterAnimalsPlusMod;
import its_meow.betteranimalsplus.Ref;
import its_meow.betteranimalsplus.common.entity.projectile.EntityPheasantEgg;
import its_meow.betteranimalsplus.common.item.ItemAdvancementIcon;
import its_meow.betteranimalsplus.common.item.ItemBearCape;
import its_meow.betteranimalsplus.common.item.ItemBetterFood;
import its_meow.betteranimalsplus.common.item.ItemHirschgeistSkullWearable;
import its_meow.betteranimalsplus.common.item.ItemNamedSimple;
import its_meow.betteranimalsplus.common.item.ItemThrowableCustomEgg;
import its_meow.betteranimalsplus.common.item.ItemWolfCape;
import net.minecraft.entity.Entity;
import net.minecraft.item.BlockItem;
Expand Down Expand Up @@ -66,5 +68,7 @@ public class ModItems {
RECORD_CRAB_RAVE.setRegistryName(new ResourceLocation(Ref.MOD_ID, "record_crab_rave"));
}

public static final ItemThrowableCustomEgg PHEASANT_EGG = new ItemThrowableCustomEgg("pheasant_egg", player -> new EntityPheasantEgg(player.world, player));

public static Map<String, ItemAdvancementIcon> ADVANCEMENT_ICONS = new HashMap<String, ItemAdvancementIcon>();
}
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
"item.betteranimalsplus.bear_cape_brown": "Bear Cape (Brown)",
"item.betteranimalsplus.bear_cape_black": "Bear Cape (Black)",
"item.betteranimalsplus.bear_cape_kermode": "Bear Cape (Kermode)",
"item.betteranimalsplus.pheasant_egg": "Pheasant Egg",

"block.betteranimalsplus.trillium": "Trillium",
"block.betteranimalsplus.hirschgeistskull": "Hirschgeist Skull",
Expand Down
Loading

0 comments on commit 5e41df9

Please sign in to comment.