Résolu Utilisation d'un mod externe dans son propre mod
-
Bonjour, excusez moi pour mes nombreux problèmes / bugs / questions…
J’aimerais savoir comment utiliser un bloc d’un mod externe dans son propre mod (si c’est possible). -
Block f; if(Loader.isModLoaded("leModID")) f = GameRegistry.findBlock("leModID", "leNomUnlocaliséDuBlock"); else System.out.println("L'utilisateur n'a pas le mod contenant le block.");
-
Comment ça ? Tu veux l’utiliser comme si il était placé dans le dossier mods pour le tester avec ton mod ? Si c’est ça regarde http://www.minecraftforgefrance.fr/showthread.php?tid=1425 , j’ai jamais essayé mais tente. Et si c’est pour utiliser les classes du bloc regarde si son créateur propose une api et/ou si c’est open source avec un lien pour les classes, et regarde ça http://www.minecraftforgefrance.fr/showthread.php?tid=875 , la pareil jamais testé mais bon je pense qu’il aide pour les apis.
-
Plaigon ce que tu m’as passé marche mais quand je le met dans la partie init de ma classe principale et quand j’utilises la variable F définissant mon block dans une méthode d’une autre classe, F est souligné en rouge en me disant f cannot be resolved to a variable
-
Il faut que tu déplaces mon code hors de init() de manière à le rajouter là où t’en as besoin. C’est logique
Sinon file ton code et on t’explique plus en détail ce qui ne va pas… -
protected void onImpact(MovingObjectPosition movingObjectPosition) { { Block f; if(Loader.isModLoaded("TeNNoX_KeyAndCodeLock")) f = GameRegistry.findBlock("TeNNoX_KeyAndCodeLock", "keylockeddoor"); else System.out.println("L'utilisateur n'a pas le mod contenant le block."); } if (this.worldObj.getBlock((movingObjectPosition.blockX), (movingObjectPosition.blockY), (movingObjectPosition.blockZ)) == Blocks.obsidian) { for (int x = -1; x < 1; x++) for (int y = -1; y < 1; y++) for (int z = -1; z < 2; z++) this.worldObj.setBlockToAir(movingObjectPosition.blockX + x,movingObjectPosition.blockY + y,movingObjectPosition.blockZ + z); } if (this.worldObj.getBlock( movingObjectPosition.blockX,movingObjectPosition.blockY, movingObjectPosition.blockZ) == f) { this.worldObj.setBlockToAir(movingObjectPosition.blockX, movingObjectPosition.blockY, movingObjectPosition.blockZ); }
-
Ton code est vraiment mauvais….As-tu au moins remarqué que la moitié des parenthèses étaient mal placées ?! Corrige tout ceci et puis ensuite on pourra t’aider…
-
Enlève les accolades qui entourent le bloc que Plaigon t’a donné
-
Toujours pas bon ça me demande d’initialiser la variable f
-
Mets
Block f = null; -
Bon le problème persiste je mets à jour la classe de l’entité :```java
package fr.freshblock.freshrocket.entity.projectile;import java.util.List;
import cpw.mods.fml.common.Loader;
import cpw.mods.fml.common.network.handshake.FMLHandshakeMessage.ModIdData;
import cpw.mods.fml.common.registry.EntityRegistry;
import cpw.mods.fml.common.registry.GameRegistry;
import cpw.mods.fml.relauncher.Side;
import cpw.mods.fml.relauncher.SideOnly;
import net.minecraft.block.Block;
import net.minecraft.block.material.Material;
import net.minecraft.enchantment.EnchantmentHelper;
import net.minecraft.entity.Entity;
import net.minecraft.entity.EntityLivingBase;
import net.minecraft.entity.IProjectile;
import net.minecraft.entity.monster.EntityBlaze;
import net.minecraft.entity.monster.EntityEnderman;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.entity.player.EntityPlayerMP;
import net.minecraft.entity.projectile.EntityThrowable;
import net.minecraft.init.Blocks;
import net.minecraft.nbt.NBTTagCompound;
import net.minecraft.nbt.NBTTagList;
import net.minecraft.network.play.server.S2BPacketChangeGameState;
import net.minecraft.util.AxisAlignedBB;
import net.minecraft.util.DamageSource;
import net.minecraft.util.IProgressUpdate;
import net.minecraft.util.MathHelper;
import net.minecraft.util.MovingObjectPosition;
import net.minecraft.util.Vec3;
import net.minecraft.util.MovingObjectPosition.MovingObjectType;
import net.minecraft.world.Explosion;
import net.minecraft.world.World;
import net.minecraftforge.client.gui.ForgeGuiFactory.ForgeConfigGui.ModIDEntry;public class EntityFreshRocket extends Entity implements IProjectile {
private Block inTile;
private int ticksAlive;
private int inData;
private boolean inGround;
public int arrowShake;
public Entity shootingEntity;
private int ticksInGround;
private int ticksInAir;
private double damage = 6.0D;
private int knockbackStrength;
public int canBePickedUp;
private int field_145795_e = -1;
private int field_145793_f = -1;
private int field_145794_g = -1;@Override
protected void entityInit() {}
@Override
protected void readEntityFromNBT(NBTTagCompound p_70037_1_) {}
@Override
protected void writeEntityToNBT(NBTTagCompound p_70014_1_) {}
public void setThrowableHeading(double p_70186_1_, double p_70186_3_, double p_70186_5_, float p_70186_7_,
float p_70186_8_) {
float f2 = MathHelper.sqrt_double(p_70186_1_ * p_70186_1_ + p_70186_3_ * p_70186_3_ + p_70186_5_ * p_70186_5_);
p_70186_1_ /= (double) f2;
p_70186_3_ /= (double) f2;
p_70186_5_ /= (double) f2;
p_70186_1_ *= (double) p_70186_7_;
p_70186_3_ *= (double) p_70186_7_;
p_70186_5_ *= (double) p_70186_7_;
this.motionX = p_70186_1_;
this.motionY = p_70186_3_;
this.motionZ = p_70186_5_;
this.ticksInGround = 0;
this.worldObj.playSound(5D, 5D, 5D, “random.fizz”, distanceWalkedModified, distanceWalkedModified, true);
}public EntityFreshRocket(World worldIn) {
super(worldIn);
this.setSize(0.5F, 0.5F);
this.renderDistanceWeight = 10.0D;
}public EntityFreshRocket(World worldIn, double x, double y, double z) {
super(worldIn);
this.setSize(0.5F, 0.5F);
this.setPosition(x, y, z);
this.renderDistanceWeight = 10.0D;
this.yOffset = 0.0F;
}@SideOnly(Side.CLIENT)
public void setPositionAndRotation2(double p_70056_1_, double p_70056_3_, double p_70056_5_, float p_70056_7_,
float p_70056_8_, int p_70056_9_) {
this.setPosition(p_70056_1_, p_70056_3_, p_70056_5_);
this.setRotation(p_70056_7_, p_70056_8_);
}@SideOnly(Side.CLIENT)
public void setVelocity(double p_70016_1_, double p_70016_3_, double p_70016_5_) {
this.motionX = p_70016_1_;
this.motionY = p_70016_3_;
this.motionZ = p_70016_5_;if (this.prevRotationPitch == 0.0F && this.prevRotationYaw == 0.0F) {
float f = MathHelper.sqrt_double(p_70016_1_ * p_70016_1_ + p_70016_5_ * p_70016_5_);
this.prevRotationYaw = this.rotationYaw = (float) (Math.atan2(p_70016_1_, p_70016_5_) * 180.0D / Math.PI);
this.prevRotationPitch = this.rotationPitch = (float) (Math.atan2(p_70016_3_, (double) f) * 180.0D
/ Math.PI);
this.prevRotationPitch = this.rotationPitch;
this.prevRotationYaw = this.rotationYaw;
this.setLocationAndAngles(this.posX, this.posY, this.posZ, this.rotationYaw, this.rotationPitch);
this.ticksInGround = 0;
}
}protected void onImpact(MovingObjectPosition movingObjectPosition)
{
if (this.worldObj.getBlock((movingObjectPosition.blockX), (movingObjectPosition.blockY), (movingObjectPosition.blockZ)) == Blocks.obsidian)
{
for (int x = -1; x < 1; x++)
for (int y = -1; y < 1; y++)
for (int z = -1; z < 2; z++)
this.worldObj.setBlockToAir(movingObjectPosition.blockX + x,movingObjectPosition.blockY + y,movingObjectPosition.blockZ + z);Block f = null;
if(Loader.isModLoaded(“TeNNoX_KeyAndCodeLock”))
f = GameRegistry.findBlock(“TeNNoX_KeyAndCodeLock”, “keylockeddoor”);
else
System.out.println(“L’utilisateur n’a pas le mod contenant le block.”);if (this.worldObj.getBlock((movingObjectPosition.blockX), (movingObjectPosition.blockY), (movingObjectPosition.blockZ)) == f)
{
this.worldObj.setBlockToAir(movingObjectPosition.blockX,movingObjectPosition.blockY,movingObjectPosition.blockZ);
}
}if (movingObjectPosition.typeOfHit == MovingObjectType.BLOCK)
{
switch (movingObjectPosition.sideHit)
{
case 0:
movingObjectPosition.blockY–;
case 1:
movingObjectPosition.blockY++;
break;
case 2:
movingObjectPosition.blockZ–;
break;
case 3:
movingObjectPosition.blockZ++;
break;
case 4: // NORTH
movingObjectPosition.blockX–;
break;
case 5: // SOUTH
movingObjectPosition.blockX++;
break;
}this.worldObj.spawnParticle(“largeexplode”, this.posX, this.posY, this.posZ, 0.0D, 0.0D, 0.0D);
this.setDead();
}
if (!this.worldObj.isRemote)
{
this.worldObj.newExplosion(this, movingObjectPosition.blockX, movingObjectPosition.blockY, movingObjectPosition.blockZ, 2F, false, true);
}
}public void onUpdate()
{
if (this.ticksInAir == 12
|| !this.worldObj.isRemote && (this.shootingEntity != null && this.shootingEntity.isDead
|| !this.worldObj.blockExists((int) this.posX, (int) this.posY, (int) this.posZ))) {
this.setDead();
} else {
super.onUpdate();if (this.inGround) {
if (this.worldObj.getBlock(this.field_145795_e, this.field_145793_f,
this.field_145794_g) == this.inTile) {
++this.ticksAlive;if (this.ticksAlive == 600) {
this.setDead();
}return;
}this.inGround = false;
this.ticksAlive = 0;
this.ticksInAir = 0;
} else {
++this.ticksInAir;
}Vec3 vec3 = Vec3.createVectorHelper(this.posX, this.posY, this.posZ);
Vec3 vec31 = Vec3.createVectorHelper(this.posX + this.motionX, this.posY + this.motionY,
this.posZ + this.motionZ);
MovingObjectPosition movingobjectposition = this.worldObj.rayTraceBlocks(vec3, vec31);
vec3 = Vec3.createVectorHelper(this.posX, this.posY, this.posZ);
vec31 = Vec3.createVectorHelper(this.posX + this.motionX, this.posY + this.motionY,
this.posZ + this.motionZ);if (movingobjectposition != null) {
vec31 = Vec3.createVectorHelper(movingobjectposition.hitVec.xCoord, movingobjectposition.hitVec.yCoord,
movingobjectposition.hitVec.zCoord);
}Entity entity = null;
List list = this.worldObj.getEntitiesWithinAABBExcludingEntity(this,
this.boundingBox.addCoord(this.motionX, this.motionY, this.motionZ).expand(1.0D, 1.0D, 1.0D));
double d0 = 0.0D;for (int i = 0; i < list.size(); ++i) {
Entity entity1 = (Entity) list.get(i);if (entity1.canBeCollidedWith()
&& (!entity1.isEntityEqual(this.shootingEntity) || this.ticksInAir >= 25)) {
float f = 0.3F;
AxisAlignedBB axisalignedbb = entity1.boundingBox.expand((double) f, (double) f, (double) f);
MovingObjectPosition movingobjectposition1 = axisalignedbb.calculateIntercept(vec3, vec31);if (movingobjectposition1 != null) {
double d1 = vec3.distanceTo(movingobjectposition1.hitVec);if (d1 < d0 || d0 == 0.0D) {
entity = entity1;
d0 = d1;
}
}
}
}if (entity != null) {
movingobjectposition = new MovingObjectPosition(entity);
}if (movingobjectposition != null) {
this.onImpact(movingobjectposition);
}this.posX += this.motionX;
this.posZ += this.motionZ;float f2 = 1.0F;
if (this.isInWater()) {
for (int j = 0; j < 4; ++j) {
float f3 = 0.25F;
this.worldObj.spawnParticle(“bubble”, this.posX, this.posY, this.posZ, this.motionX, this.motionY,
this.motionZ);
}f2 = 0.8F;
}
this.motionX *= (double) f2;
this.motionZ *= (double) f2;
this.worldObj.spawnParticle(“explode”, this.posX, this.posY + 0.5D, this.posZ, 0.0D, 0.0D, 0.0D);
this.setPosition(this.posX, this.posY, this.posZ);
}
}
} -
Ok le code ne marche toujours pas malgré toutes les aides reçues et le message println “…” n’est pas pas dans les logs donc il y a un problème : ```java
package fr.freshblock.freshrocket.entity.projectile;import java.util.List;
import cpw.mods.fml.common.Loader;
import cpw.mods.fml.common.network.handshake.FMLHandshakeMessage.ModIdData;
import cpw.mods.fml.common.registry.EntityRegistry;
import cpw.mods.fml.common.registry.GameRegistry;
import cpw.mods.fml.relauncher.Side;
import cpw.mods.fml.relauncher.SideOnly;
import net.minecraft.block.Block;
import net.minecraft.block.material.Material;
import net.minecraft.enchantment.EnchantmentHelper;
import net.minecraft.entity.Entity;
import net.minecraft.entity.EntityLivingBase;
import net.minecraft.entity.IProjectile;
import net.minecraft.entity.monster.EntityBlaze;
import net.minecraft.entity.monster.EntityEnderman;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.entity.player.EntityPlayerMP;
import net.minecraft.entity.projectile.EntityThrowable;
import net.minecraft.init.Blocks;
import net.minecraft.nbt.NBTTagCompound;
import net.minecraft.nbt.NBTTagList;
import net.minecraft.network.play.server.S2BPacketChangeGameState;
import net.minecraft.util.AxisAlignedBB;
import net.minecraft.util.DamageSource;
import net.minecraft.util.IProgressUpdate;
import net.minecraft.util.MathHelper;
import net.minecraft.util.MovingObjectPosition;
import net.minecraft.util.Vec3;
import net.minecraft.util.MovingObjectPosition.MovingObjectType;
import net.minecraft.world.Explosion;
import net.minecraft.world.World;
import net.minecraftforge.client.gui.ForgeGuiFactory.ForgeConfigGui.ModIDEntry;public class EntityFreshRocket extends Entity implements IProjectile {
private Block inTile;
private int ticksAlive;
private int inData;
private boolean inGround;
public int arrowShake;
public Entity shootingEntity;
private int ticksInGround;
private int ticksInAir;
private double damage = 6.0D;
private int knockbackStrength;
public int canBePickedUp;
private int field_145795_e = -1;
private int field_145793_f = -1;
private int field_145794_g = -1;@Override
protected void entityInit() {}
@Override
protected void readEntityFromNBT(NBTTagCompound p_70037_1_) {}
@Override
protected void writeEntityToNBT(NBTTagCompound p_70014_1_) {}
public void setThrowableHeading(double p_70186_1_, double p_70186_3_, double p_70186_5_, float p_70186_7_,
float p_70186_8_) {
float f2 = MathHelper.sqrt_double(p_70186_1_ * p_70186_1_ + p_70186_3_ * p_70186_3_ + p_70186_5_ * p_70186_5_);
p_70186_1_ /= (double) f2;
p_70186_3_ /= (double) f2;
p_70186_5_ /= (double) f2;
p_70186_1_ *= (double) p_70186_7_;
p_70186_3_ *= (double) p_70186_7_;
p_70186_5_ *= (double) p_70186_7_;
this.motionX = p_70186_1_;
this.motionY = p_70186_3_;
this.motionZ = p_70186_5_;
this.ticksInGround = 0;
this.worldObj.playSound(5D, 5D, 5D, “random.fizz”, distanceWalkedModified, distanceWalkedModified, true);
}public EntityFreshRocket(World worldIn) {
super(worldIn);
this.setSize(0.5F, 0.5F);
this.renderDistanceWeight = 10.0D;
}public EntityFreshRocket(World worldIn, double x, double y, double z) {
super(worldIn);
this.setSize(0.5F, 0.5F);
this.setPosition(x, y, z);
this.renderDistanceWeight = 10.0D;
this.yOffset = 0.0F;
}@SideOnly(Side.CLIENT)
public void setPositionAndRotation2(double p_70056_1_, double p_70056_3_, double p_70056_5_, float p_70056_7_,
float p_70056_8_, int p_70056_9_) {
this.setPosition(p_70056_1_, p_70056_3_, p_70056_5_);
this.setRotation(p_70056_7_, p_70056_8_);
}@SideOnly(Side.CLIENT)
public void setVelocity(double p_70016_1_, double p_70016_3_, double p_70016_5_) {
this.motionX = p_70016_1_;
this.motionY = p_70016_3_;
this.motionZ = p_70016_5_;if (this.prevRotationPitch == 0.0F && this.prevRotationYaw == 0.0F) {
float f = MathHelper.sqrt_double(p_70016_1_ * p_70016_1_ + p_70016_5_ * p_70016_5_);
this.prevRotationYaw = this.rotationYaw = (float) (Math.atan2(p_70016_1_, p_70016_5_) * 180.0D / Math.PI);
this.prevRotationPitch = this.rotationPitch = (float) (Math.atan2(p_70016_3_, (double) f) * 180.0D
/ Math.PI);
this.prevRotationPitch = this.rotationPitch;
this.prevRotationYaw = this.rotationYaw;
this.setLocationAndAngles(this.posX, this.posY, this.posZ, this.rotationYaw, this.rotationPitch);
this.ticksInGround = 0;
}
}protected void onImpact(MovingObjectPosition movingObjectPosition)
{
if (this.worldObj.getBlock((movingObjectPosition.blockX), (movingObjectPosition.blockY), (movingObjectPosition.blockZ)) == Blocks.obsidian)
{
for (int x = -1; x < 1; x++)
for (int y = -1; y < 1; y++)
for (int z = -1; z < 2; z++)
this.worldObj.setBlockToAir(movingObjectPosition.blockX + x,movingObjectPosition.blockY + y,movingObjectPosition.blockZ + z);Block f = null;
if(Loader.isModLoaded(“TeNNoX_KeyAndCodeLock”))
f = GameRegistry.findBlock(“TeNNoX_KeyAndCodeLock”, “keylockeddoor”);
else
System.out.println(“L’utilisateur n’a pas le mod contenant le block.”);if (this.worldObj.getBlock((movingObjectPosition.blockX), (movingObjectPosition.blockY), (movingObjectPosition.blockZ)) == f)
{
for (int x = -1; x < 1; x++)
for (int y = -1; y < 1; y++)
for (int z = -1; z < 2; z++)
this.worldObj.setBlockToAir(movingObjectPosition.blockX + x,movingObjectPosition.blockY + y,movingObjectPosition.blockZ + z);
}
}if (movingObjectPosition.typeOfHit == MovingObjectType.BLOCK)
{
switch (movingObjectPosition.sideHit)
{
case 0:
movingObjectPosition.blockY–;
case 1:
movingObjectPosition.blockY++;
break;
case 2:
movingObjectPosition.blockZ–;
break;
case 3:
movingObjectPosition.blockZ++;
break;
case 4: // NORTH
movingObjectPosition.blockX–;
break;
case 5: // SOUTH
movingObjectPosition.blockX++;
break;
}this.worldObj.spawnParticle(“largeexplode”, this.posX, this.posY, this.posZ, 0.0D, 0.0D, 0.0D);
this.setDead();
}
if (!this.worldObj.isRemote)
{
this.worldObj.newExplosion(this, movingObjectPosition.blockX, movingObjectPosition.blockY, movingObjectPosition.blockZ, 2F, false, true);
}
}public void onUpdate()
{
if (this.ticksInAir == 12
|| !this.worldObj.isRemote && (this.shootingEntity != null && this.shootingEntity.isDead
|| !this.worldObj.blockExists((int) this.posX, (int) this.posY, (int) this.posZ))) {
this.setDead();
} else {
super.onUpdate();if (this.inGround) {
if (this.worldObj.getBlock(this.field_145795_e, this.field_145793_f,
this.field_145794_g) == this.inTile) {
++this.ticksAlive;if (this.ticksAlive == 600) {
this.setDead();
}return;
}this.inGround = false;
this.ticksAlive = 0;
this.ticksInAir = 0;
} else {
++this.ticksInAir;
}Vec3 vec3 = Vec3.createVectorHelper(this.posX, this.posY, this.posZ);
Vec3 vec31 = Vec3.createVectorHelper(this.posX + this.motionX, this.posY + this.motionY,
this.posZ + this.motionZ);
MovingObjectPosition movingobjectposition = this.worldObj.rayTraceBlocks(vec3, vec31);
vec3 = Vec3.createVectorHelper(this.posX, this.posY, this.posZ);
vec31 = Vec3.createVectorHelper(this.posX + this.motionX, this.posY + this.motionY,
this.posZ + this.motionZ);if (movingobjectposition != null) {
vec31 = Vec3.createVectorHelper(movingobjectposition.hitVec.xCoord, movingobjectposition.hitVec.yCoord,
movingobjectposition.hitVec.zCoord);
}Entity entity = null;
List list = this.worldObj.getEntitiesWithinAABBExcludingEntity(this,
this.boundingBox.addCoord(this.motionX, this.motionY, this.motionZ).expand(1.0D, 1.0D, 1.0D));
double d0 = 0.0D;for (int i = 0; i < list.size(); ++i) {
Entity entity1 = (Entity) list.get(i);if (entity1.canBeCollidedWith()
&& (!entity1.isEntityEqual(this.shootingEntity) || this.ticksInAir >= 25)) {
float f = 0.3F;
AxisAlignedBB axisalignedbb = entity1.boundingBox.expand((double) f, (double) f, (double) f);
MovingObjectPosition movingobjectposition1 = axisalignedbb.calculateIntercept(vec3, vec31);if (movingobjectposition1 != null) {
double d1 = vec3.distanceTo(movingobjectposition1.hitVec);if (d1 < d0 || d0 == 0.0D) {
entity = entity1;
d0 = d1;
}
}
}
}if (entity != null) {
movingobjectposition = new MovingObjectPosition(entity);
}if (movingobjectposition != null) {
this.onImpact(movingobjectposition);
}this.posX += this.motionX;
this.posZ += this.motionZ;float f2 = 1.0F;
if (this.isInWater()) {
for (int j = 0; j < 4; ++j) {
float f3 = 0.25F;
this.worldObj.spawnParticle(“bubble”, this.posX, this.posY, this.posZ, this.motionX, this.motionY,
this.motionZ);
}f2 = 0.8F;
}
this.motionX *= (double) f2;
this.motionZ *= (double) f2;
this.worldObj.spawnParticle(“explode”, this.posX, this.posY + 0.5D, this.posZ, 0.0D, 0.0D, 0.0D);
this.setPosition(this.posX, this.posY, this.posZ);
}
}
} -
Déjà est-ce que ta condition est valide ? (Ton projectile est dans l’obsidienne à l’impact)
Fort peu probable. Nésite pas à, dans éclipse, sélectionner ton onImpact et faire CTRL+I pour mieux comprendre.