From 27aa0eeec9befae363b83849c57bc3ec20fc7290 Mon Sep 17 00:00:00 2001 From: ACGaming <4818419+ACGaming@users.noreply.github.com> Date: Thu, 6 Jun 2024 17:09:11 +0200 Subject: [PATCH] Preliminary soul altar work --- .../mod/emt/harkenscythe/HarkenScythe.java | 2 + .../emt/harkenscythe/blocks/HSSoulAltar.java | 84 +++++++ .../client/render/HSSoulAltarRender.java | 128 +++++++++++ .../mod/emt/harkenscythe/init/HSBlocks.java | 6 +- .../mod/emt/harkenscythe/init/HSRegistry.java | 16 ++ .../tileentities/HSSoulAltarTE.java | 209 ++++++++++++++++++ .../harkenscythe/blockstates/soul_altar.json | 20 ++ .../textures/blocks/soul_altar_bottom.png | Bin 0 -> 502 bytes .../textures/blocks/soul_altar_side.png | Bin 0 -> 499 bytes .../textures/blocks/soul_altar_top.png | Bin 0 -> 541 bytes 10 files changed, 464 insertions(+), 1 deletion(-) create mode 100644 src/main/java/mod/emt/harkenscythe/blocks/HSSoulAltar.java create mode 100644 src/main/java/mod/emt/harkenscythe/client/render/HSSoulAltarRender.java create mode 100644 src/main/java/mod/emt/harkenscythe/tileentities/HSSoulAltarTE.java create mode 100644 src/main/resources/assets/harkenscythe/blockstates/soul_altar.json create mode 100644 src/main/resources/assets/harkenscythe/textures/blocks/soul_altar_bottom.png create mode 100644 src/main/resources/assets/harkenscythe/textures/blocks/soul_altar_side.png create mode 100644 src/main/resources/assets/harkenscythe/textures/blocks/soul_altar_top.png diff --git a/src/main/java/mod/emt/harkenscythe/HarkenScythe.java b/src/main/java/mod/emt/harkenscythe/HarkenScythe.java index d9b70b8..645cad2 100644 --- a/src/main/java/mod/emt/harkenscythe/HarkenScythe.java +++ b/src/main/java/mod/emt/harkenscythe/HarkenScythe.java @@ -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; @@ -22,6 +23,7 @@ public class HarkenScythe @Mod.EventHandler public void init(FMLInitializationEvent event) { + HSRegistry.registerTileEntities(); LOGGER.info(NAME + " initialized"); } } diff --git a/src/main/java/mod/emt/harkenscythe/blocks/HSSoulAltar.java b/src/main/java/mod/emt/harkenscythe/blocks/HSSoulAltar.java new file mode 100644 index 0000000..f171f03 --- /dev/null +++ b/src/main/java/mod/emt/harkenscythe/blocks/HSSoulAltar.java @@ -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; + } +} diff --git a/src/main/java/mod/emt/harkenscythe/client/render/HSSoulAltarRender.java b/src/main/java/mod/emt/harkenscythe/client/render/HSSoulAltarRender.java new file mode 100644 index 0000000..671bd07 --- /dev/null +++ b/src/main/java/mod/emt/harkenscythe/client/render/HSSoulAltarRender.java @@ -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 +{ + 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(); + } +} diff --git a/src/main/java/mod/emt/harkenscythe/init/HSBlocks.java b/src/main/java/mod/emt/harkenscythe/init/HSBlocks.java index cad1e7d..33c5f34 100644 --- a/src/main/java/mod/emt/harkenscythe/init/HSBlocks.java +++ b/src/main/java/mod/emt/harkenscythe/init/HSBlocks.java @@ -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; @@ -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 event) @@ -29,7 +32,8 @@ public static void onRegisterBlocksEvent(@Nonnull final RegistryEvent.Register 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 event) + { + ClientRegistry.bindTileEntitySpecialRenderer(HSSoulAltarTE.class, new HSSoulAltarRender()); + } } diff --git a/src/main/java/mod/emt/harkenscythe/tileentities/HSSoulAltarTE.java b/src/main/java/mod/emt/harkenscythe/tileentities/HSSoulAltarTE.java new file mode 100644 index 0000000..005f4bc --- /dev/null +++ b/src/main/java/mod/emt/harkenscythe/tileentities/HSSoulAltarTE.java @@ -0,0 +1,209 @@ +package mod.emt.harkenscythe.tileentities; + +import java.util.Random; +import mod.emt.harkenscythe.blocks.HSSoulCrucible; +import net.minecraft.block.state.IBlockState; +import net.minecraft.entity.item.EntityItem; +import net.minecraft.entity.player.EntityPlayer; +import net.minecraft.item.ItemStack; +import net.minecraft.nbt.NBTTagCompound; +import net.minecraft.network.NetworkManager; +import net.minecraft.network.play.server.SPacketUpdateTileEntity; +import net.minecraft.tileentity.TileEntity; +import net.minecraft.util.ITickable; +import net.minecraft.util.math.BlockPos; +import net.minecraft.util.math.MathHelper; +import net.minecraft.world.World; + +public class HSSoulAltarTE extends TileEntity implements ITickable +{ + private static final Random rand = new Random(); + private static final int RADIUS = 4; + public int tickCount; + public float pageFlip; + public float pageFlipPrev; + public float flipT; + public float flipA; + public float bookSpread; + public float bookSpreadPrev; + public float bookRotation; + public float bookRotationPrev; + public float tRot; + public int soulCount; + private ItemStack item = ItemStack.EMPTY; + + public ItemStack getItem() + { + return item; + } + + public void setItem(ItemStack item) + { + this.item = item; + markDirty(); + } + + public void dropItem() + { + if (!world.isRemote && !item.isEmpty()) + { + BlockPos pos = getPos(); + EntityItem entityItem = new EntityItem(world, pos.getX(), pos.getY(), pos.getZ(), item); + world.spawnEntity(entityItem); + setItem(ItemStack.EMPTY); + } + } + + @Override + public void readFromNBT(NBTTagCompound compound) + { + super.readFromNBT(compound); + if (compound.hasKey("Item")) + { + item = new ItemStack(compound.getCompoundTag("Item")); + } + } + + @Override + public NBTTagCompound writeToNBT(NBTTagCompound compound) + { + super.writeToNBT(compound); + if (!item.isEmpty()) + { + NBTTagCompound itemTag = new NBTTagCompound(); + item.writeToNBT(itemTag); + compound.setTag("Item", itemTag); + } + return compound; + } + + @Override + public SPacketUpdateTileEntity getUpdatePacket() + { + NBTTagCompound nbtTag = new NBTTagCompound(); + writeToNBT(nbtTag); + return new SPacketUpdateTileEntity(getPos(), 1, nbtTag); + } + + @Override + public NBTTagCompound getUpdateTag() + { + return writeToNBT(new NBTTagCompound()); + } + + @Override + public void onDataPacket(NetworkManager net, SPacketUpdateTileEntity pkt) + { + readFromNBT(pkt.getNbtCompound()); + } + + @Override + public void handleUpdateTag(NBTTagCompound tag) + { + readFromNBT(tag); + } + + @Override + public void update() + { + this.bookSpreadPrev = this.bookSpread; + this.bookRotationPrev = this.bookRotation; + EntityPlayer entityplayer = this.world.getClosestPlayer((float) this.pos.getX() + 0.5F, (float) this.pos.getY() + 0.5F, (float) this.pos.getZ() + 0.5F, 3.0D, false); + + if (entityplayer != null) + { + double d0 = entityplayer.posX - (double) ((float) this.pos.getX() + 0.5F); + double d1 = entityplayer.posZ - (double) ((float) this.pos.getZ() + 0.5F); + this.tRot = (float) MathHelper.atan2(d1, d0); + this.bookSpread += 0.1F; + + if (this.bookSpread < 0.5F || rand.nextInt(40) == 0) + { + float f1 = this.flipT; + + do + { + this.flipT += (rand.nextInt(4) - rand.nextInt(4)); + + } while (f1 == this.flipT); + } + } + else + { + this.tRot += 0.02F; + this.bookSpread -= 0.1F; + } + + while (this.bookRotation >= (float) Math.PI) + { + this.bookRotation -= ((float) Math.PI * 2F); + } + + while (this.bookRotation < -(float) Math.PI) + { + this.bookRotation += ((float) Math.PI * 2F); + } + + while (this.tRot >= (float) Math.PI) + { + this.tRot -= ((float) Math.PI * 2F); + } + + while (this.tRot < -(float) Math.PI) + { + this.tRot += ((float) Math.PI * 2F); + } + + float f2; + + for (f2 = this.tRot - this.bookRotation; f2 >= (float) Math.PI; f2 -= ((float) Math.PI * 2F)) + { + } + + while (f2 < -(float) Math.PI) + { + f2 += ((float) Math.PI * 2F); + } + + this.bookRotation += f2 * 0.4F; + this.bookSpread = MathHelper.clamp(this.bookSpread, 0.0F, 1.0F); + ++this.tickCount; + this.pageFlipPrev = this.pageFlip; + float f = (this.flipT - this.pageFlip) * 0.4F; + f = MathHelper.clamp(f, -0.2F, 0.2F); + this.flipA += (f - this.flipA) * 0.9F; + this.pageFlip += this.flipA; + + if (this.world.getWorldTime() % 40 == 39) + { + soulCount = scanCrucibleLevels() * 10; + } + } + + public int scanCrucibleLevels() + { + int totalLevel = 0; + BlockPos pos = this.getPos(); + World world = this.getWorld(); + + for (int dx = -RADIUS; dx <= RADIUS; dx++) + { + for (int dy = -RADIUS; dy <= RADIUS; dy++) + { + for (int dz = -RADIUS; dz <= RADIUS; dz++) + { + BlockPos checkPos = pos.add(dx, dy, dz); + IBlockState state = world.getBlockState(checkPos); + + if (state.getBlock() instanceof HSSoulCrucible) + { + int level = state.getValue(HSSoulCrucible.LEVEL); + totalLevel += level; + } + } + } + } + + return totalLevel; + } +} diff --git a/src/main/resources/assets/harkenscythe/blockstates/soul_altar.json b/src/main/resources/assets/harkenscythe/blockstates/soul_altar.json new file mode 100644 index 0000000..09bc59c --- /dev/null +++ b/src/main/resources/assets/harkenscythe/blockstates/soul_altar.json @@ -0,0 +1,20 @@ +{ + "forge_marker": 1, + "defaults": { + "model": "enchanting_table_base", + "textures": { + "particle": "harkenscythe:blocks/soul_altar_bottom", + "bottom": "harkenscythe:blocks/soul_altar_bottom", + "top": "harkenscythe:blocks/soul_altar_top", + "side": "harkenscythe:blocks/soul_altar_side" + } + }, + "variants": { + "normal": [ + {} + ], + "inventory": [ + {} + ] + } +} diff --git a/src/main/resources/assets/harkenscythe/textures/blocks/soul_altar_bottom.png b/src/main/resources/assets/harkenscythe/textures/blocks/soul_altar_bottom.png new file mode 100644 index 0000000000000000000000000000000000000000..9f337a417bb0cb2c185131f1099a2c4e6eb28cf2 GIT binary patch literal 502 zcmVPx#1ZP1_K>z@;j|==^1poj532;bRa{vGi!vFvd!vV){sAK>D02*{fSaefwW^{L9 za%BKeVQFr3E>1;MAa*k@H7+qQF!XYv0004HNkls-bgeC)}FQ>BfuEhZQiK~?@zpM0F$rU+xfhAjxudi9sr)=yx*`LLgdKH z?u!ng9j7328QRBotZ%D-|s z0%D9yx>-gJks2h4?(vHxb-G~aDU-grhQK1Ot7@64vanshg3S3SI@hYKTd(fPIjD*; z)aAcWP8T#*$~C!hvAh#$xe2kNh`QYS4$YZ zo_H!r+;qPx#1ZP1_K>z@;j|==^1poj532;bRa{vGi!vFvd!vV){sAK>D02*{fSaefwW^{L9 za%BKeVQFr3E>1;MAa*k@H7+qQF!XYv0004ENklkbD5;4w*&WY6-#l#b{}W>U zd`WBj+cdhlCi8ep#w2W!#F>%Sy1f?^h8wi^`b@_k@8t6Y{`!D098nM`YZ0G-D3#i~ z=6mt-#9E&x;K1I#K1rT6blKdmnAQoya0dt)6!Lk3+qQ;45J*=gJ)}B2qRDtpaa?j& z@DYc32u%2gFo?9CSV&Iudda>qQ(Jk{o|V-^4DaVK09BpUoL~$f8SR!Q7MSr8G0I>t zW++BM{1+hS>aH5L55H`Ms(n6VA8%s?0KstRwhW<%;6%(V6J1TMAJNt6L$?zKKyb0R zqn%>GLcII2sw^P2)k2QBeV|i}m~gBEAOL|AZP{7f)?J&5W>wRR1Ay`JKEN&QN05<} pF?WLxC{GSLfY-QK3;4T9`Ua7q`C&YSvG4!@002ovPDHLkV1iiz&}RSu literal 0 HcmV?d00001 diff --git a/src/main/resources/assets/harkenscythe/textures/blocks/soul_altar_top.png b/src/main/resources/assets/harkenscythe/textures/blocks/soul_altar_top.png new file mode 100644 index 0000000000000000000000000000000000000000..1a77f4dfba47016612092c8e23bfeaa80ab1b46b GIT binary patch literal 541 zcmV+&0^Px#1ZP1_K>z@;j|==^1poj532;bRa{vGi!vFvd!vV){sAK>D02*{fSaefwW^{L9 za%BKeVQFr3E>1;MAa*k@H7+qQF!XYv0004uNklhz!TvF8R21EZM4Tgb@*+Lj|w}&v^K`%acqQxMM(7VsskQ) z#+2f;(1HUxBbBv{b2VU32to%uBuNTc3=RZd1DVn)W56s3xiNii(Y-WMNhQ#5l%i?2 z%aHgxuOv4^q-VNB3<>c$>vGFSsSXwdYT`ST=(Cqa6MP!rYaoE{c55MRLNMgpzwhB`!7Jiy$m#6oO8rTyi|2;T3^gj=s zNygP~ke+*m^O+zcwu*tvu$^1)^%P?gJ;Q!WR7}P!$RFEEB!p_+w{}F=n{r18|88rj f=MU?)bvpS1n&(dEGHe?y00000NkvXXu0mjfD;wTK literal 0 HcmV?d00001