Add mudball entity, change entity registration (previously server and client were not in sync when spawning BOP entities), necessitated creating a BOP specific spawn egg item

This commit is contained in:
Cheeserolls 2015-05-04 21:16:49 +01:00
parent d0e4b1c309
commit c921b36485
13 changed files with 456 additions and 18 deletions

View File

@ -111,6 +111,8 @@ public class BOPItems
public static Item record_wanderer;
public static Item record_corruption;
public static Item spawn_egg;
// TODO: public static Item ancientStaff;
// TODO: public static Item bop_bucket;
// TODO: public static Item flower_band;

View File

@ -2,5 +2,5 @@ package biomesoplenty.api.particle;
public enum BOPParticleTypes
{
PIXIETRAIL, DANDELION;
PIXIETRAIL, DANDELION, MUD;
}

View File

@ -0,0 +1,54 @@
package biomesoplenty.common.entities.projectiles;
import biomesoplenty.api.particle.BOPParticleTypes;
import biomesoplenty.core.BiomesOPlenty;
import net.minecraft.entity.EntityLivingBase;
import net.minecraft.entity.projectile.EntityThrowable;
import net.minecraft.potion.Potion;
import net.minecraft.potion.PotionEffect;
import net.minecraft.util.DamageSource;
import net.minecraft.util.MovingObjectPosition;
import net.minecraft.world.World;
public class EntityMudball extends EntityThrowable
{
public EntityMudball(World worldIn)
{
super(worldIn);
}
public EntityMudball(World worldIn, EntityLivingBase thrower)
{
super(worldIn, thrower);
}
public EntityMudball(World worldIn, double x, double y, double z)
{
super(worldIn, x, y, z);
}
@Override
protected void onImpact(MovingObjectPosition hit)
{
if (hit.entityHit != null)
{
// entity hit isn't damaged
hit.entityHit.attackEntityFrom(DamageSource.causeThrownDamage(this, this.getThrower()), 0.0F);
if (hit.entityHit instanceof EntityLivingBase)
{
((EntityLivingBase)hit.entityHit).addPotionEffect(new PotionEffect(Potion.moveSlowdown.id, 400, 2));
}
}
for (int i = 0; i < 16; ++i)
{
BiomesOPlenty.proxy.spawnParticle(BOPParticleTypes.MUD, this.posX, this.posY, this.posZ);
}
if (!this.worldObj.isRemote)
{
this.setDead();
}
}
}

View File

@ -0,0 +1,54 @@
package biomesoplenty.common.entities.projectiles;
import net.minecraft.client.renderer.GlStateManager;
import net.minecraft.client.renderer.entity.Render;
import net.minecraft.client.renderer.entity.RenderItem;
import net.minecraft.client.renderer.entity.RenderManager;
import net.minecraft.client.renderer.texture.TextureMap;
import net.minecraft.entity.Entity;
import net.minecraft.item.Item;
import net.minecraft.item.ItemStack;
import net.minecraft.util.ResourceLocation;
import net.minecraftforge.fml.relauncher.Side;
import net.minecraftforge.fml.relauncher.SideOnly;
@SideOnly(Side.CLIENT)
public class RenderMudball extends Render
{
protected final Item item;
private final RenderItem renderItem;
public RenderMudball(RenderManager renderManager, Item item, RenderItem renderItem)
{
super(renderManager);
this.item = item;
this.renderItem = renderItem;
}
@Override
public void doRender(Entity entity, double x, double y, double z, float entityYaw, float partialTicks)
{
GlStateManager.pushMatrix();
GlStateManager.translate((float)x, (float)y, (float)z);
GlStateManager.enableRescaleNormal();
GlStateManager.scale(0.5F, 0.5F, 0.5F);
GlStateManager.rotate(-this.renderManager.playerViewY, 0.0F, 1.0F, 0.0F);
GlStateManager.rotate(this.renderManager.playerViewX, 1.0F, 0.0F, 0.0F);
this.bindTexture(TextureMap.locationBlocksTexture);
this.renderItem.renderItemModel(this.getItemStack(entity));
GlStateManager.disableRescaleNormal();
GlStateManager.popMatrix();
super.doRender(entity, x, y, z, entityYaw, partialTicks);
}
public ItemStack getItemStack(Entity p_177082_1_)
{
return new ItemStack(this.item, 1, 0);
}
@Override
protected ResourceLocation getEntityTexture(Entity entity)
{
return TextureMap.locationBlocksTexture;
}
}

