Jump to content

ILuvYouCompanionCube

Members
  • Posts

    112
  • Joined

  • Last visited

Everything posted by ILuvYouCompanionCube

  1. But this is not an event. It would be done while loading. We can all afford a few extra miliseconds of loading time if it's not too efficient. Heck, I could even wait one whole second!
  2. Easy compared to the rest of the Forge framework, yes. So, by the standards of the autors of Forge this is probably quite easy. Easy for me? No way. By my standards making a minecart stop is a big challenge.
  3. Block should have one fake version of addInformation. And then Forge would find any overrides of it in our code, and create a class extending ItemBlock at runtime. Then it should "copy-paste" (or "cut-paste") our override of the fake method in Block to this automatically made ItemBlock subclass.
  4. That method has no implementation. Just a pair of curly braces. How should I override it, so it would show the information for the item? edit1: I searched the forums for addIndormation. Apparently, it's just a matter of adding what you want to the List object. I'll try. edit2: The only way to do the same for a block is to make a class that inherits from ItemBlock and then overriding addInformation? There must be a better way.
  5. I have downloaded a mod and the items and blocks of the mod come with descriptions. Instead of just the name of the item, you can also read a short description about it in a darker shade of gray. I think that's very useful. I was wondering if that's a feature of that mod in specific or if it's something we can do easily, like having our item/block implement an interface, or something related to the LanguageRegistry or maybe some other registry. Thanks.
  6. Sure. sorry the question got pushed bellow the stack Just noticed it had a reply. I'll post the entire class. I think the problem is related to onMinecartPass, because I don't know how to make it stop from being invoked by the minecart when it's stopped (off course I'd have to change some things in the implementation of my block and maybe in my implementation of ExtendedProperties if disabling onMinecartPass was possible). Or maybe something related to telling the minecart stop updating entirely (don't know how to do that either. [digression]Entity is way too complex. The way minecraft codes Entity and all its inheritance hierarchy, is just awful in my opinion. Whenever I see code that needs lots of aInstance instanceof aClass instead of just using polymorphism, I instantly assume the author of the code isn't so smart. Minecraft force us to code this way because we're stuck with its own code).[/digression] Enough rambling, here's my code (Stuff is the name of my mod, because I'm that creative): package stuff.blocks; import java.util.List; import java.util.Random; import pedrinholib.minecraft.DirectionXProp; import net.minecraft.block.BlockRailBase; import net.minecraft.client.renderer.texture.IconRegister; import net.minecraft.command.IEntitySelector; import net.minecraft.entity.item.EntityMinecart; import net.minecraft.entity.item.EntityMinecartContainer; import net.minecraft.inventory.Container; import net.minecraft.inventory.IInventory; import net.minecraft.util.AxisAlignedBB; import net.minecraft.util.Icon; import net.minecraft.world.World; import stuff.Stuff; public class MetaDetectorRailBlock extends BlockRailBase { Icon theIcon; String assetsCommonName = Stuff.ModPrefix() + MetaDetectorRailBlock.class.getSimpleName(); public MetaDetectorRailBlock(int id) { super(id, true);//true here says the rail is power related setUnlocalizedName(assetsCommonName); } @Override public void registerIcons(IconRegister par1IconRegister) { blockIcon = par1IconRegister.registerIcon(assetsCommonName); this.theIcon = par1IconRegister.registerIcon(assetsCommonName + "_powered"); } @Override public void updateTick(World world, int x, int y, int z, Random useless) { List list = world.selectEntitiesWithinAABB(EntityMinecartContainer.class, AxisAlignedBB.getAABBPool().getAABB(x, y, z, x + 1.0D, y + 1.0D, z + 1.0D), IEntitySelector.selectAnything); int metadata = world.getBlockMetadata(x, y, z); if(list.size() > 0)//at least one entity { int powerFromNeighbours = world.getStrongestIndirectPower(x, y, z); int redstoneSignalFromCart = 0; for(Object cart : list)//hopefully there will be only one { int temp = Container.calcRedstoneFromInventory((IInventory)cart); if(temp > redstoneSignalFromCart) redstoneSignalFromCart = temp; } //if the cart over the tracks has a stronger signal than the input from neighbour blocks, turn //the track on if(redstoneSignalFromCart > powerFromNeighbours) { turnOn(world, x, y, z, metadata); } else { turnOff(world, x, y, z, metadata); } } else //there are no minecart over this track, turn it off { turnOff(world, x, y, z, metadata); } ScheduleUpdate(world, x, y, z); } @Override public void onMinecartPass(World world, EntityMinecart cart, int x, int y, int z) { if(cart instanceof IInventory) { int currentMetadata = world.getBlockMetadata(x, y, z); if(isOn(currentMetadata)) { addVelocity(cart, currentMetadata); } else { if(registerDirection(cart)) stopCart(cart); } } } public void ScheduleUpdate(World world, int x, int y, int z) { world.scheduleBlockUpdate(x, y, z, this.blockID, 100); } /** * Called when a block is placed using its ItemBlock. Args: World, X, Y, Z, side, hitX, hitY, hitZ, block metadata */ @Override public int onBlockPlaced(World world, int x, int y, int z, int side, float hitX, float hitY, float hitZ, int metadata) { ScheduleUpdate(world, x, y, z); return metadata; } /** * Register the directions for the cart before it stops. It returns true if the cart wasn't already stopped, * and false otherwise. The result can be used to avoid calling stopCart over and over again. * @param cart * @return */ protected boolean registerDirection(EntityMinecart cart) { DirectionXProp directions = (DirectionXProp)cart.getExtendedProperties(DirectionXProp.Identifier); if(directions.IsStopped) { return false; } else { directions.IsStopped = true; if(cart.prevPosX > cart.posX) { //System.out.println("This cart is moving towards -X"); directions.XOrientation = -1; } else if(cart.prevPosX == cart.posX) { //System.out.println("this cart is not moving along the X axis"); directions.XOrientation = 0; } else { //System.out.println("this cart is moving towards +X"); directions.XOrientation = +1; } if(cart.prevPosZ > cart.posZ) { //System.out.println("This cart is moving towards -Z"); directions.ZOrientation = -1; } else if(cart.prevPosZ == cart.posZ) { //System.out.println("this cart is not moving along the Z axis"); directions.ZOrientation = 0; } else { //System.out.println("this cart is moving towards +Z"); directions.ZOrientation = +1; } return true; } } protected void turnOn(World world, int x, int y, int z, int metadata) { if((metadata & == 0)//equivalent to !isOn { int onStateMetadata = metadata ^ 8; world.setBlockMetadataWithNotify(x, y, z, onStateMetadata, 2); world.notifyBlocksOfNeighborChange(x, y, z, this.blockID); } } protected void turnOff(World world, int x, int y, int z, int metadata) { if((metadata & != 0)//equivalent to isOn { int offStateMetadata = metadata ^ 8; world.setBlockMetadataWithNotify(x, y, z, offStateMetadata, 2); world.notifyBlocksOfNeighborChange(x, y, z, this.blockID); } } protected boolean isOn(int metadata) { return (metadata & != 0; } protected void addVelocity(EntityMinecart cart, int metadata) { //otherwise this will never work, since it's only called when the 8 bit is on metadata = metadata & 7; double velocityAdjustment; DirectionXProp directions = (DirectionXProp)cart.getExtendedProperties(DirectionXProp.Identifier); switch(metadata) { case 0: case 4: case 5: if(directions.ZOrientation > 0) { //System.out.println("Resuming movement towards +Z"); velocityAdjustment = 0.4; } else { //System.out.println("Resuming movement towards -Z"); velocityAdjustment = -0.4; } velocityAdjustment = cart.motionZ == 0 ? velocityAdjustment : cart.motionZ * 0.4; directions.IsStopped = false; cart.addVelocity(0, 0, velocityAdjustment); break; case 1: case 2: case 3: if(directions.XOrientation > 0) { //System.out.println("Resuming movement towards +X"); velocityAdjustment = 0.4; } else { //System.out.println("Resuming movement towards -X"); velocityAdjustment = -0.4; } velocityAdjustment = cart.motionX == 0 ? velocityAdjustment : cart.motionX * 0.4; directions.IsStopped = false; cart.addVelocity(velocityAdjustment, 0, 0); break; } } protected void stopCart(EntityMinecart cart) { cart.setVelocity(0, 0, 0); } }
  7. If at some point something goes unexplicably wrong, this will be the first change I'll make hehe.
  8. oh, I misread. But I think they both work for that matter don't they? Cause I've been using init all this time...
  9. He's telling you to instantiate the blocks and items from the method in your mod marked with this annotation: @EventHandler That has this signature: public void *your method name here*(FMLInitializationEvent event) like this: public static Item CactiAxe; @EventHandler public void init(FMLInitializationEvent event) { CactiAxe = new ItemCactiAxe(*your args here*).setUnlocalizedName(*your unlocalized name here*); //and etc for the other items/blocks } Remember don't use ids out of range or ones that conflict with others. [edit] check this line public static Item CactiAxe = new ItemCactiAxe(300200, CactiNoThorn).setUnlocalizedName("CactusAxe");//Axe 300,200. That ID is way out of bounds. the maximum possible ID for an Item is (I think) 31,744 Another thing I noticed is that you never register your items. you have Func.itemRegisterer but it is never called. You may want to correct that too. Then try again and if it doesn't work we'll have a better error log, because this one is just caused by a silly ArrayIndexOutOfBoundsException [/edit] PS: to further clarify what diesieben07 was talking about, <clinit> is the name of the constructor of the type itself (whence CL, which stands for class), while <init> is the name of the constructor of instances of the type. Whatever field you declare as static and provide an initialization expression along with the declaration, is actually going to be initialized inside <clinit>. Forge considers bad practice to initialize blocks and items in your mod's <clinit> or <init> (I don't know why, but maybe because it generates those weird, wierd errors like the one you are getting).
  10. OT: wait, really?! I've been using the 6000s for my block and nothing fails... Then I AM wrong
  11. My only guess is the ID is still conflicting somehow. Eitheir I'm failing to spot something obvious or that's a very obscure error. Try changin the ID again for some much bigger number, like 4000 (4095 is the greater possible block ID if I'm not wrong). Sorry I can't help better.
  12. The constructor for Block (I wrote item before,sorry. I'm tired) launches a crash when you try to register something with an ID that's already registered. 2013-08-26 00:02:12 [sTDOUT] CONFLICT @ 2000 item slot already occupied by net.minecraft.item.ItemRecord@d9a418 while adding net.net46.ecbercnl.mcmods.moremoremorecraft.items.ItemCactiPick@a4513a 2013-08-26 00:02:12 [fml.ItemTracker] The mod eccore is overwriting existing item at 2256 (net.minecraft.item.ItemRecord from Minecraft) with net.net46.ecbercnl.mcmods.moremoremorecraft.items.ItemCactiPick and etc. Choose unsused IDs for your items and blocks.
  13. I knew it couldn't be complicated, or they wouldn't have put that Dinnerbone easter egg. Thanks for clarifying that for me.
  14. I may be wrong, but I don't think you should remove anything through an iterator. I don't even know why java allows this, just to say "beware, the behaviour of the iterator will be undetermined if you alter the collection in any way". So why allow us alter the collection in the first place...? Why did it have to be java, God...?
  15. I got this idea after today's talk about Dinnerbone. I got this idea that it's probably quite easy to render something upside down. You probably wouldn't need a whole new renderer or to redefine lots of things on the one you have. I can almost bet it's just a matter of setting one or 2 GL11 thingies or whatever. And your model gets upside down. That would be useful under a lot of circumstances. Does anybody know if I'm right, and if I am, what are the thingies to set to render something upside down?
  16. This is because redstone wires update frequently to keep up with changes to their circuitry. If theres a way around this, it's probably not worth the trouble it will give you. powering a redstone circuit in the normal way is already easy enough. If you really do MUST do this, I suppose we could some up with a solution. Also, you should return true from inside the if block. That method is supposed to return true when it succeeds and false when it fails. Yours always fails.
  17. Yeah, everything works fine, except that the minecart won't shut up. Unless I load another world, the minecart stopped on the tracks keeps making noises as if it was running. Forever and ever
  18. Thanks a lot. That's the first thing ever about modding that's easier than just plain java: Events.
  19. This is even better than what I was hoping for. I wasn't gonna care for NBT at all... Whenever the game started, if there was a minecart in one of my rail blocks I'd make it go in a random direction. And I'd even go as far as to call it a "feature" Anyway, how do I subscribe to an event? I know I should know this one but...
  20. Entities are very complex. Is there a way for me to know to which side a minecart was heading before it stopped? I have some kind of Powered Rail (all 4 bits of my metadata are taken, 3 for directions, set by the superclass BlockRailBase and 1 for telling when it's powered). This powered rail block makes the cart stop, and then go again after some time. But I'm having a hard time figuring how to make it go to the same direction it was going before. Both posXYZ and prevPosXYZ are set to the same values on every entity update. I can see only 2 possible solutions, and I don't like any of them so much: 1. Adding a tile entity to my powered rail 2. using ASM to add a field to minecart. Can anyone come up with a better idea, please? =/
  21. That's the weirdest piece of code I've ever seen... And this is coming from someone who's trying to subclass net.minecraft.block.BlockRailPowered at the moment.
  22. LOL I tested... It is true. I thought it was a lie. A mob named Dinnerbone will be forever upside-down
  23. Who's dinnerbone? I heard that if you name some mob dinnerbone with a nametag the mob becomes upside down forever... Is that true?
  24. did you see my edit? I think the block below the player's feet would be changin this: int blockID = player.worldObj.getBlockId(x, y, z); to this: int blockID = player.worldObj.getBlockId(x, y - 1, z); edit: sorry... we're both posting without seeing each other's answers. That thing that says "someone posted to this thread while you were typing" or something is not working
  25. Do you think this would work? int x = (int)Math.floor(player.posX); int y = (int)Math.floor(player.posY); int z = (int)Math.floor(player.posZ); int blockID = player.worldObj.getBlockId(x, y, z); edit: actually the block bellow the player would have y - 1 I think.
×
×
  • Create New...

Important Information

By using this site, you agree to our Terms of Use.