mirror of
https://github.com/GTNewHorizons/Botania.git
synced 2026-11-17 02:45:13 +00:00
Manufactory Halo. Required some changes to the Assembly Halo's code.
This commit is contained in:
1 parent
3f2dbde039
commit
959af74385
10 files changed
+104
-23
No files matched your search
@@ -132,7 +132,7 @@ public final class HUDHandler {
|
||||
profiler.endSection();
|
||||
}
|
||||
|
||||
if(equippedStack != null && equippedStack.getItem() == ModItems.craftingHalo) {
|
||||
if(equippedStack != null && equippedStack.getItem() instanceof ItemCraftingHalo) {
|
||||
profiler.startSection("craftingHalo");
|
||||
ItemCraftingHalo.renderHUD(event.resolution, mc.thePlayer, equippedStack);
|
||||
profiler.endSection();
|
||||
|
||||
@@ -116,7 +116,7 @@ public final class LibResources {
|
||||
public static final String MISC_WISP_LARGE = PREFIX_MISC + "wispLarge.png";
|
||||
public static final String MISC_WISP_SMALL = PREFIX_MISC + "wispSmall.png";
|
||||
public static final String MISC_HALO = PREFIX_MISC + "halo.png";
|
||||
public static final String MISC_GLOW_PINK = PREFIX_MISC + "glow0.png";
|
||||
public static final String MISC_GLOW_GREEN = PREFIX_MISC + "glow0.png";
|
||||
public static final String MISC_GLOW_CYAN = PREFIX_MISC + "glow1.png";
|
||||
public static final String MISC_BABYLON = PREFIX_MISC + "babylon.png";
|
||||
|
||||
|
||||
@@ -107,6 +107,7 @@ public final class BotaniaCreativeTab extends CreativeTabs {
|
||||
addItem(ModItems.enderHand);
|
||||
addItem(ModItems.spellCloth);
|
||||
addItem(ModItems.craftingHalo);
|
||||
addItem(ModItems.autocraftingHalo);
|
||||
addItem(ModItems.spawnerMover);
|
||||
addBlock(ModBlocks.spawnerClaw);
|
||||
addBlock(ModBlocks.cocoon);
|
||||
|
||||
@@ -0,0 +1,48 @@
|
||||
/**
|
||||
* This class was created by <Vazkii>. It's distributed as
|
||||
* part of the Botania Mod. Get the Source Code in github:
|
||||
* https://github.com/Vazkii/Botania
|
||||
*
|
||||
* Botania is Open Source and distributed under the
|
||||
* Botania License: http://botaniamod.net/license.php
|
||||
*
|
||||
* File Created @ [Sep 1, 2015, 2:23:26 AM (GMT)]
|
||||
*/
|
||||
package vazkii.botania.common.item;
|
||||
|
||||
import net.minecraft.entity.Entity;
|
||||
import net.minecraft.entity.player.EntityPlayer;
|
||||
import net.minecraft.inventory.IInventory;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.util.ResourceLocation;
|
||||
import net.minecraft.world.World;
|
||||
import vazkii.botania.client.lib.LibResources;
|
||||
import vazkii.botania.common.lib.LibItemNames;
|
||||
|
||||
public class ItemAutocraftingHalo extends ItemCraftingHalo {
|
||||
|
||||
private static final ResourceLocation glowTexture = new ResourceLocation(LibResources.MISC_GLOW_CYAN);
|
||||
|
||||
public ItemAutocraftingHalo() {
|
||||
super(LibItemNames.AUTOCRAFTING_HALO);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onUpdate(ItemStack stack, World world, Entity entity, int pos, boolean equipped) {
|
||||
super.onUpdate(stack, world, entity, pos, equipped);
|
||||
|
||||
if(entity instanceof EntityPlayer && !equipped) {
|
||||
EntityPlayer player = (EntityPlayer) entity;
|
||||
IInventory inv = getFakeInv(player);
|
||||
|
||||
for(int i = 1; i < SEGMENTS; i++)
|
||||
tryCraft(player, stack, i, false, inv, false);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public ResourceLocation getGlowResource() {
|
||||
return glowTexture;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -42,6 +42,7 @@ import net.minecraft.util.Vec3;
|
||||
import net.minecraft.world.World;
|
||||
import net.minecraftforge.client.event.RenderWorldLastEvent;
|
||||
import net.minecraftforge.common.MinecraftForge;
|
||||
import net.minecraftforge.common.util.ForgeDirection;
|
||||
|
||||
import org.lwjgl.opengl.GL11;
|
||||
import org.lwjgl.opengl.GL12;
|
||||
@@ -64,10 +65,10 @@ import cpw.mods.fml.relauncher.SideOnly;
|
||||
|
||||
public class ItemCraftingHalo extends ItemMod {
|
||||
|
||||
private static final ResourceLocation glowTexture = new ResourceLocation(LibResources.MISC_GLOW_PINK);
|
||||
private static final ResourceLocation glowTexture = new ResourceLocation(LibResources.MISC_GLOW_GREEN);
|
||||
private static final ItemStack craftingTable = new ItemStack(Blocks.crafting_table);
|
||||
|
||||
private static final int SEGMENTS = 12;
|
||||
public static final int SEGMENTS = 12;
|
||||
|
||||
private static final String TAG_LAST_CRAFTING = "lastCrafting";
|
||||
private static final String TAG_STORED_RECIPE_PREFIX = "storedRecipe";
|
||||
@@ -76,11 +77,15 @@ public class ItemCraftingHalo extends ItemMod {
|
||||
private static final String TAG_ROTATION_BASE = "rotationBase";
|
||||
|
||||
public ItemCraftingHalo() {
|
||||
setUnlocalizedName(LibItemNames.CRAFTING_HALO);
|
||||
setMaxStackSize(1);
|
||||
this(LibItemNames.CRAFTING_HALO);
|
||||
MinecraftForge.EVENT_BUS.register(this);
|
||||
FMLCommonHandler.instance().bus().register(this);
|
||||
}
|
||||
|
||||
public ItemCraftingHalo(String name) {
|
||||
setUnlocalizedName(name);
|
||||
setMaxStackSize(1);
|
||||
}
|
||||
|
||||
@Override
|
||||
public ItemStack onItemRightClick(ItemStack stack, World world, EntityPlayer player) {
|
||||
@@ -92,11 +97,17 @@ public class ItemCraftingHalo extends ItemMod {
|
||||
else {
|
||||
if(itemForPos == null)
|
||||
assignRecipe(stack, itemForPos, segment);
|
||||
else tryCraft(player, stack, segment);
|
||||
else tryCraft(player, stack, segment, true, getFakeInv(player), true);
|
||||
}
|
||||
|
||||
return stack;
|
||||
}
|
||||
|
||||
public static IInventory getFakeInv(EntityPlayer player) {
|
||||
GenericInventory tempInv = new GenericInventory("temp", false, player.inventory.getSizeInventory() - 4);
|
||||
tempInv.copyFrom(player.inventory);
|
||||
return tempInv;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onUpdate(ItemStack stack, World world, Entity entity, int pos, boolean equipped) {
|
||||
@@ -112,11 +123,17 @@ public class ItemCraftingHalo extends ItemMod {
|
||||
}
|
||||
}
|
||||
|
||||
private void tryCraft(EntityPlayer player, ItemStack stack, int slot) {
|
||||
ItemStack[] recipe = validateRecipe(player, stack, getCraftingItems(stack, slot), slot);
|
||||
void tryCraft(EntityPlayer player, ItemStack stack, int slot, boolean particles, IInventory inv, boolean validate) {
|
||||
ItemStack itemForPos = getItemForSlot(stack, slot);
|
||||
if(itemForPos == null)
|
||||
return;
|
||||
|
||||
ItemStack[] recipe = getCraftingItems(stack, slot);
|
||||
if(validate)
|
||||
recipe = validateRecipe(player, stack, recipe, slot);
|
||||
|
||||
if(canCraft(player, recipe))
|
||||
doCraft(player, recipe);
|
||||
if(canCraft(player, recipe, inv))
|
||||
doCraft(player, recipe, particles);
|
||||
}
|
||||
|
||||
private static ItemStack[] validateRecipe(EntityPlayer player, ItemStack stack, ItemStack[] recipe, int slot) {
|
||||
@@ -138,20 +155,24 @@ public class ItemCraftingHalo extends ItemMod {
|
||||
return recipe;
|
||||
}
|
||||
|
||||
private static boolean canCraft(EntityPlayer player, ItemStack[] recipe) {
|
||||
private static boolean canCraft(EntityPlayer player, ItemStack[] recipe, IInventory inv) {
|
||||
if(recipe == null)
|
||||
return false;
|
||||
|
||||
GenericInventory tempInv = new GenericInventory("temp", false, player.inventory.getSizeInventory());
|
||||
tempInv.copyFrom(player.inventory);
|
||||
return consumeRecipeIngredients(recipe, tempInv, null);
|
||||
if(recipe[9].stackSize != InventoryHelper.testInventoryInsertion(inv, recipe[9], ForgeDirection.UNKNOWN))
|
||||
return false;
|
||||
|
||||
return consumeRecipeIngredients(recipe, inv, null);
|
||||
}
|
||||
|
||||
private static void doCraft(EntityPlayer player, ItemStack[] recipe) {
|
||||
private static void doCraft(EntityPlayer player, ItemStack[] recipe, boolean particles) {
|
||||
consumeRecipeIngredients(recipe, player.inventory, player);
|
||||
if(!player.inventory.addItemStackToInventory(recipe[9]))
|
||||
player.dropPlayerItemWithRandomChoice(recipe[9], false);
|
||||
|
||||
if(!particles)
|
||||
return;
|
||||
|
||||
Vec3 lookVec3 = player.getLookVec();
|
||||
Vector3 centerVector = Vector3.fromEntityCenter(player).add(lookVec3.xCoord * 3, 1.3, lookVec3.zCoord * 3);
|
||||
float m = 0.1F;
|
||||
@@ -281,7 +302,7 @@ public class ItemCraftingHalo extends ItemMod {
|
||||
|
||||
for(int i = 0; i < event.player.inventory.getSizeInventory(); i++) {
|
||||
ItemStack stack = event.player.inventory.getStackInSlot(i);
|
||||
if(stack != null && stack.getItem() == this)
|
||||
if(stack != null && stack.getItem() instanceof ItemCraftingHalo)
|
||||
saveRecipeToStack(event, stack);
|
||||
}
|
||||
}
|
||||
@@ -370,7 +391,7 @@ public class ItemCraftingHalo extends ItemMod {
|
||||
public void onRenderWorldLast(RenderWorldLastEvent event) {
|
||||
EntityPlayer player = Minecraft.getMinecraft().thePlayer;
|
||||
ItemStack stack = player.getCurrentEquippedItem();
|
||||
if(stack != null && stack.getItem() == this)
|
||||
if(stack != null && stack.getItem() instanceof ItemCraftingHalo)
|
||||
render(stack, player, event.partialTicks);
|
||||
}
|
||||
|
||||
@@ -463,7 +484,9 @@ public class ItemCraftingHalo extends ItemMod {
|
||||
GL11.glColor4f(0.6F, 0.6F, 0.6F, a);
|
||||
else GL11.glColor4f(1F, 1F, 1F, a);
|
||||
|
||||
mc.renderEngine.bindTexture(glowTexture);
|
||||
GL11.glDisable(GL11.GL_CULL_FACE);
|
||||
ItemCraftingHalo item = (ItemCraftingHalo) stack.getItem();
|
||||
mc.renderEngine.bindTexture(item.getGlowResource());
|
||||
tess.startDrawingQuads();
|
||||
for(int i = 0; i < segAngles; i++) {
|
||||
float ang = i + seg * segAngles + shift;
|
||||
@@ -481,12 +504,17 @@ public class ItemCraftingHalo extends ItemMod {
|
||||
}
|
||||
y0 = 0;
|
||||
tess.draw();
|
||||
|
||||
GL11.glEnable(GL11.GL_CULL_FACE);
|
||||
GL11.glPopMatrix();
|
||||
}
|
||||
GL11.glPopMatrix();
|
||||
}
|
||||
|
||||
@SideOnly(Side.CLIENT)
|
||||
public ResourceLocation getGlowResource() {
|
||||
return glowTexture;
|
||||
}
|
||||
|
||||
@SideOnly(Side.CLIENT)
|
||||
public static void renderHUD(ScaledResolution resolution, EntityPlayer player, ItemStack stack) {
|
||||
Minecraft mc = Minecraft.getMinecraft();
|
||||
@@ -558,7 +586,7 @@ public class ItemCraftingHalo extends ItemMod {
|
||||
}
|
||||
|
||||
int yoff = 110;
|
||||
if(setRecipe && !canCraft(player, recipe)) {
|
||||
if(setRecipe && !canCraft(player, recipe, getFakeInv(player))) {
|
||||
String warning = EnumChatFormatting.RED + StatCollector.translateToLocal("botaniamisc.cantCraft");
|
||||
mc.fontRenderer.drawStringWithShadow(warning, resolution.getScaledWidth() / 2 - mc.fontRenderer.getStringWidth(warning) / 2, resolution.getScaledHeight() / 2 - yoff, 0xFFFFFF);
|
||||
yoff += 12;
|
||||
|
||||
@@ -263,6 +263,7 @@ public final class ModItems {
|
||||
public static Item manaweaveChest;
|
||||
public static Item manaweaveLegs;
|
||||
public static Item manaweaveBoots;
|
||||
public static Item autocraftingHalo;
|
||||
|
||||
public static void init() {
|
||||
lexicon = new ItemLexicon();
|
||||
@@ -408,7 +409,8 @@ public final class ModItems {
|
||||
manaweaveLegs = new ItemManaweaveLegs();
|
||||
manaweaveChest = new ItemManaweaveChest();
|
||||
manaweaveBoots = new ItemManaweaveBoots();
|
||||
|
||||
autocraftingHalo = new ItemAutocraftingHalo();
|
||||
|
||||
OreDictionary.registerOre(LibOreDict.LEXICON, lexicon);
|
||||
for(int i = 0; i < 16; i++) {
|
||||
OreDictionary.registerOre(LibOreDict.PETAL[i], new ItemStack(petal, 1, i));
|
||||
|
||||
@@ -156,7 +156,8 @@ public final class LibItemNames {
|
||||
public static final String MANAWEAVE_CHEST = "manaweaveChest";
|
||||
public static final String MANAWEAVE_LEGS = "manaweaveLegs";
|
||||
public static final String MANAWEAVE_BOOTS = "manaweaveBoots";
|
||||
|
||||
public static final String AUTOCRAFTING_HALO = "autocraftingHalo";
|
||||
|
||||
public static final String[] LENS_NAMES = new String[] {
|
||||
"lensNormal",
|
||||
"lensSpeed",
|
||||
|
||||
Reference in new issue
Block a user