-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
10 changed files
with
464 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
84 changes: 84 additions & 0 deletions
84
src/main/java/mod/emt/harkenscythe/blocks/HSSoulAltar.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,84 @@ | ||
package mod.emt.harkenscythe.blocks; | ||
|
||
import mod.emt.harkenscythe.HarkenScythe; | ||
import mod.emt.harkenscythe.tileentities.HSSoulAltarTE; | ||
import net.minecraft.block.BlockEnchantmentTable; | ||
import net.minecraft.block.state.IBlockState; | ||
import net.minecraft.entity.player.EntityPlayer; | ||
import net.minecraft.item.ItemStack; | ||
import net.minecraft.tileentity.TileEntity; | ||
import net.minecraft.util.EnumFacing; | ||
import net.minecraft.util.EnumHand; | ||
import net.minecraft.util.math.BlockPos; | ||
import net.minecraft.world.World; | ||
|
||
public class HSSoulAltar extends BlockEnchantmentTable | ||
{ | ||
public HSSoulAltar() | ||
{ | ||
super(); | ||
setCreativeTab(HarkenScythe.TAB); | ||
} | ||
|
||
@Override | ||
public boolean hasTileEntity(IBlockState state) | ||
{ | ||
return true; | ||
} | ||
|
||
@Override | ||
public void breakBlock(World world, BlockPos pos, IBlockState state) | ||
{ | ||
TileEntity te = world.getTileEntity(pos); | ||
if (te instanceof HSSoulAltarTE) | ||
{ | ||
HSSoulAltarTE altar = (HSSoulAltarTE) te; | ||
altar.dropItem(); | ||
} | ||
super.breakBlock(world, pos, state); | ||
} | ||
|
||
@Override | ||
public TileEntity createNewTileEntity(World worldIn, int meta) | ||
{ | ||
return new HSSoulAltarTE(); | ||
} | ||
|
||
@Override | ||
public boolean onBlockActivated(World world, BlockPos pos, IBlockState state, EntityPlayer player, EnumHand hand, EnumFacing side, float hitX, float hitY, float hitZ) | ||
{ | ||
TileEntity te = world.getTileEntity(pos); | ||
if (te instanceof HSSoulAltarTE) | ||
{ | ||
HSSoulAltarTE altar = (HSSoulAltarTE) te; | ||
ItemStack heldItem = player.getHeldItem(hand); | ||
|
||
if (!heldItem.isEmpty()) | ||
{ | ||
ItemStack altarItem = altar.getItem(); | ||
if (altarItem.isEmpty()) | ||
{ | ||
altar.setItem(heldItem.splitStack(1)); | ||
return true; | ||
} | ||
else if (altarItem.getMaxStackSize() > altarItem.getCount() && ItemStack.areItemsEqual(altarItem, heldItem) && ItemStack.areItemStackTagsEqual(altarItem, heldItem)) | ||
{ | ||
heldItem.shrink(1); | ||
altarItem.grow(1); | ||
return true; | ||
} | ||
} | ||
else | ||
{ | ||
ItemStack itemStack = altar.getItem(); | ||
if (!itemStack.isEmpty()) | ||
{ | ||
player.addItemStackToInventory(itemStack); | ||
altar.setItem(ItemStack.EMPTY); | ||
return true; | ||
} | ||
} | ||
} | ||
return true; | ||
} | ||
} |
128 changes: 128 additions & 0 deletions
128
src/main/java/mod/emt/harkenscythe/client/render/HSSoulAltarRender.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,128 @@ | ||
package mod.emt.harkenscythe.client.render; | ||
|
||
import mod.emt.harkenscythe.tileentities.HSSoulAltarTE; | ||
import net.minecraft.client.Minecraft; | ||
import net.minecraft.client.model.ModelBook; | ||
import net.minecraft.client.renderer.GlStateManager; | ||
import net.minecraft.client.renderer.RenderHelper; | ||
import net.minecraft.client.renderer.RenderItem; | ||
import net.minecraft.client.renderer.block.model.ItemCameraTransforms; | ||
import net.minecraft.client.renderer.tileentity.TileEntitySpecialRenderer; | ||
import net.minecraft.item.ItemStack; | ||
import net.minecraft.util.ResourceLocation; | ||
import net.minecraft.util.math.MathHelper; | ||
import net.minecraft.world.World; | ||
|
||
public class HSSoulAltarRender extends TileEntitySpecialRenderer<HSSoulAltarTE> | ||
{ | ||
private static final ResourceLocation TEXTURE_BOOK = new ResourceLocation("textures/entity/enchanting_table_book.png"); | ||
private final ModelBook modelBook = new ModelBook(); | ||
|
||
public void render(HSSoulAltarTE te, double x, double y, double z, float partialTicks, int destroyStage, float alpha) | ||
{ | ||
GlStateManager.pushMatrix(); | ||
RenderItem renderItem = Minecraft.getMinecraft().getRenderItem(); | ||
World world = te.getWorld(); | ||
//noinspection ConstantConditions | ||
if (world == null) return; | ||
|
||
GlStateManager.pushAttrib(); | ||
GlStateManager.disableLighting(); | ||
GlStateManager.translate(x, y, z); | ||
|
||
GlStateManager.pushMatrix(); | ||
float timeD = (float) (360.0 * (System.currentTimeMillis() & 0x3FFFL) / 0x3FFFL); | ||
GlStateManager.translate(0.20, 0.25, 0.25); | ||
RenderHelper.enableStandardItemLighting(); | ||
GlStateManager.pushAttrib(); | ||
|
||
ItemStack stack = te.getItem(); | ||
if (!stack.isEmpty()) | ||
{ | ||
GlStateManager.pushMatrix(); | ||
GlStateManager.translate(0.25, 1.75, 0.25); | ||
GlStateManager.rotate(timeD, 0, 1, 0); | ||
renderItem.renderItem(stack, ItemCameraTransforms.TransformType.FIXED); | ||
GlStateManager.popMatrix(); | ||
} | ||
|
||
RenderHelper.disableStandardItemLighting(); | ||
GlStateManager.popAttrib(); | ||
GlStateManager.popMatrix(); | ||
|
||
GlStateManager.popAttrib(); | ||
GlStateManager.popMatrix(); | ||
|
||
String soulsText = "Souls: " + te.soulCount; | ||
GlStateManager.pushMatrix(); | ||
GlStateManager.translate(x + 0.5, y + 1.5, z + 0.5); | ||
GlStateManager.rotate(-Minecraft.getMinecraft().getRenderManager().playerViewY, 0, 1, 0); | ||
GlStateManager.rotate(Minecraft.getMinecraft().getRenderManager().playerViewX, 1, 0, 0); | ||
GlStateManager.scale(-0.025f, -0.025f, 0.025f); | ||
GlStateManager.disableLighting(); | ||
Minecraft.getMinecraft().fontRenderer.drawString(soulsText, -Minecraft.getMinecraft().fontRenderer.getStringWidth(soulsText) / 2, 0, 0xFFFFFF); | ||
GlStateManager.enableLighting(); | ||
GlStateManager.popMatrix(); | ||
|
||
if (!stack.isEmpty()) | ||
{ | ||
String stackText = String.valueOf(stack.getCount()); | ||
GlStateManager.pushMatrix(); | ||
GlStateManager.translate(x + 0.5, y + 2.7, z + 0.5); | ||
GlStateManager.rotate(-Minecraft.getMinecraft().getRenderManager().playerViewY, 0, 1, 0); | ||
GlStateManager.rotate(Minecraft.getMinecraft().getRenderManager().playerViewX, 1, 0, 0); | ||
GlStateManager.scale(-0.025f, -0.025f, 0.025f); | ||
GlStateManager.disableLighting(); | ||
Minecraft.getMinecraft().fontRenderer.drawString(stackText, -Minecraft.getMinecraft().fontRenderer.getStringWidth(stackText) / 2, 0, 0xFFFFFF); | ||
GlStateManager.enableLighting(); | ||
GlStateManager.popMatrix(); | ||
} | ||
|
||
GlStateManager.pushMatrix(); | ||
GlStateManager.translate((float) x + 0.5F, (float) y + 0.75F, (float) z + 0.5F); | ||
float f = (float) te.tickCount + partialTicks; | ||
GlStateManager.translate(0.0F, 0.1F + MathHelper.sin(f * 0.1F) * 0.01F, 0.0F); | ||
float f1; | ||
|
||
for (f1 = te.bookRotation - te.bookRotationPrev; f1 >= (float) Math.PI; f1 -= ((float) Math.PI * 2F)) {} | ||
|
||
while (f1 < -(float) Math.PI) | ||
{ | ||
f1 += ((float) Math.PI * 2F); | ||
} | ||
|
||
float f2 = te.bookRotationPrev + f1 * partialTicks; | ||
GlStateManager.rotate(-f2 * (180F / (float) Math.PI), 0.0F, 1.0F, 0.0F); | ||
GlStateManager.rotate(80.0F, 0.0F, 0.0F, 1.0F); | ||
this.bindTexture(TEXTURE_BOOK); | ||
float f3 = te.pageFlipPrev + (te.pageFlip - te.pageFlipPrev) * partialTicks + 0.25F; | ||
float f4 = te.pageFlipPrev + (te.pageFlip - te.pageFlipPrev) * partialTicks + 0.75F; | ||
f3 = (f3 - (float) MathHelper.fastFloor(f3)) * 1.6F - 0.3F; | ||
f4 = (f4 - (float) MathHelper.fastFloor(f4)) * 1.6F - 0.3F; | ||
|
||
if (f3 < 0.0F) | ||
{ | ||
f3 = 0.0F; | ||
} | ||
|
||
if (f4 < 0.0F) | ||
{ | ||
f4 = 0.0F; | ||
} | ||
|
||
if (f3 > 1.0F) | ||
{ | ||
f3 = 1.0F; | ||
} | ||
|
||
if (f4 > 1.0F) | ||
{ | ||
f4 = 1.0F; | ||
} | ||
|
||
float f5 = te.bookSpreadPrev + (te.bookSpread - te.bookSpreadPrev) * partialTicks; | ||
GlStateManager.enableCull(); | ||
this.modelBook.render(null, f, f3, f4, f5, 0.0F, 0.0625F); | ||
GlStateManager.popMatrix(); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.