modding

Discussion in 'Offtopic' started by johnfg10, Apr 9, 2016.

  1. johnfg10

    johnfg10 Well-Known Member

    Messages:
    2,430
    Likes Received:
    200
    Local Time:
    10:29 AM
    well where do i start one there is no tutorial that is not some weird hacky stuff on the internet all i want to do i add a chest like block if anyone could help it would be appreciated
     
  2. Arcanuo

    Arcanuo Old School Poster

    Messages:
    424
    Likes Received:
    160
    Local Time:
    5:29 AM
    I would never recommend Java as your first language, coding is as much a mindset, as it a skill set.

    Unlike Spanish, as soon as I get some practice and learn the words I can be a fluent Spanish speaker.

    This isn't true for Coding, you can understand how it works but will give up in frustration because you can't think in a manner that helps you.


    Item creation is very basic yes, but more advanced things are not.
     
  3. johnfg10

    johnfg10 Well-Known Member

    Messages:
    2,430
    Likes Received:
    200
    Local Time:
    10:29 AM
    im doing fine most tutorial are really good but tile entitys and container tutorials and such are horrible or really hacky
    im new to this but even to me this
    rings alarm bells
     
  4. chugga_fan

    chugga_fan ME 4M storage cell of knowledge, all the time

    Messages:
    5,861
    Likes Received:
    730
    Local Time:
    5:29 AM
    actually, i'd reccomend java as a first language, it's simple and easy to understand compared to most and it's so high leveled that you don't deal with stuff like #define #ifdef #endif etc.
     
  5. johnfg10

    johnfg10 Well-Known Member

    Messages:
    2,430
    Likes Received:
    200
    Local Time:
    10:29 AM
    im doing good with it ive done "joke" drag and drop stuff before and that was really annoying plus i love a challange :p

    also anyone thats trying to learn this website is amazing
    Java For Beginners - Contents Page
     
    Last edited: Apr 10, 2016
  6. johnfg10

    johnfg10 Well-Known Member

    Messages:
    2,430
    Likes Received:
    200
    Local Time:
    10:29 AM
    would anyone be able to tell me how i would get a player from a string?
     
  7. The_Icy_One

    The_Icy_One Procrastinates by doing work

    Messages:
    1,044
    Likes Received:
    210
    Local Time:
    10:29 AM
    As in get an EntityPlayer from a string? I think (EntityPlayer)"playername" should work, but I can't remember exactly.
     
  8. Matryoshika

    Matryoshika Well-Known Member

    Messages:
    1,193
    Likes Received:
    606
    Local Time:
    11:29 AM
    I would wait a bit before trying to code containers. Try to get comfortable with coding before taking on containrs. I personally hate containers -.-'

    Containers & GUI's love to crash, especially with ArrayOutOfBoundsExceptions.
    Oh, and if you want to whitelist/blacklist/filter items, so that lets say you cannot insert other inventories, like bags, me-drives or whatever, you need to make your own custom slot-class, as the vanilla slot-class only filters exclusively for hoppers.
    Heres one of my own custom containers. Though switch out the New SlotRun.... for pure New Slot, if you do not have a custom slot-class.
    Code:
    public class ContainerRunicScribe extends Container{
       
    	protected TileRunicScribe tileEntity;
    
    	public ContainerRunicScribe (InventoryPlayer inventoryPlayer, TileRunicScribe te){
    			tileEntity = te;
    
    			//the Slot constructor takes the IInventory and the slot number in that it binds to
    			//and the x-y coordinates it resides on-screen
    			addSlotToContainer(new SlotRunicScribe(tileEntity, 0, (8 + 4 * 18)-39, -9));
    			addSlotToContainer(new SlotRunicScribe(tileEntity, 1, (8 + 2 * 18)-39, 11));
    			addSlotToContainer(new SlotRunicScribe(tileEntity, 2, (8 + 4 * 18)-39, 21));
    			addSlotToContainer(new SlotRunicScribe(tileEntity, 3, (8 + 6 * 18)-39, 11));
    
    
    			//commonly used vanilla code that adds the player's inventory
    			bindPlayerInventory(inventoryPlayer);
    	}
    
    	@Override
    	public boolean canInteractWith(EntityPlayer player) {
    			return tileEntity.isUseableByPlayer(player);
    	}
    
    
    	protected void bindPlayerInventory(InventoryPlayer inventoryPlayer) {
    			for (int i = 0; i < 3; i++) {
    					for (int j = 0; j < 9; j++) {
    							addSlotToContainer(new Slot(inventoryPlayer, j + i * 9 + 9,
    											(8 + j * 18)-39, (84 + i * 18)-1));
    					}
    			}
    
    			for (int i = 0; i < 9; i++) {
    					addSlotToContainer(new Slot(inventoryPlayer, i, (8 + i * 18)-39, 141));
    			}
    	}
    
    	@Override
    	public ItemStack transferStackInSlot(EntityPlayer player, int slot) {
    			ItemStack stack = null;
    			Slot slotObject = (Slot) inventorySlots.get(slot);
    
    			//null checks and checks if the item can be stacked (maxStackSize > 1)
    			if (slotObject != null && slotObject.getHasStack()) {
    					ItemStack stackInSlot = slotObject.getStack();
    					stack = stackInSlot.copy();
    
    					//merges the item into player inventory since its in the tileEntity
    					if (slot < tileEntity.getSizeInventory()) {
    							if (!this.mergeItemStack(stackInSlot, tileEntity.getSizeInventory(), tileEntity.getSizeInventory(), true)) {
    									return null;
    							}
    					}
    					//places it into the tileEntity is possible since its in the player inventory
    					else if (!this.mergeItemStack(stackInSlot, 0, tileEntity.getSizeInventory(), false)) {
    							return null;
    					}
    
    					if (stackInSlot.stackSize == 0) {
    							slotObject.putStack(null);
    					} else {
    							slotObject.onSlotChanged();
    					}
    
    					if (stackInSlot.stackSize == stack.stackSize) {
    							return null;
    					}
    					slotObject.onPickupFromSlot(player, stackInSlot);
    			}
    			return stack;
    	}
    }
     
    Arcanuo likes this.
  9. Arcanuo

    Arcanuo Old School Poster

    Messages:
    424
    Likes Received:
    160
    Local Time:
    5:29 AM
    I commend you, Sir.

    Coding containers/GUI's is annoying in any language, the basics of what you want to accomplish are the same, Java GUI/containers are especially. Several other languages have the ability to create GUI's, but anything Minecraft in that regard, makes me shut down. So therefore I commend you, because things like that make me close the tab and turn on music while I try to re-organize my brain for overload.
     
  10. johnfg10

    johnfg10 Well-Known Member

    Messages:
    2,430
    Likes Received:
    200
    Local Time:
    10:29 AM
    yup i dont need a container EVER
     
  11. Arcanuo

    Arcanuo Old School Poster

    Messages:
    424
    Likes Received:
    160
    Local Time:
    5:29 AM
    We all said this at one point.
     
  12. johnfg10

    johnfg10 Well-Known Member

    Messages:
    2,430
    Likes Received:
    200
    Local Time:
    10:29 AM
    nope not needed il just idk ummm use chests -.-
     
  13. Matryoshika

    Matryoshika Well-Known Member

    Messages:
    1,193
    Likes Received:
    606
    Local Time:
    11:29 AM
    Just "from a string" is quite insufficient. A player is an Entity, which means you need to get access to the Entity class to begin with.
    Oh, and I'd recommend using the UUID of that player instead of his/her name, as thats much more reliable.

    To say exactly how you would get the player, I'd need more information on what you are trying to do with the player. There are several ways, each with their own ways of getting a specific player, and with their own shortcomings.
     
  14. johnfg10

    johnfg10 Well-Known Member

    Messages:
    2,430
    Likes Received:
    200
    Local Time:
    10:29 AM
    trying to track a players location
    using a command /locate <playername> then works out the players position and prints to user
     
  15. chugga_fan

    chugga_fan ME 4M storage cell of knowledge, all the time

    Messages:
    5,861
    Likes Received:
    730
    Local Time:
    5:29 AM
    the EntityPlayer you get from the command thingy, use it, it's got it's coords stored SOMEWHERE in that object
     
  16. johnfg10

    johnfg10 Well-Known Member

    Messages:
    2,430
    Likes Received:
    200
    Local Time:
    10:29 AM
    not quite what i mean i mean lets say jimmy wants to know where bobby is he can do /locate bobby and it will print bobbys location in jimmys chat
     
  17. Matryoshika

    Matryoshika Well-Known Member

    Messages:
    1,193
    Likes Received:
    606
    Local Time:
    11:29 AM
    That will require an eventhandler.

    Here's some code you should find useful. You need to edit the name-variable based on the command's issued string, but that should not be too hard. ( I've never messed with commands)

    Code:
    public String name;
    double playerX;
    double playerY;
    double playerZ;
    
    @SubscribeEvent
    	public String locatePlayer(LivingUpdateEvent event){
    		if(event.entityLiving instanceof EntityPlayer){
    			EntityPlayer player = (EntityPlayer) event.entityLiving;
    		  
    			if(name == player.getDisplayName()){
    				playerX = player.posX;
    				playerY = player.posY;
    				playerZ = player.posZ;
    			}
    		}
    		return "Coords: X=" + playerX + ": Y=" + playerY + ": Z=" + playerZ;
    	}
    You then use what is returned from this method, and issue it in a player.addChatMessage for who issued the command.
     
  18. johnfg10

    johnfg10 Well-Known Member

    Messages:
    2,430
    Likes Received:
    200
    Local Time:
    10:29 AM
    ignore that :p
     
  19. Matryoshika

    Matryoshika Well-Known Member

    Messages:
    1,193
    Likes Received:
    606
    Local Time:
    11:29 AM
    Do you have that inside an initialized eventhandler?
    Eg: public class EventHandler{
    <above code>
    }

    and in your main class, have
    Code:
    @EventHandler
    	public void Init(FMLInitializationEvent event){
    		MinecraftForge.EVENT_BUS.register(new EventHandler());
    	}
     
  20. Slind

    Slind Founder

    Messages:
    8,332
    Likes Received:
    3,018
    Local Time:
    11:29 AM
    Is that event even fired client side?
     

Share This Page