View File

@ -8,19 +8,86 @@
package biomesoplenty.common.init;
import biomesoplenty.common.entities.EntityPixie;
import biomesoplenty.common.entities.EntityWasp;
import biomesoplenty.common.entities.projectiles.EntityDart;
import java.util.Map;
import com.google.common.collect.Maps;
import biomesoplenty.common.entities.*;
import biomesoplenty.common.entities.projectiles.*;
import biomesoplenty.core.BiomesOPlenty;
import net.minecraft.entity.Entity;
import net.minecraft.entity.EntityList;
import net.minecraft.entity.EntityList.EntityEggInfo;
import net.minecraft.world.World;
import net.minecraftforge.fml.common.FMLCommonHandler;
import net.minecraftforge.fml.common.ModContainer;
import net.minecraftforge.fml.common.registry.EntityRegistry;
import net.minecraftforge.fml.common.registry.EntityRegistry.EntityRegistration;
public class ModEntities
{
public static final Map<Integer, EntityEggInfo> entityEggs = Maps.<Integer, EntityEggInfo>newLinkedHashMap();
public static final Map<Integer, String> idToBOPEntityName = Maps.<Integer, String>newLinkedHashMap();
private static int nextBOPEntityId = 1;
public static void init()
{
EntityRegistry.registerGlobalEntityID(EntityDart.class, "dart", EntityRegistry.findGlobalUniqueEntityId());
EntityRegistry.registerGlobalEntityID(EntityWasp.class, "wasp", EntityRegistry.findGlobalUniqueEntityId(), 0xFEE563, 0x000000);
EntityRegistry.registerGlobalEntityID(EntityPixie.class, "pixie", EntityRegistry.findGlobalUniqueEntityId(), 0xFFFFFF, 0xFF4DFF);
// projectiles
registerBOPEntity(EntityDart.class, "dart", 80, 3, true);
registerBOPEntity(EntityMudball.class, "mudball", 80, 3, true);
// mobs
registerBOPEntityWithSpawnEgg(EntityWasp.class, "wasp", 80, 3, true, 0xFEE563, 0x000000);
registerBOPEntityWithSpawnEgg(EntityPixie.class, "pixie", 80, 3, true, 0xFFFFFF, 0xFF4DFF);
}
// register an entity
public static int registerBOPEntity(Class<? extends Entity> entityClass, String entityName, int trackingRange, int updateFrequency, boolean sendsVelocityUpdates)
{
int bopEntityId = nextBOPEntityId;
nextBOPEntityId++;
EntityRegistry.registerModEntity(entityClass, entityName, bopEntityId, BiomesOPlenty.instance, trackingRange, updateFrequency, sendsVelocityUpdates);
idToBOPEntityName.put(bopEntityId, entityName);
return bopEntityId;
}
// register an entity and in addition create a spawn egg for it
public static int registerBOPEntityWithSpawnEgg(Class<? extends Entity> entityClass, String entityName, int trackingRange, int updateFrequency, boolean sendsVelocityUpdates, int eggBackgroundColor, int eggForegroundColor)
{
int bopEntityId = registerBOPEntity(entityClass, entityName, trackingRange, updateFrequency, sendsVelocityUpdates);
entityEggs.put(Integer.valueOf(bopEntityId), new EntityList.EntityEggInfo(bopEntityId, eggBackgroundColor, eggForegroundColor));
return bopEntityId;
}
public static Entity createEntityByID(int bopEntityId, World worldIn)
{
Entity entity = null;
ModContainer mc = FMLCommonHandler.instance().findContainerFor(BiomesOPlenty.instance);
EntityRegistration er = EntityRegistry.instance().lookupModSpawn(mc, bopEntityId);
if (er != null)
{
Class<? extends Entity> clazz = er.getEntityClass();
try
{
if (clazz != null)
{
entity = (Entity)clazz.getConstructor(new Class[] {World.class}).newInstance(new Object[] {worldIn});
}
}
catch (Exception exception)
{
exception.printStackTrace();
}
}
if (entity == null)
{
BiomesOPlenty.logger.warn("Skipping BOP Entity with id " + bopEntityId);
}
return entity;
}
}

View File

@ -193,6 +193,8 @@ public class ModItems
record_wanderer = registerItem(new ItemBOPRecord("wanderer"), "record_wanderer");
record_corruption = registerItem(new ItemBOPRecord("corruption"), "record_corruption");
spawn_egg = registerItem(new ItemBOPSpawnEgg(), "spawn_egg");
}
public static Item registerItem(Item item, String name)

