Skip to content

Commit

Permalink
Preliminary soul altar work
Browse files Browse the repository at this point in the history
  • Loading branch information
ACGaming committed Jun 6, 2024
1 parent 2e8a706 commit 27aa0ee
Show file tree
Hide file tree
Showing 10 changed files with 464 additions and 1 deletion.
2 changes: 2 additions & 0 deletions src/main/java/mod/emt/harkenscythe/HarkenScythe.java
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package mod.emt.harkenscythe;

import mod.emt.harkenscythe.init.HSCreativeTabs;
import mod.emt.harkenscythe.init.HSRegistry;
import net.minecraft.creativetab.CreativeTabs;
import net.minecraftforge.fml.common.Mod;
import net.minecraftforge.fml.common.event.FMLInitializationEvent;
Expand All @@ -22,6 +23,7 @@ public class HarkenScythe
@Mod.EventHandler
public void init(FMLInitializationEvent event)
{
HSRegistry.registerTileEntities();
LOGGER.info(NAME + " initialized");
}
}
84 changes: 84 additions & 0 deletions src/main/java/mod/emt/harkenscythe/blocks/HSSoulAltar.java
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;
}
}
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();
}
}
6 changes: 5 additions & 1 deletion src/main/java/mod/emt/harkenscythe/init/HSBlocks.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import javax.annotation.Nonnull;
import mod.emt.harkenscythe.HarkenScythe;
import mod.emt.harkenscythe.blocks.HSBloodCrucible;
import mod.emt.harkenscythe.blocks.HSSoulAltar;
import mod.emt.harkenscythe.blocks.HSSoulCrucible;
import net.minecraft.block.Block;
import net.minecraftforge.event.RegistryEvent;
Expand All @@ -19,6 +20,8 @@ public class HSBlocks
public static HSBloodCrucible blood_crucible;
@GameRegistry.ObjectHolder("soul_crucible")
public static HSSoulCrucible soul_crucible;
@GameRegistry.ObjectHolder("soul_altar")
public static HSSoulAltar soul_altar;

@SubscribeEvent
public static void onRegisterBlocksEvent(@Nonnull final RegistryEvent.Register<Block> event)
Expand All @@ -29,7 +32,8 @@ public static void onRegisterBlocksEvent(@Nonnull final RegistryEvent.Register<B
registry.registerAll
(
HSRegistry.setup(new HSBloodCrucible(), "blood_crucible"),
HSRegistry.setup(new HSSoulCrucible(), "soul_crucible")
HSRegistry.setup(new HSSoulCrucible(), "soul_crucible"),
HSRegistry.setup(new HSSoulAltar(), "soul_altar")
);
}
}
16 changes: 16 additions & 0 deletions src/main/java/mod/emt/harkenscythe/init/HSRegistry.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,18 +3,22 @@
import com.google.common.base.Preconditions;
import javax.annotation.Nonnull;
import mod.emt.harkenscythe.HarkenScythe;
import mod.emt.harkenscythe.client.render.HSSoulAltarRender;
import mod.emt.harkenscythe.entities.HSSoul;
import mod.emt.harkenscythe.entities.render.HSSoulRender;
import mod.emt.harkenscythe.tileentities.HSSoulAltarTE;
import net.minecraft.block.Block;
import net.minecraft.item.Item;
import net.minecraft.util.ResourceLocation;
import net.minecraftforge.client.event.ModelRegistryEvent;
import net.minecraftforge.event.RegistryEvent;
import net.minecraftforge.fml.client.registry.ClientRegistry;
import net.minecraftforge.fml.client.registry.RenderingRegistry;
import net.minecraftforge.fml.common.Mod;
import net.minecraftforge.fml.common.eventhandler.SubscribeEvent;
import net.minecraftforge.fml.common.registry.EntityEntry;
import net.minecraftforge.fml.common.registry.EntityEntryBuilder;
import net.minecraftforge.fml.common.registry.GameRegistry;
import net.minecraftforge.fml.relauncher.Side;
import net.minecraftforge.fml.relauncher.SideOnly;
import net.minecraftforge.registries.IForgeRegistryEntry;
Expand Down Expand Up @@ -54,10 +58,22 @@ public static void registerEntities(RegistryEvent.Register<EntityEntry> event)
);
}

public static void registerTileEntities()
{
GameRegistry.registerTileEntity(HSSoulAltarTE.class, new ResourceLocation(HarkenScythe.MOD_ID, "soul_altar"));
}

@SideOnly(Side.CLIENT)
@SubscribeEvent
public static void registerEntityRenderers(ModelRegistryEvent event)
{
RenderingRegistry.registerEntityRenderingHandler(HSSoul.class, new HSSoulRender.Factory());
}

@SideOnly(Side.CLIENT)
@SubscribeEvent
public static void registerTESRs(RegistryEvent<Block> event)
{
ClientRegistry.bindTileEntitySpecialRenderer(HSSoulAltarTE.class, new HSSoulAltarRender());
}
}
Loading

0 comments on commit 27aa0ee

Please sign in to comment.