From 7eff82962acbed0eac783009f5f4ca5ee72b993a Mon Sep 17 00:00:00 2001 From: Cricket Date: Sun, 8 Mar 2015 16:48:05 -0400 Subject: [PATCH] You make special snow golems now --- .../java/com/cricketcraft/chisel/Chisel.java | 4 ++ .../chisel/block/BlockCarvablePumpkin.java | 65 +++++++++++++++++++ .../client/render/RenderChiselSnowman.java | 65 +++++++++++++++++++ .../chisel/entity/EntityChiselSnowman.java | 13 ++++ .../chisel/proxy/ClientProxy.java | 2 + .../resources/assets/chisel/lang/en_US.lang | 3 + 6 files changed, 152 insertions(+) create mode 100644 src/main/java/com/cricketcraft/chisel/client/render/RenderChiselSnowman.java create mode 100644 src/main/java/com/cricketcraft/chisel/entity/EntityChiselSnowman.java diff --git a/src/main/java/com/cricketcraft/chisel/Chisel.java b/src/main/java/com/cricketcraft/chisel/Chisel.java index 0f421eb0..26ca1602 100644 --- a/src/main/java/com/cricketcraft/chisel/Chisel.java +++ b/src/main/java/com/cricketcraft/chisel/Chisel.java @@ -2,6 +2,8 @@ package com.cricketcraft.chisel; import java.io.File; +import com.cricketcraft.chisel.entity.EntityChiselSnowman; +import cpw.mods.fml.common.registry.EntityRegistry; import net.minecraft.block.Block; import net.minecraft.item.Item; import net.minecraftforge.common.MinecraftForge; @@ -136,6 +138,8 @@ public class Chisel { addWorldgen(Features.DIORITE, ChiselBlocks.diorite, Configurations.dioriteAmount, 40, 100, 0.5); GameRegistry.registerWorldGenerator(GeneratorChisel.INSTANCE, 1000); + EntityRegistry.registerModEntity(EntityChiselSnowman.class, "snowman", 0, this, 80, 1, true); + proxy.init(); MinecraftForge.EVENT_BUS.register(this); FMLCommonHandler.instance().bus().register(instance); diff --git a/src/main/java/com/cricketcraft/chisel/block/BlockCarvablePumpkin.java b/src/main/java/com/cricketcraft/chisel/block/BlockCarvablePumpkin.java index 6e132405..2099f89f 100644 --- a/src/main/java/com/cricketcraft/chisel/block/BlockCarvablePumpkin.java +++ b/src/main/java/com/cricketcraft/chisel/block/BlockCarvablePumpkin.java @@ -1,8 +1,12 @@ package com.cricketcraft.chisel.block; +import com.cricketcraft.chisel.entity.EntityChiselSnowman; +import com.cricketcraft.chisel.init.ChiselBlocks; import net.minecraft.block.Block; import net.minecraft.block.BlockPumpkin; import net.minecraft.client.renderer.texture.IIconRegister; +import net.minecraft.entity.monster.EntityIronGolem; +import net.minecraft.init.Blocks; import net.minecraft.item.ItemStack; import net.minecraft.util.IIcon; import net.minecraft.world.IBlockAccess; @@ -14,6 +18,7 @@ import com.cricketcraft.chisel.carving.CarvableVariation; import cpw.mods.fml.relauncher.Side; import cpw.mods.fml.relauncher.SideOnly; +import net.minecraft.world.World; public class BlockCarvablePumpkin extends BlockPumpkin implements ICarvable { @@ -32,6 +37,66 @@ public class BlockCarvablePumpkin extends BlockPumpkin implements ICarvable { carverHelper = new CarvableHelper(); } + @Override + public void onBlockAdded(World world, int x, int y, int z){ + if(world.getBlock(x, y - 1, z) == Blocks.snow && world.getBlock(x, y - 2, z) == Blocks.snow){ + if(!world.isRemote){ + //Let's grab the pumpkin before we start + ItemStack pumpkin = new ItemStack(world.getBlock(x, y, z), world.getBlockMetadata(x, y, z)); + + world.setBlock(x, y, z, Blocks.air, 0, 2); + world.setBlock(x, y - 1, z, Blocks.air, 0, 2); + world.setBlock(x, y - 2, z, Blocks.air, 0, 2); + EntityChiselSnowman snowman = new EntityChiselSnowman(world); + snowman.setCurrentItemOrArmor(2, pumpkin); + snowman.setLocationAndAngles((double) x + 0.5D, (double) y - 1.95D, (double) z + 0.5D, 0.0F, 0.0F); + world.spawnEntityInWorld(snowman); + world.notifyBlockChange(x, y, z, Blocks.air); + world.notifyBlockChange(x, y - 1, z, Blocks.air); + world.notifyBlockChange(x, y - 2, z, Blocks.air); + } + + //Spawn some lovely particles + for(int c = 0; c < 120; ++c){ + world.spawnParticle("snowshovel", (double)x + world.rand.nextDouble(), (double) (y - 2) + world.rand.nextDouble() * 2.5D, (double) z + world.rand.nextDouble(), 0.0D, 0.0D, 0.0D); + } + } else if(world.getBlock(x, y - 1, z) == Blocks.iron_block || world.getBlock(x, y - 2, z) == Blocks.iron_block){ + boolean flag = world.getBlock(x - 1, y - 1, z) == Blocks.iron_block && world.getBlock(x + 1, y - 1, z) == Blocks.iron_block; + boolean flag1 = world.getBlock(x, y - 1, z - 1) == Blocks.iron_block && world.getBlock(x, y - 1, z + 1) == Blocks.iron_block; + + if(flag || flag1){ + world.setBlock(x, y, z, Blocks.air, 0, 2); + world.setBlock(x, y - 1, z, Blocks.air, 0, 2); + world.setBlock(x, y - 2, z, Blocks.air, 0, 2); + + if(flag){ + world.setBlock(x - 1, y - 1, z, Blocks.air, 0, 2); + world.setBlock(x + 1, y - 1, z, Blocks.air, 0, 2); + } else { + world.setBlock(x, y - 1, z - 1, Blocks.air, 0, 2); + world.setBlock(x, y - 1, z + 1, Blocks.air, 0, 2); + } + + EntityIronGolem ironGolem = new EntityIronGolem(world); + ironGolem.setPlayerCreated(true); + ironGolem.setLocationAndAngles((double) x + 0.5D, (double) y - 1.95D, (double) z + 0.5D, 0.0F, 0.0F); + world.spawnEntityInWorld(ironGolem); + + world.notifyBlockChange(x, y, z, Blocks.air); + world.notifyBlockChange(x, y - 1, z, Blocks.air); + world.notifyBlockChange(x, y - 2, z, Blocks.air); + + if(flag){ + world.notifyBlockChange(x - 1, y - 1, z, Blocks.air); + world.notifyBlockChange(x + 1, y - 1, z, Blocks.air); + } else { + world.notifyBlockChange(x, y - 1, z - 1, Blocks.air); + world.notifyBlockChange(x, y - 1, z + 1, Blocks.air); + } + } + } + } + @Override @SideOnly(Side.CLIENT) public IIcon getIcon(int side, int meta) { diff --git a/src/main/java/com/cricketcraft/chisel/client/render/RenderChiselSnowman.java b/src/main/java/com/cricketcraft/chisel/client/render/RenderChiselSnowman.java new file mode 100644 index 00000000..55953901 --- /dev/null +++ b/src/main/java/com/cricketcraft/chisel/client/render/RenderChiselSnowman.java @@ -0,0 +1,65 @@ +package com.cricketcraft.chisel.client.render; + +import com.cricketcraft.chisel.entity.EntityChiselSnowman; +import net.minecraft.block.Block; +import net.minecraft.client.model.ModelSnowMan; +import net.minecraft.client.renderer.RenderBlocks; +import net.minecraft.client.renderer.entity.RenderLiving; +import net.minecraft.entity.Entity; +import net.minecraft.entity.EntityLivingBase; +import net.minecraft.item.ItemBlock; +import net.minecraft.item.ItemStack; +import net.minecraft.util.ResourceLocation; +import net.minecraftforge.client.IItemRenderer; +import net.minecraftforge.client.MinecraftForgeClient; +import static net.minecraftforge.client.IItemRenderer.ItemRenderType.*; +import static net.minecraftforge.client.IItemRenderer.ItemRendererHelper.*; +import org.lwjgl.opengl.GL11; + +public class RenderChiselSnowman extends RenderLiving{ + + private static final ResourceLocation snowManTextures = new ResourceLocation("textures/entity/snowman.png"); + private ModelSnowMan snowMan; + + public RenderChiselSnowman() { + super(new ModelSnowMan(), 0.5F); + snowMan = (ModelSnowMan)super.mainModel; + setRenderPassModel(this.snowMan); + } + + @Override + protected void renderEquippedItems(EntityLivingBase entityLivingBase, float size){ + this.renderEquippedItems((EntityChiselSnowman) entityLivingBase, size); + } + + @Override + protected ResourceLocation getEntityTexture(Entity entity) { + return this.getEntityTexture((EntityChiselSnowman) entity); + } + + protected ResourceLocation getEntityTexture(EntityChiselSnowman snowman){ + return snowManTextures; + } + + protected void renderEquippedItems(EntityChiselSnowman snowman, float size){ + super.renderEquippedItems(snowman, size); + ItemStack itemStack = snowman.getEquipmentInSlot(2); + + if(itemStack.getItem() instanceof ItemBlock){ + GL11.glPushMatrix(); + this.snowMan.head.postRender(0.0625F); + + IItemRenderer customRenderer = MinecraftForgeClient.getItemRenderer(itemStack, EQUIPPED); + boolean is3D = (customRenderer != null && customRenderer.shouldUseRenderHelper(EQUIPPED, itemStack, BLOCK_3D)); + + if(is3D || RenderBlocks.renderItemIn3d(Block.getBlockFromItem(itemStack.getItem()).getRenderType())){ + float f1 = 0.625F; + GL11.glTranslatef(0.0F, -0.34375F, 0.0F); + GL11.glRotatef(90.0F, 0.0F, 1.0F, 0.0F); + GL11.glScalef(f1, -f1, f1); + } + this.renderManager.itemRenderer.renderItem(snowman, itemStack, 0); + GL11.glPopMatrix(); + } + } +} diff --git a/src/main/java/com/cricketcraft/chisel/entity/EntityChiselSnowman.java b/src/main/java/com/cricketcraft/chisel/entity/EntityChiselSnowman.java new file mode 100644 index 00000000..bffbc7ab --- /dev/null +++ b/src/main/java/com/cricketcraft/chisel/entity/EntityChiselSnowman.java @@ -0,0 +1,13 @@ +package com.cricketcraft.chisel.entity; + +import net.minecraft.entity.monster.EntitySnowman; +import net.minecraft.world.World; + +public class EntityChiselSnowman extends EntitySnowman{ + + public EntityChiselSnowman(World world){ + super(world); + } + + //No special features just needed to get around the hardcoding +} diff --git a/src/main/java/com/cricketcraft/chisel/proxy/ClientProxy.java b/src/main/java/com/cricketcraft/chisel/proxy/ClientProxy.java index 1e3d7f60..a76a97db 100644 --- a/src/main/java/com/cricketcraft/chisel/proxy/ClientProxy.java +++ b/src/main/java/com/cricketcraft/chisel/proxy/ClientProxy.java @@ -8,6 +8,7 @@ import com.cricketcraft.chisel.client.render.item.ItemChiselRenderer; import com.cricketcraft.chisel.client.render.tile.RenderAutoChisel; import com.cricketcraft.chisel.client.render.tile.RenderPresent; import com.cricketcraft.chisel.entity.EntityBallOMoss; +import com.cricketcraft.chisel.entity.EntityChiselSnowman; import com.cricketcraft.chisel.entity.EntityCloudInABottle; import com.cricketcraft.chisel.entity.EntitySmashingRock; import com.cricketcraft.chisel.init.ChiselBlocks; @@ -58,6 +59,7 @@ public class ClientProxy extends CommonProxy { RenderingRegistry.registerEntityRenderingHandler(EntityCloudInABottle.class, new RenderSnowball(ChiselItems.cloudinabottle)); RenderingRegistry.registerEntityRenderingHandler(EntityBallOMoss.class, new RenderSnowball(ChiselItems.ballomoss)); RenderingRegistry.registerEntityRenderingHandler(EntitySmashingRock.class, new RenderSnowball(ChiselItems.smashingrock)); + RenderingRegistry.registerEntityRenderingHandler(EntityChiselSnowman.class, new RenderChiselSnowman()); MinecraftForgeClient.registerItemRenderer(ChiselItems.chisel, renderer); MinecraftForgeClient.registerItemRenderer(ChiselItems.diamondChisel, renderer); diff --git a/src/main/resources/assets/chisel/lang/en_US.lang b/src/main/resources/assets/chisel/lang/en_US.lang index f0084519..c81c3829 100644 --- a/src/main/resources/assets/chisel/lang/en_US.lang +++ b/src/main/resources/assets/chisel/lang/en_US.lang @@ -1,5 +1,8 @@ # Key localizations +# Entity localizations +entity.chisel.snowman.name=Snow Golem + # Item localizations item.chisel.chisel_iron.name=Chisel