This commit is contained in:
tterrag1098 committed 2014-10-17 20:58:25 -04:00
commit 21f0213c2d
16 files changed
+485 -72

No files matched your search

@@ -9,6 +9,8 @@ import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.entity.player.EntityPlayerMP;
import net.minecraft.init.Blocks;
import net.minecraft.item.Item;
import net.minecraft.potion.Potion;
import net.minecraft.potion.PotionEffect;
import net.minecraft.util.IIcon;
import net.minecraft.world.World;
import net.minecraftforge.client.MinecraftForgeClient;
@@ -45,7 +47,9 @@ import crazypants.enderio.conduit.render.ItemConduitRenderer;
import crazypants.enderio.config.Config;
import crazypants.enderio.enderface.EnderIoRenderer;
import crazypants.enderio.enderface.TileEnderIO;
import crazypants.enderio.entity.EntityEnderCreeper;
import crazypants.enderio.entity.EntityEnderminy;
import crazypants.enderio.entity.RenderEnderCreeper;
import crazypants.enderio.entity.RenderEnderminy;
import crazypants.enderio.gui.TooltipAddera;
import crazypants.enderio.item.ConduitProbeOverlayRenderer;
@@ -396,11 +400,13 @@ public class ClientProxy extends CommonProxy {
}
});
}
RenderingRegistry.registerEntityRenderingHandler(EntityEnderminy.class, new RenderEnderminy());
}
if(Config.enderminyEnabled) {
RenderingRegistry.registerEntityRenderingHandler(EntityEnderminy.class, new RenderEnderminy());
}
if(Config.enderCreeperEnabled) {
RenderingRegistry.registerEntityRenderingHandler(EntityEnderCreeper.class, new RenderEnderCreeper());
}
}
@Override
@@ -420,5 +426,10 @@ public class ClientProxy extends CommonProxy {
}
return super.getReachDistanceForPlayer(entityPlayer);
}
public void setInstantConfusionOnPlayer(EntityPlayer ent, int duration) {
ent.addPotionEffect(new PotionEffect(Potion.confusion.getId(), duration, 1, true));
Minecraft.getMinecraft().thePlayer.timeInPortal = 1;
}
}
@@ -3,6 +3,8 @@ package crazypants.enderio;
import java.text.DecimalFormat;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.potion.Potion;
import net.minecraft.potion.PotionEffect;
import net.minecraft.world.World;
import crazypants.enderio.conduit.IConduit;
import crazypants.enderio.conduit.render.ConduitRenderer;
@@ -38,4 +40,8 @@ public class CommonProxy {
return false;
}
public void setInstantConfusionOnPlayer(EntityPlayer ent, int duration) {
ent.addPotionEffect(new PotionEffect(Potion.confusion.getId(), duration, 1, true));
}
}
+55 -23
View File
@@ -61,6 +61,7 @@ import crazypants.enderio.config.Config;
import crazypants.enderio.enderface.BlockEnderIO;
import crazypants.enderio.enderface.EnderfaceRecipes;
import crazypants.enderio.enderface.ItemEnderface;
import crazypants.enderio.entity.EntityEnderCreeper;
import crazypants.enderio.entity.EntityEnderminy;
import crazypants.enderio.entity.ItemSpawnEgg;
import crazypants.enderio.fluid.BlockFluidEio;
@@ -323,7 +324,7 @@ public class EnderIO {
blockTank = BlockTank.create();
blockReservoir = BlockReservoir.create();
blockVacuumChest = BlockVacuumChest.create();
blockTransceiver = BlockTransceiver.create();
blockEnderIo = BlockEnderIO.create();
@@ -400,21 +401,7 @@ public class EnderIO {
itemDarkSteelPickaxe = ItemDarkSteelPickaxe.create();
itemDarkSteelAxe = ItemDarkSteelAxe.create();
if(Config.enderminyEnabled) {
itemSpawnEgg = ItemSpawnEgg.create();
int rate = Config.enderminySpawnRate;
EntityRegistry.registerModEntity(EntityEnderminy.class, EntityEnderminy.NAME, 0, this, 32, 1, true);
BiomeGenBase[] biomes = BiomeDictionary.getBiomesForType(BiomeDictionary.Type.FOREST);
EntityRegistry.addSpawn(EntityEnderminy.class, rate, 1, Config.enderminyMaxGroupSize, EnumCreatureType.monster, biomes);
biomes = BiomeDictionary.getBiomesForType(BiomeDictionary.Type.SWAMP);
EntityRegistry.addSpawn(EntityEnderminy.class, rate, 1, Config.enderminyMaxGroupSize, EnumCreatureType.monster, biomes);
biomes = BiomeDictionary.getBiomesForType(BiomeDictionary.Type.JUNGLE);
EntityRegistry.addSpawn(EntityEnderminy.class, rate, 1, Config.enderminyMaxGroupSize, EnumCreatureType.monster, biomes);
}
MaterialRecipes.registerOresInDictionary();
registerMobs();
int entityID = EntityRegistry.findGlobalUniqueEntityId();
EntityRegistry.registerGlobalEntityID(SoundEntity.class, "soundEntity", entityID);
@@ -425,6 +412,51 @@ public class EnderIO {
EntityRegistry.registerModEntity(RangeEntity.class, "rangeEntity", entityID, this, 0, 0, false);
FMLInterModComms.sendMessage("Waila", "register", "crazypants.enderio.waila.WailaCompat.load");
MaterialRecipes.registerOresInDictionary();
}
private void registerMobs() {
if(Config.enderminyEnabled || Config.enderCreeperEnabled) {
itemSpawnEgg = ItemSpawnEgg.create();
}
if(Config.enderminyEnabled) {
int rate = Config.enderminySpawnRate;
EntityRegistry.registerModEntity(EntityEnderminy.class, EntityEnderminy.NAME, 0, this, 32, 1, true);
BiomeGenBase[] biomes = BiomeDictionary.getBiomesForType(BiomeDictionary.Type.FOREST);
EntityRegistry.addSpawn(EntityEnderminy.class, rate, 1, Config.enderminyMaxGroupSize, EnumCreatureType.monster, biomes);
biomes = BiomeDictionary.getBiomesForType(BiomeDictionary.Type.SWAMP);
EntityRegistry.addSpawn(EntityEnderminy.class, rate, 1, Config.enderminyMaxGroupSize, EnumCreatureType.monster, biomes);
biomes = BiomeDictionary.getBiomesForType(BiomeDictionary.Type.JUNGLE);
EntityRegistry.addSpawn(EntityEnderminy.class, rate, 1, Config.enderminyMaxGroupSize, EnumCreatureType.monster, biomes);
rate = Config.enderminySpawnRate;
EntityRegistry.registerModEntity(EntityEnderminy.class, EntityEnderminy.NAME, 0, this, 32, 1, true);
}
if(Config.enderCreeperEnabled) {
BiomeDictionary.Type[] biomeTypes = new BiomeDictionary.Type[] {
BiomeDictionary.Type.MESA,
BiomeDictionary.Type.FOREST,
BiomeDictionary.Type.PLAINS,
BiomeDictionary.Type.MOUNTAIN,
BiomeDictionary.Type.HILLS,
BiomeDictionary.Type.SWAMP,
BiomeDictionary.Type.SANDY,
BiomeDictionary.Type.SNOWY,
BiomeDictionary.Type.WASTELAND,
BiomeDictionary.Type.BEACH,
};
int rate = Config.enderCreeperSpawnRate;
for (BiomeDictionary.Type type : biomeTypes) {
BiomeGenBase[] biomes = BiomeDictionary.getBiomesForType(type);
EntityRegistry.addSpawn(EntityEnderCreeper.class, rate, 1, 2, EnumCreatureType.monster, biomes);
}
int entityID = EntityRegistry.findGlobalUniqueEntityId();
EntityRegistry.registerModEntity(EntityEnderCreeper.class, EntityEnderCreeper.NAME, entityID, this, 32, 1, true);
}
}
private void registerFluids() {
@@ -585,23 +617,23 @@ public class EnderIO {
Log.error("Liquid XP registration left to open blocks but could not be found.");
}
}
if(Config.dumpMobNames) {
File dumpFile = new File(Config.configDirectory, "mobTypes.txt");
List<String> names = EntityUtil.getAllRegisteredMobNames(false);
try{
try {
BufferedWriter br = new BufferedWriter(new FileWriter(dumpFile, false));
for(String name : names) {
for (String name : names) {
br.append(name);
br.newLine();
}
br.flush();
br.close();
}catch(Exception e) {
br.close();
} catch (Exception e) {
Log.error("Could not write mob types file: " + e);
}
}
}
@@ -354,10 +354,21 @@ public final class Config {
public static int enderminyHealth = 20;
public static boolean enderminyGroupAgro = true;
public static int enderminyMaxGroupSize = 3;
public static boolean enderminySpawnInLitAreas = false;
public static boolean enderminySpawnInLitAreas = false;
public static boolean enderminySpawnOnlyOnGrass = true;
public static int enderminyMinSpawnY = 0;
public static boolean enderCreeperEnabled = true;
public static int enderCreeperSpawnRate = 60;
public static int enderCreeperMaxTeleportRange = 32;
public static int enderCreeperConfusionDuration = 100;
public static int enderCreeperExplosionRange = 5;
public static boolean dumpMobNames = false;
public static void load(FMLPreInitializationEvent event) {
@@ -944,8 +955,22 @@ public final class Config {
"When true attacking one Enderminy will cause other Enderminies who witness the attack to attack the player as well");
enderminyMaxGroupSize= config.get(sectionMobConfig.name, "enderminyMaxGroupSize", enderminyMaxGroupSize,
"Maximum number of Enderminies that will spawn in a single group").getInt(enderminyMaxGroupSize);
enderminySpawnInLitAreas= config.getBoolean("enderminySpawnInLitAreas", sectionMobConfig.name, enderminySpawnInLitAreas,
enderminySpawnInLitAreas = config.getBoolean("enderminySpawnInLitAreas", sectionMobConfig.name, enderminySpawnInLitAreas,
"When true enderminies will spawn in well lit areas, when false they will only spawn in dark areas.");
enderminySpawnOnlyOnGrass = config.getBoolean("enderminySpawnOnlyOnGrass", sectionMobConfig.name, enderminySpawnOnlyOnGrass,
"When true enderminies will spawn only on grass blocks.");
enderminyMinSpawnY = config.get(sectionMobConfig.name, "enderminyMinSpawnY", enderminyMinSpawnY,
"The minimum Y level at which enderminies will spawn").getInt(enderminyMinSpawnY);
enderCreeperEnabled = config.getBoolean("enderCreeperEnabled", sectionMobConfig.name, enderCreeperEnabled, "Wether EnderCreepers are enabled");
enderCreeperSpawnRate = config.get(sectionMobConfig.name, "enderCreeperSpawnRate", enderCreeperSpawnRate,
"Sets the spawn rate of EnderCreepers. 10=Enderman spawn rate, 100=Zombie spawn rate").getInt(enderCreeperSpawnRate);
enderCreeperMaxTeleportRange = config.get(sectionMobConfig.name, "enderCreeperMaxTeleportRange", enderCreeperMaxTeleportRange,
"Sets the max range entites can be telported when the creeper explodes").getInt(enderCreeperMaxTeleportRange);
enderCreeperConfusionDuration = config.get(sectionMobConfig.name, "enderCreeperConfusionDuration", enderCreeperConfusionDuration,
"Sets the durtaion in ticks of the confusion effect applied on explosion").getInt(enderCreeperConfusionDuration);
enderCreeperExplosionRange = config.get(sectionMobConfig.name, "enderCreeperExplosionRange", enderCreeperExplosionRange,
"The range of the 'teleport explosion'").getInt(enderCreeperExplosionRange);
dumpMobNames = config.getBoolean("dumpMobNames", sectionMobConfig.name, dumpMobNames,
@@ -0,0 +1,112 @@
package crazypants.enderio.entity;
import java.lang.reflect.Field;
import java.util.List;
import net.minecraft.entity.EntityLiving;
import net.minecraft.entity.EntityLivingBase;
import net.minecraft.entity.monster.EntityCreeper;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.potion.Potion;
import net.minecraft.potion.PotionEffect;
import net.minecraft.util.AxisAlignedBB;
import net.minecraft.world.World;
import cpw.mods.fml.relauncher.ReflectionHelper;
import crazypants.enderio.EnderIO;
import crazypants.enderio.Log;
import crazypants.enderio.config.Config;
public class EntityEnderCreeper extends EntityCreeper {
public static final String NAME = "EnderCreeper";
private Field fTimeSinceIgnited;
private Field fFuseTime;
public EntityEnderCreeper(World world) {
super(world);
try {
fTimeSinceIgnited = ReflectionHelper.findField(EntityCreeper.class, "timeSinceIgnited", "field_70833_d");
fTimeSinceIgnited.setAccessible(true);
fFuseTime = ReflectionHelper.findField(EntityCreeper.class, "fuseTime", "field_82225_f");
fFuseTime.setAccessible(true);
} catch (Exception e) {
Log.error("Could not create ender creeper logic as fields not found");
}
}
@Override
public void onUpdate() {
if(this.isEntityAlive()) {
int timeSinceIgnited = getTimeSinceIgnited();
int fuseTime = getFuseTime();
if(timeSinceIgnited >= fuseTime - 1) {
setTimeSinceIgnited(0);
int range = Config.enderCreeperExplosionRange;
AxisAlignedBB bb = AxisAlignedBB.getBoundingBox(posX - range, posY - range, posZ - range, posX + range, posY + range, posZ + range);
List<EntityLivingBase> ents = worldObj.getEntitiesWithinAABB(EntityLivingBase.class, bb);
for (EntityLivingBase ent : ents) {
if(ent != this) {
if(!worldObj.isRemote) {
boolean done = false;
for (int i = 0; i < 20 && !done; i++) {
done = TeleportHelper.teleportRandomly(ent, Config.enderCreeperMaxTeleportRange);
}
}
if(ent instanceof EntityPlayer) {
worldObj.playSoundEffect(ent.posX, ent.posY, ent.posZ, "mob.endermen.portal", 1.0F, 1.0F);
EnderIO.proxy.setInstantConfusionOnPlayer((EntityPlayer) ent, Config.enderCreeperConfusionDuration);
}
}
}
worldObj.playSoundEffect(posX, posY, posZ, "random.explode", 4.0F,
(1.0F + (this.worldObj.rand.nextFloat() - this.worldObj.rand.nextFloat()) * 0.2F) * 0.7F);
worldObj.spawnParticle("hugeexplosion", posX, posY, posZ, 1.0D, 0.0D, 0.0D);
setDead();
}
}
super.onUpdate();
}
private void setTimeSinceIgnited(int i) {
if(fTimeSinceIgnited == null) {
return;
}
try {
fTimeSinceIgnited.setInt(this, i);
} catch (Exception e) {
e.printStackTrace();
}
}
private int getTimeSinceIgnited() {
if(fTimeSinceIgnited == null) {
return 0;
}
try {
return fTimeSinceIgnited.getInt(this);
} catch (Exception e) {
e.printStackTrace();
return 0;
}
}
private int getFuseTime() {
if(fFuseTime == null) {
return 0;
}
try {
return fFuseTime.getInt(this);
} catch (Exception e) {
e.printStackTrace();
return 0;
}
}
}
@@ -17,6 +17,7 @@ import crazypants.vecmath.Vector3d;
import net.minecraft.block.Block;
import net.minecraft.client.model.ModelEnderman;
import net.minecraft.entity.Entity;
import net.minecraft.entity.EnumCreatureType;
import net.minecraft.entity.SharedMonsterAttributes;
import net.minecraft.entity.ai.attributes.AttributeModifier;
import net.minecraft.entity.ai.attributes.IAttributeInstance;
@@ -40,7 +41,6 @@ import net.minecraftforge.event.entity.living.EnderTeleportEvent;
public class EntityEnderminy extends EntityMob {
public static String NAME = "Enderminy";
private static final int MAX_RND_TP_DISTANCE = 32;
@@ -79,7 +79,7 @@ public class EntityEnderminy extends EntityMob {
public float getShadowSize() {
return 0.01F;
}
@Override
protected boolean isValidLightLevel() {
return Config.enderminySpawnInLitAreas ? true : super.isValidLightLevel();
@@ -98,11 +98,20 @@ public class EntityEnderminy extends EntityMob {
dataWatcher.addObject(17, new Byte((byte) 0));
dataWatcher.addObject(18, new Byte((byte) 0));
}
@Override
public boolean getCanSpawnHere() {
return posY > 60 && super.getCanSpawnHere();
}
boolean passedGrassCheck = true;
if(Config.enderminySpawnOnlyOnGrass) {
int i = MathHelper.floor_double(this.posX);
int j = MathHelper.floor_double(this.boundingBox.minY);
int k = MathHelper.floor_double(this.posZ);
passedGrassCheck = worldObj.getBlock(i, j - 1, k) == Blocks.grass;
}
return posY > Config.enderminyMinSpawnY && super.getCanSpawnHere();
}
protected Entity findPlayerToAttack() {
@@ -125,7 +134,7 @@ public class EntityEnderminy extends EntityMob {
stareTimer = 0;
}
}
}
}
if(attackCreepers) {
int range = 16;
AxisAlignedBB bb = AxisAlignedBB.getBoundingBox(posX - range, posY - range, posZ - range, posX + range, posY + range, posZ + range);
@@ -210,7 +219,7 @@ public class EntityEnderminy extends EntityMob {
}
if(!worldObj.isRemote && isEntityAlive()) {
if(entityToAttack != null) {
if(entityToAttack != null) {
if(entityToAttack.getDistanceSqToEntity(this) > 256.0D && teleportDelay++ >= 30 && teleportToEntity(entityToAttack)) {
teleportDelay = 0;
}
@@ -357,11 +366,10 @@ public class EntityEnderminy extends EntityMob {
}
return super.attackEntityFrom(damageSource, p_70097_2_);
}
boolean res = super.attackEntityFrom(damageSource, p_70097_2_);
boolean res = super.attackEntityFrom(damageSource, p_70097_2_);
if(damageSource instanceof EntityDamageSource && damageSource.getEntity() instanceof EntityPlayer &&
getHealth() > 0 && !ItemDarkSteelSword.isEquippedAndPowered((EntityPlayer)damageSource.getEntity(), 1)) {
getHealth() > 0 && !ItemDarkSteelSword.isEquippedAndPowered((EntityPlayer) damageSource.getEntity(), 1)) {
isAggressive = true;
if(rand.nextInt(3) == 0) {
for (int i = 0; i < 64; ++i) {
@@ -373,7 +381,7 @@ public class EntityEnderminy extends EntityMob {
}
}
}
if(res) {
doGroupArgo();
}
@@ -385,7 +393,7 @@ public class EntityEnderminy extends EntityMob {
if(!groupAgroEnabled) {
return;
}
if(! (entityToAttack instanceof EntityPlayer)) {
if(!(entityToAttack instanceof EntityPlayer)) {
return;
}
System.out.println("EntityEnderminy.doGroupArgo: ");
@@ -393,14 +401,14 @@ public class EntityEnderminy extends EntityMob {
AxisAlignedBB bb = AxisAlignedBB.getBoundingBox(posX - range, posY - range, posZ - range, posX + range, posY + range, posZ + range);
List<EntityEnderminy> minies = worldObj.getEntitiesWithinAABB(EntityEnderminy.class, bb);
if(minies != null && !minies.isEmpty()) {
for (EntityEnderminy miny : minies) {
if(miny.entityToAttack == null) { //&& miny.canEntityBeSeen(this)) {
miny.entityToAttack = entityToAttack;
}
}
}
}
}
public boolean isScreaming() {
return dataWatcher.getWatchableObjectByte(18) > 0;
@@ -409,18 +417,17 @@ public class EntityEnderminy extends EntityMob {
public void setScreaming(boolean p_70819_1_) {
dataWatcher.updateObject(18, Byte.valueOf((byte) (p_70819_1_ ? 1 : 0)));
}
private final class ClosestEntityComparator implements Comparator<EntityCreeper> {
Vector3d pos = new Vector3d();
@Override
public int compare(EntityCreeper o1, EntityCreeper o2) {
pos.set(posX,posY,posZ);
pos.set(posX, posY, posZ);
double d1 = new Vector3d(o1.posX, o1.posY, o1.posZ).distanceSquared(pos);
double d2 = new Vector3d(o2.posX, o2.posY, o2.posZ).distanceSquared(pos);
return Double.compare(d1, d2);
}
}
}
@@ -6,6 +6,7 @@ import cpw.mods.fml.common.registry.GameRegistry;
import cpw.mods.fml.relauncher.Side;
import cpw.mods.fml.relauncher.SideOnly;
import crazypants.enderio.EnderIOTab;
import crazypants.enderio.config.Config;
import net.minecraft.block.Block;
import net.minecraft.client.renderer.texture.IIconRegister;
import net.minecraft.creativetab.CreativeTabs;
@@ -28,9 +29,9 @@ public class ItemSpawnEgg extends Item {
return res;
}
int[] primaryColor = { 0x27624D};
int[] secondaryColor = { 0x212121};
String[] mobNames = { "EnderIO." + EntityEnderminy.NAME };
int[] primaryColor = { 0x27624D, 0x56FF8E};
int[] secondaryColor = { 0x212121, 0xFF0A22};
String[] mobNames = { "EnderIO." + EntityEnderminy.NAME, "EnderIO." + EntityEnderCreeper.NAME };
private ItemSpawnEgg() {
setUnlocalizedName("itemSpawnEggEnderIO");
@@ -68,8 +69,11 @@ public class ItemSpawnEgg extends Item {
@Override
public void getSubItems(Item id, CreativeTabs tab, List list) {
for (int i = 0; i < mobNames.length; i++) {
list.add(new ItemStack(id, 1, i));
if(Config.enderminyEnabled) {
list.add(new ItemStack(id, 1, 0));
}
if(Config.enderCreeperEnabled) {
list.add(new ItemStack(id, 1, 1));
}
}
@@ -108,6 +112,10 @@ public class ItemSpawnEgg extends Item {
entity = new EntityEnderminy(world);
spawnEntity(posX, posY, posZ, entity, world);
break;
case 1:
entity = new EntityEnderCreeper(world);
spawnEntity(posX, posY, posZ, entity, world);
break;
}
return entity;
}
@@ -0,0 +1,19 @@
package crazypants.enderio.entity;
import net.minecraft.client.renderer.entity.RenderCreeper;
import net.minecraft.entity.monster.EntityCreeper;
import net.minecraft.util.ResourceLocation;
public class RenderEnderCreeper extends RenderCreeper {
private static final ResourceLocation creeperTextures = new ResourceLocation("enderio:entity/enderCreeper.png");
/**
* Returns the location of an entity's texture. Doesn't seem to be called unless you call Render.bindEntityTexture.
*/
@Override
protected ResourceLocation getEntityTexture(EntityCreeper p_110775_1_) {
return creeperTextures;
}
}
@@ -0,0 +1,109 @@
package crazypants.enderio.entity;
import java.util.Random;
import net.minecraft.block.Block;
import net.minecraft.entity.Entity;
import net.minecraft.entity.EntityLiving;
import net.minecraft.entity.EntityLivingBase;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.util.MathHelper;
import net.minecraft.util.Vec3;
import net.minecraftforge.common.MinecraftForge;
import net.minecraftforge.event.entity.living.EnderTeleportEvent;
public class TeleportHelper {
private static final int DEFAULT_RND_TP_DISTANCE = 16;
private static Random rand = new Random();
public static boolean teleportRandomly(EntityLivingBase entity, int distance) {
double d0 = entity.posX + (rand.nextDouble() - 0.5D) * distance;
double d1 = entity.posY + rand.nextInt(distance) - distance / 2;
double d2 = entity.posZ + (rand.nextDouble() - 0.5D) * distance;
return teleportTo(entity, d0, d1, d2, false);
}
public static boolean teleportRandomly(EntityLivingBase entity) {
return teleportRandomly(entity, DEFAULT_RND_TP_DISTANCE);
}
public static boolean teleportToEntity(EntityLivingBase entity, Entity toEntity) {
Vec3 vec3 = Vec3.createVectorHelper(entity.posX - toEntity.posX, entity.boundingBox.minY + (double) (entity.height / 2.0F) - toEntity.posY
+ (double) toEntity.getEyeHeight(), entity.posZ - toEntity.posZ);
vec3 = vec3.normalize();
double d0 = 16.0D;
double d1 = entity.posX + (rand.nextDouble() - 0.5D) * 8.0D - vec3.xCoord * d0;
double d2 = entity.posY + (double) (rand.nextInt(16) - 8) - vec3.yCoord * d0;
double d3 = entity.posZ + (rand.nextDouble() - 0.5D) * 8.0D - vec3.zCoord * d0;
return teleportTo(entity, d1, d2, d3, false);
}
public static boolean teleportTo(EntityLivingBase entity, double x, double y, double z, boolean fireEndermanEvent) {
EnderTeleportEvent event = new EnderTeleportEvent(entity, x, y, z, 0);
if(fireEndermanEvent) {
if(MinecraftForge.EVENT_BUS.post(event)) {
return false;
}
}
double d3 = entity.posX;
double d4 = entity.posY;
double d5 = entity.posZ;
entity.posX = event.targetX;
entity.posY = event.targetY;
entity.posZ = event.targetZ;
int xInt = MathHelper.floor_double(entity.posX);
int yInt = MathHelper.floor_double(entity.posY);
int zInt = MathHelper.floor_double(entity.posZ);
boolean flag = false;
if(entity.worldObj.blockExists(xInt, yInt, zInt)) {
boolean foundGround = false;
while (!foundGround && yInt > 0) {
Block block = entity.worldObj.getBlock(xInt, yInt - 1, zInt);
if(block.getMaterial().blocksMovement()) {
foundGround = true;
} else {
--entity.posY;
--yInt;
}
}
if(foundGround) {
entity.setPosition(entity.posX, entity.posY, entity.posZ);
if(entity.worldObj.getCollidingBoundingBoxes(entity, entity.boundingBox).isEmpty() && !entity.worldObj.isAnyLiquid(entity.boundingBox)) {
flag = true;
}
}
}
if(!flag) {
entity.setPosition(d3, d4, d5);
return false;
}
entity.setPositionAndUpdate(entity.posX, entity.posY, entity.posZ);
short short1 = 128;
for (int l = 0; l < short1; ++l) {
double d6 = (double) l / ((double) short1 - 1.0D);
float f = (rand.nextFloat() - 0.5F) * 0.2F;
float f1 = (rand.nextFloat() - 0.5F) * 0.2F;
float f2 = (rand.nextFloat() - 0.5F) * 0.2F;
double d7 = d3 + (entity.posX - d3) * d6 + (rand.nextDouble() - 0.5D) * (double) entity.width * 2.0D;
double d8 = d4 + (entity.posY - d4) * d6 + rand.nextDouble() * (double) entity.height;
double d9 = d5 + (entity.posZ - d5) * d6 + (rand.nextDouble() - 0.5D) * (double) entity.width * 2.0D;
entity.worldObj.spawnParticle("portal", d7, d8, d9, (double) f, (double) f1, (double) f2);
}
entity.worldObj.playSoundEffect(d3, d4, d5, "mob.endermen.portal", 1.0F, 1.0F);
entity.playSound("mob.endermen.portal", 1.0F, 1.0F);
return true;
}
}
@@ -7,11 +7,12 @@ import net.minecraft.creativetab.CreativeTabs;
import net.minecraft.item.Item;
import net.minecraft.item.ItemBlock;
import net.minecraft.item.ItemStack;
import cofh.api.energy.IEnergyContainerItem;
import crazypants.enderio.EnderIO;
import crazypants.enderio.EnderIOTab;
import crazypants.enderio.power.PowerHandlerUtil;
public class BlockItemCapacitorBank extends ItemBlock {
public class BlockItemCapacitorBank extends ItemBlock implements IEnergyContainerItem {
public static ItemStack createItemStackWithPower(int storedEnergy) {
ItemStack res = new ItemStack(EnderIO.blockCapacitorBank);
@@ -23,7 +24,7 @@ public class BlockItemCapacitorBank extends ItemBlock {
super(EnderIO.blockCapacitorBank);
setHasSubtypes(true);
}
public BlockItemCapacitorBank(Block block) {
super(block);
setHasSubtypes(true);
@@ -39,12 +40,12 @@ public class BlockItemCapacitorBank extends ItemBlock {
public String getUnlocalizedName(ItemStack par1ItemStack) {
int meta = par1ItemStack.getItemDamage();
String result = super.getUnlocalizedName(par1ItemStack);
if(meta == 1) {
if(meta == 1) {
result += ".creative";
}
return result;
}
@Override
@SuppressWarnings({ "rawtypes", "unchecked" })
public void getSubItems(Item par1, CreativeTabs par2CreativeTabs, List par3List) {
@@ -53,11 +54,59 @@ public class BlockItemCapacitorBank extends ItemBlock {
stack = createItemStackWithPower(TileCapacitorBank.BASE_CAP.getMaxEnergyStored());
par3List.add(stack);
stack = createItemStackWithPower(TileCapacitorBank.BASE_CAP.getMaxEnergyStored()/2);
stack = createItemStackWithPower(TileCapacitorBank.BASE_CAP.getMaxEnergyStored() / 2);
stack.setItemDamage(1);
par3List.add(stack);
}
@Override
public boolean showDurabilityBar(ItemStack itemStack) {
return true;
}
@Override
public double getDurabilityForDisplay(ItemStack itemStack) {
double stored = this.getMaxEnergyStored(itemStack) - this.getEnergyStored(itemStack) + 1;
double max = this.getMaxEnergyStored(itemStack) + 1;
return stored / max;
}
@Override
public int receiveEnergy(ItemStack container, int maxReceive, boolean simulate) {
int energy = this.getEnergyStored(container);
int maxInput = TileCapacitorBank.BASE_CAP.getMaxEnergyReceived();
int energyReceived = Math.min(this.getMaxEnergyStored(container) - energy, Math.min(maxReceive, maxInput));
if(!simulate) {
energy += energyReceived;
PowerHandlerUtil.setStoredEnergyForItem(container, energy);
}
return energyReceived;
}
@Override
public int extractEnergy(ItemStack container, int maxExtract, boolean simulate) {
int energy = this.getEnergyStored(container);
int maxOutput = TileCapacitorBank.BASE_CAP.getMaxEnergyExtracted();
int energyExtracted = Math.min(energy, Math.min(maxExtract, maxOutput));
if(!simulate) {
energy -= energyExtracted;
PowerHandlerUtil.setStoredEnergyForItem(container, energy);
}
return energyExtracted;
}
@Override
public int getEnergyStored(ItemStack container) {
return PowerHandlerUtil.getStoredEnergyForItem(container);
}
@Override
public int getMaxEnergyStored(ItemStack container) {
return TileCapacitorBank.BASE_CAP.getMaxEnergyStored();
}
}
@@ -210,9 +210,12 @@ public class ServerChannelRegister extends ChannelRegister {
private ItemStack sendItem(TileTransceiver from, int slot, ItemStack contents, TileTransceiver to) {
SlotDefinition sd = to.getSlotDefinition();
//try merging into existing stacks
for (int i = sd.minOutputSlot; i <= sd.maxOutputSlot; i++) {
boolean recieverHasItem = false; // Only allow 1 stack per item type
for (int i = sd.minOutputSlot; i <= sd.maxOutputSlot && !recieverHasItem; i++) {
ItemStack existing = to.getStackInSlot(i);
if(ItemUtil.canMergeStacks(existing, contents)) {
if(ItemUtil.areStackTypesEqual(existing, contents)) {
recieverHasItem = true;
int numCanMerge = existing.getMaxStackSize() - existing.stackSize;
ItemStack remaining;
if(numCanMerge >= contents.stackSize) {
@@ -223,7 +226,7 @@ public class ServerChannelRegister extends ChannelRegister {
}
ItemStack destStack = existing.copy();
destStack.stackSize += numCanMerge;
to.setInventorySlotContents(i, destStack);
to.setInventorySlotContents(i, destStack);
from.setInventorySlotContents(slot, remaining);
if(remaining == null) {
return null;
@@ -232,13 +235,15 @@ public class ServerChannelRegister extends ChannelRegister {
}
}
}
//then fill empty stack
for (int i = sd.minOutputSlot; i <= sd.maxOutputSlot; i++) {
ItemStack existing = to.getStackInSlot(i);
if(existing == null) {
to.setInventorySlotContents(i, contents.copy());
from.setInventorySlotContents(slot, null);
return null;
if(!recieverHasItem) {
//then fill empty stack
for (int i = sd.minOutputSlot; i <= sd.maxOutputSlot; i++) {
ItemStack existing = to.getStackInSlot(i);
if(existing == null) {
to.setInventorySlotContents(i, contents.copy());
from.setInventorySlotContents(slot, null);
return null;
}
}
}
return contents;
@@ -33,6 +33,7 @@ import crazypants.enderio.power.Capacitors;
import crazypants.enderio.power.ICapacitor;
import crazypants.enderio.power.PowerDistributor;
import crazypants.util.FluidUtil;
import crazypants.util.ItemUtil;
import crazypants.vecmath.VecmathUtil;
public class TileTransceiver extends AbstractPoweredTaskEntity implements IFluidHandler {
@@ -424,7 +425,7 @@ public class TileTransceiver extends AbstractPoweredTaskEntity implements IFluid
return false;
}
//item handling
//---------------- item handling
private void processItems() {
List<Channel> sendItemChannels = getSendChannels(ChannelType.ITEM);
if(!sendItemChannels.isEmpty()) {
@@ -437,4 +438,31 @@ public class TileTransceiver extends AbstractPoweredTaskEntity implements IFluid
}
}
@Override
public boolean canInsertItem(int slot, ItemStack itemstack, int j) {
if(itemstack == null) {
return false;
}
//only allow 1 stack per type
if(slotDefinition.isInputSlot(slot)) {
for (int i = slotDefinition.getMinInputSlot(); i <= slotDefinition.getMaxInputSlot(); i++) {
if(i != slot) {
if(ItemUtil.areStackTypesEqual(itemstack, getStackInSlot(i))) {
return false;
}
}
}
} else if(slotDefinition.isOutputSlot(slot)) {
for (int i = slotDefinition.getMinOutputSlot(); i <= slotDefinition.getMaxOutputSlot(); i++) {
if(i != slot) {
if(ItemUtil.areStackTypesEqual(itemstack, getStackInSlot(i))) {
return false;
}
}
}
}
return super.canInsertItem(slot, itemstack, j);
}
}
+1 -1
View File
@@ -170,7 +170,7 @@ public class ItemUtil {
* @param s2
* @return
*/
public static boolean canMergeStacks(ItemStack s1, ItemStack s2) {
public static boolean areStackTypesEqual(ItemStack s1, ItemStack s2) {
if(s1 == null || s2 == null || !s1.isStackable() || !s2.isStackable()) {
return false;
}