View File

@ -0,0 +1,218 @@
/*******************************************************************************
* Copyright 2014, the Biomes O' Plenty Team
*
* This work is licensed under a Creative Commons Attribution-NonCommercial-NoDerivatives 4.0 International Public License.
*
* To view a copy of this license, visit http://creativecommons.org/licenses/by-nc-nd/4.0/.
******************************************************************************/
package biomesoplenty.common.item;
import java.util.Iterator;
import java.util.List;
import biomesoplenty.common.init.ModEntities;
import net.minecraft.block.BlockFence;
import net.minecraft.block.BlockLiquid;
import net.minecraft.block.state.IBlockState;
import net.minecraft.creativetab.CreativeTabs;
import net.minecraft.entity.Entity;
import net.minecraft.entity.EntityList;
import net.minecraft.entity.EntityLiving;
import net.minecraft.entity.EntityLivingBase;
import net.minecraft.entity.IEntityLivingData;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.init.Blocks;
import net.minecraft.item.Item;
import net.minecraft.item.ItemStack;
import net.minecraft.stats.StatList;
import net.minecraft.tileentity.MobSpawnerBaseLogic;
import net.minecraft.tileentity.TileEntity;
import net.minecraft.tileentity.TileEntityMobSpawner;
import net.minecraft.util.BlockPos;
import net.minecraft.util.EnumFacing;
import net.minecraft.util.MathHelper;
import net.minecraft.util.MovingObjectPosition;
import net.minecraft.world.World;
import net.minecraftforge.fml.relauncher.Side;
import net.minecraftforge.fml.relauncher.SideOnly;
public class ItemBOPSpawnEgg extends Item
{
public ItemBOPSpawnEgg()
{
this.setHasSubtypes(true);
this.setMaxDamage(0);
}
@Override
@SideOnly(Side.CLIENT)
public void getSubItems(Item itemIn, CreativeTabs tab, List subItems)
{
Iterator iterator = ModEntities.entityEggs.values().iterator();
while (iterator.hasNext())
{
EntityList.EntityEggInfo entityegginfo = (EntityList.EntityEggInfo)iterator.next();
subItems.add(new ItemStack(itemIn, 1, entityegginfo.spawnedID));
}
}
public static Entity spawnBOPCreature(World worldIn, int entityID, double x, double y, double z)
{
Entity entity = ModEntities.createEntityByID(entityID, worldIn);
if (entity instanceof EntityLivingBase)
{
EntityLiving entityliving = (EntityLiving)entity;
entity.setLocationAndAngles(x, y, z, MathHelper.wrapAngleTo180_float(worldIn.rand.nextFloat() * 360.0F), 0.0F);
entityliving.rotationYawHead = entityliving.rotationYaw;
entityliving.renderYawOffset = entityliving.rotationYaw;
entityliving.onSpawnFirstTime(worldIn.getDifficultyForLocation(new BlockPos(entityliving)), (IEntityLivingData)null);
worldIn.spawnEntityInWorld(entity);
entityliving.playLivingSound();
}
return entity;
}
// get the correct name for this item by looking up the meta value in the DartType enum
@Override
public String getUnlocalizedName(ItemStack stack)
{
int bopEntityId = stack.getMetadata();
String entityName = ModEntities.idToBOPEntityName.get(bopEntityId);
return super.getUnlocalizedName(stack)+"_"+entityName;
}
@Override
@SideOnly(Side.CLIENT)
public int getColorFromItemStack(ItemStack stack, int renderPass)
{
EntityList.EntityEggInfo entityegginfo = ModEntities.entityEggs.get(Integer.valueOf(stack.getMetadata()));
return entityegginfo != null ? (renderPass == 0 ? entityegginfo.primaryColor : entityegginfo.secondaryColor) : 16777215;
}
@Override
public boolean onItemUse(ItemStack stack, EntityPlayer playerIn, World worldIn, BlockPos pos, EnumFacing side, float hitX, float hitY, float hitZ)
{
if (worldIn.isRemote)
{
return true;
}
else if (!playerIn.canPlayerEdit(pos.offset(side), side, stack))
{
return false;
}
else
{
IBlockState iblockstate = worldIn.getBlockState(pos);
if (iblockstate.getBlock() == Blocks.mob_spawner)
{
TileEntity tileentity = worldIn.getTileEntity(pos);
if (tileentity instanceof TileEntityMobSpawner)
{
MobSpawnerBaseLogic mobspawnerbaselogic = ((TileEntityMobSpawner)tileentity).getSpawnerBaseLogic();
mobspawnerbaselogic.setEntityName(EntityList.getStringFromID(stack.getMetadata()));
tileentity.markDirty();
worldIn.markBlockForUpdate(pos);
if (!playerIn.capabilities.isCreativeMode)
{
--stack.stackSize;
}
return true;
}
}
pos = pos.offset(side);
double d0 = 0.0D;
if (side == EnumFacing.UP && iblockstate instanceof BlockFence)
{
d0 = 0.5D;
}
Entity entity = spawnBOPCreature(worldIn, stack.getMetadata(), (double)pos.getX() + 0.5D, (double)pos.getY() + d0, (double)pos.getZ() + 0.5D);
if (entity != null)
{
if (entity instanceof EntityLivingBase && stack.hasDisplayName())
{
entity.setCustomNameTag(stack.getDisplayName());
}
if (!playerIn.capabilities.isCreativeMode)
{
--stack.stackSize;
}
}
return true;
}
}
@Override
public ItemStack onItemRightClick(ItemStack itemStackIn, World worldIn, EntityPlayer playerIn)
{
if (worldIn.isRemote)
{
return itemStackIn;
}
else
{
MovingObjectPosition movingobjectposition = this.getMovingObjectPositionFromPlayer(worldIn, playerIn, true);
if (movingobjectposition == null)
{
return itemStackIn;
}
else
{
if (movingobjectposition.typeOfHit == MovingObjectPosition.MovingObjectType.BLOCK)
{
BlockPos blockpos = movingobjectposition.getBlockPos();
if (!worldIn.isBlockModifiable(playerIn, blockpos))
{
return itemStackIn;
}
if (!playerIn.canPlayerEdit(blockpos, movingobjectposition.sideHit, itemStackIn))
{
return itemStackIn;
}
if (worldIn.getBlockState(blockpos).getBlock() instanceof BlockLiquid)
{
Entity entity = spawnBOPCreature(worldIn, itemStackIn.getMetadata(), (double)blockpos.getX() + 0.5D, (double)blockpos.getY() + 0.5D, (double)blockpos.getZ() + 0.5D);
if (entity != null)
{
if (entity instanceof EntityLivingBase && itemStackIn.hasDisplayName())
{
((EntityLiving)entity).setCustomNameTag(itemStackIn.getDisplayName());
}
if (!playerIn.capabilities.isCreativeMode)
{
--itemStackIn.stackSize;
}
playerIn.triggerAchievement(StatList.objectUseStats[Item.getIdFromItem(this)]);
}
}
}
return itemStackIn;
}
}
}
}

