This commit is contained in:
tterrag1098 committed 2014-12-09 03:10:57 -05:00
commit 6fdd14788c
8 files changed
+90 -81

No files matched your search

@@ -1,58 +1,30 @@
package crazypants.enderio.item.darksteel;
import java.lang.reflect.Method;
import java.util.ArrayList;
import java.util.ConcurrentModificationException;
import java.util.HashMap;
import java.util.LinkedList;
import java.util.List;
import java.util.ListIterator;
import java.util.Map;
import org.lwjgl.opengl.GL11;
import java.util.concurrent.ArrayBlockingQueue;
import net.minecraft.client.Minecraft;
import net.minecraft.client.entity.EntityClientPlayerMP;
import net.minecraft.client.gui.ScaledResolution;
import net.minecraft.client.renderer.EntityRenderer;
import net.minecraft.client.renderer.Tessellator;
import net.minecraft.entity.Entity;
import net.minecraft.entity.EntityLiving;
import net.minecraft.entity.EntityLivingBase;
import net.minecraft.util.AxisAlignedBB;
import net.minecraft.util.IIcon;
import net.minecraft.util.MovingObjectPosition;
import net.minecraft.util.Vec3;
import net.minecraftforge.client.event.sound.PlaySoundEvent17;
import net.minecraftforge.client.event.sound.PlaySoundSourceEvent;
import net.minecraftforge.client.event.sound.SoundEvent;
import net.minecraftforge.client.event.sound.SoundEvent.SoundSourceEvent;
import net.minecraftforge.event.entity.PlaySoundAtEntityEvent;
import cpw.mods.fml.common.eventhandler.SubscribeEvent;
import cpw.mods.fml.common.gameevent.TickEvent;
import cpw.mods.fml.common.gameevent.TickEvent.Phase;
import cpw.mods.fml.common.gameevent.TickEvent.RenderTickEvent;
import cpw.mods.fml.relauncher.Side;
import cpw.mods.fml.relauncher.SideOnly;
import crazypants.enderio.config.Config;
import crazypants.render.BoundingBox;
import crazypants.render.CubeRenderer;
import crazypants.render.IconUtil;
import crazypants.render.RenderUtil;
import crazypants.util.BlockCoord;
import crazypants.util.Util;
import crazypants.vecmath.Camera;
import crazypants.vecmath.Matrix4d;
import crazypants.vecmath.Vector3d;
import crazypants.vecmath.ViewFrustum;
public class SoundDetector {
private static final int MAX_ENTITIES = 64;
public static SoundDetector instance = new SoundDetector();
private List<SoundSource> soundQueue = new ArrayList<SoundDetector.SoundSource>();
private List<SoundSource> sounds = new LinkedList<SoundSource>();
private List<SoundSource> sounds;
private ArrayBlockingQueue<SoundSource> soundQueue = new ArrayBlockingQueue<SoundSource>(MAX_ENTITIES);
private Minecraft mc = Minecraft.getMinecraft();
@@ -62,15 +34,15 @@ public class SoundDetector {
@SubscribeEvent
public void onSound(PlaySoundAtEntityEvent evt) {
if(enabled && evt.entity != null && evt.entity != Minecraft.getMinecraft().thePlayer) {
soundQueue.add(new SoundSource(evt.entity, evt.volume));
if(enabled && evt.entity != null && evt.entity != Minecraft.getMinecraft().thePlayer && soundQueue.size() < MAX_ENTITIES) {
soundQueue.offer(new SoundSource(evt.entity, evt.volume));
}
}
@SubscribeEvent
public void onSound(PlaySoundSourceEvent evt) {
if(enabled) {
soundQueue.add(new SoundSource(evt.sound.getXPosF(), evt.sound.getYPosF(), evt.sound.getZPosF(), evt.sound.getVolume()));
if(enabled && soundQueue.size() < MAX_ENTITIES) {
soundQueue.offer(new SoundSource(evt.sound.getXPosF(), evt.sound.getYPosF(), evt.sound.getZPosF(), evt.sound.getVolume()));
}
}
@@ -82,9 +54,8 @@ public class SoundDetector {
return;
}
List<SoundSource> tmp = soundQueue;
soundQueue = sounds;
sounds = tmp;
sounds = new ArrayList<SoundSource>(MAX_ENTITIES);
soundQueue.drainTo(sounds);
try {
Vector3d eye = Util.getEyePositionEio(mc.thePlayer);
@@ -95,13 +66,9 @@ public class SoundDetector {
mc.thePlayer.worldObj.spawnEntityInWorld(new SoundEntity(mc.thePlayer.worldObj, ss.pos, ss.volume));
}
}
sounds.clear();
} catch (Exception ex) {
//very small chance of getting an exception here due to non synchronized swapping of the lists
//Just catching and ignoring this is the lesser of the two evils compared to the cost of syncronizing the lists
//TODO: Maybe look at the impact of using atomic references
//Probably not necessary anymore but saftey first!
}
}
public boolean isEnabled() {
@@ -1,26 +1,18 @@
package crazypants.enderio.item.darksteel;
import net.minecraft.client.Minecraft;
import net.minecraft.client.entity.EntityClientPlayerMP;
import net.minecraft.client.renderer.OpenGlHelper;
import net.minecraft.client.renderer.entity.RenderEntity;
import net.minecraft.entity.Entity;
import org.lwjgl.opengl.GL11;
import crazypants.enderio.gui.IconEIO;
import crazypants.render.BoundingBox;
import crazypants.render.CubeRenderer;
import crazypants.render.IconUtil;
import crazypants.render.RenderUtil;
import crazypants.vecmath.Matrix4d;
import crazypants.vecmath.Vector3d;
import net.minecraft.client.Minecraft;
import net.minecraft.client.entity.EntityClientPlayerMP;
import net.minecraft.client.renderer.Tessellator;
import net.minecraft.client.renderer.entity.Render;
import net.minecraft.client.renderer.entity.RenderEntity;
import net.minecraft.entity.Entity;
import net.minecraft.entity.EntityLivingBase;
import net.minecraft.util.IIcon;
import net.minecraft.util.ResourceLocation;
public class SoundRenderer extends RenderEntity {
@Override
public void doRender(Entity entity, double x, double y, double z, float p_76986_8_, float p_76986_9_) {
SoundEntity se = ((SoundEntity) entity);
@@ -29,8 +21,10 @@ public class SoundRenderer extends RenderEntity {
GL11.glDisable(GL11.GL_DEPTH_TEST);
GL11.glDisable(GL11.GL_LIGHTING);
GL11.glEnable(GL11.GL_BLEND);
GL11.glBlendFunc(GL11.GL_SRC_ALPHA, GL11.GL_ONE_MINUS_SRC_ALPHA);
//float alpha = Math.min(1, se.volume) * 0.5f;
OpenGlHelper.setLightmapTextureCoords(OpenGlHelper.lightmapTexUnit, 240, 240);
float alpha = 0.5f;
GL11.glColor4f(1, 1, 1, alpha);
@@ -10,6 +10,7 @@ import cpw.mods.fml.common.registry.GameRegistry;
import crazypants.enderio.EnderIO;
import crazypants.enderio.config.Config;
import crazypants.enderio.item.skull.BlockEndermanSkull;
import crazypants.enderio.machine.capbank.BlockItemCapBank;
import crazypants.enderio.machine.capbank.CapBankType;
import crazypants.enderio.machine.capbank.ConvertOldRecipe;
import crazypants.enderio.machine.light.BlockItemElectricLight;
@@ -131,18 +132,12 @@ public class MachineRecipes {
GameRegistry.addShapedRecipe(still, "eve", "tmt", "efe", 'v', Items.cauldron, 'm', machineChassi, 'e', electricSteel, 'f', Blocks.furnace, 't', basicTank);
//capacitor bank
// ItemStack capacitorBank = new ItemStack(EnderIO.blockCapacitorBank, 1, 0);
// if(Config.useHardRecipes) {
// GameRegistry.addRecipe(new ShapedOreRecipe(capacitorBank, "rcr", "ccc", "rMr", 'm', electricSteel, 'c', capacitor2, 'r', Blocks.redstone_block, 'M',
// machineChassi));
// } else {
// GameRegistry.addRecipe(new ShapedOreRecipe(capacitorBank, "mcm", "crc", "mcm", 'm', electricSteel, 'c', capacitor2, 'r', Blocks.redstone_block));
// }
ItemStack capBank = new ItemStack(EnderIO.blockCapBank, 1, CapBankType.getMetaFromType(CapBankType.SIMPLE));
ItemStack capBank = BlockItemCapBank.createItemStackWithPower(CapBankType.getMetaFromType(CapBankType.SIMPLE), 0);
GameRegistry.addShapedRecipe(capBank, "bcb", "cmc", "bcb", 'b', Items.iron_ingot, 'c', capacitor, 'm', Blocks.redstone_block);
capBank = new ItemStack(EnderIO.blockCapBank, 1, CapBankType.getMetaFromType(CapBankType.ACTIVATED));
capBank = BlockItemCapBank.createItemStackWithPower(CapBankType.getMetaFromType(CapBankType.ACTIVATED), 0);
GameRegistry.addShapedRecipe(capBank, "bcb", "cmc", "bcb", 'b', electricSteel, 'c', capacitor2, 'm', Blocks.redstone_block);
capBank = new ItemStack(EnderIO.blockCapBank, 1, CapBankType.getMetaFromType(CapBankType.VIBRANT));
capBank = BlockItemCapBank.createItemStackWithPower(CapBankType.getMetaFromType(CapBankType.VIBRANT), 0);
GameRegistry.addShapedRecipe(capBank, "bcb", "cmc", "bcb", 'b', electricSteel, 'c', capacitor3, 'm', vibCry);
ConvertOldRecipe convertRecipe = new ConvertOldRecipe();
@@ -101,7 +101,7 @@ public class TileCrusher extends AbstractPoweredTaskEntity {
if(gb != null) {
useGrindingBall = !CrusherRecipeManager.getInstance().isExcludedFromBallBonus(getRecipeInputs());
if(useGrindingBall) {
res = new PoweredTask(nextRecipe, chance * gb.getChanceMultiplier(), getRecipeInputs());
res = new PoweredTask(nextRecipe, chance / gb.getChanceMultiplier(), getRecipeInputs());
res.setRequiredEnergy(res.getRequiredEnergy() * gb.getPowerMultiplier());
} else {
res = new PoweredTask(nextRecipe, chance, getRecipeInputs());
@@ -1,10 +1,13 @@
package crazypants.enderio.machine.spawner;
import java.lang.reflect.Field;
import java.util.ArrayList;
import java.util.List;
import net.minecraft.block.BlockMobSpawner;
import net.minecraft.creativetab.CreativeTabs;
import net.minecraft.entity.Entity;
import net.minecraft.entity.EntityLiving;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.item.Item;
import net.minecraft.item.ItemStack;
@@ -16,6 +19,7 @@ import net.minecraft.util.StatCollector;
import net.minecraft.world.World;
import net.minecraftforge.common.MinecraftForge;
import net.minecraftforge.event.AnvilUpdateEvent;
import net.minecraftforge.event.entity.living.LivingEvent.LivingUpdateEvent;
import net.minecraftforge.event.world.BlockEvent;
import net.minecraftforge.event.world.BlockEvent.BreakEvent;
import cpw.mods.fml.common.FMLCommonHandler;
@@ -23,10 +27,12 @@ import cpw.mods.fml.common.eventhandler.SubscribeEvent;
import cpw.mods.fml.common.gameevent.TickEvent;
import cpw.mods.fml.common.registry.GameRegistry;
import cpw.mods.fml.common.registry.GameRegistry.UniqueIdentifier;
import cpw.mods.fml.relauncher.ReflectionHelper;
import cpw.mods.fml.relauncher.Side;
import cpw.mods.fml.relauncher.SideOnly;
import crazypants.enderio.EnderIO;
import crazypants.enderio.GuiHandler;
import crazypants.enderio.Log;
import crazypants.enderio.ModObject;
import crazypants.enderio.config.Config;
import crazypants.enderio.gui.IAdvancedTooltipProvider;
@@ -68,6 +74,8 @@ public class BlockPoweredSpawner extends AbstractMachineBlock<TilePoweredSpawner
return readMobTypeFromNBT(stack.stackTagCompound);
}
public static final String KEY_SPAWNED_BY_POWERED_SPAWNER = "spawnedByPoweredSpawner";
public static BlockPoweredSpawner create() {
MachineRecipeRegistry.instance.registerRecipe(ModObject.blockPoweredSpawner.unlocalisedName, new DummyRecipe());
@@ -86,6 +94,8 @@ public class BlockPoweredSpawner extends AbstractMachineBlock<TilePoweredSpawner
private final List<DropInfo> dropQueue = new ArrayList<BlockPoweredSpawner.DropInfo>();
private final List<UniqueIdentifier> toolBlackList = new ArrayList<UniqueIdentifier>();
private Field fieldpersistenceRequired;
protected BlockPoweredSpawner() {
super(ModObject.blockPoweredSpawner, TilePoweredSpawner.class);
@@ -93,6 +103,12 @@ public class BlockPoweredSpawner extends AbstractMachineBlock<TilePoweredSpawner
for (String name : blackListNames) {
toolBlackList.add(new UniqueIdentifier(name));
}
try {
fieldpersistenceRequired = ReflectionHelper.findField(EntityLiving.class, "field_82179_bU", "persistenceRequired");
} catch (Exception e) {
Log.error("BlockPoweredSpawner: Could not find field: persistenceRequired");
}
}
@SubscribeEvent
@@ -163,6 +179,31 @@ public class BlockPoweredSpawner extends AbstractMachineBlock<TilePoweredSpawner
}
@SubscribeEvent
public void onLivingUpdate(LivingUpdateEvent livingUpdate) {
Entity ent = livingUpdate.entityLiving;
if(!ent.getEntityData().hasKey(KEY_SPAWNED_BY_POWERED_SPAWNER)) {
return;
}
if(fieldpersistenceRequired == null) {
ent.getEntityData().removeTag(KEY_SPAWNED_BY_POWERED_SPAWNER);
return;
}
long spawnTime = ent.getEntityData().getLong(KEY_SPAWNED_BY_POWERED_SPAWNER);
long livedFor = livingUpdate.entity.worldObj.getTotalWorldTime() - spawnTime;
if(livedFor > 1200) { //after two minutes stop forcing it to be around
try {
fieldpersistenceRequired.setBoolean(livingUpdate.entityLiving, false);
ent.getEntityData().removeTag(KEY_SPAWNED_BY_POWERED_SPAWNER);
} catch (Exception e) {
Log.warn("BlockPoweredSpawner.onLivingUpdate: Error occured allowing entity to despawn: " + e);
ent.getEntityData().removeTag(KEY_SPAWNED_BY_POWERED_SPAWNER);
}
}
}
public boolean isBlackListed(String entityId) {
return PoweredSpawnerConfig.getInstance().isBlackListed(entityId);
}
@@ -73,7 +73,7 @@ public class TilePoweredSpawner extends AbstractPoweredTaskEntity {
if(getStackInSlot(0) == null || getStackInSlot(1) != null) {
return;
}
Entity ent = logic.createEntity();
Entity ent = logic.createEntity(false);
if(ent == null) {
return;
}
@@ -340,7 +340,7 @@ public class TilePoweredSpawner extends AbstractPoweredTaskEntity {
for (int i = 0; i < spawnCount; ++i) {
Entity entity = createEntity();
Entity entity = createEntity(true);
if(entity == null) {
return;
}
@@ -375,8 +375,13 @@ public class TilePoweredSpawner extends AbstractPoweredTaskEntity {
}
}
Entity createEntity() {
return EntityList.createEntityByName(getEntityNameToSpawn(), getSpawnerWorld());
Entity createEntity(boolean forceAlive) {
Entity ent = EntityList.createEntityByName(getEntityNameToSpawn(), getSpawnerWorld());
if(forceAlive && MIN_PLAYER_DISTANCE <= 0 && ent instanceof EntityLiving) {
ent.getEntityData().setLong(BlockPoweredSpawner.KEY_SPAWNED_BY_POWERED_SPAWNER, getSpawnerWorld().getTotalWorldTime());
((EntityLiving) ent).func_110163_bv();
}
return ent;
}
void resetTimer() {
@@ -50,7 +50,7 @@ public class BlockFusedQuartz extends BlockEio {
}
public boolean connectTo(int otherMeta) {
if (otherMeta == this.ordinal()) {
if (otherMeta == ordinal()) {
return true;
}
@@ -95,8 +95,8 @@ public class BlockFusedQuartz extends BlockEio {
@Override
public float getExplosionResistance(Entity par1Entity, World world, int x, int y, int z, double explosionX, double explosionY, double explosionZ) {
int meta = world.getBlockMetadata(x, y, z);
meta = MathHelper.clamp_int(meta, 0, 1);
if(meta == 0) {
meta = MathHelper.clamp_int(meta, 0, Type.values().length - 1);
if(meta == Type.FUSED_QUARTZ.ordinal() || meta == Type.ENLIGHTENED_FUSED_QUARTZ.ordinal()) {
return 2000;
} else {
return super.getExplosionResistance(par1Entity);