Plusieurs problèmes de mise à jour
-
Salut
Je n’ai pas de crash à proprement dit : j’ai une erreur dans la console, mais Minecraft ne s’éteint pas et je n’ai pas de crash-report, juste l’erreur dans la console. J’ai peut-être une mauvaise définition de crashSinon, j’ai essayé de mettre le transfer dans une commande, mais quand je la fait, c’est la même erreur.
J’ai essayé de “refaire” la classe du blockPortal en réduisant : ```java
package thisishalloween.block;import java.util.Map;
import java.util.Random;import javax.annotation.Nullable;
import com.google.common.cache.LoadingCache;
import com.google.common.collect.Maps;import net.minecraft.block.Block;
import net.minecraft.block.BlockBreakable;
import net.minecraft.block.BlockPortal;
import net.minecraft.block.SoundType;
import net.minecraft.block.material.Material;
import net.minecraft.block.properties.IProperty;
import net.minecraft.block.properties.PropertyEnum;
import net.minecraft.block.state.BlockStateContainer;
import net.minecraft.block.state.BlockWorldState;
import net.minecraft.block.state.IBlockState;
import net.minecraft.block.state.pattern.BlockPattern;
import net.minecraft.entity.Entity;
import net.minecraft.entity.EntityList;
import net.minecraft.entity.monster.EntityPigZombie;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.entity.player.EntityPlayerMP;
import net.minecraft.init.Blocks;
import net.minecraft.init.SoundEvents;
import net.minecraft.item.ItemMonsterPlacer;
import net.minecraft.item.ItemStack;
import net.minecraft.server.MinecraftServer;
import net.minecraft.util.BlockRenderLayer;
import net.minecraft.util.EnumFacing;
import net.minecraft.util.EnumParticleTypes;
import net.minecraft.util.Rotation;
import net.minecraft.util.SoundCategory;
import net.minecraft.util.math.AxisAlignedBB;
import net.minecraft.util.math.BlockPos;
import net.minecraft.util.math.MathHelper;
import net.minecraft.util.math.Vec3d;
import net.minecraft.world.IBlockAccess;
import net.minecraft.world.Teleporter;
import net.minecraft.world.World;
import net.minecraft.world.WorldServer;
import net.minecraftforge.fml.common.ObfuscationReflectionHelper;
import net.minecraftforge.fml.relauncher.Side;
import net.minecraftforge.fml.relauncher.SideOnly;
import thisishalloween.CreateBlocks;
import thisishalloween.ThisisHalloween;
import thisishalloween.world.frightful.TeleporterFrightful;public class BlockPortalFrightful extends BlockPortal
{
public static final PropertyEnum <enumfacing.axis>AXIS = PropertyEnum.<enumfacing.axis>create(“axis”, EnumFacing.Axis.class, new EnumFacing.Axis[] {EnumFacing.Axis.X, EnumFacing.Axis.Z});
protected static final AxisAlignedBB field_185683_b = new AxisAlignedBB(0.0D, 0.0D, 0.375D, 1.0D, 1.0D, 0.625D);
protected static final AxisAlignedBB field_185684_c = new AxisAlignedBB(0.375D, 0.0D, 0.0D, 0.625D, 1.0D, 1.0D);
protected static final AxisAlignedBB field_185685_d = new AxisAlignedBB(0.375D, 0.0D, 0.375D, 0.625D, 1.0D, 0.625D);public BlockPortalFrightful()
{
setTickRandomly(false);
setBlockUnbreakable();
isCollidable();
}public void updateTick(World worldIn, BlockPos pos, IBlockState state, Random rand)
{}
public boolean trySpawnPortal(World worldIn, BlockPos pos)
{
BlockPortalFrightful.Size blockportal$size = new BlockPortalFrightful.Size(worldIn, pos, EnumFacing.Axis.X);if (blockportal$size.isValid() && blockportal$size.portalBlockCount == 0)
{
blockportal$size.placePortalBlocks();
return true;
}BlockPortalFrightful.Size blockportal$size1 = new BlockPortalFrightful.Size(worldIn, pos, EnumFacing.Axis.Z);
if (blockportal$size1.isValid() && blockportal$size1.portalBlockCount == 0)
{
blockportal$size1.placePortalBlocks();
return true;
}
return false;
}public void neighborChanged(IBlockState state, World worldIn, BlockPos pos, Block blockIn)
{
EnumFacing.Axis axis = (EnumFacing.Axis)state.getValue(AXIS);if (axis == EnumFacing.Axis.X)
{
BlockPortalFrightful.Size size = new BlockPortalFrightful.Size(worldIn, pos, EnumFacing.Axis.X);if (!size.isValid() || size.portalBlockCount < size.width * size.height)
{
if(ThisisHalloween.portal)
{
worldIn.setBlockState(pos, Blocks.AIR.getDefaultState());
}
}
}
else if (axis == EnumFacing.Axis.Z)
{
BlockPortalFrightful.Size size = new BlockPortalFrightful.Size(worldIn, pos, EnumFacing.Axis.Z);if (!size.isValid() || size.portalBlockCount < size.width * size.height)
{
if(ThisisHalloween.portal)
{
worldIn.setBlockState(pos, Blocks.AIR.getDefaultState());
}
}
}
}@Override
public void onEntityCollidedWithBlock(World worldIn, BlockPos pos, IBlockState state, Entity entityIn)
{
if ((entityIn.getRidingEntity() == null) && (!entityIn.isDead))
{
if(entityIn instanceof EntityPlayerMP)
{
EntityPlayerMP player = (EntityPlayerMP) entityIn;
if(entityIn.isEntityAlive())
{
if (player.dimension != -1)
{
// ThisisHalloween.portal = false;
// player.timeUntilPortal = 100;
player.mcServer.getPlayerList().transferPlayerToDimension(player, -1, new Teleporter(player.mcServer.worldServerForDimension(-1)));
// player.timeUntilPortal = 100;
// ThisisHalloween.portal = true;
}
else
{
player.mcServer.getPlayerList().transferPlayerToDimension(player, 0, new Teleporter(player.mcServer.worldServerForDimension(0)));
// player.timeUntilPortal = 100;
}
}
}
}
}@SideOnly(Side.CLIENT)
public void randomDisplayTick(IBlockState state, World world, BlockPos pos, Random rand)
{}
protected BlockStateContainer createBlockState()
{
return new BlockStateContainer(this, new IProperty[] {AXIS});
}public static class Size
{
private final World world;
private final EnumFacing.Axis axis;
private final EnumFacing rightDir;
private final EnumFacing leftDir;
private int portalBlockCount = 0;
private BlockPos bottomLeft;
private int height;
private int width;public Size(World worldIn, BlockPos p_i45694_2_, EnumFacing.Axis p_i45694_3_)
{
this.world = worldIn;
this.axis = p_i45694_3_;if (p_i45694_3_ == EnumFacing.Axis.X)
{
this.leftDir = EnumFacing.EAST;
this.rightDir = EnumFacing.WEST;
}
else
{
this.leftDir = EnumFacing.NORTH;
this.rightDir = EnumFacing.SOUTH;
}for (BlockPos blockpos = p_i45694_2_; p_i45694_2_.getY() > blockpos.getY() - 21 && p_i45694_2_.getY() > 0 && (isEmptyBlock(worldIn.getBlockState(p_i45694_2_.down()), p_i45694_2_.down())); p_i45694_2_ = p_i45694_2_.down())
{}
int i = this.getDistanceUntilEdge(p_i45694_2_, this.leftDir) - 1;
if (i >= 0)
{
this.bottomLeft = p_i45694_2_.offset(this.leftDir, i);
this.width = this.getDistanceUntilEdge(this.bottomLeft, this.rightDir);if (this.width < 1 || this.width > 21)
{
this.bottomLeft = null;
this.width = 0;
}
}if (this.bottomLeft != null)
{
this.height = this.calculatePortalHeight();
}
}protected int getDistanceUntilEdge(BlockPos p_180120_1_, EnumFacing p_180120_2_)
{
int i = 0;
if(i < 22){i++;}BlockPos blockpos = p_180120_1_.offset(p_180120_2_, i);
if (!this.isEmptyBlock(this.world.getBlockState(blockpos), blockpos) || this.world.getBlockState(blockpos.down()).getBlock() != Blocks.NETHER_BRICK)
{}
Block block = this.world.getBlockState(p_180120_1_.offset(p_180120_2_, i)).getBlock();
return block == Blocks.NETHER_BRICK ? i : 0;
}public int getHeight()
{
return this.height;
}public int getWidth()
{
return this.width;
}protected int calculatePortalHeight()
{
label190:
for (this.height = 0; this.height < 21; this.height += 1)
{
for (int i = 0; i < this.width; ++i)
{
BlockPos blockpos = this.bottomLeft.offset(this.rightDir, i).up(this.height);
IBlockState state = this.world.getBlockState(blockpos);
Block block = state.getBlock();if (!this.isEmptyBlock(state, blockpos))
{
break label190;
}if (block == CreateBlocks.portalFrightful)
{
this.portalBlockCount += 1;
}if (i == 0)
{
block = this.world.getBlockState(blockpos.offset(this.leftDir)).getBlock();if (block != Blocks.NETHER_BRICK)
{
break label190;
}
}
else if (i == this.width - 1)
{
block = this.world.getBlockState(blockpos.offset(this.rightDir)).getBlock();if (block != Blocks.NETHER_BRICK)
{
break label190;
}
}
}
}for (int j = 0; j < this.width; ++j)
{
if (this.world.getBlockState(this.bottomLeft.offset(this.rightDir, j).up(this.height)).getBlock() != Blocks.NETHER_BRICK)
{
this.height = 0;
break;
}
}if ((this.height <= 21) && (this.height >= 2))
{
return this.height;
}this.bottomLeft = null;
this.width = 0;
this.height = 0;
return 0;
}protected boolean isEmptyBlock(IBlockState blockIn, BlockPos pos)
{
return (blockIn.getBlock().isAir(blockIn, world, pos)) || (blockIn.getBlock() == CreateBlocks.portalFrightful);
}public boolean isValid()
{
return (this.bottomLeft != null) && (this.width >= 1) && (this.width <= 21) && (this.height >= 2) && (this.height <= 21);
}public void placePortalBlocks()
{
for (int i = 0; i < this.width; ++i)
{
BlockPos blockpos = this.bottomLeft.offset(this.rightDir, i);for (int j = 0; j < this.height; ++j)
{
this.world.setBlockState(blockpos.up(j), CreateBlocks.portalFrightful.getDefaultState().withProperty(BlockPortalFrightful.AXIS, this.axis), 2);
}
}
}
}
}déjà, je comprend pas pourquoi dans l'erreur, y'a un NPE. Pourtant, rien n'est null. PS : Voilà l'erreur pour ceux qui n'ont pas lu les messages au-dessus :
Caused by: java.lang.NullPointerException
at net.minecraft.world.Teleporter.placeInExistingPortal(Teleporter.java:134) ~[Teleporter.class:?]
at net.minecraft.world.Teleporter.placeInPortal(Teleporter.java:38) ~[Teleporter.class:?]
at net.minecraft.server.management.PlayerList.transferEntityToWorld(PlayerList.java:734) ~[PlayerList.class:?]
at net.minecraft.server.management.PlayerList.transferPlayerToDimension(PlayerList.java:641) ~[PlayerList.class:?]
at thisishalloween.block.BlockPortalFrightful.onEntityCollidedWithBlock(BlockPortalFrightful.java:137) ~[BlockPortalFrightful.class:?]
at net.minecraft.entity.Entity.doBlockCollisions(Entity.java:1040) ~[Entity.class:?]
at net.minecraft.entity.Entity.moveEntity(Entity.java:958) ~[Entity.class:?]
at net.minecraft.network.NetHandlerPlayServer.processPlayer(NetHandlerPlayServer.java:500) ~[NetHandlerPlayServer.class:?]
at net.minecraft.network.play.client.CPacketPlayer.processPacket(CPacketPlayer.java:36) ~[CPacketPlayer.class:?]
at net.minecraft.network.play.client.CPacketPlayer$PositionRotation.processPacket(CPacketPlayer.java:125) ~[CPacketPlayer$PositionRotation.class:?]
at net.minecraft.network.PacketThreadUtil$1.run(PacketThreadUtil.java:15) ~[PacketThreadUtil$1.class:?]
at java.util.concurrent.Executors$RunnableAdapter.call(Unknown Source) ~[?:1.8.0_92]
at java.util.concurrent.FutureTask.run(Unknown Source) ~[?:1.8.0_92]
at net.minecraft.util.Util.runTask(Util.java:25) ~[Util.class:?]
… 5 moreEDIT : J'ai enfin réussi à faire crash le jeu (oui je sais, un mec qui fait crash un jeu est content -_- ). Bref, j'ai utilisé la fonction transferEntityToWorld, en voulant toujours me téléporter vers le Nether et en utilisant le teleporter de base. Dans le crash-report, 2 chose m'ont interpellé :
Entity Type: null (net.minecraft.entity.player.EntityPlayerMP)
Entity’s Vehicle:ERRORNullPointerException: nullEst-ce normal que le type de l'entité soit null et en même temps EntityPlayerMP (c'est ce que j'en ai compris) ? Sur le véhicule, ça dit erreur NPE. Ce qui est bizarre, c'est que ça tp seulement si le joueur n'est pas monté ou n'est pas en train de monté. Voilà le code : ```java if ((entityIn.getRidingEntity() == null) && (!entityIn.isDead) && (!entityIn.isBeingRidden()) && (!entityIn.isRiding())) { if(entityIn instanceof EntityPlayerMP) { EntityPlayerMP player = (EntityPlayerMP) entityIn; if(entityIn.isEntityAlive()) { if (player.dimension != -1) { // ThisisHalloween.portal = false; // player.timeUntilPortal = 100; //player.mcServer.getPlayerList().transferPlayerToDimension(player, -1, new Teleporter(player.mcServer.worldServerForDimension(-1))); player.mcServer.getPlayerList().transferEntityToWorld(player, -1, player.mcServer.worldServerForDimension(0), player.mcServer.worldServerForDimension(-1), new Teleporter(player.mcServer.worldServerForDimension(-1))); // player.timeUntilPortal = 100; // ThisisHalloween.portal = true; } else { // player.mcServer.getPlayerList().transferPlayerToDimension(player, 0, new Teleporter(player.mcServer.worldServerForDimension(0))); // player.timeUntilPortal = 100; } } } }
Merci d’avance
EDIT n°2 : Je vous met quand même le crash-report : ```
---- Minecraft Crash Report ----
// Don’t be sad, have a hug!Time: 24/09/16 23:56
Description: Colliding entity with blockjava.lang.NullPointerException: Colliding entity with block
A detailed walkthrough of the error, its code path and all known details is as follows:
– Head –
Thread: Server thread
Stacktrace:
at net.minecraft.entity.Entity.doBlockCollisions(Entity.java:1045)– Block being collided with –
Details:
Block: this_is_halloween:PortalFrightful[axis=x]
Block location: World: (-575,4,-1163), Chunk: (at 1,0,5 in -36,-73; contains blocks -576,0,-1168 to -561,255,-1153), Region: (-2,-3; contains chunks -64,-96 to -33,-65, blocks -1024,0,-1536 to -513,255,-1025)
Stacktrace:
at net.minecraft.entity.Entity.doBlockCollisions(Entity.java:1045)
at net.minecraft.entity.Entity.moveEntity(Entity.java:958)
at net.minecraft.entity.EntityLivingBase.moveEntityWithHeading(EntityLivingBase.java:1952)
at net.minecraft.entity.player.EntityPlayer.moveEntityWithHeading(EntityPlayer.java:1921)
at net.minecraft.entity.EntityLivingBase.onLivingUpdate(EntityLivingBase.java:2382)
at net.minecraft.entity.player.EntityPlayer.onLivingUpdate(EntityPlayer.java:549)
at net.minecraft.entity.EntityLivingBase.onUpdate(EntityLivingBase.java:2174)
at net.minecraft.entity.player.EntityPlayer.onUpdate(EntityPlayer.java:253)
at net.minecraft.entity.player.EntityPlayerMP.onUpdateEntity(EntityPlayerMP.java:341)
at net.minecraft.network.NetHandlerPlayServer.update(NetHandlerPlayServer.java:175)
at net.minecraftforge.fml.common.network.handshake.NetworkDispatcher$1.update(NetworkDispatcher.java:196)
at net.minecraft.network.NetworkManager.processReceivedPackets(NetworkManager.java:308)
at net.minecraft.network.NetworkSystem.networkTick(NetworkSystem.java:195)
at net.minecraft.server.MinecraftServer.updateTimeLightAndEntities(MinecraftServer.java:804)
at net.minecraft.server.MinecraftServer.tick(MinecraftServer.java:685)
at net.minecraft.server.integrated.IntegratedServer.tick(IntegratedServer.java:155)
at net.minecraft.server.MinecraftServer.run(MinecraftServer.java:534)
at java.lang.Thread.run(Unknown Source)– Entity being checked for collision –
Details:
Entity Type: null (net.minecraft.entity.player.EntityPlayerMP)
Entity ID: 49
Entity Name: Player732
Entity’s Exact location: -71,00, 4,25, -145,00
Entity’s Block location: World: (-71,4,-145), Chunk: (at 9,0,15 in -5,-10; contains blocks -80,0,-160 to -65,255,-145), Region: (-1,-1; contains chunks -32,-32 to -1,-1, blocks -512,0,-512 to -1,255,-1)
Entity’s Momentum: 0,00, 0,00, 0,00
Entity’s Passengers: []
Entity’s Vehicle:ERRORNullPointerException: null– Player being ticked –
Details:
Entity Type: null (net.minecraft.entity.player.EntityPlayerMP)
Entity ID: 49
Entity Name: Player732
Entity’s Exact location: -71,00, 4,25, -145,00
Entity’s Block location: World: (-71,4,-145), Chunk: (at 9,0,15 in -5,-10; contains blocks -80,0,-160 to -65,255,-145), Region: (-1,-1; contains chunks -32,-32 to -1,-1, blocks -512,0,-512 to -1,255,-1)
Entity’s Momentum: 0,00, 0,00, 0,00
Entity’s Passengers: []
Entity’s Vehicle:ERRORNullPointerException: null– Ticking connection –
Details:
Connection: net.minecraft.network.NetworkManager@3b2dafa7– System Details –
Details:
Minecraft Version: 1.9.4
Operating System: Windows 10 (amd64) version 10.0
Java Version: 1.8.0_92, Oracle Corporation
Java VM Version: Java HotSpot 64-Bit Server VM (mixed mode), Oracle Corporation
Memory: 471250968 bytes (449 MB) / 1038876672 bytes (990 MB) up to 1038876672 bytes (990 MB)
JVM Flags: 3 total; -Xincgc -Xmx1024M -Xms1024M
IntCache: cache: 0, tcache: 0, allocated: 0, tallocated: 0
FML: MCP 9.28 Powered by Forge 12.17.0.1976 4 mods loaded, 4 mods active
States: ‘U’ = Unloaded ‘L’ = Loaded ‘C’ = Constructed ‘H’ = Pre-initialized ‘I’ = Initialized ‘J’ = Post-initialized ‘A’ = Available ‘D’ = Disabled ‘E’ = Errored
UCHIJAAAA mcp{9.19} [Minecraft Coder Pack] (minecraft.jar)
UCHIJAAAA FML{8.0.99.99} [Forge Mod Loader] (forgeSrc-1.9.4-12.17.0.1976.jar)
UCHIJAAAA Forge{12.17.0.1976} [Minecraft Forge] (forgeSrc-1.9.4-12.17.0.1976.jar)
UCHIJAAAA This_is_Halloween{1.3} [This_is_Halloween] (bin)
Loaded coremods (and transformers):
GL info:ERRORRuntimeException: No OpenGL context found in the current thread.
Profiler Position: N/A (disabled)
Player Count: 1 / 8; [EntityPlayerMP[‘Player732’/49, l=‘New World’, x=-71,00, y=4,25, z=-145,00]]
Type: Integrated Server (map_client.txt)
Is Modded: Definitely; Client brand changed to ‘fml,forge’ -
Le joueur ne doit pas être transféré correctement je pense
-
Salut
Désolé du temps de la réponse.
Ca marche enfin ……après 3 moi -_-C’était dans le teleporter, j’ai juste mis quelques trucs en commentaire et ça remarche (je met le code en bas, j’ai ajouté des TODO).
Par contre, j’ai quelques problèmes : 1) Quand je rentre dans le portal, ça me tp bien. Seulement si je suis en créatif. Si je suis en survie, ça me tp à la couche 4. Pourtant, le portail est bien créer et activé.
2) Ensuite, quand je casse un block du portail (pas la structure, le portal), seul le block que j’ai cassé est détruit, pas les autres.
3) Je ne peux pas revenir dans l’Overworld sans casser et recréer le portail
4) Enfin, une fois que j’ai passer le portail, je ne peux plus créer d’autres portail à cause d’une variable je pense (on m’avais conseillé de la créer pour régler ce problème, et ça marchait. Jusqu’à aujorud’hui).Le BlockPortal :
package thisishalloween.block; import java.util.Map; import java.util.Random; import javax.annotation.Nullable; import com.google.common.cache.LoadingCache; import com.google.common.collect.Maps; import net.minecraft.block.Block; import net.minecraft.block.BlockBreakable; import net.minecraft.block.SoundType; import net.minecraft.block.material.Material; import net.minecraft.block.properties.IProperty; import net.minecraft.block.properties.PropertyEnum; import net.minecraft.block.state.BlockStateContainer; import net.minecraft.block.state.BlockWorldState; import net.minecraft.block.state.IBlockState; import net.minecraft.block.state.pattern.BlockPattern; import net.minecraft.entity.Entity; import net.minecraft.entity.EntityList; import net.minecraft.entity.monster.EntityPigZombie; import net.minecraft.entity.player.EntityPlayer; import net.minecraft.entity.player.EntityPlayerMP; import net.minecraft.init.Blocks; import net.minecraft.init.SoundEvents; import net.minecraft.item.ItemMonsterPlacer; import net.minecraft.item.ItemStack; import net.minecraft.server.MinecraftServer; import net.minecraft.server.management.PlayerList; import net.minecraft.util.BlockRenderLayer; import net.minecraft.util.EnumFacing; import net.minecraft.util.EnumParticleTypes; import net.minecraft.util.Rotation; import net.minecraft.util.SoundCategory; import net.minecraft.util.math.AxisAlignedBB; import net.minecraft.util.math.BlockPos; import net.minecraft.util.math.MathHelper; import net.minecraft.util.math.Vec3d; import net.minecraft.world.IBlockAccess; import net.minecraft.world.Teleporter; import net.minecraft.world.World; import net.minecraft.world.WorldServer; import net.minecraftforge.fml.common.ObfuscationReflectionHelper; import net.minecraftforge.fml.relauncher.Side; import net.minecraftforge.fml.relauncher.SideOnly; import thisishalloween.CreateBlocks; import thisishalloween.ThisisHalloween; import thisishalloween.world.frightful.TeleporterFrightful; public class BlockPortalFrightful extends BlockBreakable { public static final PropertyEnum <enumfacing.axis>AXIS = PropertyEnum.<enumfacing.axis>create("axis", EnumFacing.Axis.class, new EnumFacing.Axis[] {EnumFacing.Axis.X, EnumFacing.Axis.Z}); protected static final AxisAlignedBB field_185683_b = new AxisAlignedBB(0.0D, 0.0D, 0.375D, 1.0D, 1.0D, 0.625D); protected static final AxisAlignedBB field_185684_c = new AxisAlignedBB(0.375D, 0.0D, 0.0D, 0.625D, 1.0D, 1.0D); protected static final AxisAlignedBB field_185685_d = new AxisAlignedBB(0.375D, 0.0D, 0.375D, 0.625D, 1.0D, 0.625D); public BlockPortalFrightful() { super(Material.PORTAL, false); this.setDefaultState(this.blockState.getBaseState().withProperty(AXIS, EnumFacing.Axis.X)); this.setTickRandomly(true); this.setSoundType(SoundType.GLASS); } //TODO public void updateTick(World worldIn, BlockPos pos, IBlockState state, Random rand) { super.updateTick(worldIn, pos, state, rand); if (worldIn.provider.isSurfaceWorld() && worldIn.getGameRules().getBoolean("doMobSpawning") && rand.nextInt(2000) < worldIn.getDifficulty().getDifficultyId()) { int i = pos.getY(); BlockPos blockpos; for (blockpos = pos; !worldIn.getBlockState(blockpos).isFullyOpaque() && blockpos.getY() > 0; blockpos = blockpos.down()) { ; } if (i > 0 && !worldIn.getBlockState(blockpos.up()).isNormalCube()) { Entity entity = ItemMonsterPlacer.spawnCreature(worldIn, EntityList.getEntityStringFromClass(EntityPigZombie.class), (double)blockpos.getX() + 0.5D, (double)blockpos.getY() + 1.1D, (double)blockpos.getZ() + 0.5D); if (entity != null) { entity.timeUntilPortal = entity.getPortalCooldown(); } } } } @Nullable public AxisAlignedBB getCollisionBoundingBox(IBlockState blockState, World worldIn, BlockPos pos) { return NULL_AABB; } public AxisAlignedBB getBoundingBox(IBlockState state, IBlockAccess source, BlockPos pos) { switch ((EnumFacing.Axis)state.getValue(AXIS)) { case X: return field_185683_b; case Y: default: return field_185685_d; case Z: return field_185684_c; } } public static int getMetaForAxis(EnumFacing.Axis axis) { return axis == EnumFacing.Axis.X ? 1 : (axis == EnumFacing.Axis.Z ? 2 : 0); } public boolean isFullCube(IBlockState state) { return false; } public boolean trySpawnPortal(World worldIn, BlockPos pos) { BlockPortalFrightful.Size blockportal$size = new BlockPortalFrightful.Size(worldIn, pos, EnumFacing.Axis.X); if (blockportal$size.isValid() && blockportal$size.portalBlockCount == 0) { blockportal$size.placePortalBlocks(); return true; } else { BlockPortalFrightful.Size blockportal$size1 = new BlockPortalFrightful.Size(worldIn, pos, EnumFacing.Axis.Z); if (blockportal$size1.isValid() && blockportal$size1.portalBlockCount == 0) { blockportal$size1.placePortalBlocks(); return true; } else { return false; } } } public void neighborChanged(IBlockState state, World worldIn, BlockPos pos, Block blockIn) { EnumFacing.Axis axis = (EnumFacing.Axis)state.getValue(AXIS); if (axis == EnumFacing.Axis.X) { BlockPortalFrightful.Size size = new BlockPortalFrightful.Size(worldIn, pos, EnumFacing.Axis.X); if (!size.isValid() || size.portalBlockCount < size.width * size.height) { if(ThisisHalloween.portal) { worldIn.setBlockState(pos, Blocks.AIR.getDefaultState()); } } } else if (axis == EnumFacing.Axis.Z) { BlockPortalFrightful.Size size = new BlockPortalFrightful.Size(worldIn, pos, EnumFacing.Axis.Z); if (!size.isValid() || size.portalBlockCount < size.width * size.height) { if(ThisisHalloween.portal) { worldIn.setBlockState(pos, Blocks.AIR.getDefaultState()); } } } } @SideOnly(Side.CLIENT) public boolean shouldSideBeRendered(IBlockState blockState, IBlockAccess blockAccess, BlockPos pos, EnumFacing side) { EnumFacing.Axis axis = null; pos = pos.offset(side); if (blockState.getBlock() == this) { axis = (EnumFacing.Axis)blockState.getValue(AXIS); if (axis == null) { return false; } if (axis == EnumFacing.Axis.Z && side != EnumFacing.EAST && side != EnumFacing.WEST) { return false; } if (axis == EnumFacing.Axis.X && side != EnumFacing.SOUTH && side != EnumFacing.NORTH) { return false; } } boolean flag = blockAccess.getBlockState(pos.west()).getBlock() == this && blockAccess.getBlockState(pos.west(2)).getBlock() != this; boolean flag1 = blockAccess.getBlockState(pos.east()).getBlock() == this && blockAccess.getBlockState(pos.east(2)).getBlock() != this; boolean flag2 = blockAccess.getBlockState(pos.north()).getBlock() == this && blockAccess.getBlockState(pos.north(2)).getBlock() != this; boolean flag3 = blockAccess.getBlockState(pos.south()).getBlock() == this && blockAccess.getBlockState(pos.south(2)).getBlock() != this; boolean flag4 = flag || flag1 || axis == EnumFacing.Axis.X; boolean flag5 = flag2 || flag3 || axis == EnumFacing.Axis.Z; return flag4 && side == EnumFacing.WEST ? true : (flag4 && side == EnumFacing.EAST ? true : (flag5 && side == EnumFacing.NORTH ? true : flag5 && side == EnumFacing.SOUTH)); } /** * Returns the quantity of items to drop on block destruction. */ public int quantityDropped(Random random) { return 0; } /** * Called When an Entity Collided with the Block */ @Override public void onEntityCollidedWithBlock(World worldIn, BlockPos pos, IBlockState state, Entity entityIn) { if (!entityIn.isRiding() && !entityIn.isBeingRidden() && entityIn.isNonBoss()) { int id = ThisisHalloween.DIMENSION_ID; if (entityIn.dimension == id) { id = 0; } if(entityIn instanceof EntityPlayerMP) { EntityPlayerMP player = (EntityPlayerMP) entityIn; if (player.timeUntilPortal > 0) { player.timeUntilPortal = 100; } else if (player.dimension != ThisisHalloween.DIMENSION_ID) { ThisisHalloween.portal = false; player.mcServer.getPlayerList().transferPlayerToDimension(player, ThisisHalloween.DIMENSION_ID, new TeleporterFrightful(player.mcServer.worldServerForDimension(ThisisHalloween.DIMENSION_ID))); player.timeUntilPortal = 100; // ThisisHalloween.portal = true; } else { player.mcServer.getPlayerList().transferPlayerToDimension(player, 0, new TeleporterFrightful(player.mcServer.worldServerForDimension(0))); player.timeUntilPortal = 100; } // System.out.println("appel travel"); // player.timeUntilPortal = 100; } } } /** * Convert the given metadata into a BlockState for this Block */ public IBlockState getStateFromMeta(int meta) { return this.getDefaultState().withProperty(AXIS, (meta & 3) == 2 ? EnumFacing.Axis.Z : EnumFacing.Axis.X); } @SideOnly(Side.CLIENT) public BlockRenderLayer getBlockLayer() { return BlockRenderLayer.TRANSLUCENT; } @SideOnly(Side.CLIENT) public void randomDisplayTick(IBlockState state, World world, BlockPos pos, Random rand) { if (rand.nextInt(100) == 0) { world.playSound((double)pos.getX() + 0.5D, (double)pos.getY() + 0.5D, (double)pos.getZ() + 0.5D, SoundEvents.BLOCK_PORTAL_AMBIENT, SoundCategory.BLOCKS, 0.5F, rand.nextFloat() * 0.4F + 0.8F, false); } for (int i = 0; i < 4; ++i) { double d0 = (double)((float)pos.getX() + rand.nextFloat()); double d1 = (double)((float)pos.getY() + rand.nextFloat()); double d2 = (double)((float)pos.getZ() + rand.nextFloat()); double d3 = ((double)rand.nextFloat() - 0.5D) * 0.5D; double d4 = ((double)rand.nextFloat() - 0.5D) * 0.5D; double d5 = ((double)rand.nextFloat() - 0.5D) * 0.5D; int j = rand.nextInt(2) * 2 - 1; if (world.getBlockState(pos.west()).getBlock() != this && world.getBlockState(pos.east()).getBlock() != this) { d0 = (double)pos.getX() + 0.5D + 0.25D * (double)j; d3 = (double)(rand.nextFloat() * 2.0F * (float)j); } else { d2 = (double)pos.getZ() + 0.5D + 0.25D * (double)j; d5 = (double)(rand.nextFloat() * 2.0F * (float)j); } world.spawnParticle(EnumParticleTypes.PORTAL, d0, d1, d2, d3, d4, d5, new int[0]); } } /** * Convert the BlockState into the correct metadata value */ public int getMetaFromState(IBlockState state) { return getMetaForAxis((EnumFacing.Axis)state.getValue(AXIS)); } @SideOnly(Side.CLIENT) public ItemStack getItem(World worldIn, BlockPos pos, IBlockState state) { return null; } protected BlockStateContainer createBlockState() { return new BlockStateContainer(this, new IProperty[] {AXIS}); } public IBlockState withRotation(IBlockState state, Rotation rot) { switch (rot) { case COUNTERCLOCKWISE_90: case CLOCKWISE_90: switch ((EnumFacing.Axis)state.getValue(AXIS)) { case X: return state.withProperty(AXIS, EnumFacing.Axis.Z); case Z: return state.withProperty(AXIS, EnumFacing.Axis.X); default: return state; } default: return state; } } public BlockPattern.PatternHelper createPatternHelper(World worldIn, BlockPos p_181089_2_) { EnumFacing.Axis enumfacing$axis = EnumFacing.Axis.Z; BlockPortalFrightful.Size blockportal$size = new BlockPortalFrightful.Size(worldIn, p_181089_2_, EnumFacing.Axis.X); LoadingCache <blockpos, blockworldstate="">loadingcache = BlockPattern.createLoadingCache(worldIn, true); if (!blockportal$size.isValid()) { enumfacing$axis = EnumFacing.Axis.X; blockportal$size = new BlockPortalFrightful.Size(worldIn, p_181089_2_, EnumFacing.Axis.Z); } if (!blockportal$size.isValid()) { return new BlockPattern.PatternHelper(p_181089_2_, EnumFacing.NORTH, EnumFacing.UP, loadingcache, 1, 1, 1); } else { int[] aint = new int[EnumFacing.AxisDirection.values().length]; EnumFacing enumfacing = blockportal$size.rightDir.rotateYCCW(); BlockPos blockpos = blockportal$size.bottomLeft.up(blockportal$size.getHeight() - 1); for (EnumFacing.AxisDirection enumfacing$axisdirection : EnumFacing.AxisDirection.values()) { BlockPattern.PatternHelper blockpattern$patternhelper = new BlockPattern.PatternHelper(enumfacing.getAxisDirection() == enumfacing$axisdirection ? blockpos : blockpos.offset(blockportal$size.rightDir, blockportal$size.getWidth() - 1), EnumFacing.getFacingFromAxis(enumfacing$axisdirection, enumfacing$axis), EnumFacing.UP, loadingcache, blockportal$size.getWidth(), blockportal$size.getHeight(), 1); for (int i = 0; i < blockportal$size.getWidth(); ++i) { for (int j = 0; j < blockportal$size.getHeight(); ++j) { BlockWorldState blockworldstate = blockpattern$patternhelper.translateOffset(i, j, 1); if (blockworldstate.getBlockState() != null && blockworldstate.getBlockState().getMaterial() != Material.AIR) { ++aint[enumfacing$axisdirection.ordinal()]; } } } } EnumFacing.AxisDirection enumfacing$axisdirection1 = EnumFacing.AxisDirection.POSITIVE; for (EnumFacing.AxisDirection enumfacing$axisdirection2 : EnumFacing.AxisDirection.values()) { if (aint[enumfacing$axisdirection2.ordinal()] < aint[enumfacing$axisdirection1.ordinal()]) { enumfacing$axisdirection1 = enumfacing$axisdirection2; } } return new BlockPattern.PatternHelper(enumfacing.getAxisDirection() == enumfacing$axisdirection1 ? blockpos : blockpos.offset(blockportal$size.rightDir, blockportal$size.getWidth() - 1), EnumFacing.getFacingFromAxis(enumfacing$axisdirection1, enumfacing$axis), EnumFacing.UP, loadingcache, blockportal$size.getWidth(), blockportal$size.getHeight(), 1); } } public static class Size { private final World world; private final EnumFacing.Axis axis; private final EnumFacing rightDir; private final EnumFacing leftDir; private int portalBlockCount; private BlockPos bottomLeft; private int height; private int width; public Size(World worldIn, BlockPos p_i45694_2_, EnumFacing.Axis p_i45694_3_) { this.world = worldIn; this.axis = p_i45694_3_; if (p_i45694_3_ == EnumFacing.Axis.X) { this.leftDir = EnumFacing.EAST; this.rightDir = EnumFacing.WEST; } else { this.leftDir = EnumFacing.NORTH; this.rightDir = EnumFacing.SOUTH; } for (BlockPos blockpos = p_i45694_2_; p_i45694_2_.getY() > blockpos.getY() - 21 && p_i45694_2_.getY() > 0 && this.isEmptyBlock(worldIn.getBlockState(p_i45694_2_.down()).getBlock()); p_i45694_2_ = p_i45694_2_.down()) { ; } int i = this.getDistanceUntilEdge(p_i45694_2_, this.leftDir) - 1; if (i >= 0) { this.bottomLeft = p_i45694_2_.offset(this.leftDir, i); this.width = this.getDistanceUntilEdge(this.bottomLeft, this.rightDir); if (this.width < 2 || this.width > 21) { this.bottomLeft = null; this.width = 0; } } if (this.bottomLeft != null) { this.height = this.calculatePortalHeight(); } } protected int getDistanceUntilEdge(BlockPos p_180120_1_, EnumFacing p_180120_2_) { int i; for (i = 0; i < 22; ++i) { BlockPos blockpos = p_180120_1_.offset(p_180120_2_, i); if (!this.isEmptyBlock(this.world.getBlockState(blockpos).getBlock()) || this.world.getBlockState(blockpos.down()).getBlock() != Blocks.NETHER_BRICK) { break; } } Block block = this.world.getBlockState(p_180120_1_.offset(p_180120_2_, i)).getBlock(); return block == Blocks.NETHER_BRICK ? i : 0; } public int getHeight() { return this.height; } public int getWidth() { return this.width; } protected int calculatePortalHeight() { label24: for (this.height = 0; this.height < 21; ++this.height) { for (int i = 0; i < this.width; ++i) { BlockPos blockpos = this.bottomLeft.offset(this.rightDir, i).up(this.height); Block block = this.world.getBlockState(blockpos).getBlock(); if (!this.isEmptyBlock(block)) { break label24; } if (block == Blocks.PORTAL) { ++this.portalBlockCount; } if (i == 0) { block = this.world.getBlockState(blockpos.offset(this.leftDir)).getBlock(); if (block != Blocks.NETHER_BRICK) { break label24; } } else if (i == this.width - 1) { block = this.world.getBlockState(blockpos.offset(this.rightDir)).getBlock(); if (block != Blocks.NETHER_BRICK) { break label24; } } } } for (int j = 0; j < this.width; ++j) { if (this.world.getBlockState(this.bottomLeft.offset(this.rightDir, j).up(this.height)).getBlock() != Blocks.NETHER_BRICK) { this.height = 0; break; } } if (this.height <= 21 && this.height >= 3) { return this.height; } else { this.bottomLeft = null; this.width = 0; this.height = 0; return 0; } } protected boolean isEmptyBlock(Block p_150857_1_) { return p_150857_1_.getMaterial(p_150857_1_.getDefaultState()) == Material.AIR || p_150857_1_ == CreateBlocks.portalFrightful; } public boolean isValid() { return this.bottomLeft != null && this.width >= 2 && this.width <= 21 && this.height >= 3 && this.height <= 21; } public void placePortalBlocks() { for (int i = 0; i < this.width; ++i) { BlockPos blockpos = this.bottomLeft.offset(this.rightDir, i); for (int j = 0; j < this.height; ++j) { this.world.setBlockState(blockpos.up(j), CreateBlocks.portalFrightful.getDefaultState().withProperty(BlockPortalFrightful.AXIS, this.axis), 2); } } } } }
Le Teleporter :
package thisishalloween.world.frightful; import java.util.Iterator; import java.util.List; import java.util.Random; import com.google.common.collect.Lists; import it.unimi.dsi.fastutil.longs.Long2ObjectMap; import it.unimi.dsi.fastutil.longs.Long2ObjectOpenHashMap; import it.unimi.dsi.fastutil.objects.ObjectIterator; import net.minecraft.block.BlockPortal; import net.minecraft.block.state.IBlockState; import net.minecraft.block.state.pattern.BlockPattern; import net.minecraft.entity.Entity; import net.minecraft.entity.player.EntityPlayerMP; import net.minecraft.init.Blocks; import net.minecraft.util.EnumFacing; import net.minecraft.util.math.BlockPos; import net.minecraft.util.math.ChunkPos; import net.minecraft.util.math.MathHelper; import net.minecraft.world.Teleporter; import net.minecraft.world.WorldServer; import thisishalloween.CreateBlocks; public class TeleporterFrightful extends Teleporter { private final WorldServer worldServerInstance; private final Random random; private final Long2ObjectMap destinationCoordinateCache = new Long2ObjectOpenHashMap(); private final List destinationCoordinateKeys = Lists.newArrayList(); public TeleporterFrightful(WorldServer worldIn) { super(worldIn); this.worldServerInstance = worldIn; this.random = new Random(worldIn.getSeed()); } public void placeInPortal(Entity entityIn, float rotationYaw) { if (this.worldServerInstance.provider.getDimension() != 1) { if (!this.placeInExistingPortal(entityIn, rotationYaw)) { this.makePortal(entityIn); this.placeInExistingPortal(entityIn, rotationYaw); } } else { int i = MathHelper.floor_double(entityIn.posX); int j = MathHelper.floor_double(entityIn.posY) - 1; int k = MathHelper.floor_double(entityIn.posZ); byte b0 = 1; byte b1 = 0; for (int l = -2; l <= 2; ++l) { for (int i1 = -2; i1 <= 2; ++i1) { for (int j1 = -1; j1 < 3; ++j1) { int k1 = i + i1 * b0 + l * b1; int l1 = j + j1; int i2 = k + i1 * b1 - l * b0; boolean flag = j1 < 0; this.worldServerInstance.setBlockState(new BlockPos(k1, l1, i2), flag ? Blocks.NETHER_BRICK.getDefaultState() : Blocks.AIR.getDefaultState()); } } } entityIn.setLocationAndAngles((double)i, (double)j, (double)k, entityIn.rotationYaw, 0.0F); entityIn.motionX = entityIn.motionY = entityIn.motionZ = 0.0D; } } public boolean placeInExistingPortal(Entity entityIn, float rotationYaw) { int i = 128; double d0 = -1.0D; int j = MathHelper.floor_double(entityIn.posX); int k = MathHelper.floor_double(entityIn.posZ); boolean flag = true; BlockPos blockpos = BlockPos.ORIGIN; long l = ChunkPos.chunkXZ2Int(j, k); if (this.destinationCoordinateCache.containsKey(l)) { Teleporter.PortalPosition teleporter$portalposition = (Teleporter.PortalPosition)this.destinationCoordinateCache.get(l); d0 = 0.0D; blockpos = teleporter$portalposition; teleporter$portalposition.lastUpdateTime = this.worldServerInstance.getTotalWorldTime(); flag = false; } else { BlockPos blockpos3 = new BlockPos(entityIn); for (int i1 = -128; i1 <= 128; ++i1) { BlockPos blockpos2; for (int j1 = -128; j1 <= 128; ++j1) { for (BlockPos blockpos1 = blockpos3.add(i1, this.worldServerInstance.getActualHeight() - 1 - blockpos3.getY(), j1); blockpos1.getY() >= 0; blockpos1 = blockpos2) { blockpos2 = blockpos1.down(); if (this.worldServerInstance.getBlockState(blockpos1).getBlock() == CreateBlocks.portalFrightful) { while (this.worldServerInstance.getBlockState(blockpos2 = blockpos1.down()).getBlock() == CreateBlocks.portalFrightful) { blockpos1 = blockpos2; } double d1 = blockpos1.distanceSq(blockpos3); if (d0 < 0.0D || d1 < d0) { d0 = d1; blockpos = blockpos1; } } } } } } if (d0 >= 0.0D) { if (flag) { this.destinationCoordinateCache.put(l, new Teleporter.PortalPosition(blockpos, this.worldServerInstance.getTotalWorldTime())); } double d5 = (double)blockpos.getX() + 0.5D; double d6 = (double)blockpos.getY() + 0.5D; double d7 = (double)blockpos.getZ() + 0.5D; BlockPattern.PatternHelper blockpattern$patternhelper = Blocks.PORTAL.createPatternHelper(this.worldServerInstance, blockpos); boolean flag1 = blockpattern$patternhelper.getForwards().rotateY().getAxisDirection() == EnumFacing.AxisDirection.NEGATIVE; double d2 = blockpattern$patternhelper.getForwards().getAxis() == EnumFacing.Axis.X ? (double)blockpattern$patternhelper.getFrontTopLeft().getZ() : (double)blockpattern$patternhelper.getFrontTopLeft().getX(); //TODO d6 = (double)(blockpattern$patternhelper.getFrontTopLeft().getY() + 1) - /*entityIn.getLastPortalVec().yCoord * */(double)blockpattern$patternhelper.getHeight(); if (flag1) { ++d2; } if (blockpattern$patternhelper.getForwards().getAxis() == EnumFacing.Axis.X) { d7 = d2 + (1.0D - entityIn.getLastPortalVec().xCoord) * (double)blockpattern$patternhelper.getWidth() * (double)blockpattern$patternhelper.getForwards().rotateY().getAxisDirection().getOffset(); } else { //TODO d5 = d2 + (1.0D /*- entityIn.getLastPortalVec().xCoord*/) * (double)blockpattern$patternhelper.getWidth() * (double)blockpattern$patternhelper.getForwards().rotateY().getAxisDirection().getOffset(); } float f = 0.0F; float f1 = 0.0F; float f2 = 0.0F; float f3 = 0.0F; if (blockpattern$patternhelper.getForwards().getOpposite() == entityIn.getTeleportDirection()) { f = 1.0F; f1 = 1.0F; } //TODO /* else if (blockpattern$patternhelper.getForwards().getOpposite() == entityIn.getTeleportDirection().getOpposite()) { f = -1.0F; f1 = -1.0F; }*/ /* else if (blockpattern$patternhelper.getForwards().getOpposite() == entityIn.getTeleportDirection().rotateY()) { f2 = 1.0F; f3 = -1.0F; }*/ else { f2 = -1.0F; f3 = 1.0F; } double d3 = entityIn.motionX; double d4 = entityIn.motionZ; entityIn.motionX = d3 * (double)f + d4 * (double)f3; entityIn.motionZ = d3 * (double)f2 + d4 * (double)f1; //TODO entityIn.rotationYaw = rotationYaw /*- (float)(entityIn.getTeleportDirection().getOpposite().getHorizontalIndex() * 90) + (float)(blockpattern$patternhelper.getForwards().getHorizontalIndex() * 90)*/; if (entityIn instanceof EntityPlayerMP) { ((EntityPlayerMP)entityIn).connection.setPlayerLocation(d5, d6, d7, entityIn.rotationYaw, entityIn.rotationPitch); } else { entityIn.setLocationAndAngles(d5, d6, d7, entityIn.rotationYaw, entityIn.rotationPitch); } return true; } else { return false; } } private boolean func_180265_a(BlockPos p_180265_1_) { return !this.worldServerInstance.isAirBlock(p_180265_1_) || !this.worldServerInstance.isAirBlock(p_180265_1_.up()); } public boolean makePortal(Entity p_85188_1_) { byte b0 = 16; double d0 = -1.0D; int i = MathHelper.floor_double(p_85188_1_.posX); int j = MathHelper.floor_double(p_85188_1_.posY); int k = MathHelper.floor_double(p_85188_1_.posZ); int l = i; int i1 = j; int j1 = k; int k1 = 0; int l1 = this.random.nextInt(4); int i2; double d1; int k2; double d2; int i3; int j3; int k3; int l3; int i4; int j4; int k4; int l4; int i5; double d3; double d4; for (i2 = i - b0; i2 <= i + b0; ++i2) { d1 = (double)i2 + 0.5D - p_85188_1_.posX; for (k2 = k - b0; k2 <= k + b0; ++k2) { d2 = (double)k2 + 0.5D - p_85188_1_.posZ; label271: for (i3 = this.worldServerInstance.getActualHeight() - 1; i3 >= 0; –i3) { if (this.worldServerInstance.isAirBlock(new BlockPos(i2, i3, k2))) { while (i3 > 0 && this.worldServerInstance.isAirBlock(new BlockPos(i2, i3 - 1, k2))) { --i3; } for (j3 = l1; j3 < l1 + 4; ++j3) { k3 = j3 % 2; l3 = 1 - k3; if (j3 % 4 >= 2) { k3 = -k3; l3 = -l3; } for (i4 = 0; i4 < 3; ++i4) { for (j4 = 0; j4 < 4; ++j4) { for (k4 = -1; k4 < 4; ++k4) { l4 = i2 + (j4 - 1) * k3 + i4 * l3; i5 = i3 + k4; int j5 = k2 + (j4 - 1) * l3 - i4 * k3; if (k4 < 0 && !this.worldServerInstance.getBlockState(new BlockPos(l4, i5, j5)).getMaterial().isSolid() || k4 >= 0 && !this.worldServerInstance.isAirBlock(new BlockPos(l4, i5, j5))) { continue label271; } } } } d3 = (double)i3 + 0.5D - p_85188_1_.posY; d4 = d1 * d1 + d3 * d3 + d2 * d2; if (d0 < 0.0D || d4 < d0) { d0 = d4; l = i2; i1 = i3; j1 = k2; k1 = j3 % 4; } } } } } } if (d0 < 0.0D) { for (i2 = i - b0; i2 <= i + b0; ++i2) { d1 = (double)i2 + 0.5D - p_85188_1_.posX; for (k2 = k - b0; k2 <= k + b0; ++k2) { d2 = (double)k2 + 0.5D - p_85188_1_.posZ; label219: for (i3 = this.worldServerInstance.getActualHeight() - 1; i3 >= 0; --i3) { if (this.worldServerInstance.isAirBlock(new BlockPos(i2, i3, k2))) { while (i3 > 0 && this.worldServerInstance.isAirBlock(new BlockPos(i2, i3 - 1, k2))) { --i3; } for (j3 = l1; j3 < l1 + 2; ++j3) { k3 = j3 % 2; l3 = 1 - k3; for (i4 = 0; i4 < 4; ++i4) { for (j4 = -1; j4 < 4; ++j4) { k4 = i2 + (i4 - 1) * k3; l4 = i3 + j4; i5 = k2 + (i4 - 1) * l3; if (j4 < 0 && !this.worldServerInstance.getBlockState(new BlockPos(k4, l4, i5)).getMaterial().isSolid() || j4 >= 0 && !this.worldServerInstance.isAirBlock(new BlockPos(k4, l4, i5))) { continue label219; } } } d3 = (double)i3 + 0.5D - p_85188_1_.posY; d4 = d1 * d1 + d3 * d3 + d2 * d2; if (d0 < 0.0D || d4 < d0) { d0 = d4; l = i2; i1 = i3; j1 = k2; k1 = j3 % 2; } } } } } } } int k5 = l; int j2 = i1; k2 = j1; int l5 = k1 % 2; int l2 = 1 - l5; if (k1 % 4 >= 2) { l5 = -l5; l2 = -l2; } if (d0 < 0.0D) { i1 = MathHelper.clamp_int(i1, 70, this.worldServerInstance.getActualHeight() - 10); j2 = i1; for (i3 = -1; i3 <= 1; ++i3) { for (j3 = 1; j3 < 3; ++j3) { for (k3 = -1; k3 < 3; ++k3) { l3 = k5 + (j3 - 1) * l5 + i3 * l2; i4 = j2 + k3; j4 = k2 + (j3 - 1) * l2 - i3 * l5; boolean flag = k3 < 0; this.worldServerInstance.setBlockState(new BlockPos(l3, i4, j4), flag ? Blocks.NETHER_BRICK.getDefaultState() : Blocks.AIR.getDefaultState()); } } } } IBlockState iblockstate = CreateBlocks.portalFrightful.getDefaultState().withProperty(BlockPortal.AXIS, l5 != 0 ? EnumFacing.Axis.X : EnumFacing.Axis.Z); for (j3 = 0; j3 < 4; ++j3) { for (k3 = 0; k3 < 4; ++k3) { for (l3 = -1; l3 < 4; ++l3) { i4 = k5 + (k3 - 1) * l5; j4 = j2 + l3; k4 = k2 + (k3 - 1) * l2; boolean flag1 = k3 == 0 || k3 == 3 || l3 == -1 || l3 == 3; this.worldServerInstance.setBlockState(new BlockPos(i4, j4, k4), flag1 ? Blocks.NETHER_BRICK.getDefaultState() : iblockstate, 2); } } for (k3 = 0; k3 < 4; ++k3) { for (l3 = -1; l3 < 4; ++l3) { i4 = k5 + (k3 - 1) * l5; j4 = j2 + l3; k4 = k2 + (k3 - 1) * l2; this.worldServerInstance.notifyNeighborsOfStateChange(new BlockPos(i4, j4, k4), this.worldServerInstance.getBlockState(new BlockPos(i4, j4, k4)).getBlock()); } } } return true; } /** * called periodically to remove out-of-date portal locations from the cache list. Argument par1 is a * WorldServer.getTotalWorldTime() value. */ public void removeStalePortalLocations(long worldTime) { if (worldTime % 100L == 0L) { long i = worldTime - 300L; ObjectIterator <teleporterfrightful.portalposition>objectiterator = this.destinationCoordinateCache.values().iterator(); while (objectiterator.hasNext()) { TeleporterFrightful.PortalPosition teleporter$portalposition = (TeleporterFrightful.PortalPosition)objectiterator.next(); if (teleporter$portalposition == null || teleporter$portalposition.lastUpdateTime < i) { objectiterator.remove(); } } } } public class PortalPosition extends BlockPos { /** The worldtime at which this PortalPosition was last verified */ public long lastUpdateTime; public PortalPosition(BlockPos pos, long p_i45747_3_) { super(pos.getX(), pos.getY(), pos.getZ()); this.lastUpdateTime = p_i45747_3_; } } }
Merci d’avance</teleporterfrightful.portalposition></blockpos,></enumfacing.axis></enumfacing.axis>
-
Salut
J’ai réussi à régler un bug (en réalité deux, car les deux étaient liés ensemble).
Quand je casse un block du portal, ça détruit tout les blocksPortal. Du coup, je peux aussi créer des portails quand je veux.J’ai fait comme ça :
public void neighborChanged(IBlockState state, World worldIn, BlockPos pos, Block blockIn) { EnumFacing.Axis axis = (EnumFacing.Axis)state.getValue(AXIS); { if (axis == EnumFacing.Axis.X) { BlockPortalFrightful.Size size = new BlockPortalFrightful.Size(worldIn, pos, EnumFacing.Axis.X); if (!size.isValid() || size.portalBlockCount < size.width * size.height) { boolean isAir = worldIn.isAirBlock(new BlockPos(pos.getX(), pos.getY(), pos.getZ())) || worldIn.isAirBlock(new BlockPos(pos.getX() - 1, pos.getY(), pos.getZ())) || worldIn.isAirBlock(new BlockPos(pos.getX() + 1, pos.getY(), pos.getZ())) || worldIn.isAirBlock(new BlockPos(pos.getX(), pos.getY() - 1, pos.getZ())) || worldIn.isAirBlock(new BlockPos(pos.getX(), pos.getY() + 1, pos.getZ())); if(isAir) { worldIn.setBlockState(pos, Blocks.AIR.getDefaultState()); } } } else if (axis == EnumFacing.Axis.Z) { BlockPortalFrightful.Size size = new BlockPortalFrightful.Size(worldIn, pos, EnumFacing.Axis.Z); if (!size.isValid() || size.portalBlockCount < size.width * size.height) { boolean isAir = worldIn.isAirBlock(new BlockPos(pos.getX(), pos.getY(), pos.getZ())) || worldIn.isAirBlock(new BlockPos(pos.getX(), pos.getY(), pos.getZ() - 1)) || worldIn.isAirBlock(new BlockPos(pos.getX(), pos.getY(), pos.getZ() + 1)) || worldIn.isAirBlock(new BlockPos(pos.getX(), pos.getY() - 1, pos.getZ())) || worldIn.isAirBlock(new BlockPos(pos.getX(), pos.getY() + 1, pos.getZ())); if(isAir) { worldIn.setBlockState(pos, Blocks.AIR.getDefaultState()); } } } } }
Par contre, il me reste toujours les problèmes que je ne peux pas revenir dans l’Overworld sans recréer le portail, et que quand je suis en survie, ça me tp dans mon monde à la couche -4 (malgré que le portail soit créé et activé). D’ailleurs, j’ai aussi remarqué que quand je suis dans ma dimension et que je retourne dans l’Overworld en étant en survie, ça me tp vers la couche 64.
Si vous savez comment faire, …
Merci d’avance
EDIT : le bug que je ne peux pas revenir dans l’Overworld semble s’être réglé de lui-même. Pour le bug que ça me tp pas au bon endroit (couche -4), ça le fait uniquement en flatgrass. En normal, ça me tp à la bonne couche, mais parfois j’atteris en l’air (genre 2-3 blocks de hauteur) et parfois dans des blocks
-
Salut
J’ai cherché pour le bug mais je n’ai rien trouvé. Je pense que ça doit être dans la fonctio placeInExistingPortal de la classe Teleporter : ```java
public boolean placeInExistingPortal(Entity entityIn, float rotationYaw)
{
int i = 128;
double d0 = -1.0D;
int j = MathHelper.floor_double(entityIn.posX);
int k = MathHelper.floor_double(entityIn.posZ);
boolean flag = true;
BlockPos blockpos = BlockPos.ORIGIN;
long l = ChunkPos.chunkXZ2Int(j, k);if (this.destinationCoordinateCache.containsKey(l))
{
Teleporter.PortalPosition teleporter$portalposition = (Teleporter.PortalPosition)this.destinationCoordinateCache.get(l);
d0 = 0.0D;
blockpos = teleporter$portalposition;
teleporter$portalposition.lastUpdateTime = this.worldServerInstance.getTotalWorldTime();
flag = false;
}
else
{
BlockPos blockpos3 = new BlockPos(entityIn);for (int i1 = -128; i1 <= 128; ++i1)
{
BlockPos blockpos2;for (int j1 = -128; j1 <= 128; ++j1)
{
for (BlockPos blockpos1 = blockpos3.add(i1, this.worldServerInstance.getActualHeight() - 1 - blockpos3.getY(), j1); blockpos1.getY() >= 0; blockpos1 = blockpos2)
{
blockpos2 = blockpos1.down();if (this.worldServerInstance.getBlockState(blockpos1).getBlock() == CreateBlocks.portalFrightful)
{
while (this.worldServerInstance.getBlockState(blockpos2 = blockpos1.down()).getBlock() == CreateBlocks.portalFrightful)
{
blockpos1 = blockpos2;
}double d1 = blockpos1.distanceSq(blockpos3);
if (d0 < 0.0D || d1 < d0)
{
d0 = d1;
blockpos = blockpos1;
}
}
}
}
}
}if (d0 >= 0.0D)
{
if (flag)
{
this.destinationCoordinateCache.put(l, new Teleporter.PortalPosition(blockpos, this.worldServerInstance.getTotalWorldTime()));
}double d5 = (double)blockpos.getX() + 0.5D;
double d6 = (double)blockpos.getY() + 0.5D;
double d7 = (double)blockpos.getZ() + 0.5D;
BlockPattern.PatternHelper blockpattern$patternhelper = Blocks.PORTAL.createPatternHelper(this.worldServerInstance, blockpos);
boolean flag1 = blockpattern$patternhelper.getForwards().rotateY().getAxisDirection() == EnumFacing.AxisDirection.NEGATIVE;
double d2 = blockpattern$patternhelper.getForwards().getAxis() == EnumFacing.Axis.X ? (double)blockpattern$patternhelper.getFrontTopLeft().getZ() : (double)blockpattern$patternhelper.getFrontTopLeft().getX();
//TODO
d6 = (double)(blockpattern$patternhelper.getFrontTopLeft().getY() + 1) - /*entityIn.getLastPortalVec().yCoord * */(double)blockpattern$patternhelper.getHeight();if (flag1)
{
++d2;
}if (blockpattern$patternhelper.getForwards().getAxis() == EnumFacing.Axis.X)
{
d7 = d2 + (1.0D - entityIn.getLastPortalVec().xCoord) * (double)blockpattern$patternhelper.getWidth() * (double)blockpattern$patternhelper.getForwards().rotateY().getAxisDirection().getOffset();
}
else
{
//TODO
d5 = d2 + (1.0D /- entityIn.getLastPortalVec().xCoord/) * (double)blockpattern$patternhelper.getWidth() * (double)blockpattern$patternhelper.getForwards().rotateY().getAxisDirection().getOffset();
}float f = 0.0F;
float f1 = 0.0F;
float f2 = 0.0F;
float f3 = 0.0F;if (blockpattern$patternhelper.getForwards().getOpposite() == entityIn.getTeleportDirection())
{
f = 1.0F;
f1 = 1.0F;
}
//TODO
/* else if (blockpattern$patternhelper.getForwards().getOpposite() == entityIn.getTeleportDirection().getOpposite())
{
f = -1.0F;
f1 = -1.0F;
}/
/ else if (blockpattern$patternhelper.getForwards().getOpposite() == entityIn.getTeleportDirection().rotateY())
{
f2 = 1.0F;
f3 = -1.0F;
}*/
else
{
f2 = -1.0F;
f3 = 1.0F;
}double d3 = entityIn.motionX;
double d4 = entityIn.motionZ;
entityIn.motionX = d3 * (double)f + d4 * (double)f3;
entityIn.motionZ = d3 * (double)f2 + d4 * (double)f1;
//TODO
entityIn.rotationYaw = rotationYaw /- (float)(entityIn.getTeleportDirection().getOpposite().getHorizontalIndex() * 90) + (float)(blockpattern$patternhelper.getForwards().getHorizontalIndex() * 90)/;if (entityIn instanceof EntityPlayerMP)
{
((EntityPlayerMP)entityIn).connection.setPlayerLocation(d5, d6, d7, entityIn.rotationYaw, entityIn.rotationPitch);
}
else
{
entityIn.setLocationAndAngles(d5, d6, d7, entityIn.rotationYaw, entityIn.rotationPitch);
}return true;
}
else
{
return false;
}
}Je me souviens avoir déjà eu ce bug une fois (enfin …, plus ou moins) : je spawnais pareil dans des blocks, pareil à la mauvaise couche, sauf que avant le portail n'était pas activé tandis que là il l'est. Je pense que le portail doit se créer peu de temps (genre une demi-seconde voire moins) après que je spawn. Mais ce que je ne comprend pas, c'est que je spawn mal seulement si je suis en survie. Si vous avez une idée, je suis preneur. Merci d'avance
-
Salut
Un petit UP pour mon dernier problème avec ce mod. Sérieux, je vois pas pourquoi ça bugMerci d’avance
-
Salut
Ca m’a énerver, j’arrête de chercher. On trouve pas, c’est inutile, je ne fais que perdre du temps pour mon autre mod (celui de Noël). Je préfère faire celui-là. En tout cas, si vous avez une solution, n’hésitez pas, ça peut aider des gens. Sachez juste que moi j’abandonne. Pourtant je suis persévérant mais là, … Je vais plutôt mettre en ligne la seule version du mod qui marche, à savoir la MC1.8, qui date un peuDu coup, j’ai des problèmes dans mon autre mod (mais beaucoup moins et moins dur). Je les poste ici ou je créer un autre post (vu que les problèmes n’ont rien à voir) ? Perso je préfère créer un autre post, comme ça si d’autres personnes ont ces problèmes ils ne seront pas perdu
Et si je créer un nouveau post, j’en fait quoi de celui-là ? Sans suite ? Résolu ?
-
Laisses celui-ci, il finira dans sans suite du-coup.
Envoies-moi quand même ton dossier src par mp, (ou mets ton mod en open source sur github si tu souhaites soutenir l’open source), je regarderai si je trouve un moment et la motivation. -
Salut
Je te l’ai envoyé par mp, je ne souhaite pas trop le mettre en open-source, en tout cas pas pour l’instant.
Si j’ai la solution, je vous la poste ici