feat: implement enchanter

This commit is contained in:
LordMZTE 2023-06-01 18:30:06 +02:00
parent 23b2be9cc4
commit 7805180516
Signed by: LordMZTE
GPG Key ID: B64802DC33A64FF6
17 changed files with 1016 additions and 31 deletions

View File

@ -11,6 +11,7 @@ import net.anvilcraft.thaummach.gui.GuiBore;
import net.anvilcraft.thaummach.gui.GuiCondenser;
import net.anvilcraft.thaummach.gui.GuiCrystallizer;
import net.anvilcraft.thaummach.gui.GuiDuplicator;
import net.anvilcraft.thaummach.gui.GuiEnchanter;
import net.anvilcraft.thaummach.gui.GuiGenerator;
import net.anvilcraft.thaummach.gui.GuiRepairer;
import net.anvilcraft.thaummach.gui.GuiSoulBrazier;
@ -23,6 +24,7 @@ import net.anvilcraft.thaummach.render.tile.TileCondenserRenderer;
import net.anvilcraft.thaummach.render.tile.TileConduitPumpRenderer;
import net.anvilcraft.thaummach.render.tile.TileCrystallizerRenderer;
import net.anvilcraft.thaummach.render.tile.TileDuplicatorRenderer;
import net.anvilcraft.thaummach.render.tile.TileEnchanterRenderer;
import net.anvilcraft.thaummach.render.tile.TileGeneratorRenderer;
import net.anvilcraft.thaummach.render.tile.TileRepairerRenderer;
import net.anvilcraft.thaummach.render.tile.TileSealRenderer;
@ -39,6 +41,7 @@ import net.anvilcraft.thaummach.tiles.TileConduitValveAdvanced;
import net.anvilcraft.thaummach.tiles.TileCrucible;
import net.anvilcraft.thaummach.tiles.TileCrystallizer;
import net.anvilcraft.thaummach.tiles.TileDuplicator;
import net.anvilcraft.thaummach.tiles.TileEnchanter;
import net.anvilcraft.thaummach.tiles.TileFilter;
import net.anvilcraft.thaummach.tiles.TileGenerator;
import net.anvilcraft.thaummach.tiles.TilePurifier;
@ -82,6 +85,7 @@ public class ClientProxy extends CommonProxy {
ClientRegistry.registerTileEntity(TileConduitPump.class, "conduit_pump", new TileConduitPumpRenderer());
ClientRegistry.registerTileEntity(TileCrystallizer.class, "crystallizer", new TileCrystallizerRenderer());
ClientRegistry.registerTileEntity(TileDuplicator.class, "duplicator", new TileDuplicatorRenderer());
ClientRegistry.registerTileEntity(TileEnchanter.class, "enchanter", new TileEnchanterRenderer());
ClientRegistry.registerTileEntity(TileGenerator.class, "generator", new TileGeneratorRenderer());
ClientRegistry.registerTileEntity(TileRepairer.class, "repairer", new TileRepairerRenderer());
ClientRegistry.registerTileEntity(TileSeal.class, "seal", new TileSealRenderer());
@ -110,6 +114,9 @@ public class ClientProxy extends CommonProxy {
case DUPLICATOR:
return new GuiDuplicator(player.inventory, (TileDuplicator) te);
case ENCHANTER:
return new GuiEnchanter(player.inventory, (TileEnchanter) te);
case GENERATOR:
return new GuiGenerator((TileGenerator) te);

View File

@ -8,6 +8,7 @@ import net.anvilcraft.thaummach.container.ContainerBore;
import net.anvilcraft.thaummach.container.ContainerCondenser;
import net.anvilcraft.thaummach.container.ContainerCrystallizer;
import net.anvilcraft.thaummach.container.ContainerDuplicator;
import net.anvilcraft.thaummach.container.ContainerEnchanter;
import net.anvilcraft.thaummach.container.ContainerRepairer;
import net.anvilcraft.thaummach.container.ContainerSoulBrazier;
import net.anvilcraft.thaummach.container.ContainerVoidChest;
@ -23,6 +24,7 @@ import net.anvilcraft.thaummach.tiles.TileConduitValveAdvanced;
import net.anvilcraft.thaummach.tiles.TileCrucible;
import net.anvilcraft.thaummach.tiles.TileCrystallizer;
import net.anvilcraft.thaummach.tiles.TileDuplicator;
import net.anvilcraft.thaummach.tiles.TileEnchanter;
import net.anvilcraft.thaummach.tiles.TileFilter;
import net.anvilcraft.thaummach.tiles.TileGenerator;
import net.anvilcraft.thaummach.tiles.TilePurifier;
@ -54,6 +56,7 @@ public class CommonProxy implements IGuiHandler {
GameRegistry.registerTileEntity(TileCrucible.class, "crucible");
GameRegistry.registerTileEntity(TileCrystallizer.class, "crystallizer");
GameRegistry.registerTileEntity(TileDuplicator.class, "duplicator");
GameRegistry.registerTileEntity(TileEnchanter.class, "enchanter");
GameRegistry.registerTileEntity(TileFilter.class, "filter");
GameRegistry.registerTileEntity(TileGenerator.class, "generator");
GameRegistry.registerTileEntity(TilePurifier.class, "purifier");
@ -85,6 +88,9 @@ public class CommonProxy implements IGuiHandler {
case DUPLICATOR:
return new ContainerDuplicator(player.inventory, (TileDuplicator) te);
case ENCHANTER:
return new ContainerEnchanter(player.inventory, (TileEnchanter) te);
case REPAIRER:
return new ContainerRepairer(player.inventory, (TileRepairer) te);

View File

@ -6,6 +6,7 @@ public enum GuiID {
CONDENSER,
CRYSTALLIZER,
DUPLICATOR,
ENCHANTER,
GENERATOR,
REPAIRER,
SOUL_BRAZIER,

View File

@ -17,6 +17,7 @@ import net.anvilcraft.thaummach.packets.PacketChangeVoidInterfaceChannel;
import net.anvilcraft.thaummach.packets.PacketChangeVoidInterfaceContainerPage;
import net.anvilcraft.thaummach.packets.PacketDuplicatorPress;
import net.anvilcraft.thaummach.packets.PacketDuplicatorSetRepeat;
import net.anvilcraft.thaummach.packets.PacketEnchanterStart;
import net.anvilcraft.thaummach.packets.PacketFXSparkle;
import net.anvilcraft.thaummach.packets.PacketFXWisp;
import net.anvilcraft.thaummach.tiles.TileSeal;
@ -46,6 +47,7 @@ public class ThaumicMachinery {
channel.registerMessage(new PacketChangeVoidInterfaceContainerPage.Handler(), PacketChangeVoidInterfaceContainerPage.class, pktid++, Side.SERVER);
channel.registerMessage(new PacketDuplicatorPress.Handler(), PacketDuplicatorPress.class, pktid++, Side.CLIENT);
channel.registerMessage(new PacketDuplicatorSetRepeat.Handler(), PacketDuplicatorSetRepeat.class, pktid++, Side.SERVER);
channel.registerMessage(new PacketEnchanterStart.Handler(), PacketEnchanterStart.class, pktid++, Side.SERVER);
channel.registerMessage(new PacketFXSparkle.Handler(), PacketFXSparkle.class, pktid++, Side.CLIENT);
channel.registerMessage(new PacketFXWisp.Handler(), PacketFXWisp.class, pktid++, Side.CLIENT);
// clang-format on

View File

@ -41,6 +41,8 @@ public abstract class BlockApparatus extends BlockContainer {
public abstract IApparatusRenderer getApparatusRenderer(int meta);
public void setBlockBoundsForItemRenderBasedOnMeta(int meta) {}
@Override
public int quantityDropped(Random random) {
return 1;

View File

@ -9,6 +9,7 @@ import net.anvilcraft.alec.jalec.factories.AlecUnexpectedRuntimeErrorExceptionFa
import net.anvilcraft.thaummach.render.BlockApparatusRenderer;
import net.anvilcraft.thaummach.render.apparatus.IApparatusRenderer;
import net.anvilcraft.thaummach.render.apparatus.SimpleBlockApparatusRenderer;
import net.anvilcraft.thaummach.tiles.TileEnchanter;
import net.anvilcraft.thaummach.tiles.TileSeal;
import net.minecraft.block.Block;
import net.minecraft.block.material.Material;
@ -23,9 +24,13 @@ import net.minecraft.util.AxisAlignedBB;
import net.minecraft.util.IIcon;
import net.minecraft.world.IBlockAccess;
import net.minecraft.world.World;
import net.minecraftforge.common.util.ForgeDirection;
public class BlockApparatusStone extends BlockApparatus {
public IIcon iconEldritchStone;
public IIcon iconEnchanterBottom;
public IIcon iconEnchanterSide;
public IIcon iconEnchanterTop;
public BlockApparatusStone() {
super(Material.rock);
@ -39,6 +44,9 @@ public class BlockApparatusStone extends BlockApparatus {
Function<String, IIcon> reg = (s) -> register.registerIcon("thaummach:" + s);
this.iconEldritchStone = reg.apply("eldritch_stone");
this.iconEnchanterBottom = reg.apply("enchanter_bottom");
this.iconEnchanterSide = reg.apply("enchanter_side");
this.iconEnchanterTop = reg.apply("enchanter_top");
}
@Override
@ -46,6 +54,7 @@ public class BlockApparatusStone extends BlockApparatus {
MetaVals meta = MetaVals.get(meta_);
switch (meta) {
case ELDRITCH_STONE:
case ENCHANTER:
return SimpleBlockApparatusRenderer.INSTANCE;
default:
@ -159,6 +168,9 @@ public class BlockApparatusStone extends BlockApparatus {
case ELDRITCH_STONE:
return null;
case ENCHANTER:
return new TileEnchanter();
default:
throw AlecUnexpectedRuntimeErrorExceptionFactory.PLAIN.createAlecException(
"Invalid meta!"
@ -195,11 +207,30 @@ public class BlockApparatusStone extends BlockApparatus {
@Override
public IIcon getIcon(int i, int j) {
MetaVals meta = MetaVals.get(j);
ForgeDirection side = ForgeDirection.getOrientation(i);
switch (meta) {
case ELDRITCH_STONE:
return this.iconEldritchStone;
case ENCHANTER:
switch (side) {
case UP:
return this.iconEnchanterTop;
case DOWN:
return this.iconEnchanterBottom;
case NORTH:
case EAST:
case SOUTH:
case WEST:
return this.iconEnchanterSide;
default:
return null;
}
default:
return null;
}
@ -386,37 +417,7 @@ public class BlockApparatusStone extends BlockApparatus {
@Override
public void setBlockBoundsBasedOnState(IBlockAccess iblockaccess, int i, int j, int k) {
int md = iblockaccess.getBlockMetadata(i, j, k);
if (md == 0) {
if (iblockaccess.getTileEntity(i, j, k) == null) {
return;
}
int l = ((TileSeal) ((TileSeal) iblockaccess.getTileEntity(i, j, k))).orientation;
float thickness = 0.0625F;
if (l == 0) {
this.setBlockBounds(0.3F, 1.0F - thickness, 0.3F, 0.7F, 1.0F, 0.7F);
}
if (l == 1) {
this.setBlockBounds(0.3F, 0.0F, 0.3F, 0.7F, thickness, 0.7F);
}
if (l == 2) {
this.setBlockBounds(0.3F, 0.3F, 1.0F - thickness, 0.7F, 0.7F, 1.0F);
}
if (l == 3) {
this.setBlockBounds(0.3F, 0.3F, 0.0F, 0.7F, 0.7F, thickness);
}
if (l == 4) {
this.setBlockBounds(1.0F - thickness, 0.3F, 0.3F, 1.0F, 0.7F, 0.7F);
}
if (l == 5) {
this.setBlockBounds(0.0F, 0.3F, 0.3F, thickness, 0.7F, 0.7F);
}
} else if (md == 3) {
if (md == 3) {
this.setBlockBounds(0.0F, 0.0F, 0.0F, 1.0F, 0.75F, 1.0F);
} else {
float w1;
@ -466,6 +467,29 @@ public class BlockApparatusStone extends BlockApparatus {
return super.getSelectedBoundingBoxFromPool(w, i, j, k);
}
@Override
public void setBlockBoundsForItemRenderBasedOnMeta(int meta) {
MetaVals md = MetaVals.get(meta);
if (md == MetaVals.ENCHANTER) {
this.setBlockBounds(0.0F, 0.0F, 0.0F, 1.0F, 0.75F, 1.0F);
} else {
float w1;
if (md != MetaVals.INFUSER && md != MetaVals.INFUSER_DARK) {
if (md == MetaVals.DARKNESS_GENERATOR) {
w1 = 0.0625F;
this.setBlockBounds(0.0F, 0.0F, 0.0F, 1.0F, 0.5F - w1, 1.0F);
} else if (md == MetaVals.URN) {
this.setBlockBounds(0.125F, 0.0F, 0.125F, 0.875F, 0.5625F, 0.875F);
} else {
this.setBlockBounds(0.0F, 0.0F, 0.0F, 1.0F, 1.0F, 1.0F);
}
} else {
w1 = 0.0625F;
this.setBlockBounds(0.0F, 0.0F, 0.0F, 1.0F, 1.0F - w1, 1.0F);
}
}
}
@Override
public void setBlockBoundsForItemRender() {
this.setBlockBounds(0.0F, 0.0F, 0.0F, 1.0F, 1.0F, 1.0F);

View File

@ -0,0 +1,87 @@
package net.anvilcraft.thaummach.container;
import net.anvilcraft.thaummach.InventorySlot;
import net.anvilcraft.thaummach.tiles.TileEnchanter;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.entity.player.InventoryPlayer;
import net.minecraft.inventory.Container;
import net.minecraft.inventory.Slot;
import net.minecraft.item.ItemStack;
public class ContainerEnchanter extends Container {
public TileEnchanter te;
public ContainerEnchanter(InventoryPlayer inventoryplayer, TileEnchanter tile) {
this.te = tile;
this.addSlotToContainer(new InventorySlot(this.te, 0, 25, 47));
int i1;
for (i1 = 0; i1 < 3; ++i1) {
for (int j1 = 0; j1 < 9; ++j1) {
this.addSlotToContainer(
new Slot(inventoryplayer, j1 + i1 * 9 + 9, 8 + j1 * 18, 100 + i1 * 18)
);
}
}
for (i1 = 0; i1 < 9; ++i1) {
this.addSlotToContainer(new Slot(inventoryplayer, i1, 8 + i1 * 18, 158));
}
}
// TODO: WTF
//@Override
//public void updateCraftingResults() {
// super.updateCraftingResults();
// for (int i = 0; i < super.crafters.size(); ++i) {
// ICrafting icrafting = (ICrafting) super.crafters.get(i);
// icrafting.updateCraftingInventoryInfo(this, 0, this.te.enchantLevels[0]);
// icrafting.updateCraftingInventoryInfo(this, 1, this.te.enchantLevels[1]);
// icrafting.updateCraftingInventoryInfo(this, 2, this.te.enchantLevels[2]);
// }
//}
@Override
public void updateProgressBar(int i, int j) {
if (i >= 0 && i <= 2) {
this.te.enchantLevels[i] = j;
} else {
super.updateProgressBar(i, j);
}
}
@Override
public ItemStack transferStackInSlot(EntityPlayer pl, int i) {
ItemStack itemstack = null;
Slot slot = (Slot) super.inventorySlots.get(i);
if (slot != null && slot.getHasStack()) {
ItemStack itemstack1 = slot.getStack();
itemstack = itemstack1.copy();
if (i != 0) {
return null;
}
if (!this.mergeItemStack(itemstack1, 1, 37, true)) {
return null;
}
if (itemstack1.stackSize == 0) {
slot.putStack((ItemStack) null);
} else {
slot.onSlotChanged();
}
if (itemstack1.stackSize == itemstack.stackSize) {
return null;
}
}
return itemstack;
}
@Override
public boolean canInteractWith(EntityPlayer arg0) {
return true;
}
}

View File

@ -0,0 +1,249 @@
package net.anvilcraft.thaummach.gui;
import java.util.Random;
import net.anvilcraft.thaummach.ThaumicMachinery;
import net.anvilcraft.thaummach.container.ContainerEnchanter;
import net.anvilcraft.thaummach.packets.PacketEnchanterStart;
import net.anvilcraft.thaummach.tiles.TileEnchanter;
import net.minecraft.client.gui.FontRenderer;
import net.minecraft.client.gui.ScaledResolution;
import net.minecraft.client.gui.inventory.GuiContainer;
import net.minecraft.client.model.ModelBook;
import net.minecraft.client.renderer.RenderHelper;
import net.minecraft.entity.Entity;
import net.minecraft.entity.player.InventoryPlayer;
import net.minecraft.item.ItemStack;
import net.minecraft.util.EnchantmentNameParts;
import net.minecraft.util.MathHelper;
import net.minecraft.util.ResourceLocation;
import org.lwjgl.opengl.GL11;
import org.lwjgl.util.glu.GLU;
public class GuiEnchanter extends GuiContainer {
private static ModelBook bookModel = new ModelBook();
private Random field_40230_x = new Random();
public int field_40227_h;
public float field_40229_i;
public float field_40225_j;
public float field_40226_k;
public float field_40223_l;
public float field_40224_m;
public float field_40221_n;
ItemStack field_40222_o;
public TileEnchanter te;
public GuiEnchanter(InventoryPlayer inventoryplayer, TileEnchanter tile) {
super(new ContainerEnchanter(inventoryplayer, tile));
this.te = tile;
super.ySize = 182;
}
@Override
public void onGuiClosed() {
super.onGuiClosed();
}
@Override
protected void drawGuiContainerForegroundLayer(/* useless parameters: */ int alec1, int alec2) {
super.fontRendererObj.drawString("Thaumic Enchanter", 12, 6, 0x404040);
super.fontRendererObj.drawString("Inventory", 8, super.ySize - 96 + 2, 0x404040);
}
@Override
public void updateScreen() {
super.updateScreen();
this.doStuff();
}
@Override
protected void mouseClicked(int i, int j, int k) {
super.mouseClicked(i, j, k);
int l = (super.width - super.xSize) / 2;
int i1 = (super.height - super.ySize) / 2;
for (int j1 = 0; j1 < 3; ++j1) {
int k1 = i - (l + 60);
int l1 = j - (i1 + 22 + 19 * j1);
if (k1 >= 0 && l1 >= 0 && k1 < 108 && l1 < 19 && this.te.enchantLevels[j1] > 0
&& this.te.getStackInSlot(0) != null) {
ThaumicMachinery.channel.sendToServer(
new PacketEnchanterStart(this.te.xCoord, this.te.yCoord, this.te.zCoord, j1)
);
}
}
}
@Override
protected void drawGuiContainerBackgroundLayer(float f, int i, int j) {
GL11.glColor4f(1.0F, 1.0F, 1.0F, 1.0F);
this.mc.renderEngine.bindTexture(
new ResourceLocation("thaummach", "textures/guis/enchanter.png")
);
int l = (super.width - super.xSize) / 2;
int i1 = (super.height - super.ySize) / 2;
this.drawTexturedModalRect(l, i1, 0, 0, super.xSize, super.ySize);
int p1 = this.te.getProgressScaled(25);
this.drawTexturedModalRect(l + 21, i1 + 71, 176, 0, p1, 3);
GL11.glPushMatrix();
GL11.glMatrixMode(5889);
GL11.glPushMatrix();
GL11.glLoadIdentity();
ScaledResolution scaledresolution
= new ScaledResolution(super.mc, super.mc.displayWidth, super.mc.displayHeight);
GL11.glViewport(
(scaledresolution.getScaledWidth() - 320) / 2 * scaledresolution.getScaleFactor(),
(scaledresolution.getScaledHeight() - 240) / 2 * scaledresolution.getScaleFactor(),
320 * scaledresolution.getScaleFactor(),
240 * scaledresolution.getScaleFactor()
);
GL11.glTranslatef(-0.34F, 0.28F, 0.0F);
GLU.gluPerspective(90.0F, 1.333333F, 9.0F, 80.0F);
float f1 = 1.0F;
GL11.glMatrixMode(5888);
GL11.glLoadIdentity();
RenderHelper.enableStandardItemLighting();
GL11.glTranslatef(0.0F, 3.3F, -16.0F);
GL11.glScalef(f1, f1, f1);
float f2 = 5.0F;
GL11.glScalef(f2, f2, f2);
GL11.glRotatef(180.0F, 0.0F, 0.0F, 1.0F);
this.mc.renderEngine.bindTexture(
new ResourceLocation("thaummach", "textures/models/book.png")
);
GL11.glRotatef(20.0F, 1.0F, 0.0F, 0.0F);
float f3 = this.field_40221_n + (this.field_40224_m - this.field_40221_n) * f;
GL11.glTranslatef((1.0F - f3) * 0.2F, (1.0F - f3) * 0.1F, (1.0F - f3) * 0.25F);
GL11.glRotatef(-(1.0F - f3) * 90.0F - 90.0F, 0.0F, 1.0F, 0.0F);
GL11.glRotatef(180.0F, 1.0F, 0.0F, 0.0F);
float f4 = this.field_40225_j + (this.field_40229_i - this.field_40225_j) * f + 0.25F;
float f5 = this.field_40225_j + (this.field_40229_i - this.field_40225_j) * f + 0.75F;
f4 = (f4 - (float) MathHelper.truncateDoubleToInt((double) f4)) * 1.6F - 0.3F;
f5 = (f5 - (float) MathHelper.truncateDoubleToInt((double) f5)) * 1.6F - 0.3F;
if (f4 < 0.0F) {
f4 = 0.0F;
}
if (f5 < 0.0F) {
f5 = 0.0F;
}
if (f4 > 1.0F) {
f4 = 1.0F;
}
if (f5 > 1.0F) {
f5 = 1.0F;
}
GL11.glEnable(32826);
bookModel.render((Entity) null, 0.0F, f4, f5, f3, 0.0F, 0.0625F);
GL11.glDisable(32826);
RenderHelper.disableStandardItemLighting();
GL11.glMatrixMode(5889);
GL11.glViewport(0, 0, super.mc.displayWidth, super.mc.displayHeight);
GL11.glPopMatrix();
GL11.glMatrixMode(5888);
GL11.glPopMatrix();
RenderHelper.disableStandardItemLighting();
GL11.glColor4f(1.0F, 1.0F, 1.0F, 1.0F);
this.mc.renderEngine.bindTexture(
new ResourceLocation("thaummach", "textures/guis/enchanter.png")
);
EnchantmentNameParts.instance.reseedRandomGenerator(this.te.nameSeed);
for (int j1 = 0; j1 < 3; ++j1) {
String s = EnchantmentNameParts.instance.generateNewRandomName();
super.zLevel = 0.0F;
this.mc.renderEngine.bindTexture(
new ResourceLocation("thaummach", "textures/guis/enchanter.png")
);
int k1 = this.te.enchantLevels[j1] * 2 * (this.te.enchantLevels[j1] / 2);
GL11.glColor4f(1.0F, 1.0F, 1.0F, 1.0F);
if (this.te.enchantLevels[j1] > 0) {
String s1 = "" + k1;
String s2 = "" + this.te.enchantLevels[j1];
FontRenderer fontrenderer = super.mc.standardGalacticFontRenderer;
int l1 = 6839882;
int i2 = i - (l + 60);
int j2 = j - (i1 + 22 + 19 * j1);
if (i2 >= 0 && j2 >= 0 && i2 < 108 && j2 < 19) {
this.drawTexturedModalRect(l + 60, i1 + 22 + 19 * j1, 0, 220, 108, 19);
l1 = 16777088;
} else {
this.drawTexturedModalRect(l + 60, i1 + 22 + 19 * j1, 0, 182, 108, 19);
}
if (this.te.enchantmentChoice == j1 && this.te.enchantmentCost > 0
&& this.te.progress < (float) this.te.enchantmentCost) {
this.drawTexturedModalRect(l + 60, i1 + 22 + 19 * j1, 0, 201, 108, 19);
}
fontrenderer.drawSplitString(s, l + 62, i1 + 24 + 19 * j1, 104, l1);
fontrenderer = super.mc.fontRenderer;
l1 = 10764287;
fontrenderer.drawStringWithShadow(
s1, l + 166 - fontrenderer.getStringWidth(s1), i1 + 24 + 19 * j1 + 8, l1
);
l1 = 8453920;
fontrenderer.drawStringWithShadow(
s2, l + 166 - fontrenderer.getStringWidth(s2), i1 + 24 + 19 * j1 - 1, l1
);
}
}
}
/**
* No one knows exactly what this function does.
*/
public void doStuff() {
ItemStack itemstack = super.inventorySlots.getSlot(0).getStack();
if (!ItemStack.areItemStacksEqual(itemstack, this.field_40222_o)) {
this.field_40222_o = itemstack;
do {
this.field_40226_k
+= (float) (this.field_40230_x.nextInt(4) - this.field_40230_x.nextInt(4));
} while (this.field_40229_i <= this.field_40226_k + 1.0F
&& this.field_40229_i >= this.field_40226_k - 1.0F);
}
++this.field_40227_h;
this.field_40225_j = this.field_40229_i;
this.field_40221_n = this.field_40224_m;
boolean flag = false;
for (int i = 0; i < 3; ++i) {
if (this.te.enchantLevels[i] != 0) {
flag = true;
}
}
if (flag) {
this.field_40224_m += 0.2F;
} else {
this.field_40224_m -= 0.2F;
}
if (this.field_40224_m < 0.0F) {
this.field_40224_m = 0.0F;
}
if (this.field_40224_m > 1.0F) {
this.field_40224_m = 1.0F;
}
float f = (this.field_40226_k - this.field_40229_i) * 0.4F;
float f1 = 0.2F;
if (f < -f1) {
f = -f1;
}
if (f > f1) {
f = f1;
}
this.field_40223_l += (f - this.field_40223_l) * 0.9F;
this.field_40229_i += this.field_40223_l;
}
}

View File

@ -0,0 +1,55 @@
package net.anvilcraft.thaummach.packets;
import cpw.mods.fml.common.network.simpleimpl.IMessage;
import cpw.mods.fml.common.network.simpleimpl.IMessageHandler;
import cpw.mods.fml.common.network.simpleimpl.MessageContext;
import io.netty.buffer.ByteBuf;
import net.anvilcraft.thaummach.tiles.TileEnchanter;
import net.minecraft.tileentity.TileEntity;
import net.minecraft.world.World;
public class PacketEnchanterStart implements IMessage {
int x;
int y;
int z;
int idx;
public PacketEnchanterStart() {}
public PacketEnchanterStart(int x, int y, int z, int idx) {
this.x = x;
this.y = y;
this.z = z;
this.idx = idx;
}
@Override
public void fromBytes(ByteBuf buf) {
this.x = buf.readInt();
this.y = buf.readInt();
this.z = buf.readInt();
this.idx = buf.readInt();
}
@Override
public void toBytes(ByteBuf buf) {
buf.writeInt(this.x);
buf.writeInt(this.y);
buf.writeInt(this.z);
buf.writeInt(this.idx);
}
public static class Handler implements IMessageHandler<PacketEnchanterStart, IMessage> {
@Override
public IMessage onMessage(PacketEnchanterStart pkt, MessageContext ctx) {
World world = ctx.getServerHandler().playerEntity.worldObj;
TileEntity te = world.getTileEntity(pkt.x, pkt.y, pkt.z);
if (te instanceof TileEnchanter) {
((TileEnchanter) te).startEnchantingItem(pkt.idx);
}
return null;
}
}
}

View File

@ -1,5 +1,6 @@
package net.anvilcraft.thaummach.render.apparatus;
import net.anvilcraft.thaummach.blocks.BlockApparatus;
import net.minecraft.block.Block;
import net.minecraft.client.renderer.RenderBlocks;
import net.minecraft.world.IBlockAccess;
@ -13,6 +14,7 @@ public class SimpleBlockApparatusRenderer implements IApparatusRenderer {
IBlockAccess w, RenderBlocks rb, int x, int y, int z, Block block, int meta, boolean inv
) {
if (inv) {
((BlockApparatus) block).setBlockBoundsForItemRenderBasedOnMeta(meta);
rb.setRenderBoundsFromBlock(block);
BlockRenderer.drawFaces(
rb,

View File

@ -0,0 +1,93 @@
package net.anvilcraft.thaummach.render.tile;
import net.anvilcraft.thaummach.tiles.TileEnchanter;
import net.minecraft.client.Minecraft;
import net.minecraft.client.model.ModelBook;
import net.minecraft.client.renderer.Tessellator;
import net.minecraft.client.renderer.tileentity.TileEntitySpecialRenderer;
import net.minecraft.entity.Entity;
import net.minecraft.tileentity.TileEntity;
import net.minecraft.util.MathHelper;
import net.minecraft.util.ResourceLocation;
import org.lwjgl.opengl.GL11;
public class TileEnchanterRenderer extends TileEntitySpecialRenderer {
private ModelBook field_40450_a = new ModelBook();
private void drawDisk(double x, double y, double z) {
float angle = (float) Minecraft.getMinecraft().thePlayer.ticksExisted % 360.0F;
Tessellator tessellator = Tessellator.instance;
GL11.glPushMatrix();
GL11.glTranslatef((float) x + 0.5F, (float) y, (float) z + 0.5F);
GL11.glPushMatrix();
GL11.glRotatef(angle, 0.0F, 1.0F, 0.0F);
GL11.glTranslatef(-0.5F, 0.0F, -0.5F);
GL11.glDepthMask(false);
GL11.glEnable(3042);
GL11.glBlendFunc(770, 1);
this.bindTexture(new ResourceLocation("thaummach", "textures/misc/seal5.png"));
GL11.glColor4f(1.0F, 1.0F, 1.0F, 1.0F);
tessellator.startDrawingQuads();
tessellator.setBrightness(200);
tessellator.setColorRGBA_F(1.0F, 0.5F, 1.0F, 1.0F);
tessellator.addVertexWithUV(0.0, 0.0, 1.0, 0.0, 1.0);
tessellator.addVertexWithUV(1.0, 0.0, 1.0, 1.0, 1.0);
tessellator.addVertexWithUV(1.0, 0.0, 0.0, 1.0, 0.0);
tessellator.addVertexWithUV(0.0, 0.0, 0.0, 0.0, 0.0);
tessellator.draw();
GL11.glDisable(3042);
GL11.glDepthMask(true);
GL11.glPopMatrix();
GL11.glPopMatrix();
}
public void render(TileEnchanter te, double d, double d1, double d2, float f) {
GL11.glPushMatrix();
GL11.glTranslatef((float) d + 0.5F, (float) d1 + 0.75F, (float) d2 + 0.5F);
float f1 = (float) te.tickCount + f;
GL11.glTranslatef(0.0F, 0.1F + MathHelper.sin(f1 * 0.1F) * 0.01F, 0.0F);
float f2;
for (f2 = te.bookRotation2 - te.bookRotationPrev; f2 >= 3.141593F; f2 -= 6.283185F) {}
while (f2 < -3.141593F) {
f2 += 6.283185F;
}
float f3 = te.bookRotationPrev + f2 * f;
GL11.glRotatef(-f3 * 180.0F / 3.141593F, 0.0F, 1.0F, 0.0F);
GL11.glRotatef(80.0F, 0.0F, 0.0F, 1.0F);
this.bindTexture(new ResourceLocation("thaummach", "textures/models/book.png"));
float f4 = te.pageFlipPrev + (te.pageFlip - te.pageFlipPrev) * f + 0.25F;
float f5 = te.pageFlipPrev + (te.pageFlip - te.pageFlipPrev) * f + 0.75F;
f4 = (f4 - (float) MathHelper.truncateDoubleToInt((double) f4)) * 1.6F - 0.3F;
f5 = (f5 - (float) MathHelper.truncateDoubleToInt((double) f5)) * 1.6F - 0.3F;
if (f4 < 0.0F) {
f4 = 0.0F;
}
if (f5 < 0.0F) {
f5 = 0.0F;
}
if (f4 > 1.0F) {
f4 = 1.0F;
}
if (f5 > 1.0F) {
f5 = 1.0F;
}
float f6 = te.bookSpreadPrev + (te.bookSpread - te.bookSpreadPrev) * f;
this.field_40450_a.render((Entity) null, f1, f4, f5, f6, 0.0F, 0.0625F);
GL11.glPopMatrix();
if (te.enchantmentChoice != -1 && te.enchantmentCost > 0) {
this.drawDisk(d, d1 + 0.7599999904632568, d2);
}
}
@Override
public void renderTileEntityAt(TileEntity tileentity, double d, double d1, double d2, float f) {
this.render((TileEnchanter) tileentity, d, d1, d2, f);
}
}

View File

@ -0,0 +1,457 @@
package net.anvilcraft.thaummach.tiles;
import java.util.List;
import java.util.Random;
import dev.tilera.auracore.api.machine.TileVisUser;
import net.anvilcraft.thaummach.GuiID;
import net.anvilcraft.thaummach.ITileGui;
import net.minecraft.enchantment.EnchantmentData;
import net.minecraft.enchantment.EnchantmentHelper;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.init.Items;
import net.minecraft.inventory.IInventory;
import net.minecraft.inventory.ISidedInventory;
import net.minecraft.item.Item;
import net.minecraft.item.ItemStack;
import net.minecraft.nbt.NBTTagCompound;
import net.minecraft.nbt.NBTTagList;
import net.minecraft.network.NetworkManager;
import net.minecraft.network.Packet;
import net.minecraft.network.play.server.S35PacketUpdateTileEntity;
import net.minecraftforge.common.ForgeHooks;
import net.minecraftforge.common.util.ForgeDirection;
public class TileEnchanter extends TileVisUser implements ISidedInventory, ITileGui {
public int tickCount;
public float pageFlip;
public float pageFlipPrev;
public float field_40061_d;
public float field_40062_e;
public float bookSpread;
public float bookSpreadPrev;
public float bookRotation2;
public float bookRotationPrev;
public float bookRotation;
private static Random RNG = new Random();
private ItemStack[] itemStacks = new ItemStack[1];
public int[] enchantLevels = new int[3];
public long nameSeed;
private Random rand = new Random();
public float progress = 0.0F;
public int enchantmentCost = 0;
public int enchantmentChoice = -1;
@Override
public GuiID getGuiID() {
return GuiID.ENCHANTER;
}
@Override
public void readFromNBT(NBTTagCompound nbttagcompound) {
super.readFromNBT(nbttagcompound);
this.progress = nbttagcompound.getFloat("progress");
this.enchantmentCost = nbttagcompound.getInteger("enchantmentCost");
this.enchantmentChoice = nbttagcompound.getInteger("enchantmentChoice");
this.enchantLevels[0] = nbttagcompound.getInteger("enchantment0");
this.enchantLevels[1] = nbttagcompound.getInteger("enchantment1");
this.enchantLevels[2] = nbttagcompound.getInteger("enchantment2");
NBTTagList nbttaglist = nbttagcompound.getTagList("Items", 10);
this.itemStacks = new ItemStack[this.getSizeInventory()];
for (int i = 0; i < nbttaglist.tagCount(); ++i) {
NBTTagCompound nbttagcompound1 = (NBTTagCompound) nbttaglist.getCompoundTagAt(i);
byte byte0 = nbttagcompound1.getByte("Slot");
if (byte0 >= 0 && byte0 < this.itemStacks.length) {
this.itemStacks[byte0] = ItemStack.loadItemStackFromNBT(nbttagcompound1);
}
}
}
@Override
public void writeToNBT(NBTTagCompound nbttagcompound) {
super.writeToNBT(nbttagcompound);
nbttagcompound.setFloat("progress", this.progress);
nbttagcompound.setInteger("enchantmentCost", this.enchantmentCost);
nbttagcompound.setInteger("enchantmentChoice", this.enchantmentChoice);
nbttagcompound.setInteger("enchantment0", this.enchantLevels[0]);
nbttagcompound.setInteger("enchantment1", this.enchantLevels[1]);
nbttagcompound.setInteger("enchantment2", this.enchantLevels[2]);
NBTTagList nbttaglist = new NBTTagList();
for (int i = 0; i < this.itemStacks.length; ++i) {
if (this.itemStacks[i] != null) {
NBTTagCompound nbttagcompound1 = new NBTTagCompound();
nbttagcompound1.setByte("Slot", (byte) i);
this.itemStacks[i].writeToNBT(nbttagcompound1);
nbttaglist.appendTag(nbttagcompound1);
}
}
nbttagcompound.setTag("Items", nbttaglist);
}
@Override
public void updateEntity() {
super.updateEntity();
if (this.worldObj.isRemote) {
this.rotateBook();
} else {
if (this.progress >= (float) this.enchantmentCost && this.enchantmentChoice != -1) {
this.enchantItem(this.enchantmentChoice);
this.progress = (float) (this.enchantmentCost = 0);
this.enchantmentChoice = -1;
this.worldObj.markBlockForUpdate(this.xCoord, this.yCoord, this.zCoord);
}
if (this.progress<(float) this.enchantmentCost&& this.enchantmentCost> 0
&& this.enchantmentChoice != -1) {
this.progress += this.getAvailablePureVis(10.0F);
this.worldObj.markBlockForUpdate(this.xCoord, this.yCoord, this.zCoord);
}
}
}
public int getProgressScaled(int i) {
return (int) (this.progress * (float) i / (float) this.enchantmentCost);
}
private void rotateBook() {
this.bookSpreadPrev = this.bookSpread;
this.bookRotationPrev = this.bookRotation2;
EntityPlayer entityplayer = super.worldObj.getClosestPlayer(
(double) ((float) super.xCoord + 0.5F),
(double) ((float) super.yCoord + 0.5F),
(double) ((float) super.zCoord + 0.5F),
3.0
);
if (entityplayer != null) {
double d = entityplayer.posX - (double) ((float) super.xCoord + 0.5F);
double d1 = entityplayer.posZ - (double) ((float) super.zCoord + 0.5F);
this.bookRotation = (float) Math.atan2(d1, d);
this.bookSpread += 0.1F;
if (this.bookSpread < 0.5F || RNG.nextInt(40) == 0) {
float f3 = this.field_40061_d;
do {
this.field_40061_d += (float) (RNG.nextInt(4) - RNG.nextInt(4));
} while (f3 == this.field_40061_d);
}
} else {
this.bookRotation += 0.02F;
this.bookSpread -= 0.1F;
}
while (this.bookRotation2 >= 3.141593F) {
this.bookRotation2 -= 6.283185F;
}
while (this.bookRotation2 < -3.141593F) {
this.bookRotation2 += 6.283185F;
}
while (this.bookRotation >= 3.141593F) {
this.bookRotation -= 6.283185F;
}
while (this.bookRotation < -3.141593F) {
this.bookRotation += 6.283185F;
}
float f;
for (f = this.bookRotation - this.bookRotation2; f >= 3.141593F; f -= 6.283185F) {}
while (f < -3.141593F) {
f += 6.283185F;
}
this.bookRotation2 += f * 0.4F;
if (this.bookSpread < 0.0F) {
this.bookSpread = 0.0F;
}
if (this.bookSpread > 1.0F) {
this.bookSpread = 1.0F;
}
++this.tickCount;
this.pageFlipPrev = this.pageFlip;
float f1 = (this.field_40061_d - this.pageFlip) * 0.4F;
float f2 = 0.2F;
if (f1 < -f2) {
f1 = -f2;
}
if (f1 > f2) {
f1 = f2;
}
this.field_40062_e += (f1 - this.field_40062_e) * 0.9F;
this.pageFlip += this.field_40062_e;
}
@Override
public boolean getConnectable(ForgeDirection face) {
switch (face) {
case NORTH:
case EAST:
case SOUTH:
case WEST:
return true;
default:
return false;
}
}
// TODO: AZANOR, WTF
public void onCraftMatrixChanged(IInventory iinventory) {
if (this.worldObj.isRemote)
return;
this.progress = (float) (this.enchantmentCost = 0);
this.enchantmentChoice = -1;
ItemStack itemstack = iinventory.getStackInSlot(0);
if (itemstack != null && itemstack.isItemEnchantable()) {
this.worldObj.markBlockForUpdate(this.xCoord, this.yCoord, this.zCoord);
this.nameSeed = this.rand.nextLong();
float power = 0.0f;
for (int j = -1; j <= 1; ++j) {
for (int k = -1; k <= 1; ++k) {
if ((j != 0 || k != 0)
&& this.worldObj.isAirBlock(this.xCoord + k, this.yCoord, this.zCoord + j)
&& this.worldObj.isAirBlock(
this.xCoord + k, this.yCoord + 1, this.zCoord + j
)) {
power += ForgeHooks.getEnchantPower(
this.worldObj, this.xCoord + k * 2, this.yCoord, this.zCoord + j * 2
);
power += ForgeHooks.getEnchantPower(
this.worldObj, this.xCoord + k * 2, this.yCoord + 1, this.zCoord + j * 2
);
if (k != 0 && j != 0) {
power += ForgeHooks.getEnchantPower(
this.worldObj, this.xCoord + k * 2, this.yCoord, this.zCoord + j
);
power += ForgeHooks.getEnchantPower(
this.worldObj, this.xCoord + k * 2, this.yCoord + 1, this.zCoord + j
);
power += ForgeHooks.getEnchantPower(
this.worldObj, this.xCoord + k, this.yCoord, this.zCoord + j * 2
);
power += ForgeHooks.getEnchantPower(
this.worldObj, this.xCoord + k, this.yCoord + 1, this.zCoord + j * 2
);
}
}
}
if (power > 40) {
power = 40;
}
for (int l = 0; l < 3; ++l) {
this.enchantLevels[l]
= calcItemStackEnchantability(this.rand, l, (int) power, itemstack);
}
}
} else {
for (int i = 0; i < 3; ++i) {
this.enchantLevels[i] = 0;
}
}
}
public static int
calcItemStackEnchantability(Random par0Random, int par1, int par2, ItemStack par3ItemStack) {
Item var4 = par3ItemStack.getItem();
int var5 = var4.getItemEnchantability();
if (var5 <= 0) {
return 0;
} else {
if (par2 > 40) {
par2 = 40;
}
par2 = 1 + (par2 >> 1) + par0Random.nextInt(par2 + 1);
int var6 = par0Random.nextInt(5) + par2;
return par1 == 0 ? (var6 >> 1) + 1 : (par1 == 1 ? var6 * 2 / 3 + 1 : var6);
}
}
public boolean startEnchantingItem(int i) {
ItemStack itemstack = this.getStackInSlot(0);
if (this.enchantLevels[i] > 0 && itemstack != null) {
this.enchantmentChoice = i;
this.enchantmentCost = this.enchantLevels[i] * 2 * (this.enchantLevels[i] / 2);
this.progress = 0.0F;
return true;
} else {
this.enchantmentChoice = -1;
return false;
}
}
public boolean enchantItem(int i) {
ItemStack itemstack = this.itemStacks[0];
if (this.enchantLevels[i] <= 0 || itemstack == null) {
return false;
}
if (!this.worldObj.isRemote) {
List list = EnchantmentHelper.buildEnchantmentList(
this.rand, itemstack, this.enchantLevels[i]
);
boolean flag = itemstack.getItem() == Items.book;
if (list != null) {
if (flag) {
itemstack.func_150996_a(Items.enchanted_book);
}
int j = flag && list.size() > 1 ? this.rand.nextInt(list.size()) : -1;
for (int k = 0; k < list.size(); ++k) {
EnchantmentData enchantmentdata = (EnchantmentData) list.get(k);
if (!flag || k != j) {
if (flag) {
Items.enchanted_book.addEnchantment(itemstack, enchantmentdata);
} else {
itemstack.addEnchantment(
enchantmentdata.enchantmentobj, enchantmentdata.enchantmentLevel
);
}
}
}
this.onCraftMatrixChanged(this);
}
}
return true;
}
@Override
public ItemStack decrStackSize(int i, int j) {
this.markDirty();
if (this.itemStacks[i] != null) {
ItemStack itemstack1;
if (this.itemStacks[i].stackSize <= j) {
itemstack1 = this.itemStacks[i];
this.itemStacks[i] = null;
this.onCraftMatrixChanged(this);
return itemstack1;
} else {
itemstack1 = this.itemStacks[i].splitStack(j);
if (this.itemStacks[i].stackSize == 0) {
this.itemStacks[i] = null;
}
this.onCraftMatrixChanged(this);
return itemstack1;
}
}
return null;
}
@Override
public void setInventorySlotContents(int i, ItemStack itemstack) {
this.markDirty();
this.itemStacks[i] = itemstack;
if (itemstack != null && itemstack.stackSize > this.getInventoryStackLimit()) {
itemstack.stackSize = this.getInventoryStackLimit();
}
this.onCraftMatrixChanged(this);
}
@Override
public String getInventoryName() {
return "Thaumic Enchanter";
}
@Override
public boolean hasCustomInventoryName() {
return true;
}
@Override
public int getInventoryStackLimit() {
return 1;
}
@Override
public int getSizeInventory() {
return this.itemStacks.length;
}
@Override
public ItemStack getStackInSlot(int i) {
return this.itemStacks[i];
}
@Override
public ItemStack getStackInSlotOnClosing(int var1) {
if (this.itemStacks[var1] != null) {
ItemStack var2 = this.itemStacks[var1];
this.itemStacks[var1] = null;
return var2;
} else {
return null;
}
}
@Override
public void closeInventory() {}
@Override
public void openInventory() {}
@Override
public boolean isItemValidForSlot(int slot, ItemStack stack) {
return stack.isItemEnchantable();
}
@Override
public boolean isUseableByPlayer(EntityPlayer arg0) {
return true;
}
@Override
public boolean canExtractItem(int arg0, ItemStack arg1, int arg2) {
return arg1.getEnchantmentTagList() != null;
}
@Override
public boolean canInsertItem(int slot, ItemStack stack, int side) {
return this.isItemValidForSlot(slot, stack);
}
@Override
public int[] getAccessibleSlotsFromSide(int arg0) {
return new int[] { 0 };
}
@Override
public Packet getDescriptionPacket() {
NBTTagCompound nbt = new NBTTagCompound();
nbt.setFloat("progress", this.progress);
nbt.setInteger("enchantmentCost", this.enchantmentCost);
nbt.setInteger("enchantmentChoice", this.enchantmentChoice);
nbt.setIntArray("enchantLevels", this.enchantLevels);
return new S35PacketUpdateTileEntity(
this.xCoord, this.yCoord, this.zCoord, this.getBlockMetadata(), nbt
);
}
@Override
public void onDataPacket(NetworkManager arg0, S35PacketUpdateTileEntity pkt) {
NBTTagCompound nbt = pkt.func_148857_g();
this.progress = nbt.getFloat("progress");
this.enchantmentCost = nbt.getInteger("enchantmentCost");
this.enchantmentChoice = nbt.getInteger("enchantmentChoice");
this.enchantLevels = nbt.getIntArray("enchantLevels");
}
}

Binary file not shown.

After

Width:  |  Height:  |  Size: 595 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 384 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 669 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 5.3 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 16 KiB