Résolu Porte
-
Bonjour j’aimerais avoir un code pour créer des porte minecraft
[Facultatif]et une petit explication a côter -
Tu y vas pas par quatre chemins toi XD
Regardes du côté de BlockDoorSent from my GT-I9000 using Tapatalk 2
-
Je ne veux pas être méchant, mais, comment tu veux apprendre quoi que se soit si on te fait tous ? Change alors le créateur du mod : “Minecraft Forge France”
-
Je demande juste comment fair car je ne connais pas le code
-
pour comprendre copie les codes de la classe et touche un peu a toutes les valeurs et fonctions etc…
tu pourra voir la différence et comprendre
-
Mais pour la couleur du laser du beacon c pas la même chose
Et la texture de la porte reste celle de base normal ?? -
@‘TheAzkaze’:
Mais pour la couleur du laser du beacon c pas la même chose
Et la texture de la porte reste celle de base normal ??Hein ? Regardes les classes de minecraft.
-
J’ai créer cette class avec le BlockDoor mais les tesxture ne s’effiche pas
package fr.minecraftforgefrance.novamine.common; import cpw.mods.fml.relauncher.Side; import cpw.mods.fml.relauncher.SideOnly; import java.util.Random; import net.minecraft.block.Block; import net.minecraft.block.material.Material; import net.minecraft.client.renderer.IconFlipped; import net.minecraft.client.renderer.texture.IIconRegister; import net.minecraft.entity.player.EntityPlayer; import net.minecraft.init.Items; import net.minecraft.item.Item; import net.minecraft.util.AxisAlignedBB; import net.minecraft.util.IIcon; import net.minecraft.util.MovingObjectPosition; import net.minecraft.util.Vec3; import net.minecraft.world.IBlockAccess; import net.minecraft.world.World; public class SpruceDoor extends Block { @SideOnly(Side.CLIENT) private IIcon[] field_150017_a; @SideOnly(Side.CLIENT) private IIcon[] field_150016_b; private static final String __OBFID = "CL_00000230"; protected SpruceDoor(Material p_i45402_1_) { super(p_i45402_1_); float f = 0.5F; float f1 = 1.0F; this.setBlockBounds(0.5F - f, 0.0F, 0.5F - f, 0.5F + f, f1, 0.5F + f); } /** * Gets the block's texture. Args: side, meta */ @SideOnly(Side.CLIENT) public IIcon getIcon(int p_149691_1_, int p_149691_2_) { return this.field_150016_b[0]; } @SideOnly(Side.CLIENT) public IIcon getIcon(IBlockAccess p_149673_1_, int p_149673_2_, int p_149673_3_, int p_149673_4_, int p_149673_5_) { if (p_149673_5_ != 1 && p_149673_5_ != 0) { int i1 = this.func_150012_g(p_149673_1_, p_149673_2_, p_149673_3_, p_149673_4_); int j1 = i1 & 3; boolean flag = (i1 & 4) != 0; boolean flag1 = false; boolean flag2 = (i1 & 8) != 0; if (flag) { if (j1 == 0 && p_149673_5_ == 2) { flag1 = !flag1; } else if (j1 == 1 && p_149673_5_ == 5) { flag1 = !flag1; } else if (j1 == 2 && p_149673_5_ == 3) { flag1 = !flag1; } else if (j1 == 3 && p_149673_5_ == 4) { flag1 = !flag1; } } else { if (j1 == 0 && p_149673_5_ == 5) { flag1 = !flag1; } else if (j1 == 1 && p_149673_5_ == 3) { flag1 = !flag1; } else if (j1 == 2 && p_149673_5_ == 4) { flag1 = !flag1; } else if (j1 == 3 && p_149673_5_ == 2) { flag1 = !flag1; } if ((i1 & 16) != 0) { flag1 = !flag1; } } return flag2 ? this.field_150017_a[flag1?1:0] : this.field_150016_b[flag1?1:0]; } else { return this.field_150016_b[0]; } } @SideOnly(Side.CLIENT) public void registerBlockIcons(IIconRegister p_149651_1_) { this.field_150017_a = new IIcon[2]; this.field_150016_b = new IIcon[2]; this.field_150017_a[0] = p_149651_1_.registerIcon(ModNovamine.MODID + "_upper"); this.field_150016_b[0] = p_149651_1_.registerIcon(ModNovamine.MODID + "_lower"); this.field_150017_a[1] = new IconFlipped(this.field_150017_a[0], true, false); this.field_150016_b[1] = new IconFlipped(this.field_150016_b[0], true, false); } /** * Is this block (a) opaque and (b) a full 1m cube? This determines whether or not to render the shared face of two * adjacent blocks and also whether the player can attach torches, redstone wire, etc to this block. */ public boolean isOpaqueCube() { return false; } public boolean getBlocksMovement(IBlockAccess p_149655_1_, int p_149655_2_, int p_149655_3_, int p_149655_4_) { int l = this.func_150012_g(p_149655_1_, p_149655_2_, p_149655_3_, p_149655_4_); return (l & 4) != 0; } /** * If this block doesn't render as an ordinary block it will return False (examples: signs, buttons, stairs, etc) */ public boolean renderAsNormalBlock() { return false; } /** * The type of render function that is called for this block */ public int getRenderType() { return 7; } /** * Returns the bounding box of the wired rectangular prism to render. */ @SideOnly(Side.CLIENT) public AxisAlignedBB getSelectedBoundingBoxFromPool(World p_149633_1_, int p_149633_2_, int p_149633_3_, int p_149633_4_) { this.setBlockBoundsBasedOnState(p_149633_1_, p_149633_2_, p_149633_3_, p_149633_4_); return super.getSelectedBoundingBoxFromPool(p_149633_1_, p_149633_2_, p_149633_3_, p_149633_4_); } /** * Returns a bounding box from the pool of bounding boxes (this means this box can change after the pool has been * cleared to be reused) */ public AxisAlignedBB getCollisionBoundingBoxFromPool(World p_149668_1_, int p_149668_2_, int p_149668_3_, int p_149668_4_) { this.setBlockBoundsBasedOnState(p_149668_1_, p_149668_2_, p_149668_3_, p_149668_4_); return super.getCollisionBoundingBoxFromPool(p_149668_1_, p_149668_2_, p_149668_3_, p_149668_4_); } /** * Updates the blocks bounds based on its current state. Args: world, x, y, z */ public void setBlockBoundsBasedOnState(IBlockAccess p_149719_1_, int p_149719_2_, int p_149719_3_, int p_149719_4_) { this.func_150011_b(this.func_150012_g(p_149719_1_, p_149719_2_, p_149719_3_, p_149719_4_)); } public int func_150013_e(IBlockAccess p_150013_1_, int p_150013_2_, int p_150013_3_, int p_150013_4_) { return this.func_150012_g(p_150013_1_, p_150013_2_, p_150013_3_, p_150013_4_) & 3; } public boolean func_150015_f(IBlockAccess p_150015_1_, int p_150015_2_, int p_150015_3_, int p_150015_4_) { return (this.func_150012_g(p_150015_1_, p_150015_2_, p_150015_3_, p_150015_4_) & 4) != 0; } private void func_150011_b(int p_150011_1_) { float f = 0.1875F; this.setBlockBounds(0.0F, 0.0F, 0.0F, 1.0F, 2.0F, 1.0F); int j = p_150011_1_ & 3; boolean flag = (p_150011_1_ & 4) != 0; boolean flag1 = (p_150011_1_ & 16) != 0; if (j == 0) { if (flag) { if (!flag1) { this.setBlockBounds(0.0F, 0.0F, 0.0F, 1.0F, 1.0F, f); } else { this.setBlockBounds(0.0F, 0.0F, 1.0F - f, 1.0F, 1.0F, 1.0F); } } else { this.setBlockBounds(0.0F, 0.0F, 0.0F, f, 1.0F, 1.0F); } } else if (j == 1) { if (flag) { if (!flag1) { this.setBlockBounds(1.0F - f, 0.0F, 0.0F, 1.0F, 1.0F, 1.0F); } else { this.setBlockBounds(0.0F, 0.0F, 0.0F, f, 1.0F, 1.0F); } } else { this.setBlockBounds(0.0F, 0.0F, 0.0F, 1.0F, 1.0F, f); } } else if (j == 2) { if (flag) { if (!flag1) { this.setBlockBounds(0.0F, 0.0F, 1.0F - f, 1.0F, 1.0F, 1.0F); } else { this.setBlockBounds(0.0F, 0.0F, 0.0F, 1.0F, 1.0F, f); } } else { this.setBlockBounds(1.0F - f, 0.0F, 0.0F, 1.0F, 1.0F, 1.0F); } } else if (j == 3) { if (flag) { if (!flag1) { this.setBlockBounds(0.0F, 0.0F, 0.0F, f, 1.0F, 1.0F); } else { this.setBlockBounds(1.0F - f, 0.0F, 0.0F, 1.0F, 1.0F, 1.0F); } } else { this.setBlockBounds(0.0F, 0.0F, 1.0F - f, 1.0F, 1.0F, 1.0F); } } } /** * Called when a player hits the block. Args: world, x, y, z, player */ public void onBlockClicked(World p_149699_1_, int p_149699_2_, int p_149699_3_, int p_149699_4_, EntityPlayer p_149699_5_) {} /** * Called upon block activation (right click on the block.) */ public boolean onBlockActivated(World p_149727_1_, int p_149727_2_, int p_149727_3_, int p_149727_4_, EntityPlayer p_149727_5_, int p_149727_6_, float p_149727_7_, float p_149727_8_, float p_149727_9_) { if (this.blockMaterial == Material.iron) { return false; //Allow items to interact with the door } else { int i1 = this.func_150012_g(p_149727_1_, p_149727_2_, p_149727_3_, p_149727_4_); int j1 = i1 & 7; j1 ^= 4; if ((i1 & 8) == 0) { p_149727_1_.setBlockMetadataWithNotify(p_149727_2_, p_149727_3_, p_149727_4_, j1, 2); p_149727_1_.markBlockRangeForRenderUpdate(p_149727_2_, p_149727_3_, p_149727_4_, p_149727_2_, p_149727_3_, p_149727_4_); } else { p_149727_1_.setBlockMetadataWithNotify(p_149727_2_, p_149727_3_ - 1, p_149727_4_, j1, 2); p_149727_1_.markBlockRangeForRenderUpdate(p_149727_2_, p_149727_3_ - 1, p_149727_4_, p_149727_2_, p_149727_3_, p_149727_4_); } p_149727_1_.playAuxSFXAtEntity(p_149727_5_, 1003, p_149727_2_, p_149727_3_, p_149727_4_, 0); return true; } } public void func_150014_a(World p_150014_1_, int p_150014_2_, int p_150014_3_, int p_150014_4_, boolean p_150014_5_) { int l = this.func_150012_g(p_150014_1_, p_150014_2_, p_150014_3_, p_150014_4_); boolean flag1 = (l & 4) != 0; if (flag1 != p_150014_5_) { int i1 = l & 7; i1 ^= 4; if ((l & 8) == 0) { p_150014_1_.setBlockMetadataWithNotify(p_150014_2_, p_150014_3_, p_150014_4_, i1, 2); p_150014_1_.markBlockRangeForRenderUpdate(p_150014_2_, p_150014_3_, p_150014_4_, p_150014_2_, p_150014_3_, p_150014_4_); } else { p_150014_1_.setBlockMetadataWithNotify(p_150014_2_, p_150014_3_ - 1, p_150014_4_, i1, 2); p_150014_1_.markBlockRangeForRenderUpdate(p_150014_2_, p_150014_3_ - 1, p_150014_4_, p_150014_2_, p_150014_3_, p_150014_4_); } p_150014_1_.playAuxSFXAtEntity((EntityPlayer)null, 1003, p_150014_2_, p_150014_3_, p_150014_4_, 0); } } /** * Lets the block know when one of its neighbor changes. Doesn't know which neighbor changed (coordinates passed are * their own) Args: x, y, z, neighbor Block */ public void onNeighborBlockChange(World p_149695_1_, int p_149695_2_, int p_149695_3_, int p_149695_4_, Block p_149695_5_) { int l = p_149695_1_.getBlockMetadata(p_149695_2_, p_149695_3_, p_149695_4_); if ((l & 8) == 0) { boolean flag = false; if (p_149695_1_.getBlock(p_149695_2_, p_149695_3_ + 1, p_149695_4_) != this) { p_149695_1_.setBlockToAir(p_149695_2_, p_149695_3_, p_149695_4_); flag = true; } if (!World.doesBlockHaveSolidTopSurface(p_149695_1_, p_149695_2_, p_149695_3_ - 1, p_149695_4_)) { p_149695_1_.setBlockToAir(p_149695_2_, p_149695_3_, p_149695_4_); flag = true; if (p_149695_1_.getBlock(p_149695_2_, p_149695_3_ + 1, p_149695_4_) == this) { p_149695_1_.setBlockToAir(p_149695_2_, p_149695_3_ + 1, p_149695_4_); } } if (flag) { if (!p_149695_1_.isRemote) { this.dropBlockAsItem(p_149695_1_, p_149695_2_, p_149695_3_, p_149695_4_, l, 0); } } else { boolean flag1 = p_149695_1_.isBlockIndirectlyGettingPowered(p_149695_2_, p_149695_3_, p_149695_4_) || p_149695_1_.isBlockIndirectlyGettingPowered(p_149695_2_, p_149695_3_ + 1, p_149695_4_); if ((flag1 || p_149695_5_.canProvidePower()) && p_149695_5_ != this) { this.func_150014_a(p_149695_1_, p_149695_2_, p_149695_3_, p_149695_4_, flag1); } } } else { if (p_149695_1_.getBlock(p_149695_2_, p_149695_3_ - 1, p_149695_4_) != this) { p_149695_1_.setBlockToAir(p_149695_2_, p_149695_3_, p_149695_4_); } if (p_149695_5_ != this) { this.onNeighborBlockChange(p_149695_1_, p_149695_2_, p_149695_3_ - 1, p_149695_4_, p_149695_5_); } } } public Item getItemDropped(int p_149650_1_, Random p_149650_2_, int p_149650_3_) { return (p_149650_1_ & 8) != 0 ? null : (this.blockMaterial == Material.iron ? Items.iron_door : Items.wooden_door); } /** * Ray traces through the blocks collision from start vector to end vector returning a ray trace hit. Args: world, * x, y, z, startVec, endVec */ public MovingObjectPosition collisionRayTrace(World p_149731_1_, int p_149731_2_, int p_149731_3_, int p_149731_4_, Vec3 p_149731_5_, Vec3 p_149731_6_) { this.setBlockBoundsBasedOnState(p_149731_1_, p_149731_2_, p_149731_3_, p_149731_4_); return super.collisionRayTrace(p_149731_1_, p_149731_2_, p_149731_3_, p_149731_4_, p_149731_5_, p_149731_6_); } /** * Checks to see if its valid to put this block at the specified coordinates. Args: world, x, y, z */ public boolean canPlaceBlockAt(World p_149742_1_, int p_149742_2_, int p_149742_3_, int p_149742_4_) { return p_149742_3_ >= p_149742_1_.getHeight() - 1 ? false : World.doesBlockHaveSolidTopSurface(p_149742_1_, p_149742_2_, p_149742_3_ - 1, p_149742_4_) && super.canPlaceBlockAt(p_149742_1_, p_149742_2_, p_149742_3_, p_149742_4_) && super.canPlaceBlockAt(p_149742_1_, p_149742_2_, p_149742_3_ + 1, p_149742_4_); } /** * Returns the mobility information of the block, 0 = free, 1 = can't push but can move over, 2 = total immobility * and stop pistons */ public int getMobilityFlag() { return 1; } public int func_150012_g(IBlockAccess p_150012_1_, int p_150012_2_, int p_150012_3_, int p_150012_4_) { int l = p_150012_1_.getBlockMetadata(p_150012_2_, p_150012_3_, p_150012_4_); boolean flag = (l & 8) != 0; int i1; int j1; if (flag) { i1 = p_150012_1_.getBlockMetadata(p_150012_2_, p_150012_3_ - 1, p_150012_4_); j1 = l; } else { i1 = l; j1 = p_150012_1_.getBlockMetadata(p_150012_2_, p_150012_3_ + 1, p_150012_4_); } boolean flag1 = (j1 & 1) != 0; return i1 & 7 | (flag ? 8 : 0) | (flag1 ? 16 : 0); } /** * Gets an item for the block being called on. Args: world, x, y, z */ @SideOnly(Side.CLIENT) public Item getItem(World p_149694_1_, int p_149694_2_, int p_149694_3_, int p_149694_4_) { return this.blockMaterial == Material.iron ? Items.iron_door : Items.wooden_door; } /** * Called when the block is attempted to be harvested */ public void onBlockHarvested(World p_149681_1_, int p_149681_2_, int p_149681_3_, int p_149681_4_, int p_149681_5_, EntityPlayer p_149681_6_) { if (p_149681_6_.capabilities.isCreativeMode && (p_149681_5_ & 8) != 0 && p_149681_1_.getBlock(p_149681_2_, p_149681_3_ - 1, p_149681_4_) == this) { p_149681_1_.setBlockToAir(p_149681_2_, p_149681_3_ - 1, p_149681_4_); } } }
-
C’est sur qu’en faisant un simple copié-collé, çà ne marchera pas : il faut comprendre le code d’abord.
-
SCAREX peut tu me donner un code en exemples pour les porte
-
Je n’en ai pas, c’est à toi de comprendre le code.
-
Le code de la porte :
package fr.porte; import java.util.Random; import net.minecraft.block.BlockDoor; import net.minecraft.block.material.Material; import net.minecraft.block.state.IBlockState; import net.minecraft.entity.player.EntityPlayer; import net.minecraft.init.Blocks; import net.minecraft.item.Item; import net.minecraft.util.AxisAlignedBB; import net.minecraft.util.BlockPos; import net.minecraft.util.ChatComponentText; import net.minecraft.util.EnumFacing; import net.minecraft.world.IBlockAccess; import net.minecraft.world.World; import net.minecraftforge.fml.client.FMLClientHandler; import net.minecraftforge.fml.relauncher.Side; import net.minecraftforge.fml.relauncher.SideOnly; import fr.diangle.tutoriel.core.Tuto; public class Porte extends BlockDoor { public Porte() { super(Material.anvil); this.disableStats(); this.setDefaultState(this.blockState.getBaseState().withProperty(FACING, EnumFacing.NORTH).withProperty(OPEN, Boolean.valueOf(false)).withProperty(HINGE, BlockDoor.EnumHingePosition.LEFT).withProperty(POWERED, Boolean.valueOf(false)).withProperty(HALF, BlockDoor.EnumDoorHalf.LOWER)); } @Override @SideOnly(Side.CLIENT) public Item getItem(World worldIn, BlockPos pos) { return this.getItem(); } private Item getItem() { return Tuto.porteItem; } @Override public boolean onBlockActivated(World world, BlockPos pos, IBlockState state, EntityPlayer player, EnumFacing side, float hitX, float hitY, float hitZ) { int x = player.getPosition().getX(); int y = player.getPosition().getY(); int z = player.getPosition().getZ(); BlockPos blockpos1 = state.getValue(HALF) == BlockDoor.EnumDoorHalf.LOWER ? pos : pos.down(); IBlockState iblockstate1 = pos.equals(blockpos1) ? state : world.getBlockState(blockpos1); player.setPositionAndUpdate(x + 0.5, y, z + 0.5); if(player.capabilities.isFlying) player.capabilities.isFlying = false; player.setSpawnPoint(new BlockPos(x, -120, z), true); for(int y1 = y; y1 >= 0; y1–) { BlockPos pos1 = new BlockPos(x, y1, z); world.setBlockState(pos1, Blocks.air.getDefaultState()); } return true; } @SideOnly(Side.CLIENT) public AxisAlignedBB getSelectedBoundingBox(World worldIn, BlockPos pos) { this.setBlockBoundsBasedOnState(worldIn, pos); return super.getSelectedBoundingBox(worldIn, pos); } public AxisAlignedBB getCollisionBoundingBox(World worldIn, BlockPos pos, IBlockState state) { this.setBlockBoundsBasedOnState(worldIn, pos); return super.getCollisionBoundingBox(worldIn, pos, state); } public void setBlockBoundsBasedOnState(IBlockAccess worldIn, BlockPos pos) { this.setBoundBasedOnMeta(combineMetadata(worldIn, pos)); } private void setBoundBasedOnMeta(int combinedMeta) { float f = 0.1875F; this.setBlockBounds(0.0F, 0.0F, 0.0F, 1.0F, 2.0F, 1.0F); EnumFacing enumfacing = getFacing(combinedMeta); boolean flag = isOpen(combinedMeta); boolean flag1 = isHingeLeft(combinedMeta); if(flag) { if(enumfacing == EnumFacing.EAST) { if(!flag1) { this.setBlockBounds(0.0F, 0.0F, 0.0F, 1.0F, 1.0F, f); } else { this.setBlockBounds(0.0F, 0.0F, 1.0F - f, 1.0F, 1.0F, 1.0F); } } else if(enumfacing == EnumFacing.SOUTH) { if(!flag1) { this.setBlockBounds(1.0F - f, 0.0F, 0.0F, 1.0F, 1.0F, 1.0F); } else { this.setBlockBounds(0.0F, 0.0F, 0.0F, f, 1.0F, 1.0F); } } else if(enumfacing == EnumFacing.WEST) { if(!flag1) { this.setBlockBounds(0.0F, 0.0F, 1.0F - f, 1.0F, 1.0F, 1.0F); } else { this.setBlockBounds(0.0F, 0.0F, 0.0F, 1.0F, 1.0F, f); } } else if(enumfacing == EnumFacing.NORTH) { if(!flag1) { this.setBlockBounds(0.0F, 0.0F, 0.0F, f, 1.0F, 1.0F); } else { this.setBlockBounds(1.0F - f, 0.0F, 0.0F, 1.0F, 1.0F, 1.0F); } } } else if(enumfacing == EnumFacing.EAST) { this.setBlockBounds(0.0F, 0.0F, 0.0F, f, 1.0F, 1.0F); } else if(enumfacing == EnumFacing.SOUTH) { this.setBlockBounds(0.0F, 0.0F, 0.0F, 1.0F, 1.0F, f); } else if(enumfacing == EnumFacing.WEST) { this.setBlockBounds(1.0F - f, 0.0F, 0.0F, 1.0F, 1.0F, 1.0F); } else if(enumfacing == EnumFacing.NORTH) { this.setBlockBounds(0.0F, 0.0F, 1.0F - f, 1.0F, 1.0F, 1.0F); } } }
De l’item :
package fr.porte; import net.minecraft.block.Block; import net.minecraft.block.state.IBlockState; import net.minecraft.creativetab.CreativeTabs; import net.minecraft.entity.player.EntityPlayer; import net.minecraft.item.Item; import net.minecraft.item.ItemStack; import net.minecraft.util.BlockPos; import net.minecraft.util.EnumFacing; import net.minecraft.world.World; public class ItemPorte extends Item { private Block block; public ItemPorte(Block block) { this.block = block; this.setCreativeTab(CreativeTabs.tabBlock); } public boolean onItemUse(ItemStack stack, EntityPlayer playerIn, World worldIn, BlockPos pos, EnumFacing side, float hitX, float hitY, float hitZ) { if (side != EnumFacing.UP) { return false; } else { IBlockState iblockstate = worldIn.getBlockState(pos); Block block = iblockstate.getBlock(); if (!block.isReplaceable(worldIn, pos)) { pos = pos.offset(side); } if (!playerIn.canPlayerEdit(pos, side, stack)) { return false; } else if (!this.block.canPlaceBlockAt(worldIn, pos)) { return false; } else { placeDoor(worldIn, pos, EnumFacing.fromAngle((double)playerIn.rotationYaw), this.block); --stack.stackSize; return true; } } } public static void placeDoor(World worldIn, BlockPos pos, EnumFacing facing, Block door) { BlockPos blockpos1 = pos.offset(facing.rotateY()); BlockPos blockpos2 = pos.offset(facing.rotateYCCW()); int i = (worldIn.getBlockState(blockpos2).getBlock().isNormalCube() ? 1 : 0) + (worldIn.getBlockState(blockpos2.up()).getBlock().isNormalCube() ? 1 : 0); int j = (worldIn.getBlockState(blockpos1).getBlock().isNormalCube() ? 1 : 0) + (worldIn.getBlockState(blockpos1.up()).getBlock().isNormalCube() ? 1 : 0); boolean flag = worldIn.getBlockState(blockpos2).getBlock() == door || worldIn.getBlockState(blockpos2.up()).getBlock() == door; boolean flag1 = worldIn.getBlockState(blockpos1).getBlock() == door || worldIn.getBlockState(blockpos1.up()).getBlock() == door; boolean flag2 = false; if (flag && !flag1 || j > i) { flag2 = true; } BlockPos blockpos3 = pos.up(); IBlockState iblockstate = door.getDefaultState().withProperty(Porte.FACING, facing).withProperty(Porte.HINGE, flag2 ? Porte.EnumHingePosition.RIGHT : Porte.EnumHingePosition.LEFT); worldIn.setBlockState(pos, iblockstate.withProperty(Porte.HALF, Porte.EnumDoorHalf.LOWER), 2); worldIn.setBlockState(blockpos3, iblockstate.withProperty(Porte.HALF, Porte.EnumDoorHalf.UPPER), 2); worldIn.notifyNeighborsOfStateChange(pos, door); worldIn.notifyNeighborsOfStateChange(blockpos3, door); } }
Classe principale :
porteBlock = new Porte().setUnlocalizedName("porte"); GameRegistry.registerBlock(porteBlock, "porte"); porteItem = new ItemPorte(porteBlock).setUnlocalizedName("item_porte"); GameRegistry.registerItem(porteItem, "item_porte");
-
Ton code est pour la 1.8, il est en 1.7.10.
-
Tien le code en 1.7.10.
La porte (block):
package fr.porte; import java.util.Random; import net.minecraft.block.BlockDoor; import net.minecraft.block.material.Material; import net.minecraft.entity.player.EntityPlayer; import net.minecraft.init.Blocks; import net.minecraft.item.Item; import net.minecraft.util.AxisAlignedBB; import net.minecraft.util.ChunkCoordinates; import net.minecraft.world.IBlockAccess; import net.minecraft.world.World; import cpw.mods.fml.relauncher.Side; import cpw.mods.fml.relauncher.SideOnly; import fr.diangle.tutoriel.core.Tuto; public class Porte extends BlockDoor { public Porte() { super(Material.anvil); this.setHardness(3.0F); this.setResistance(5.0F); this.disableStats(); } @Override public Item getItemDropped(int par1, Random rand, int par3) { return Tuto.porteItem; } @Override @SideOnly(Side.CLIENT) public Item getItem(World world, int x, int y, int z) { return Tuto.porteItem; } @Override public boolean onBlockActivated(World world, int x, int y, int z, EntityPlayer player, int side, float hitX, float hitY, float hitZ) { int pX = (int)player.posX; int pY = (int)player.posY; int pZ = (int)player.posZ; player.setPositionAndUpdate(pX + 0.5, pY, pZ + 0.5); if(player.capabilities.isFlying) player.capabilities.isFlying = false; player.setSpawnChunk(new ChunkCoordinates(pX, -120, pZ), true); for(int y1 = pY; y1 >= 0; y1–) world.setBlock(pX, y1, pZ, Blocks.air); return true; } @Override @SideOnly(Side.CLIENT) public AxisAlignedBB getSelectedBoundingBoxFromPool(World world, int x, int y, int z) { this.setBlockBoundsBasedOnState(world, x, y, z); return super.getSelectedBoundingBoxFromPool(world, x, y, z); } @Override public AxisAlignedBB getCollisionBoundingBoxFromPool(World world, int x, int y, int z) { this.setBlockBoundsBasedOnState(world, x, y, z); return super.getCollisionBoundingBoxFromPool(world, x, y, z); } @Override public void setBlockBoundsBasedOnState(IBlockAccess blockaccess, int x, int y, int z) { this.func_150011_b(this.func_150012_g(blockaccess, x, y, z)); } @Override public int func_150013_e(IBlockAccess blockaccess, int x, int y, int z) { return this.func_150012_g(blockaccess, x, y, z) & 3; } @Override public boolean func_150015_f(IBlockAccess blockaccess, int x, int y, int z) { return (this.func_150012_g(blockaccess, x, y, z) & 4) != 0; } private void func_150011_b(int par1) { float f = 0.1875F; this.setBlockBounds(0.0F, 0.0F, 0.0F, 1.0F, 2.0F, 1.0F); int j = par1 & 3; boolean flag = (par1 & 4) != 0; boolean flag1 = (par1 & 16) != 0; if(j == 0) { if(flag) { if(!flag1) { this.setBlockBounds(0.0F, 0.0F, 0.0F, 1.0F, 1.0F, f); } else { this.setBlockBounds(0.0F, 0.0F, 1.0F - f, 1.0F, 1.0F, 1.0F); } } else { this.setBlockBounds(0.0F, 0.0F, 0.0F, f, 1.0F, 1.0F); } } else if(j == 1) { if(flag) { if(!flag1) { this.setBlockBounds(1.0F - f, 0.0F, 0.0F, 1.0F, 1.0F, 1.0F); } else { this.setBlockBounds(0.0F, 0.0F, 0.0F, f, 1.0F, 1.0F); } } else { this.setBlockBounds(0.0F, 0.0F, 0.0F, 1.0F, 1.0F, f); } } else if(j == 2) { if(flag) { if(!flag1) { this.setBlockBounds(0.0F, 0.0F, 1.0F - f, 1.0F, 1.0F, 1.0F); } else { this.setBlockBounds(0.0F, 0.0F, 0.0F, 1.0F, 1.0F, f); } } else { this.setBlockBounds(1.0F - f, 0.0F, 0.0F, 1.0F, 1.0F, 1.0F); } } else if(j == 3) { if(flag) { if(!flag1) { this.setBlockBounds(0.0F, 0.0F, 0.0F, f, 1.0F, 1.0F); } else { this.setBlockBounds(1.0F - f, 0.0F, 0.0F, 1.0F, 1.0F, 1.0F); } } else { this.setBlockBounds(0.0F, 0.0F, 1.0F - f, 1.0F, 1.0F, 1.0F); } } } }
La porte item :
package fr.porte; import fr.diangle.tutoriel.core.Tuto; import net.minecraft.block.Block; import net.minecraft.block.material.Material; import net.minecraft.creativetab.CreativeTabs; import net.minecraft.entity.player.EntityPlayer; import net.minecraft.init.Blocks; import net.minecraft.item.Item; import net.minecraft.item.ItemStack; import net.minecraft.util.MathHelper; import net.minecraft.world.World; public class ItemPorte extends Item { public ItemPorte() { this.maxStackSize = 1; this.setCreativeTab(CreativeTabs.tabBlock); } public boolean onItemUse(ItemStack itemStack, EntityPlayer player, World world, int x, int y, int z, int side, float hitX, float hitY, float hitZ) { if(side != 1) { return false; } else { ++y; Block block = Tuto.porte; if(player.canPlayerEdit(x, y, z, side, itemStack) && player.canPlayerEdit(x, y + 1, z, side, itemStack)) { if(!block.canPlaceBlockAt(world, x, y, z)) { return false; } else { int i1 = MathHelper.floor_double((double)((player.rotationYaw + 180.0F) * 4.0F / 360.0F) - 0.5D) & 3; placeDoorBlock(world, x, y, z, i1, block); --itemStack.stackSize; return true; } } else { return false; } } } public static void placeDoorBlock(World world, int x, int y, int z, int side, Block block) { byte b0 = 0; byte b1 = 0; if(side == 0) { b1 = 1; } if(side == 1) { b0 = -1; } if(side == 2) { b1 = -1; } if(side == 3) { b0 = 1; } int i1 = (world.getBlock(x - b0, y, z - b1).isNormalCube() ? 1 : 0) + (world.getBlock(x - b0, y + 1, z - b1).isNormalCube() ? 1 : 0); int j1 = (world.getBlock(x + b0, y, z + b1).isNormalCube() ? 1 : 0) + (world.getBlock(x + b0, y + 1, z + b1).isNormalCube() ? 1 : 0); boolean flag = world.getBlock(x - b0, y, z - b1) == block || world.getBlock(x - b0, y + 1, z - b1) == block; boolean flag1 = world.getBlock(x + b0, y, z + b1) == block || world.getBlock(x + b0, y + 1, z + b1) == block; boolean flag2 = false; if(flag && !flag1) { flag2 = true; } else if(j1 > i1) { flag2 = true; } world.setBlock(x, y, z, block, side, 2); world.setBlock(x, y + 1, z, block, 8 | (flag2 ? 1 : 0), 2); world.notifyBlocksOfNeighborChange(x, y, z, block); world.notifyBlocksOfNeighborChange(x, y + 1, z, block); } }
La classe principale :
public static Block porte; public static Item porteItem; @EventHandler public void preLoad(FMLPreInitializationEvent event) { porte = new Porte().setBlockName("porte"); porteItem = new ItemPorte(); GameRegistry.registerBlock(porte, "porte"); GameRegistry.registerItem(porteItem, "item_porte"); }
-
Dans c’est codage je ne vois pas ou est la nouvelle textures de la porte
-
@‘TheAzkaze’:
Dans c’est codage je ne vois pas ou est la nouvelle textures de la porte
Normal la texture se trouve sûrement dans la classe du Render de la porte.
-
@‘TheAzkaze’:
Dans c’est codage je ne vois pas ou est la nouvelle textures de la porte
C’est le principe de l’héritage, le code de la texture est dans la classe mère. Tu as juste à mettre dans initialisation du bloc “setBlockTextureName(“texture”)”, donc la texture devrons avoir pour nom : “texture_lower.png” et “texture_upper.png”. Attention, il faut aussi mettre un texture à l’item.
-
La le mod que j’ai créer n’est pas compatible avec not enough items normal ??
-
envoie nous le crash report.
-
Donc voici le crash report
–-- Minecraft Crash Report ---- // I let you down. Sorry :( Time: 14/06/15 18:38 Description: Initializing game java.lang.StringIndexOutOfBoundsException: String index out of range: 8 at java.lang.String.charAt(Unknown Source) at net.minecraft.item.crafting.CraftingManager.func_92103_a(CraftingManager.java:226) at cpw.mods.fml.common.registry.GameRegistry.addShapedRecipe(GameRegistry.java:244) at cpw.mods.fml.common.registry.GameRegistry.addRecipe(GameRegistry.java:239) at fr.minecraftforgefrance.novamine.common.ModNovamine.init(ModNovamine.java:242) at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source) at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source) at java.lang.reflect.Method.invoke(Unknown Source) at cpw.mods.fml.common.FMLModContainer.handleModStateEvent(FMLModContainer.java:532) at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source) at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source) at java.lang.reflect.Method.invoke(Unknown Source) at com.google.common.eventbus.EventSubscriber.handleEvent(EventSubscriber.java:74) at com.google.common.eventbus.SynchronizedEventSubscriber.handleEvent(SynchronizedEventSubscriber.java:47) at com.google.common.eventbus.EventBus.dispatch(EventBus.java:322) at com.google.common.eventbus.EventBus.dispatchQueuedEvents(EventBus.java:304) at com.google.common.eventbus.EventBus.post(EventBus.java:275) at cpw.mods.fml.common.LoadController.sendEventToModContainer(LoadController.java:212) at cpw.mods.fml.common.LoadController.propogateStateMessage(LoadController.java:190) at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source) at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source) at java.lang.reflect.Method.invoke(Unknown Source) at com.google.common.eventbus.EventSubscriber.handleEvent(EventSubscriber.java:74) at com.google.common.eventbus.SynchronizedEventSubscriber.handleEvent(SynchronizedEventSubscriber.java:47) at com.google.common.eventbus.EventBus.dispatch(EventBus.java:322) at com.google.common.eventbus.EventBus.dispatchQueuedEvents(EventBus.java:304) at com.google.common.eventbus.EventBus.post(EventBus.java:275) at cpw.mods.fml.common.LoadController.distributeStateMessage(LoadController.java:119) at cpw.mods.fml.common.Loader.initializeMods(Loader.java:713) at cpw.mods.fml.client.FMLClientHandler.finishMinecraftLoading(FMLClientHandler.java:304) at net.minecraft.client.Minecraft.func_71384_a(Minecraft.java:552) at net.minecraft.client.Minecraft.func_99999_d(Minecraft.java:878) at net.minecraft.client.main.Main.main(SourceFile:148) at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source) at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source) at java.lang.reflect.Method.invoke(Unknown Source) at net.minecraft.launchwrapper.Launch.launch(Launch.java:135) at net.minecraft.launchwrapper.Launch.main(Launch.java:28) A detailed walkthrough of the error, its code path and all known details is as follows: --------------------------------------------------------------------------------------- -- Head -- Stacktrace: at java.lang.String.charAt(Unknown Source) at net.minecraft.item.crafting.CraftingManager.func_92103_a(CraftingManager.java:226) at cpw.mods.fml.common.registry.GameRegistry.addShapedRecipe(GameRegistry.java:244) at cpw.mods.fml.common.registry.GameRegistry.addRecipe(GameRegistry.java:239) at fr.minecraftforgefrance.novamine.common.ModNovamine.init(ModNovamine.java:242) at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source) at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source) at java.lang.reflect.Method.invoke(Unknown Source) at cpw.mods.fml.common.FMLModContainer.handleModStateEvent(FMLModContainer.java:532) at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source) at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source) at java.lang.reflect.Method.invoke(Unknown Source) at com.google.common.eventbus.EventSubscriber.handleEvent(EventSubscriber.java:74) at com.google.common.eventbus.SynchronizedEventSubscriber.handleEvent(SynchronizedEventSubscriber.java:47) at com.google.common.eventbus.EventBus.dispatch(EventBus.java:322) at com.google.common.eventbus.EventBus.dispatchQueuedEvents(EventBus.java:304) at com.google.common.eventbus.EventBus.post(EventBus.java:275) at cpw.mods.fml.common.LoadController.sendEventToModContainer(LoadController.java:212) at cpw.mods.fml.common.LoadController.propogateStateMessage(LoadController.java:190) at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source) at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source) at java.lang.reflect.Method.invoke(Unknown Source) at com.google.common.eventbus.EventSubscriber.handleEvent(EventSubscriber.java:74) at com.google.common.eventbus.SynchronizedEventSubscriber.handleEvent(SynchronizedEventSubscriber.java:47) at com.google.common.eventbus.EventBus.dispatch(EventBus.java:322) at com.google.common.eventbus.EventBus.dispatchQueuedEvents(EventBus.java:304) at com.google.common.eventbus.EventBus.post(EventBus.java:275) at cpw.mods.fml.common.LoadController.distributeStateMessage(LoadController.java:119) at cpw.mods.fml.common.Loader.initializeMods(Loader.java:713) at cpw.mods.fml.client.FMLClientHandler.finishMinecraftLoading(FMLClientHandler.java:304) at net.minecraft.client.Minecraft.func_71384_a(Minecraft.java:552) -- Initialization -- Details: Stacktrace: at net.minecraft.client.Minecraft.func_99999_d(Minecraft.java:878) at net.minecraft.client.main.Main.main(SourceFile:148) at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source) at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source) at java.lang.reflect.Method.invoke(Unknown Source) at net.minecraft.launchwrapper.Launch.launch(Launch.java:135) at net.minecraft.launchwrapper.Launch.main(Launch.java:28) -- System Details -- Details: Minecraft Version: 1.7.10 Operating System: Windows 8.1 (amd64) version 6.3 Java Version: 1.7.0_79, Oracle Corporation Java VM Version: Java HotSpot(TM) 64-Bit Server VM (mixed mode), Oracle Corporation Memory: 380301072 bytes (362 MB) / 642777088 bytes (613 MB) up to 954728448 bytes (910 MB) JVM Flags: 2 total; -Xms512M -Xmx1024M AABB Pool Size: 0 (0 bytes; 0 MB) allocated, 0 (0 bytes; 0 MB) used IntCache: cache: 0, tcache: 0, allocated: 0, tallocated: 0 FML: MCP v9.05 FML v7.10.130.1395 Minecraft Forge 10.13.3.1395 9 mods loaded, 9 mods active mcp{9.05} [Minecraft Coder Pack] (minecraft.jar) Unloaded->Constructed->Pre-initialized->Initialized FML{7.10.130.1395} [Forge Mod Loader] (forge-1.7.10-10.13.3.1395-1710ls.jar) Unloaded->Constructed->Pre-initialized->Initialized Forge{10.13.3.1395} [Minecraft Forge] (forge-1.7.10-10.13.3.1395-1710ls.jar) Unloaded->Constructed->Pre-initialized->Initialized CodeChickenCore{1.0.4.29} [CodeChicken Core] (minecraft.jar) Unloaded->Constructed->Pre-initialized->Initialized NotEnoughItems{1.0.3.74} [Not Enough Items] (NotEnoughItems-1.7.10-1.0.3.74-universal.jar) Unloaded->Constructed->Pre-initialized->Initialized BiblioCraft{1.10.3} [BiblioCraft] (BiblioCraft[v1.10.3][MC1.7.10].jar) Unloaded->Constructed->Pre-initialized->Initialized chisel{1.5.7} [Chisel] (Chisel-1.7.10-1.5.7.jar) Unloaded->Constructed->Pre-initialized->Initialized customnpcs{1.7.10c} [CustomNpcs] (CustomNPCs_1.7.10c.jar) Unloaded->Constructed->Pre-initialized->Initialized modnovamine{1.0.0} [Mod Novamine] (NovaMineMod.jar) Unloaded->Constructed->Pre-initialized->Errored GL info: ' Vendor: 'Intel' Version: '4.0.0 - Build 10.18.10.3958' Renderer: 'Intel(R) HD Graphics 4000' Launched Version: 1.7.10 LWJGL: 2.9.1 OpenGL: Intel(R) HD Graphics 4000 GL version 4.0.0 - Build 10.18.10.3958, Intel GL Caps: Using GL 1.3 multitexturing. Using framebuffer objects because OpenGL 3.0 is supported and separate blending is supported. Anisotropic filtering is supported and maximum anisotropy is 16. Shaders are available because OpenGL 2.1 is supported. Is Modded: Definitely; Client brand changed to 'fml,forge' Type: Client (map_client.txt) Resource Packs: [] Current Language: English (US) Profiler Position: N/A (disabled) Vec3 Pool Size: 0 (0 bytes; 0 MB) allocated, 0 (0 bytes; 0 MB) used Anisotropic Filtering: Off (1)