View File

@ -59,7 +59,6 @@ public class ItemDartBlower extends Item
itemStackIn.damageItem(1, playerIn);
playerIn.inventory.decrStackSize(bestDartSlot, 1);
}
System.out.println("spawn dart "+bestAvailableDartType.getName());
worldIn.spawnEntityInWorld(entityDart);
worldIn.playSoundAtEntity(playerIn, "random.bow", 1.0F, 1.75F);
}

View File

@ -8,10 +8,10 @@
package biomesoplenty.common.item;
import biomesoplenty.common.entities.projectiles.EntityMudball;
import net.minecraft.item.Item;
import net.minecraft.item.ItemStack;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.entity.projectile.EntitySnowball;
import net.minecraft.stats.StatList;
import net.minecraft.world.World;
@ -35,8 +35,7 @@ public class ItemMudball extends Item
if (!worldIn.isRemote)
{
// TODO: implement EntityMudball worldIn.spawnEntityInWorld(new EntityMudball(worldIn, playerIn));
worldIn.spawnEntityInWorld(new EntitySnowball(worldIn, playerIn));
worldIn.spawnEntityInWorld(new EntityMudball(worldIn, playerIn));
}
playerIn.triggerAchievement(StatList.objectUseStats[Item.getIdFromItem(this)]);

View File

@ -55,8 +55,8 @@ public class BiomesOPlenty
// setup blocks before items, because some items need to reference blocks in their constructors (eg seeds)
ModBlocks.init();
ModItems.init();
ModEntities.init();
ModItems.init();
ModGenerators.init();
ModBiomes.init();

