Skip to content

Instantly share code, notes, and snippets.

@Epidra
Created June 9, 2016 10:50
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Epidra/acf7c589de8488d2763352342a29e018 to your computer and use it in GitHub Desktop.
Save Epidra/acf7c589de8488d2763352342a29e018 to your computer and use it in GitHub Desktop.
package net.acecraft.mod.proxy;
import net.acecraft.mod.ShopKeeper;
import net.acecraft.mod.entity.EntityDynamite;
import net.acecraft.mod.entity.EntityNugget;
import net.acecraft.mod.entity.EntitySpear;
import net.acecraft.mod.render.RenderDynamite;
import net.acecraft.mod.render.RenderNugget;
import net.acecraft.mod.render.RenderSpear;
import net.minecraft.client.Minecraft;
import net.minecraft.client.renderer.entity.Render;
import net.minecraft.client.renderer.entity.RenderManager;
import net.minecraft.entity.Entity;
import net.minecraftforge.fml.client.registry.IRenderFactory;
import net.minecraftforge.fml.client.registry.RenderingRegistry;
import net.minecraftforge.fml.common.event.FMLPreInitializationEvent;
public class ClientProxy extends CommonProxy {
public static void register(){
}
public void PreInit(FMLPreInitializationEvent preEvent){
//RenderingRegistry.registerEntityRenderingHandler(EntitySpear.class, new IRenderFactory<Entity>(){@Override public Render<? super Entity> createRenderFor(RenderManager manager){ return new RenderSpear(manager); }});
//RenderingRegistry.registerEntityRenderingHandler(EntityNugget.class, new IRenderFactory<Entity>(){@Override public Render<? super Entity> createRenderFor(RenderManager manager){ return new RenderNugget(manager, ShopKeeper.nuggetAdamantium, manager); }});
}
public void registerRenderThings(){
RenderingRegistry.registerEntityRenderingHandler(EntityDynamite.class, new RenderDynamite(Minecraft.getMinecraft().getRenderManager(), ShopKeeper.explosiveDynamite, Minecraft.getMinecraft().getRenderItem()));
RenderingRegistry.registerEntityRenderingHandler(EntityNugget.class, new RenderNugget(Minecraft.getMinecraft().getRenderManager(), ShopKeeper.nuggetAdamantium, Minecraft.getMinecraft().getRenderItem()));
}
public void registerTileEntitySpecialRenderer(){
}
}
package net.acecraft.mod.entity;
import net.acecraft.mod.ShopKeeper;
import net.acecraft.mod.entity.EntitySpear.PickupStatus;
import net.minecraft.entity.EntityLivingBase;
import net.minecraft.entity.monster.EntityBlaze;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.entity.projectile.EntityThrowable;
import net.minecraft.init.Items;
import net.minecraft.init.SoundEvents;
import net.minecraft.item.ItemStack;
import net.minecraft.util.DamageSource;
import net.minecraft.util.EnumParticleTypes;
import net.minecraft.util.SoundCategory;
import net.minecraft.util.math.RayTraceResult;
import net.minecraft.world.World;
public class EntityDynamite extends EntityThrowable
{
public EntityDynamite(World worldIn)
{
super(worldIn);
}
public EntityDynamite(World worldIn, EntityLivingBase throwerIn)
{
super(worldIn, throwerIn);
}
public EntityDynamite(World worldIn, double x, double y, double z)
{
super(worldIn, x, y, z);
}
/**
* Called when this EntityThrowable hits a block or entity.
*/
protected void onImpact(RayTraceResult result)
{
if (result.entityHit != null)
{
int i = 0;
result.entityHit.attackEntityFrom(DamageSource.causeThrownDamage(this, this.getThrower()), (float)i);
}
for (int j = 0; j < 8; ++j)
{
this.worldObj.spawnParticle(EnumParticleTypes.SNOWBALL, this.posX, this.posY, this.posZ, 0.0D, 0.0D, 0.0D, new int[0]);
}
if (!this.worldObj.isRemote)
{
this.setDead();
if (!this.worldObj.isRemote)
{
this.explode();
}
}
}
private void explode()
{
float f = 2.0F;
this.worldObj.createExplosion(this, this.posX, this.posY + (double)(this.height / 16.0F), this.posZ, f, true);
}
}
package net.acecraft.mod.entity;
import net.acecraft.mod.ShopKeeper;
import net.acecraft.mod.entity.EntitySpear.PickupStatus;
import net.minecraft.entity.EntityLivingBase;
import net.minecraft.entity.monster.EntityBlaze;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.entity.projectile.EntityThrowable;
import net.minecraft.init.Items;
import net.minecraft.init.SoundEvents;
import net.minecraft.item.ItemStack;
import net.minecraft.util.DamageSource;
import net.minecraft.util.EnumParticleTypes;
import net.minecraft.util.SoundCategory;
import net.minecraft.util.math.RayTraceResult;
import net.minecraft.world.World;
public class EntityNugget extends EntityThrowable
{
public String id = "empty";
public EntityNugget(World worldIn)
{
super(worldIn);
}
public EntityNugget(World worldIn, EntityLivingBase throwerIn)
{
super(worldIn, throwerIn);
}
public EntityNugget(World worldIn, EntityLivingBase throwerIn, String name)
{
super(worldIn, throwerIn);
id = name;
}
public EntityNugget(World worldIn, double x, double y, double z)
{
super(worldIn, x, y, z);
}
/**
* Called when this EntityThrowable hits a block or entity.
*/
protected void onImpact(RayTraceResult result)
{
if (result.entityHit != null)
{
int i = 2;
if (result.entityHit instanceof EntityBlaze)
{
i = 3;
}
result.entityHit.attackEntityFrom(DamageSource.causeThrownDamage(this, this.getThrower()), (float)i);
}
for (int j = 0; j < 8; ++j)
{
this.worldObj.spawnParticle(EnumParticleTypes.SNOWBALL, this.posX, this.posY, this.posZ, 0.0D, 0.0D, 0.0D, new int[0]);
}
if (!this.worldObj.isRemote)
{
//this.setDead();
}
}
public void onCollideWithPlayer(EntityPlayer player){
if (!this.worldObj.isRemote && this.inGround){
boolean flag = !player.capabilities.isCreativeMode;
ItemStack stack;
if(id.compareTo("ToolSpearFlint") == 0) { stack = new ItemStack(ShopKeeper.toolSpearFlint, 1); }
else if(id.compareTo("ToolSpearObsidian") == 0) { stack = new ItemStack(ShopKeeper.toolSpearObsidian, 1); }
else if(id.compareTo("ToolSpearIron") == 0) { stack = new ItemStack(ShopKeeper.toolSpearIron, 1); }
else if(id.compareTo("ToolSpearGold") == 0) { stack = new ItemStack(ShopKeeper.toolSpearGold, 1); }
else if(id.compareTo("ToolSpearCopper") == 0) { stack = new ItemStack(ShopKeeper.toolSpearCopper, 1); }
else if(id.compareTo("ToolSpearBronze") == 0) { stack = new ItemStack(ShopKeeper.toolSpearBronze, 1); }
else if(id.compareTo("ToolSpearSteel") == 0) { stack = new ItemStack(ShopKeeper.toolSpearSteel, 1); }
else if(id.compareTo("ToolSpearMythril") == 0) { stack = new ItemStack(ShopKeeper.toolSpearMythril, 1); }
else if(id.compareTo("ToolSpearIridium") == 0) { stack = new ItemStack(ShopKeeper.toolSpearIridium, 1); }
else if(id.compareTo("ToolSpearAdamantium") == 0) { stack = new ItemStack(ShopKeeper.toolSpearAdamantium, 1); }
else if(id.compareTo("ToolSpearUnobtanium") == 0) { stack = new ItemStack(ShopKeeper.toolSpearUnobtanium, 1); }
else{ stack = new ItemStack(Items.flint, 1); }
if (flag){
player.worldObj.playSound((EntityPlayer)null, player.posX, player.posY, player.posZ, SoundEvents.entity_arrow_shoot, SoundCategory.NEUTRAL, 1.0F, 1.0F / (rand.nextFloat() * 0.4F + 1.2F));
//player.onItemPickup(this, 1);
this.setDead();
}
}
}
}
package net.acecraft.mod.items;
import net.acecraft.mod.entity.EntityDynamite;
import net.minecraft.creativetab.CreativeTabs;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.init.SoundEvents;
import net.minecraft.item.Item;
import net.minecraft.item.ItemStack;
import net.minecraft.stats.StatList;
import net.minecraft.util.ActionResult;
import net.minecraft.util.EnumActionResult;
import net.minecraft.util.EnumHand;
import net.minecraft.util.SoundCategory;
import net.minecraft.world.World;
public class ItemDynamite extends Item {
public ItemDynamite(String name){
this.setUnlocalizedName(name);
this.setRegistryName(name);
this.setCreativeTab(CreativeTabs.tabTools);
}
public ActionResult<ItemStack> onItemRightClick(ItemStack itemStackIn, World worldIn, EntityPlayer playerIn, EnumHand hand)
{
if (!playerIn.capabilities.isCreativeMode)
{
--itemStackIn.stackSize;
}
worldIn.playSound((EntityPlayer)null, playerIn.posX, playerIn.posY, playerIn.posZ, SoundEvents.entity_firework_launch, SoundCategory.NEUTRAL, 0.5F, 0.4F / (itemRand.nextFloat() * 0.4F + 0.8F));
if (!worldIn.isRemote)
{
EntityDynamite entitysnowball = new EntityDynamite(worldIn, playerIn);
entitysnowball.func_184538_a(playerIn, playerIn.rotationPitch, playerIn.rotationYaw, 0.0F, 1.5F, 1.0F);
worldIn.spawnEntityInWorld(entitysnowball);
}
playerIn.addStat(StatList.func_188057_b(this));
return new ActionResult(EnumActionResult.SUCCESS, itemStackIn);
}
}
package net.acecraft.mod.items;
import net.acecraft.mod.entity.EntityNugget;
import net.minecraft.creativetab.CreativeTabs;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.entity.projectile.EntitySnowball;
import net.minecraft.init.SoundEvents;
import net.minecraft.item.Item;
import net.minecraft.item.ItemStack;
import net.minecraft.stats.StatList;
import net.minecraft.util.ActionResult;
import net.minecraft.util.EnumActionResult;
import net.minecraft.util.EnumHand;
import net.minecraft.util.SoundCategory;
import net.minecraft.world.World;
public class ItemNugget extends Item {
public ItemNugget(String name){
this.setUnlocalizedName(name);
this.setRegistryName(name);
this.setCreativeTab(CreativeTabs.tabMaterials);
}
public ActionResult<ItemStack> onItemRightClick(ItemStack itemStackIn, World worldIn, EntityPlayer playerIn, EnumHand hand)
{
if (!playerIn.capabilities.isCreativeMode)
{
--itemStackIn.stackSize;
}
worldIn.playSound((EntityPlayer)null, playerIn.posX, playerIn.posY, playerIn.posZ, SoundEvents.entity_snowball_throw, SoundCategory.NEUTRAL, 0.5F, 0.4F / (itemRand.nextFloat() * 0.4F + 0.8F));
if (!worldIn.isRemote)
{
EntityNugget entitysnowball = new EntityNugget(worldIn, playerIn, this.getUnlocalizedName().substring(5));
entitysnowball.func_184538_a(playerIn, playerIn.rotationPitch, playerIn.rotationYaw, 0.0F, 1.5F, 1.0F);
worldIn.spawnEntityInWorld(entitysnowball);
}
playerIn.addStat(StatList.func_188057_b(this));
return new ActionResult(EnumActionResult.SUCCESS, itemStackIn);
}
}
package net.acecraft.mod.render;
import net.acecraft.mod.AceCraft;
import net.acecraft.mod.entity.EntityDynamite;
import net.minecraft.client.renderer.GlStateManager;
import net.minecraft.client.renderer.RenderItem;
import net.minecraft.client.renderer.block.model.ItemCameraTransforms;
import net.minecraft.client.renderer.entity.Render;
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 RenderDynamite<T extends EntityDynamite> extends Render<T>
{
protected final Item field_177084_a;
private final RenderItem field_177083_e;
public RenderDynamite(RenderManager renderManagerIn, Item p_i46137_2_, RenderItem p_i46137_3_)
{
super(renderManagerIn);
this.field_177084_a = p_i46137_2_;
this.field_177083_e = p_i46137_3_;
}
/**
* Renders the desired {@code T} type Entity.
*/
public void doRender(T entity, double x, double y, double z, float entityYaw, float partialTicks)
{
GlStateManager.pushMatrix();
GlStateManager.translate((float)x, (float)y, (float)z);
GlStateManager.enableRescaleNormal();
GlStateManager.rotate(-this.renderManager.playerViewY, 0.0F, 1.0F, 0.0F);
GlStateManager.rotate((float)(this.renderManager.options.thirdPersonView == 2 ? -1 : 1) * this.renderManager.playerViewX, 1.0F, 0.0F, 0.0F);
GlStateManager.rotate(180.0F, 0.0F, 1.0F, 0.0F);
this.bindTexture(new ResourceLocation(AceCraft.modid + ":" + field_177084_a.getUnlocalizedName().substring(5)));
if (this.renderOutlines)
{
GlStateManager.enableColorMaterial();
GlStateManager.enableOutlineMode(this.getTeamColor(entity));
}
this.field_177083_e.renderItem(this.getPotion(entity), ItemCameraTransforms.TransformType.GROUND);
if (this.renderOutlines)
{
GlStateManager.disableOutlineMode();
GlStateManager.disableColorMaterial();
}
GlStateManager.disableRescaleNormal();
GlStateManager.popMatrix();
super.doRender(entity, x, y, z, entityYaw, partialTicks);
}
public ItemStack getPotion(T entityIn)
{
return new ItemStack(this.field_177084_a);
}
/**
* Returns the location of an entity's texture. Doesn't seem to be called unless you call Render.bindEntityTexture.
*/
protected ResourceLocation getEntityTexture(T entity){
return TextureMap.locationBlocksTexture;
}
protected boolean bindEntityTexture(T entity)
{
ResourceLocation resourcelocation = this.getEntityTexture(entity);
if (resourcelocation == null)
{
return false;
}
else
{
this.bindTexture(resourcelocation);
return true;
}
}
public void bindTexture(ResourceLocation location)
{
this.renderManager.renderEngine.bindTexture(location);
}
}
package net.acecraft.mod.render;
import net.acecraft.mod.AceCraft;
import net.acecraft.mod.entity.EntityNugget;
import net.minecraft.client.renderer.GlStateManager;
import net.minecraft.client.renderer.RenderItem;
import net.minecraft.client.renderer.block.model.ItemCameraTransforms;
import net.minecraft.client.renderer.entity.Render;
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 RenderNugget<T extends EntityNugget> extends Render<T>
{
protected final Item field_177084_a;
private final RenderItem field_177083_e;
public RenderNugget(RenderManager renderManagerIn, Item p_i46137_2_, RenderItem p_i46137_3_)
{
super(renderManagerIn);
this.field_177084_a = p_i46137_2_;
this.field_177083_e = p_i46137_3_;
}
/**
* Renders the desired {@code T} type Entity.
*/
public void doRender(T entity, double x, double y, double z, float entityYaw, float partialTicks)
{
GlStateManager.pushMatrix();
GlStateManager.translate((float)x, (float)y, (float)z);
GlStateManager.enableRescaleNormal();
GlStateManager.rotate(-this.renderManager.playerViewY, 0.0F, 1.0F, 0.0F);
GlStateManager.rotate((float)(this.renderManager.options.thirdPersonView == 2 ? -1 : 1) * this.renderManager.playerViewX, 1.0F, 0.0F, 0.0F);
GlStateManager.rotate(180.0F, 0.0F, 1.0F, 0.0F);
this.bindTexture(new ResourceLocation(AceCraft.modid + ":" + field_177084_a.getUnlocalizedName().substring(5)));
if (this.renderOutlines)
{
GlStateManager.enableColorMaterial();
GlStateManager.enableOutlineMode(this.getTeamColor(entity));
}
this.field_177083_e.renderItem(this.getPotion(entity), ItemCameraTransforms.TransformType.GROUND);
if (this.renderOutlines)
{
GlStateManager.disableOutlineMode();
GlStateManager.disableColorMaterial();
}
GlStateManager.disableRescaleNormal();
GlStateManager.popMatrix();
super.doRender(entity, x, y, z, entityYaw, partialTicks);
}
public ItemStack getPotion(T entityIn)
{
return new ItemStack(this.field_177084_a);
}
/**
* Returns the location of an entity's texture. Doesn't seem to be called unless you call Render.bindEntityTexture.
*/
protected ResourceLocation getEntityTexture(T entity){
return TextureMap.locationBlocksTexture;
}
protected boolean bindEntityTexture(T entity)
{
ResourceLocation resourcelocation = this.getEntityTexture(entity);
if (resourcelocation == null)
{
return false;
}
else
{
this.bindTexture(resourcelocation);
return true;
}
}
public void bindTexture(ResourceLocation location)
{
this.renderManager.renderEngine.bindTexture(location);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment