Smash up ores, get broken bits. Really broken!

This commit is contained in:
Alex Spinks committed 2015-08-01 02:33:58 +01:00
1 parent 72b260e758
commit bbf04e5542
8 files changed
+449 -1

No files matched your search

@@ -17,6 +17,7 @@ import fox.spiteful.avaritia.crafting.Grinder;
import fox.spiteful.avaritia.crafting.Mincer;
import fox.spiteful.avaritia.entity.LudicrousEntities;
import fox.spiteful.avaritia.gui.GooeyHandler;
import fox.spiteful.avaritia.items.ItemFracturedOre;
import fox.spiteful.avaritia.items.LudicrousItems;
import net.minecraft.creativetab.CreativeTabs;
import net.minecraft.init.Items;
@@ -62,6 +63,7 @@ public class Avaritia {
NetworkRegistry.INSTANCE.registerGuiHandler(instance, new GooeyHandler());
proxy.makeThingsPretty();
MinecraftForge.EVENT_BUS.register(new LudicrousEvents());
ItemFracturedOre.brushUpUncomfortablyAgainstTheOreDictionary();
}
@EventHandler
@@ -71,5 +73,6 @@ public class Avaritia {
Grinder.lastMinuteChanges();
Achievements.achieve();
PotionHelper.healthInspection();
}
}
@@ -8,6 +8,7 @@ import fox.spiteful.avaritia.entity.EntityGapingVoid;
import fox.spiteful.avaritia.items.LudicrousItems;
import fox.spiteful.avaritia.render.CosmicItemRenderer;
import fox.spiteful.avaritia.render.FancyHaloRenderer;
import fox.spiteful.avaritia.render.FracturedOreRenderer;
import fox.spiteful.avaritia.render.LudicrousRenderEvents;
import fox.spiteful.avaritia.render.RenderGapingVoid;
import fox.spiteful.avaritia.render.ShaderHelper;
@@ -38,6 +39,8 @@ public class ClientProxy extends CommonProxy {
MinecraftForgeClient.registerItemRenderer(LudicrousItems.infinity_pants, sparkly);
MinecraftForgeClient.registerItemRenderer(LudicrousItems.infinity_shoes, sparkly);
MinecraftForgeClient.registerItemRenderer(LudicrousItems.fractured_ore, new FracturedOreRenderer());
CompatClient.comprettify();
LudicrousRenderEvents fancyevents = new LudicrousRenderEvents();
@@ -27,6 +27,8 @@ import net.minecraftforge.event.entity.living.LivingHurtEvent;
import net.minecraftforge.event.entity.player.ItemTooltipEvent;
import net.minecraftforge.event.entity.player.PlayerEvent;
import net.minecraftforge.event.entity.player.PlayerInteractEvent;
import net.minecraftforge.oredict.OreDictionary;
import org.apache.logging.log4j.Level;
import java.util.ArrayList;
@@ -69,7 +71,7 @@ public class LudicrousEvents {
}
}
@SubscribeEvent
/*@SubscribeEvent
public void extraLuck(HarvestDropsEvent event){
if(event.harvester == null)
return;
@@ -100,6 +102,34 @@ public class LudicrousEvents {
event.dropChance = 1.0F;
}
}
}*/
public void extraLuck(HarvestDropsEvent event){
if(event.harvester == null)
return;
if(event.harvester.getHeldItem() == null)
return;
ItemStack held = event.harvester.getHeldItem();
if(held.getItem() == LudicrousItems.infinity_pickaxe){
if(event.block.getMaterial() == Material.rock){
for(ItemStack drop : event.drops){
if(drop.getItem() != Item.getItemFromBlock(event.block) && !(drop.getItem() instanceof ItemBlock)){
drop.stackSize = Math.min(drop.stackSize * 4, drop.getMaxStackSize());
}
else if(drop.getItem() == Item.getItemFromBlock(event.block))
{
int[] oreids = OreDictionary.getOreIDs(drop);
for (int i=0; i<oreids.length; i++) {
String orename = OreDictionary.getOreName(oreids[i]);
if (orename.startsWith("ore")) {
// add the fractured ores
break;
}
}
}
}
}
}
}
private void dropItem(ItemStack drop, World world, int x, int y, int z){
@@ -0,0 +1,178 @@
package fox.spiteful.avaritia.items;
import java.util.ArrayList;
import java.util.Collection;
import java.util.HashSet;
import java.util.List;
import java.util.Set;
import com.google.common.collect.HashMultimap;
import com.google.common.collect.Multimap;
import cpw.mods.fml.common.registry.GameRegistry;
import cpw.mods.fml.relauncher.Side;
import cpw.mods.fml.relauncher.SideOnly;
import fox.spiteful.avaritia.Avaritia;
import fox.spiteful.avaritia.Lumberjack;
import net.minecraft.creativetab.CreativeTabs;
import net.minecraft.item.Item;
import net.minecraft.item.ItemStack;
import net.minecraft.item.crafting.FurnaceRecipes;
import net.minecraft.nbt.NBTTagCompound;
import net.minecraft.util.StatCollector;
import net.minecraftforge.oredict.OreDictionary;
public class ItemFracturedOre extends Item {
public static final String OREKEY = "ore";
protected static List<ItemStack> emulatedOres = new ArrayList<ItemStack>();
public ItemFracturedOre() {
this.setCreativeTab(Avaritia.tab);
this.setUnlocalizedName("avaritia_fracturedore");
this.setTextureName("avaritia:fracturedore");
this.setHasSubtypes(true);
}
@SuppressWarnings({ "rawtypes", "unchecked" })
@SideOnly(Side.CLIENT)
@Override
public void getSubItems(Item item, CreativeTabs tab, List list)
{
for (ItemStack stack : emulatedOres) {
list.add(getStackForOre(stack, 1));
}
}
public ItemStack getStackForOre(ItemStack orestack, int stacksize) {
NBTTagCompound oretag = orestack.writeToNBT(new NBTTagCompound());
ItemStack outstack = new ItemStack(this, stacksize, 0);
NBTTagCompound stacktag = new NBTTagCompound();
stacktag.setTag(OREKEY, oretag);
outstack.setTagCompound(stacktag);
outstack.setItemDamage(this.getDamage(outstack));
return outstack;
}
@Override
public String getItemStackDisplayName(ItemStack stack)
{
if (stack.hasTagCompound() && stack.getTagCompound().hasKey(OREKEY)) {
ItemStack orestack = ItemStack.loadItemStackFromNBT(stack.getTagCompound().getCompoundTag(OREKEY));
return StatCollector.translateToLocal("item.avaritia_fracturedore.prefix") +" "+ orestack.getItem().getItemStackDisplayName(orestack);
}
return super.getItemStackDisplayName(stack);
}
@Override
public int getDamage(ItemStack stack) {
if (stack.hasTagCompound() && stack.getTagCompound().hasKey(OREKEY)) {
; NBTTagCompound tag = stack.getTagCompound().getCompoundTag(OREKEY);
int id = tag.getInteger("id");
int meta = tag.getInteger("Damage");
return meta + (id << 4);
}
return 0;
}
// ########################################
public static void brushUpUncomfortablyAgainstTheOreDictionary() {
String[] names = OreDictionary.getOreNames();
ItemFracturedOre fracore = (ItemFracturedOre)LudicrousItems.fractured_ore;
Multimap<String, ItemStack> toRegister = HashMultimap.create();
Set<ItemStackWrapper> antiDupePool = new HashSet<ItemStackWrapper>();
for (String name : names) {
if (name.startsWith("ore")) {
Lumberjack.info("ORE: "+name);
List<ItemStack> ores = OreDictionary.getOres(name);
for(ItemStack ore : ores) {
ItemStackWrapper compare = new ItemStackWrapper(ore);
if (!antiDupePool.contains(compare)) {
Lumberjack.info(ore);
antiDupePool.add(compare);
emulatedOres.add(ore.copy());
ItemStack frac = fracore.getStackForOre(ore, 1);
toRegister.put(name, frac);
}
}
}
}
for (String name : toRegister.keySet()) {
Collection<ItemStack> stacks = toRegister.get(name);
for (ItemStack stack : stacks) {
ItemStack orestack = ItemStack.loadItemStackFromNBT(stack.getTagCompound().getCompoundTag(OREKEY));
int[] oreids = OreDictionary.getOreIDs(orestack);
for (int i=0; i<oreids.length; i++) {
String oreidname = OreDictionary.getOreName(oreids[i]);
Lumberjack.info("Registering "+orestack.getItem().getItemStackDisplayName(orestack)+" ("+orestack+") ---> "+stack.getItem().getItemStackDisplayName(stack)+"#"+stack.getItemDamage()+" as "+oreidname);
OreDictionary.registerOre(oreidname, stack);
}
ItemStack smeltingResult = FurnaceRecipes.smelting().getSmeltingResult(orestack);
if (smeltingResult != null) {
float exp = FurnaceRecipes.smelting().func_151398_b(orestack);
Lumberjack.info("Registering "+stack+" to smelt to "+smeltingResult+" for "+exp+" experience");
GameRegistry.addSmelting(stack, smeltingResult, exp);
}
}
}
}
private static class ItemStackWrapper {
public final ItemStack stack;
public ItemStackWrapper(ItemStack stack) {
this.stack = stack;
}
@Override
public boolean equals(Object otherobj) {
if (otherobj instanceof ItemStackWrapper) {
ItemStackWrapper other = (ItemStackWrapper)otherobj;
if (this.stack.getItem().equals(other.stack.getItem())
&& this.stack.getItemDamage() == other.stack.getItemDamage()
) {
if (this.stack.stackTagCompound == null && other.stack.stackTagCompound == null) {
return true;
} else {
if (this.stack.stackTagCompound == null ^ other.stack.stackTagCompound == null) {
return false;
}
else if (this.stack.stackTagCompound.equals(other.stack.stackTagCompound)) {
return true;
}
}
}
}
return false;
}
@Override
public int hashCode() {
int h = this.stack.getItem().hashCode();
if (this.stack.stackTagCompound != null) {
h ^= this.stack.stackTagCompound.hashCode();
}
return h ^ this.stack.getItemDamage();
}
@Override
public String toString() {
return this.stack.toString();
}
}
}
@@ -27,6 +27,7 @@ public class LudicrousItems {
public static Item ultimate_stew;
public static Item cosmic_meatballs;
public static Item endest_pearl;
public static Item fractured_ore;
public static Item infinity_helm;
public static Item infinity_armor;
@@ -65,6 +66,8 @@ public class LudicrousItems {
GameRegistry.registerItem(infinity_pants, "Infinity_Pants");
infinity_shoes = new ItemArmorInfinity(3);
GameRegistry.registerItem(infinity_shoes, "Infinity_Shoes");
fractured_ore = new ItemFracturedOre();
GameRegistry.registerItem(fractured_ore, "Fractured_Ore");
MinecraftForge.EVENT_BUS.register(new ItemArmorInfinity.abilityHandler());
}
@@ -0,0 +1,229 @@
package fox.spiteful.avaritia.render;
import org.lwjgl.opengl.GL11;
import org.lwjgl.opengl.GL12;
import fox.spiteful.avaritia.items.ItemFracturedOre;
import net.minecraft.block.Block;
import net.minecraft.client.Minecraft;
import net.minecraft.client.renderer.ItemRenderer;
import net.minecraft.client.renderer.RenderHelper;
import net.minecraft.client.renderer.Tessellator;
import net.minecraft.client.renderer.entity.RenderItem;
import net.minecraft.client.renderer.texture.TextureMap;
import net.minecraft.item.Item;
import net.minecraft.item.ItemBlock;
import net.minecraft.item.ItemStack;
import net.minecraft.util.IIcon;
import net.minecraftforge.client.IItemRenderer;
public class FracturedOreRenderer implements IItemRenderer {
@Override
public boolean handleRenderType(ItemStack item, ItemRenderType type) {
//return type != ItemRenderType.INVENTORY;
return true;
}
@Override
public boolean shouldUseRenderHelper(ItemRenderType type, ItemStack item, ItemRendererHelper helper) {
return helper == ItemRendererHelper.ENTITY_ROTATION || helper == ItemRendererHelper.ENTITY_BOBBING;
}
@Override
public void renderItem(ItemRenderType type, ItemStack item, Object... data) {
Minecraft mc = Minecraft.getMinecraft();
switch(type) {
case ENTITY : {
GL11.glPushMatrix();
GL11.glTranslatef(-0.5F, 0F, 0F);
if(item.isOnItemFrame())
GL11.glTranslatef(0F, -0.3F, 0.01F);
render(item);
GL11.glPopMatrix();
break;
}
case EQUIPPED : {
render(item);
break;
}
case EQUIPPED_FIRST_PERSON : {
render(item);
break;
}
case INVENTORY: {
GL11.glPushMatrix();
RenderHelper.enableGUIStandardItemLighting();
//GL11.glDisable(GL11.GL_DEPTH_TEST);
GL11.glEnable(GL11.GL_ALPHA_TEST);
RenderItem r = RenderItem.getInstance();
r.renderItemIntoGUI(mc.fontRenderer, mc.getTextureManager(), item, 0, 0, true);
GL11.glDisable(GL11.GL_ALPHA_TEST);
if (item.hasTagCompound() && item.getTagCompound().hasKey(ItemFracturedOre.OREKEY)) {
ItemStack orestack = ItemStack.loadItemStackFromNBT(item.getTagCompound().getCompoundTag(ItemFracturedOre.OREKEY));
mc.renderEngine.bindTexture(TextureMap.locationBlocksTexture);
Item oreitem = orestack.getItem();
if (oreitem instanceof ItemBlock) {
ItemBlock ib = (ItemBlock)oreitem;
Block b = ib.field_150939_a;
IIcon oreicon = b.getIcon(0, orestack.getItemDamage());
float minu = oreicon.getMinU();
float maxu = oreicon.getMaxU();
float minv = oreicon.getMinV();
float maxv = oreicon.getMaxV();
Tessellator t = Tessellator.instance;
t.startDrawingQuads();
t.addVertexWithUV(0, 0, 0, minu, minv);
t.addVertexWithUV(0, 16, 0, minu, maxv);
t.addVertexWithUV(16, 16, 0, maxu, maxv);
t.addVertexWithUV(16, 0, 0, maxu, minv);
GL11.glDepthFunc(GL11.GL_EQUAL);
t.draw();
GL11.glDepthFunc(GL11.GL_LEQUAL);
mc.renderEngine.bindTexture(TextureMap.locationItemsTexture);
}
}
GL11.glDisable(GL11.GL_LIGHTING);
GL11.glEnable(GL11.GL_BLEND);
GL11.glBlendFunc(GL11.GL_SRC_ALPHA, GL11.GL_ONE);
GL11.glColor4d(1, 1, 1, 0.2);
IIcon fracicon = item.getItem().getIcon(item, 0);
float minu = fracicon.getMinU();
float maxu = fracicon.getMaxU();
float minv = fracicon.getMinV();
float maxv = fracicon.getMaxV();
Tessellator t = Tessellator.instance;
t.startDrawingQuads();
t.addVertexWithUV(0, 0, 0, minu, minv);
t.addVertexWithUV(0, 16, 0, minu, maxv);
t.addVertexWithUV(16, 16, 0, maxu, maxv);
t.addVertexWithUV(16, 0, 0, maxu, minv);
t.draw();
GL11.glEnable(GL11.GL_ALPHA_TEST);
GL11.glBlendFunc(GL11.GL_DST_COLOR, GL11.GL_ONE_MINUS_SRC_ALPHA);
GL11.glColor4d(1, 1, 1, 1);
t.startDrawingQuads();
t.addVertexWithUV(0, 0, 0, minu, minv);
t.addVertexWithUV(0, 16, 0, minu, maxv);
t.addVertexWithUV(16, 16, 0, maxu, maxv);
t.addVertexWithUV(16, 0, 0, maxu, minv);
t.draw();
GL11.glEnable(GL12.GL_RESCALE_NORMAL);
GL11.glEnable(GL11.GL_DEPTH_TEST);
r.renderWithColor = true;
GL11.glDisable(GL11.GL_BLEND);
GL11.glPopMatrix();
break;
}
default : break;
}
}
public void render(ItemStack item) {
Minecraft mc = Minecraft.getMinecraft();
GL11.glPushMatrix();
GL11.glEnable(GL11.GL_BLEND);
GL11.glBlendFunc(GL11.GL_SRC_ALPHA, GL11.GL_ONE_MINUS_SRC_ALPHA);
GL11.glColor4f(1F, 1F, 1F, 1F);
IIcon icon;
float f,f1,f2,f3;
float scale = 1F / 16F;
GL11.glColor4f(1F, 1F, 1F, 1F);
icon = item.getItem().getIcon(item, 0);
f = icon.getMinU();
f1 = icon.getMaxU();
f2 = icon.getMinV();
f3 = icon.getMaxV();
ItemRenderer.renderItemIn2D(Tessellator.instance, f1, f2, f, f3, icon.getIconWidth(), icon.getIconHeight(), scale);
if (item.hasTagCompound() && item.getTagCompound().hasKey(ItemFracturedOre.OREKEY)) {
ItemStack orestack = ItemStack.loadItemStackFromNBT(item.getTagCompound().getCompoundTag(ItemFracturedOre.OREKEY));
mc.renderEngine.bindTexture(TextureMap.locationBlocksTexture);
Item oreitem = orestack.getItem();
if (oreitem instanceof ItemBlock) {
ItemBlock ib = (ItemBlock)oreitem;
Block b = ib.field_150939_a;
IIcon oreicon = b.getIcon(0, orestack.getItemDamage());
//IIcon oreicon = item.getIconIndex();
float minu = oreicon.getMinU();
float maxu = oreicon.getMaxU();
float minv = oreicon.getMinV();
float maxv = oreicon.getMaxV();
GL11.glDepthFunc(GL11.GL_EQUAL);
ItemRenderer.renderItemIn2D(Tessellator.instance, maxu, minv, minu, maxv, icon.getIconWidth(), icon.getIconHeight(), scale);
GL11.glDepthFunc(GL11.GL_LEQUAL);
mc.renderEngine.bindTexture(TextureMap.locationItemsTexture);
}
}
GL11.glDisable(GL11.GL_LIGHTING);
GL11.glEnable(GL11.GL_BLEND);
GL11.glBlendFunc(GL11.GL_SRC_ALPHA, GL11.GL_ONE);
GL11.glColor4d(1, 1, 1, 0.2);
IIcon fracicon = item.getItem().getIcon(item, 0);
float minu = fracicon.getMinU();
float maxu = fracicon.getMaxU();
float minv = fracicon.getMinV();
float maxv = fracicon.getMaxV();
ItemRenderer.renderItemIn2D(Tessellator.instance, maxu, minv, minu, maxv, icon.getIconWidth(), icon.getIconHeight(), scale);
GL11.glEnable(GL11.GL_ALPHA_TEST);
GL11.glBlendFunc(GL11.GL_DST_COLOR, GL11.GL_ONE_MINUS_SRC_ALPHA);
GL11.glColor4d(1, 1, 1, 1);
mc.entityRenderer.disableLightmap(0.0);
ItemRenderer.renderItemIn2D(Tessellator.instance, maxu, minv, minu, maxv, icon.getIconWidth(), icon.getIconHeight(), scale);
GL11.glEnable(GL12.GL_RESCALE_NORMAL);
GL11.glEnable(GL11.GL_DEPTH_TEST);
GL11.glDisable(GL11.GL_BLEND);
GL11.glPopMatrix();
GL11.glColor4f(1F, 1F, 1F, 1F);
if (!CosmicRenderShenanigans.inventoryRender) {
mc.entityRenderer.enableLightmap(0.0);
}
}
}