View File

@ -20,22 +20,20 @@ import net.minecraft.client.renderer.texture.SimpleTexture;
import net.minecraft.client.resources.model.ModelBakery;
import net.minecraft.client.resources.model.ModelResourceLocation;
import net.minecraft.item.Item;
import net.minecraft.util.EnumParticleTypes;
import net.minecraft.util.MathHelper;
import net.minecraft.util.ResourceLocation;
import net.minecraftforge.client.model.ModelLoader;
import net.minecraftforge.fluids.BlockFluidBase;
import net.minecraftforge.fml.client.registry.RenderingRegistry;
import biomesoplenty.api.block.IBOPBlock;
import biomesoplenty.api.item.BOPItems;
import biomesoplenty.api.particle.BOPParticleTypes;
import biomesoplenty.client.handler.ModelBakeHandler;
import biomesoplenty.client.particle.*;
import biomesoplenty.common.config.MiscConfigurationHandler;
import biomesoplenty.common.entities.EntityPixie;
import biomesoplenty.common.entities.EntityWasp;
import biomesoplenty.common.entities.RenderPixie;
import biomesoplenty.common.entities.RenderWasp;
import biomesoplenty.common.entities.projectiles.EntityDart;
import biomesoplenty.common.entities.projectiles.RenderDart;
import biomesoplenty.common.entities.*;
import biomesoplenty.common.entities.projectiles.*;
public class ClientProxy extends CommonProxy
{
@ -54,6 +52,9 @@ public class ClientProxy extends CommonProxy
RenderingRegistry.registerEntityRenderingHandler(EntityDart.class, new RenderDart(minecraft.getRenderManager()));
RenderingRegistry.registerEntityRenderingHandler(EntityWasp.class, new RenderWasp(minecraft.getRenderManager()));
RenderingRegistry.registerEntityRenderingHandler(EntityPixie.class, new RenderPixie(minecraft.getRenderManager()));
RenderingRegistry.registerEntityRenderingHandler(EntityMudball.class, new RenderMudball(minecraft.getRenderManager(), BOPItems.mudball, minecraft.getRenderItem()));
//RenderingRegistry.registerEntityRenderingHandler(EntityMudball.class, new RenderSnowball(minecraft.getRenderManager(), BOPItems.mudball, minecraft.getRenderItem()));
ITextureObject particleTextures = (ITextureObject)(new SimpleTexture(particleTexturesLocation));
minecraft.renderEngine.loadTexture(particleTexturesLocation, particleTextures);
@ -108,6 +109,10 @@ public class ClientProxy extends CommonProxy
case DANDELION:
entityFx = new EntityDandelionFX(minecraft.theWorld, x, y, z, 2.0F);
break;
case MUD:
int itemId = Item.getIdFromItem(BOPItems.mudball);
minecraft.theWorld.spawnParticle(EnumParticleTypes.ITEM_CRACK, x, y, z, MathHelper.getRandomDoubleInRange(minecraft.theWorld.rand, -0.08D, 0.08D), MathHelper.getRandomDoubleInRange(minecraft.theWorld.rand, -0.08D, 0.08D), MathHelper.getRandomDoubleInRange(minecraft.theWorld.rand, -0.08D, 0.08D), new int[] {itemId});
return;
default:
break;
}

View File

@ -0,0 +1,19 @@
{
"parent": "builtin/generated",
"textures": {
"layer0": "items/spawn_egg",
"layer1": "items/spawn_egg_overlay"
},
"display": {
"thirdperson": {
"rotation": [ -90, 0, 0 ],
"translation": [ 0, 1, -3 ],
"scale": [ 0.55, 0.55, 0.55 ]
},
"firstperson": {
"rotation": [ 0, -135, 25 ],
"translation": [ 0, 4, 2 ],
"scale": [ 1.7, 1.7, 1.7 ]
}
}
}

View File

@ -0,0 +1,19 @@
{
"parent": "builtin/generated",
"textures": {
"layer0": "items/spawn_egg",
"layer1": "items/spawn_egg_overlay"
},
"display": {
"thirdperson": {
"rotation": [ -90, 0, 0 ],
"translation": [ 0, 1, -3 ],
"scale": [ 0.55, 0.55, 0.55 ]
},
"firstperson": {
"rotation": [ 0, -135, 25 ],
"translation": [ 0, 4, 2 ],
"scale": [ 1.7, 1.7, 1.7 ]
}
}
}