diff --git a/src/main/java/WayofTime/bloodmagic/block/BlockMimic.java b/src/main/java/WayofTime/bloodmagic/block/BlockMimic.java index 9a107cf9..a27aceb2 100644 --- a/src/main/java/WayofTime/bloodmagic/block/BlockMimic.java +++ b/src/main/java/WayofTime/bloodmagic/block/BlockMimic.java @@ -31,7 +31,6 @@ import WayofTime.bloodmagic.api.Constants; import WayofTime.bloodmagic.block.base.BlockStringContainer; import WayofTime.bloodmagic.client.IVariantProvider; import WayofTime.bloodmagic.tile.TileMimic; -import WayofTime.bloodmagic.tile.TileMimic; import WayofTime.bloodmagic.util.Utils; public class BlockMimic extends BlockStringContainer implements IVariantProvider @@ -123,7 +122,7 @@ public class BlockMimic extends BlockStringContainer implements IVariantProvider { Block block = ((ItemBlock) stack.getItem()).getBlock(); IBlockState mimicState = block.getStateFromMeta(stack.getItemDamage()); - return mimicState; + return block.getActualState(mimicState, world, pos); } } return state; diff --git a/src/main/java/WayofTime/bloodmagic/client/render/entity/MimicRenderFactory.java b/src/main/java/WayofTime/bloodmagic/client/render/entity/MimicRenderFactory.java new file mode 100644 index 00000000..00d5f642 --- /dev/null +++ b/src/main/java/WayofTime/bloodmagic/client/render/entity/MimicRenderFactory.java @@ -0,0 +1,15 @@ +package WayofTime.bloodmagic.client.render.entity; + +import net.minecraft.client.renderer.entity.Render; +import net.minecraft.client.renderer.entity.RenderManager; +import net.minecraftforge.fml.client.registry.IRenderFactory; +import WayofTime.bloodmagic.entity.mob.EntityMimic; + +public class MimicRenderFactory implements IRenderFactory +{ + @Override + public Render createRenderFor(RenderManager manager) + { + return new RenderEntityMimic(manager); + } +} diff --git a/src/main/java/WayofTime/bloodmagic/client/render/entity/RenderEntityMimic.java b/src/main/java/WayofTime/bloodmagic/client/render/entity/RenderEntityMimic.java new file mode 100644 index 00000000..a79ae603 --- /dev/null +++ b/src/main/java/WayofTime/bloodmagic/client/render/entity/RenderEntityMimic.java @@ -0,0 +1,135 @@ +package WayofTime.bloodmagic.client.render.entity; + +import java.util.UUID; + +import net.minecraft.client.Minecraft; +import net.minecraft.client.renderer.GlStateManager; +import net.minecraft.client.renderer.block.model.ItemCameraTransforms; +import net.minecraft.client.renderer.entity.RenderLiving; +import net.minecraft.client.renderer.entity.RenderManager; +import net.minecraft.client.renderer.tileentity.TileEntitySkullRenderer; +import net.minecraft.init.Items; +import net.minecraft.inventory.EntityEquipmentSlot; +import net.minecraft.item.Item; +import net.minecraft.item.ItemArmor; +import net.minecraft.item.ItemStack; +import net.minecraft.nbt.NBTTagCompound; +import net.minecraft.nbt.NBTUtil; +import net.minecraft.tileentity.TileEntitySkull; +import net.minecraft.util.EnumFacing; +import net.minecraft.util.ResourceLocation; +import net.minecraft.util.StringUtils; +import net.minecraftforge.fml.relauncher.Side; +import net.minecraftforge.fml.relauncher.SideOnly; +import WayofTime.bloodmagic.client.render.model.ModelMimic; +import WayofTime.bloodmagic.entity.mob.EntityMimic; + +import com.mojang.authlib.GameProfile; + +@SideOnly(Side.CLIENT) +public class RenderEntityMimic extends RenderLiving +{ + private static final ResourceLocation SPIDER_TEXTURES = new ResourceLocation("textures/entity/spider/spider.png"); + Minecraft minecraft = Minecraft.getMinecraft(); + + public RenderEntityMimic(RenderManager renderManagerIn) + { + super(renderManagerIn, new ModelMimic(), 1.0F); + } + + @Override + public void doRender(EntityMimic mimic, double x, double y, double z, float entityYaw, float partialTicks) + { + super.doRender(mimic, x, y, z, entityYaw, partialTicks); + + GlStateManager.pushMatrix(); + if (mimic.getItemStack() != null) + { + GlStateManager.pushMatrix(); + + if (this.renderOutlines) + { + GlStateManager.enableColorMaterial(); + GlStateManager.enableOutlineMode(this.getTeamColor(mimic)); + } + + GlStateManager.translate(x, y, z); + + ItemStack itemstack = mimic.getItemStack(); + Item item = itemstack.getItem(); + Minecraft minecraft = Minecraft.getMinecraft(); + GlStateManager.pushMatrix(); + + GlStateManager.color(1.0F, 1.0F, 1.0F, 1.0F); + + if (item == Items.SKULL) + { + float f2 = 1.1875F; + GlStateManager.scale(1.1875F, -1.1875F, -1.1875F); + + GameProfile gameprofile = null; + + if (itemstack.hasTagCompound()) + { + NBTTagCompound nbttagcompound = itemstack.getTagCompound(); + + if (nbttagcompound.hasKey("SkullOwner", 10)) + { + gameprofile = NBTUtil.readGameProfileFromNBT(nbttagcompound.getCompoundTag("SkullOwner")); + } else if (nbttagcompound.hasKey("SkullOwner", 8)) + { + String s = nbttagcompound.getString("SkullOwner"); + + if (!StringUtils.isNullOrEmpty(s)) + { + gameprofile = TileEntitySkull.updateGameprofile(new GameProfile((UUID) null, s)); + nbttagcompound.setTag("SkullOwner", NBTUtil.writeGameProfile(new NBTTagCompound(), gameprofile)); + } + } + } + + TileEntitySkullRenderer.instance.renderSkull(-0.5F, 0.0F, -0.5F, EnumFacing.UP, 180.0F, itemstack.getMetadata(), gameprofile, -1, 0); + } else if (!(item instanceof ItemArmor) || ((ItemArmor) item).getEquipmentSlot() != EntityEquipmentSlot.HEAD) + { + GlStateManager.translate(0, 0.5f, 0); + GlStateManager.rotate(-(mimic.prevRotationYawHead + partialTicks * (mimic.rotationYawHead - mimic.prevRotationYawHead)) - 180, 0, 1, 0); + + minecraft.getItemRenderer().renderItem(mimic, itemstack, ItemCameraTransforms.TransformType.HEAD); + } + + GlStateManager.popMatrix(); + + if (this.renderOutlines) + { + GlStateManager.disableOutlineMode(); + GlStateManager.disableColorMaterial(); + } + + GlStateManager.popMatrix(); + super.doRender(mimic, x, y, z, entityYaw, partialTicks); + + } + GlStateManager.popMatrix(); + + if (!this.renderOutlines) + { + this.renderLeash(mimic, x, y, z, entityYaw, partialTicks); + } + } + + @Override + protected float getDeathMaxRotation(EntityMimic mimic) + { + return 180.0F; + } + + /** + * Returns the location of an entity's texture. Doesn't seem to be called + * unless you call Render.bindEntityTexture. + */ + @Override + protected ResourceLocation getEntityTexture(EntityMimic mimic) + { + return SPIDER_TEXTURES; + } +} \ No newline at end of file diff --git a/src/main/java/WayofTime/bloodmagic/client/render/model/ModelMimic.java b/src/main/java/WayofTime/bloodmagic/client/render/model/ModelMimic.java new file mode 100644 index 00000000..cc1d3914 --- /dev/null +++ b/src/main/java/WayofTime/bloodmagic/client/render/model/ModelMimic.java @@ -0,0 +1,124 @@ +package WayofTime.bloodmagic.client.render.model; + +import net.minecraft.client.model.ModelBase; +import net.minecraft.client.model.ModelRenderer; +import net.minecraft.entity.Entity; +import net.minecraft.util.math.MathHelper; +import net.minecraftforge.fml.relauncher.Side; +import net.minecraftforge.fml.relauncher.SideOnly; + +@SideOnly(Side.CLIENT) +public class ModelMimic extends ModelBase +{ + /** Spider's first leg */ + public ModelRenderer mimicLeg1; + /** Spider's second leg */ + public ModelRenderer mimicLeg2; + /** Spider's third leg */ + public ModelRenderer mimicLeg3; + /** Spider's fourth leg */ + public ModelRenderer mimicLeg4; + /** Spider's fifth leg */ + public ModelRenderer mimicLeg5; + /** Spider's sixth leg */ + public ModelRenderer mimicLeg6; + /** Spider's seventh leg */ + public ModelRenderer mimicLeg7; + /** Spider's eight leg */ + public ModelRenderer mimicLeg8; + + public ModelMimic() + { + this.mimicLeg1 = new ModelRenderer(this, 18, 0); + this.mimicLeg1.addBox(-15.0F, -1.0F, -1.0F, 16, 2, 2, 0.0F); + this.mimicLeg1.setRotationPoint(-4.0F, 15.0F, 2.0F); + this.mimicLeg2 = new ModelRenderer(this, 18, 0); + this.mimicLeg2.addBox(-1.0F, -1.0F, -1.0F, 16, 2, 2, 0.0F); + this.mimicLeg2.setRotationPoint(4.0F, 15.0F, 2.0F); + this.mimicLeg3 = new ModelRenderer(this, 18, 0); + this.mimicLeg3.addBox(-15.0F, -1.0F, -1.0F, 16, 2, 2, 0.0F); + this.mimicLeg3.setRotationPoint(-4.0F, 15.0F, 1.0F); + this.mimicLeg4 = new ModelRenderer(this, 18, 0); + this.mimicLeg4.addBox(-1.0F, -1.0F, -1.0F, 16, 2, 2, 0.0F); + this.mimicLeg4.setRotationPoint(4.0F, 15.0F, 1.0F); + this.mimicLeg5 = new ModelRenderer(this, 18, 0); + this.mimicLeg5.addBox(-15.0F, -1.0F, -1.0F, 16, 2, 2, 0.0F); + this.mimicLeg5.setRotationPoint(-4.0F, 15.0F, 0.0F); + this.mimicLeg6 = new ModelRenderer(this, 18, 0); + this.mimicLeg6.addBox(-1.0F, -1.0F, -1.0F, 16, 2, 2, 0.0F); + this.mimicLeg6.setRotationPoint(4.0F, 15.0F, 0.0F); + this.mimicLeg7 = new ModelRenderer(this, 18, 0); + this.mimicLeg7.addBox(-15.0F, -1.0F, -1.0F, 16, 2, 2, 0.0F); + this.mimicLeg7.setRotationPoint(-4.0F, 15.0F, -1.0F); + this.mimicLeg8 = new ModelRenderer(this, 18, 0); + this.mimicLeg8.addBox(-1.0F, -1.0F, -1.0F, 16, 2, 2, 0.0F); + this.mimicLeg8.setRotationPoint(4.0F, 15.0F, -1.0F); + } + + /** + * Sets the models various rotation angles then renders the model. + */ + public void render(Entity entityIn, float limbSwing, float limbSwingAmount, float ageInTicks, float netHeadYaw, float headPitch, float scale) + { + this.setRotationAngles(limbSwing, limbSwingAmount, ageInTicks, netHeadYaw, headPitch, scale, entityIn); + this.mimicLeg1.render(scale); + this.mimicLeg2.render(scale); + this.mimicLeg3.render(scale); + this.mimicLeg4.render(scale); + this.mimicLeg5.render(scale); + this.mimicLeg6.render(scale); + this.mimicLeg7.render(scale); + this.mimicLeg8.render(scale); + } + + /** + * Sets the model's various rotation angles. For bipeds, par1 and par2 are + * used for animating the movement of arms and legs, where par1 represents + * the time(so that arms and legs swing back and forth) and par2 represents + * how "far" arms and legs can swing at most. + */ + public void setRotationAngles(float limbSwing, float limbSwingAmount, float ageInTicks, float netHeadYaw, float headPitch, float scaleFactor, Entity entityIn) + { + this.mimicLeg1.rotateAngleZ = -((float) Math.PI / 4F); + this.mimicLeg2.rotateAngleZ = ((float) Math.PI / 4F); + this.mimicLeg3.rotateAngleZ = -0.58119464F; + this.mimicLeg4.rotateAngleZ = 0.58119464F; + this.mimicLeg5.rotateAngleZ = -0.58119464F; + this.mimicLeg6.rotateAngleZ = 0.58119464F; + this.mimicLeg7.rotateAngleZ = -((float) Math.PI / 4F); + this.mimicLeg8.rotateAngleZ = ((float) Math.PI / 4F); + + this.mimicLeg1.rotateAngleY = ((float) Math.PI / 4F); + this.mimicLeg2.rotateAngleY = -((float) Math.PI / 4F); + this.mimicLeg3.rotateAngleY = 0.3926991F; + this.mimicLeg4.rotateAngleY = -0.3926991F; + this.mimicLeg5.rotateAngleY = -0.3926991F; + this.mimicLeg6.rotateAngleY = 0.3926991F; + this.mimicLeg7.rotateAngleY = -((float) Math.PI / 4F); + this.mimicLeg8.rotateAngleY = ((float) Math.PI / 4F); + float f3 = -(MathHelper.cos(limbSwing * 0.6662F * 2.0F + 0.0F) * 0.4F) * limbSwingAmount; + float f4 = -(MathHelper.cos(limbSwing * 0.6662F * 2.0F + (float) Math.PI) * 0.4F) * limbSwingAmount; + float f5 = -(MathHelper.cos(limbSwing * 0.6662F * 2.0F + ((float) Math.PI / 2F)) * 0.4F) * limbSwingAmount; + float f6 = -(MathHelper.cos(limbSwing * 0.6662F * 2.0F + ((float) Math.PI * 3F / 2F)) * 0.4F) * limbSwingAmount; + float f7 = Math.abs(MathHelper.sin(limbSwing * 0.6662F + 0.0F) * 0.4F) * limbSwingAmount; + float f8 = Math.abs(MathHelper.sin(limbSwing * 0.6662F + (float) Math.PI) * 0.4F) * limbSwingAmount; + float f9 = Math.abs(MathHelper.sin(limbSwing * 0.6662F + ((float) Math.PI / 2F)) * 0.4F) * limbSwingAmount; + float f10 = Math.abs(MathHelper.sin(limbSwing * 0.6662F + ((float) Math.PI * 3F / 2F)) * 0.4F) * limbSwingAmount; + this.mimicLeg1.rotateAngleY += f3; + this.mimicLeg2.rotateAngleY += -f3; + this.mimicLeg3.rotateAngleY += f4; + this.mimicLeg4.rotateAngleY += -f4; + this.mimicLeg5.rotateAngleY += f5; + this.mimicLeg6.rotateAngleY += -f5; + this.mimicLeg7.rotateAngleY += f6; + this.mimicLeg8.rotateAngleY += -f6; + this.mimicLeg1.rotateAngleZ += f7; + this.mimicLeg2.rotateAngleZ += -f7; + this.mimicLeg3.rotateAngleZ += f8; + this.mimicLeg4.rotateAngleZ += -f8; + this.mimicLeg5.rotateAngleZ += f9; + this.mimicLeg6.rotateAngleZ += -f9; + this.mimicLeg7.rotateAngleZ += f10; + this.mimicLeg8.rotateAngleZ += -f10; + } +} \ No newline at end of file diff --git a/src/main/java/WayofTime/bloodmagic/entity/mob/EntityMimic.java b/src/main/java/WayofTime/bloodmagic/entity/mob/EntityMimic.java new file mode 100644 index 00000000..ae5980c4 --- /dev/null +++ b/src/main/java/WayofTime/bloodmagic/entity/mob/EntityMimic.java @@ -0,0 +1,247 @@ +package WayofTime.bloodmagic.entity.mob; + +import net.minecraft.block.Block; +import net.minecraft.entity.EntityLivingBase; +import net.minecraft.entity.EnumCreatureAttribute; +import net.minecraft.entity.SharedMonsterAttributes; +import net.minecraft.entity.ai.EntityAIAttackMelee; +import net.minecraft.entity.ai.EntityAIHurtByTarget; +import net.minecraft.entity.ai.EntityAILeapAtTarget; +import net.minecraft.entity.ai.EntityAILookIdle; +import net.minecraft.entity.ai.EntityAINearestAttackableTarget; +import net.minecraft.entity.ai.EntityAISwimming; +import net.minecraft.entity.ai.EntityAIWander; +import net.minecraft.entity.ai.EntityAIWatchClosest; +import net.minecraft.entity.monster.EntityIronGolem; +import net.minecraft.entity.monster.EntityMob; +import net.minecraft.entity.player.EntityPlayer; +import net.minecraft.init.Blocks; +import net.minecraft.init.MobEffects; +import net.minecraft.init.SoundEvents; +import net.minecraft.item.ItemStack; +import net.minecraft.network.datasync.DataParameter; +import net.minecraft.network.datasync.DataSerializers; +import net.minecraft.network.datasync.EntityDataManager; +import net.minecraft.pathfinding.PathNavigate; +import net.minecraft.pathfinding.PathNavigateClimber; +import net.minecraft.potion.PotionEffect; +import net.minecraft.util.SoundEvent; +import net.minecraft.util.math.BlockPos; +import net.minecraft.world.World; + +public class EntityMimic extends EntityMob +{ + /** + * Copy of EntitySpider's AI (should be pretty evident...) + */ + private static final DataParameter CLIMBING = EntityDataManager.createKey(EntityMimic.class, DataSerializers.BYTE); + + public EntityMimic(World worldIn) + { + super(worldIn); + this.setSize(1.4F, 0.9F); + } + + public ItemStack getItemStack() + { + return new ItemStack(Blocks.CHEST); + } + + protected void initEntityAI() + { + this.tasks.addTask(1, new EntityAISwimming(this)); + this.tasks.addTask(3, new EntityAILeapAtTarget(this, 0.4F)); + this.tasks.addTask(4, new EntityMimic.AISpiderAttack(this)); + this.tasks.addTask(5, new EntityAIWander(this, 0.8D)); + this.tasks.addTask(6, new EntityAIWatchClosest(this, EntityPlayer.class, 8.0F)); + this.tasks.addTask(6, new EntityAILookIdle(this)); + this.targetTasks.addTask(1, new EntityAIHurtByTarget(this, false, new Class[0])); + this.targetTasks.addTask(2, new EntityMimic.AISpiderTarget(this, EntityPlayer.class)); + this.targetTasks.addTask(3, new EntityMimic.AISpiderTarget(this, EntityIronGolem.class)); + } + + /** + * Returns the Y offset from the entity's position for any entity riding + * this one. + */ + @Override + public double getMountedYOffset() + { + return (double) (this.height * 0.5F); + } + + /** + * Returns new PathNavigateGround instance + */ + @Override + protected PathNavigate getNewNavigator(World worldIn) + { + return new PathNavigateClimber(this, worldIn); + } + + @Override + protected void entityInit() + { + super.entityInit(); + this.dataManager.register(CLIMBING, Byte.valueOf((byte) 0)); + } + + /** + * Called to update the entity's position/logic. + */ + @Override + public void onUpdate() + { + super.onUpdate(); + + if (!this.worldObj.isRemote) + { + this.setBesideClimbableBlock(this.isCollidedHorizontally); + } + } + + @Override + protected void applyEntityAttributes() + { + super.applyEntityAttributes(); + this.getEntityAttribute(SharedMonsterAttributes.MAX_HEALTH).setBaseValue(16.0D); + this.getEntityAttribute(SharedMonsterAttributes.MOVEMENT_SPEED).setBaseValue(0.3D); + } + + @Override + protected SoundEvent getAmbientSound() + { + return SoundEvents.ENTITY_SPIDER_AMBIENT; + } + + @Override + protected SoundEvent getHurtSound() + { + return SoundEvents.ENTITY_SPIDER_HURT; + } + + @Override + protected SoundEvent getDeathSound() + { + return SoundEvents.ENTITY_SPIDER_DEATH; + } + + @Override + protected void playStepSound(BlockPos pos, Block blockIn) + { + this.playSound(SoundEvents.ENTITY_SPIDER_STEP, 0.15F, 1.0F); + } + + /** + * returns true if this entity is by a ladder, false otherwise + */ + @Override + public boolean isOnLadder() + { + return this.isBesideClimbableBlock(); + } + + /** + * Sets the Entity inside a web block. + */ + @Override + public void setInWeb() + { + + } + + /** + * Get this Entity's EnumCreatureAttribute + */ + @Override + public EnumCreatureAttribute getCreatureAttribute() + { + return EnumCreatureAttribute.ARTHROPOD; + } + + @Override + public boolean isPotionApplicable(PotionEffect potioneffectIn) + { + return potioneffectIn.getPotion() == MobEffects.POISON ? false : super.isPotionApplicable(potioneffectIn); + } + + /** + * Returns true if the WatchableObject (Byte) is 0x01 otherwise returns + * false. The WatchableObject is updated using setBesideClimableBlock. + */ + public boolean isBesideClimbableBlock() + { + return (((Byte) this.dataManager.get(CLIMBING)).byteValue() & 1) != 0; + } + + /** + * Updates the WatchableObject (Byte) created in entityInit(), setting it to + * 0x01 if par1 is true or 0x00 if it is false. + */ + public void setBesideClimbableBlock(boolean climbing) + { + byte b0 = ((Byte) this.dataManager.get(CLIMBING)).byteValue(); + + if (climbing) + { + b0 = (byte) (b0 | 1); + } else + { + b0 = (byte) (b0 & -2); + } + + this.dataManager.set(CLIMBING, Byte.valueOf(b0)); + } + + public float getEyeHeight() + { + return 0.65F; + } + + static class AISpiderAttack extends EntityAIAttackMelee + { + public AISpiderAttack(EntityMimic spider) + { + super(spider, 1.0D, true); + } + + /** + * Returns whether an in-progress EntityAIBase should continue executing + */ + public boolean continueExecuting() + { + float f = this.attacker.getBrightness(1.0F); + + if (f >= 0.5F && this.attacker.getRNG().nextInt(100) == 0) + { + this.attacker.setAttackTarget((EntityLivingBase) null); + return false; + } else + { + return super.continueExecuting(); + } + } + + protected double getAttackReachSqr(EntityLivingBase attackTarget) + { + return (double) (4.0F + attackTarget.width); + } + } + + static class AISpiderTarget extends EntityAINearestAttackableTarget + { + public AISpiderTarget(EntityMimic spider, Class classTarget) + { + super(spider, classTarget, true); + } + + /** + * Returns whether the EntityAIBase should begin execution. + */ + public boolean shouldExecute() + { + float f = this.taskOwner.getBrightness(1.0F); + return f >= 0.5F ? false : super.shouldExecute(); + } + } +} \ No newline at end of file diff --git a/src/main/java/WayofTime/bloodmagic/item/block/ItemBlockMimic.java b/src/main/java/WayofTime/bloodmagic/item/block/ItemBlockMimic.java index ad8bf900..7766565f 100644 --- a/src/main/java/WayofTime/bloodmagic/item/block/ItemBlockMimic.java +++ b/src/main/java/WayofTime/bloodmagic/item/block/ItemBlockMimic.java @@ -1,9 +1,20 @@ package WayofTime.bloodmagic.item.block; import net.minecraft.block.Block; +import net.minecraft.block.SoundType; +import net.minecraft.block.state.IBlockState; +import net.minecraft.entity.player.EntityPlayer; import net.minecraft.item.ItemBlock; import net.minecraft.item.ItemStack; +import net.minecraft.tileentity.TileEntity; +import net.minecraft.util.EnumActionResult; +import net.minecraft.util.EnumFacing; +import net.minecraft.util.EnumHand; +import net.minecraft.util.SoundCategory; +import net.minecraft.util.math.BlockPos; +import net.minecraft.world.World; import WayofTime.bloodmagic.block.BlockMimic; +import WayofTime.bloodmagic.tile.TileMimic; public class ItemBlockMimic extends ItemBlock { @@ -19,6 +30,59 @@ public class ItemBlockMimic extends ItemBlock return super.getUnlocalizedName(stack) + BlockMimic.names[stack.getItemDamage()]; } + @Override + public EnumActionResult onItemUse(ItemStack stack, EntityPlayer player, World world, BlockPos pos, EnumHand hand, EnumFacing facing, float hitX, float hitY, float hitZ) + { + IBlockState iblockstate = world.getBlockState(pos); + Block block = iblockstate.getBlock(); + + if (player.isSneaking()) + { + return super.onItemUse(stack, player, world, pos, hand, facing, hitX, hitY, hitZ); + } + + if (stack.stackSize != 0 && player.canPlayerEdit(pos, facing, stack)) + { + int i = this.getMetadata(stack.getMetadata()); + IBlockState iblockstate1 = this.block.onBlockPlaced(world, pos, facing, hitX, hitY, hitZ, i, player); + + TileEntity tileReplaced = world.getTileEntity(pos); + if (!canReplaceTile(i, tileReplaced)) + { + return EnumActionResult.FAIL; + } + + ItemStack replacedStack = block.getItem(world, pos, iblockstate); + + if (placeBlockAt(stack, player, world, pos, facing, hitX, hitY, hitZ, iblockstate1)) + { + SoundType soundtype = this.block.getSoundType(); + world.playSound(player, pos, soundtype.getPlaceSound(), SoundCategory.BLOCKS, (soundtype.getVolume() + 1.0F) / 2.0F, soundtype.getPitch() * 0.8F); + --stack.stackSize; + + TileEntity tile = world.getTileEntity(pos); + if (tile instanceof TileMimic) + { + TileMimic mimic = (TileMimic) tile; + mimic.setInventorySlotContents(0, replacedStack); + if (player.capabilities.isCreativeMode) + { + mimic.dropItemsOnBreak = false; + } + } + + return EnumActionResult.SUCCESS; + } + } + + return EnumActionResult.FAIL; + } + + public boolean canReplaceTile(int meta, TileEntity tile) + { + return tile == null; + } + @Override public int getMetadata(int meta) { diff --git a/src/main/java/WayofTime/bloodmagic/item/sigil/ItemSigilDivination.java b/src/main/java/WayofTime/bloodmagic/item/sigil/ItemSigilDivination.java index 170a93bf..ac071eda 100644 --- a/src/main/java/WayofTime/bloodmagic/item/sigil/ItemSigilDivination.java +++ b/src/main/java/WayofTime/bloodmagic/item/sigil/ItemSigilDivination.java @@ -12,12 +12,11 @@ import net.minecraft.util.math.RayTraceResult; import net.minecraft.util.text.ITextComponent; import net.minecraft.util.text.TextComponentTranslation; import net.minecraft.world.World; -import net.minecraft.world.WorldServer; import WayofTime.bloodmagic.api.altar.IBloodAltar; import WayofTime.bloodmagic.api.iface.IAltarReader; import WayofTime.bloodmagic.api.util.helper.NetworkHelper; import WayofTime.bloodmagic.api.util.helper.PlayerHelper; -import WayofTime.bloodmagic.structures.DungeonTester; +import WayofTime.bloodmagic.entity.mob.EntityMimic; import WayofTime.bloodmagic.tile.TileIncenseAltar; import WayofTime.bloodmagic.util.ChatUtil; import WayofTime.bloodmagic.util.helper.NumeralHelper; @@ -32,12 +31,26 @@ public class ItemSigilDivination extends ItemSigilBase implements IAltarReader @Override public ActionResult onItemRightClick(ItemStack stack, World world, EntityPlayer player, EnumHand hand) { - if (world instanceof WorldServer) +// if (world instanceof WorldServer) +// { +// System.out.println("Testing..."); +//// BuildTestStructure s = new BuildTestStructure(); +//// s.placeStructureAtPosition(new Random(), Rotation.CLOCKWISE_180, (WorldServer) world, player.getPosition(), 0); +// DungeonTester.testDungeonElementWithOutput((WorldServer) world, player.getPosition()); +// } + + if (!world.isRemote) { - System.out.println("Testing..."); -// BuildTestStructure s = new BuildTestStructure(); -// s.placeStructureAtPosition(new Random(), Rotation.CLOCKWISE_180, (WorldServer) world, player.getPosition(), 0); - DungeonTester.testDungeonElementWithOutput((WorldServer) world, player.getPosition()); + EntityMimic mimic = new EntityMimic(world); + + mimic.setPosition(player.posX, player.posY, player.posZ); + world.spawnEntityInWorld(mimic); + + System.out.println("Spawning Mimic"); +// EntityZombie zombie = new EntityZombie(world); +// zombie.setPosition(player.posX, player.posY, player.posZ); +// zombie.setItemStackToSlot(EntityEquipmentSlot.HEAD, new ItemStack(Blocks.CHEST)); +// world.spawnEntityInWorld(zombie); } if (!world.isRemote) diff --git a/src/main/java/WayofTime/bloodmagic/proxy/ClientProxy.java b/src/main/java/WayofTime/bloodmagic/proxy/ClientProxy.java index 185b07e4..00811468 100644 --- a/src/main/java/WayofTime/bloodmagic/proxy/ClientProxy.java +++ b/src/main/java/WayofTime/bloodmagic/proxy/ClientProxy.java @@ -35,9 +35,11 @@ import WayofTime.bloodmagic.client.render.RenderDemonCrucible; import WayofTime.bloodmagic.client.render.RenderItemRoutingNode; import WayofTime.bloodmagic.client.render.entity.BloodLightRenderFactory; import WayofTime.bloodmagic.client.render.entity.MeteorRenderFactory; +import WayofTime.bloodmagic.client.render.entity.MimicRenderFactory; import WayofTime.bloodmagic.client.render.entity.SentientArrowRenderFactory; import WayofTime.bloodmagic.client.render.entity.SentientSpecterRenderFactory; import WayofTime.bloodmagic.client.render.entity.SoulSnareRenderFactory; +import WayofTime.bloodmagic.entity.mob.EntityMimic; import WayofTime.bloodmagic.entity.mob.EntitySentientSpecter; import WayofTime.bloodmagic.entity.projectile.EntityBloodLight; import WayofTime.bloodmagic.entity.projectile.EntityMeteor; @@ -98,6 +100,7 @@ public class ClientProxy extends CommonProxy RenderingRegistry.registerEntityRenderingHandler(EntityBloodLight.class, new BloodLightRenderFactory()); RenderingRegistry.registerEntityRenderingHandler(EntityMeteor.class, new MeteorRenderFactory()); RenderingRegistry.registerEntityRenderingHandler(EntitySentientSpecter.class, new SentientSpecterRenderFactory()); + RenderingRegistry.registerEntityRenderingHandler(EntityMimic.class, new MimicRenderFactory()); ShaderHelper.init(); } diff --git a/src/main/java/WayofTime/bloodmagic/registry/ModEntities.java b/src/main/java/WayofTime/bloodmagic/registry/ModEntities.java index e0d9bba5..e9336e05 100644 --- a/src/main/java/WayofTime/bloodmagic/registry/ModEntities.java +++ b/src/main/java/WayofTime/bloodmagic/registry/ModEntities.java @@ -2,6 +2,7 @@ package WayofTime.bloodmagic.registry; import net.minecraftforge.fml.common.registry.EntityRegistry; import WayofTime.bloodmagic.BloodMagic; +import WayofTime.bloodmagic.entity.mob.EntityMimic; import WayofTime.bloodmagic.entity.mob.EntitySentientSpecter; import WayofTime.bloodmagic.entity.projectile.EntityBloodLight; import WayofTime.bloodmagic.entity.projectile.EntityMeteor; @@ -19,5 +20,6 @@ public class ModEntities EntityRegistry.registerModEntity(EntitySentientArrow.class, "SoulArrow", id++, BloodMagic.instance, 64, 1, true); EntityRegistry.registerModEntity(EntityMeteor.class, "Meteor", id++, BloodMagic.instance, 64, 1, true); EntityRegistry.registerModEntity(EntitySentientSpecter.class, "SentientSpecter", id++, BloodMagic.instance, 64, 1, true); + EntityRegistry.registerModEntity(EntityMimic.class, "Mimic", id++, BloodMagic.instance, 64, 1, true); } } diff --git a/src/main/java/WayofTime/bloodmagic/structures/DungeonRoomLoader.java b/src/main/java/WayofTime/bloodmagic/structures/DungeonRoomLoader.java index 4145018f..f21614fb 100644 --- a/src/main/java/WayofTime/bloodmagic/structures/DungeonRoomLoader.java +++ b/src/main/java/WayofTime/bloodmagic/structures/DungeonRoomLoader.java @@ -49,10 +49,11 @@ public class DungeonRoomLoader public static void loadDungeons() { - String folder = "config/BloodMagic/schematics"; +// String folder = "config/BloodMagic/schematics"; Gson gson = new GsonBuilder().setPrettyPrinting().registerTypeAdapter(EnumFacing.class, Adapters.adapter).create(); - File file = new File(folder); + File file = new File(MinecraftServer.class.getResource("/assets/" + "BloodMagic" + "/schematics").getFile()); + File[] files = file.listFiles(); BufferedReader br; diff --git a/src/main/resources/assets/bloodmagic/schematics/-1930356124.json b/src/main/resources/assets/bloodmagic/schematics/-1930356124.json new file mode 100644 index 00000000..a5029314 --- /dev/null +++ b/src/main/resources/assets/bloodmagic/schematics/-1930356124.json @@ -0,0 +1,48 @@ +{ + "structureMap": { + "bloodmagic:Corridor1": { + "x": 0, + "y": 0, + "z": 0 + } + }, + "doorMap": { + "west": [ + { + "x": 0, + "y": 0, + "z": 3 + } + ], + "south": [ + { + "x": 3, + "y": 0, + "z": 6 + } + ], + "north": [ + { + "x": 3, + "y": 0, + "z": 0 + } + ] + }, + "descriptorList": [ + { + "minimumOffset": { + "x": 0, + "y": 0, + "z": 0 + }, + "maximumOffset": { + "x": 5, + "y": 3, + "z": 7 + }, + "blockPosCache": [], + "cache": true + } + ] +} \ No newline at end of file