Jump to content

[1.15.2]insertItem this is wierd


Mightydanp

Recommended Posts

Ok so this might be simple to explain. This works as intended puts item into that slot
 

if (SlotCircuit.getValidItems().contains(handStack.getItem())) {
                    if (slotHandler.getStackInSlot(0).isEmpty()) {
                        slotHandler.insertItem(0, handStack, false);
                    }
                }

 

Below code doesnt put item in slot but deletes item in hand..... why does it not put item into the slot when i put a line of code after it?
 

if (SlotCircuit.getValidItems().contains(handStack.getItem())) {
                    if (slotHandler.getStackInSlot(0).isEmpty()) {
                        slotHandler.insertItem(0, handStack, false);
                        handStack.shrink(1);
                    }
                }

 

Edited by Mightydanp
add version
Link to comment
Share on other sites

Apparently I'm a complete and utter jerk and come to this forum just like to make fun of people, be confrontational, and make your personal life miserable.  If you think this is the case, JUST REPORT ME.  Otherwise you're just going to get reported when you reply to my posts and point it out, because odds are, I was trying to be nice.

 

Exception: If you do not understand Java, I WILL NOT HELP YOU and your thread will get locked.

 

DO NOT PM ME WITH PROBLEMS. No help will be given.

Link to comment
Share on other sites

ItemStack heldItem = player.getHeldItem(hand);
		if(!heldItem.isEmpty()) {
			MillstoneTileEntity te = (MillstoneTileEntity)world.getTileEntity(pos);
			IItemHandler inventory = te.getCapability(CapabilityItemHandler.ITEM_HANDLER_CAPABILITY, Direction.UP).orElse(null);
			if(inventory == null) return false;
			ItemStack stack = heldItem.copy();
			stack.setCount(1);
			stack = inventory.insertItem(0, stack, true);
			if(stack.isEmpty()) {
				stack = inventory.insertItem(0, heldItem.split(1), false);

Can your code. I dont understand where you remove 1 from handItem

Link to comment
Share on other sites

15 minutes ago, Mightydanp said:

heldItem.split(1)

 

Apparently I'm a complete and utter jerk and come to this forum just like to make fun of people, be confrontational, and make your personal life miserable.  If you think this is the case, JUST REPORT ME.  Otherwise you're just going to get reported when you reply to my posts and point it out, because odds are, I was trying to be nice.

 

Exception: If you do not understand Java, I WILL NOT HELP YOU and your thread will get locked.

 

DO NOT PM ME WITH PROBLEMS. No help will be given.

Link to comment
Share on other sites

To the surprise of no one: Yes. It splits the stack such that the returned stack has the indicated size (or the original's size, whichever is lower) and the original stack is reduced by that amount (to a minimum of zero).

 

Oh and this:

27 minutes ago, Mightydanp said:

stack = inventory.insertItem(0, stack, true);

Is what checks to see if the item can be inserted, regardless of what stack is currently in the TE's inventory.

Edited by Draco18s

Apparently I'm a complete and utter jerk and come to this forum just like to make fun of people, be confrontational, and make your personal life miserable.  If you think this is the case, JUST REPORT ME.  Otherwise you're just going to get reported when you reply to my posts and point it out, because odds are, I was trying to be nice.

 

Exception: If you do not understand Java, I WILL NOT HELP YOU and your thread will get locked.

 

DO NOT PM ME WITH PROBLEMS. No help will be given.

Link to comment
Share on other sites

  You want to do it for real, or just simulate it.

Apparently I'm a complete and utter jerk and come to this forum just like to make fun of people, be confrontational, and make your personal life miserable.  If you think this is the case, JUST REPORT ME.  Otherwise you're just going to get reported when you reply to my posts and point it out, because odds are, I was trying to be nice.

 

Exception: If you do not understand Java, I WILL NOT HELP YOU and your thread will get locked.

 

DO NOT PM ME WITH PROBLEMS. No help will be given.

Link to comment
Share on other sites

stack = inventory.insertItem(0, stack, true);
			if(stack.isEmpty()) {
				stack = inventory.insertItem(0, heldItem.split(1), false);
Can your code. I dont understand where you remove 1 from handItem

Ok so line 1 will visually put an item in slot 0. Which will make stack empty

This will let it pass the of statement and then you insert the item and split it 

Link to comment
Share on other sites

6 minutes ago, Mightydanp said:

Ok so line 1 will visually put an item in slot 0.

No. The first line calculates what would be left over if the stack were to be inserted.

Apparently I'm a complete and utter jerk and come to this forum just like to make fun of people, be confrontational, and make your personal life miserable.  If you think this is the case, JUST REPORT ME.  Otherwise you're just going to get reported when you reply to my posts and point it out, because odds are, I was trying to be nice.

 

Exception: If you do not understand Java, I WILL NOT HELP YOU and your thread will get locked.

 

DO NOT PM ME WITH PROBLEMS. No help will be given.

Link to comment
Share on other sites

Yes.

But keep in mind that that is not the only way these methods can be used. That's what it does here because only 1 of whatever item is trying to be inserted at a time. If we wanted to do more than 1, it gets a little trickier, but the general process is still the same:

  1. Attempt to insert
  2. Check if the remainder has a smaller stack size than what we tried to insert
  3. Actually split off and insert only the amount that will fit

 

Apparently I'm a complete and utter jerk and come to this forum just like to make fun of people, be confrontational, and make your personal life miserable.  If you think this is the case, JUST REPORT ME.  Otherwise you're just going to get reported when you reply to my posts and point it out, because odds are, I was trying to be nice.

 

Exception: If you do not understand Java, I WILL NOT HELP YOU and your thread will get locked.

 

DO NOT PM ME WITH PROBLEMS. No help will be given.

Link to comment
Share on other sites

Vanilla treats stacks of size zero as identical to air. You don't have to do anything about it.

That's why .isEmpty() is a thing.

Apparently I'm a complete and utter jerk and come to this forum just like to make fun of people, be confrontational, and make your personal life miserable.  If you think this is the case, JUST REPORT ME.  Otherwise you're just going to get reported when you reply to my posts and point it out, because odds are, I was trying to be nice.

 

Exception: If you do not understand Java, I WILL NOT HELP YOU and your thread will get locked.

 

DO NOT PM ME WITH PROBLEMS. No help will be given.

Link to comment
Share on other sites

50 minutes ago, Mightydanp said:

I understand that but You put handstack.split(1) in the insertItem. How would that set the item in slot 1 and then split it

There are two functions here.

One is inserting a stack into a slot.

The other is splitting the item stack in the player's hand and returning a new stack.

The former is taking as a parameter the result of the latter.

50 minutes ago, Mightydanp said:

i am confused i thought it would take the handstack and split it then you would be left with air making it not work as intended

handstack is indeed left empty if it was a stack of 1 item.

Empty stacks that are not air, and stacks of air, are functionally identical as far as all of vanilla's code is concerned. The whole point of split() is that you have TWO stacks after calling it, the original (now empty) and the new stack (with one item) that gets inserted into the tile entity. That's how the player's held item is cleared.

Apparently I'm a complete and utter jerk and come to this forum just like to make fun of people, be confrontational, and make your personal life miserable.  If you think this is the case, JUST REPORT ME.  Otherwise you're just going to get reported when you reply to my posts and point it out, because odds are, I was trying to be nice.

 

Exception: If you do not understand Java, I WILL NOT HELP YOU and your thread will get locked.

 

DO NOT PM ME WITH PROBLEMS. No help will be given.

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Unfortunately, your content contains terms that we do not allow. Please edit your content to remove the highlighted words below.
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.



  • Recently Browsing

    • No registered users viewing this page.
  • Posts

    • Direct Entry /Pre degree into,2023/(2024 Tansian University, Umunya transfer form is out ☎️08O-3664OI34) OR {2348036640134)} …Supplementary Form,Pre-Degree Form (08O3664O134, Jupeb form IJMB Form, masters form,Ph.D  Form,Sandwich Form,Diploma Form,Change of institution form call (08O3664O134 OR {08O3664O134} Change of course Form,POST UTME Form
    • 화성단란주점 ♠BCGAME88·COM♣ 월계단란주점 돈암단란주점 역삼단란주점 용두단란주점 ydk82 용인단란주점 원효단란주점 북가좌단란주점 삼성단란주점 kmp69 송현단란주점 서린단란주점 금산단란주점 금천단란주점 jfr89 효창단란주점 오산단란주점 외발산단란주점 양주단란주점 kpt13 항동단란주점 구기단란주점 흑석단란주점 송현단란주점 lhy27 익산단란주점 논현단란주점 온수단란주점 김포단란주점 fjn70 역삼단란주점 오류단란주점 의왕단란주점 금천단란주점 syc21 신수단란주점 한남단란주점 안국단란주점 냉천단란주점 bte37 시흥단란주점 마포단란주점 봉원단란주점 권농단란주점 pqc10 과해단란주점 무악단란주점 와룡단란주점 석관단란주점 mkb49 쌍림단란주점 내발산단란주점 혜화단란주점 마곡단란주점 vlw22 마포단란주점 고척단란주점 평창단란주점 당산단란주점 wlx27 광주단란주점 용두단란주점 여주단란주점 이문단란주점 enx86 홍익단란주점 주교단란주점 도렴단란주점 화곡단란주점 arg87 내발산단란주점 칠곡단란주점 옥천단란주점 하계단란주점 juh46 원효단란주점 오곡단란주점 개포단란주점 노고산단란주점 bwx73 숭인단란주점 시흥단란주점 여주단란주점 묵정단란주점 hpu44 배방단란주점 청암단란주점 보광단란주점 마포단란주점 phf31 거제단란주점 광명단란주점 성구단란주점 안산단란주점 pwg54 내발산단란주점 관수단란주점 목포단란주점 평창단란주점 fbx65 흥인단란주점 금천단란주점 함안단란주점 돈암단란주점 cxb24 서린단란주점 남현단란주점 영암단란주점 남가좌단란주점 fpl33 대치단란주점 남학단란주점 양천단란주점 중림단란주점 xth07
    • 수원셔츠룸 ■BCGAME88·COM♬ 천호셔츠룸 흑석셔츠룸 명륜셔츠룸 광명셔츠룸 ahy88 동두천셔츠룸 신원셔츠룸 논산셔츠룸 도선셔츠룸 epf07 신대방셔츠룸 신원셔츠룸 남산셔츠룸 염창셔츠룸 wwq30 상일셔츠룸 중림셔츠룸 관철셔츠룸 누상셔츠룸 fqx18 만리셔츠룸 사당셔츠룸 부산셔츠룸 금호셔츠룸 hen32 원지셔츠룸 신원셔츠룸 흥인셔츠룸 항동셔츠룸 obr14 신천셔츠룸 마포셔츠룸 평택셔츠룸 합정셔츠룸 swf58 개포셔츠룸 관수셔츠룸 필동셔츠룸 동교셔츠룸 vvi93 삼전셔츠룸 평택셔츠룸 화성셔츠룸 율현셔츠룸 wqg17 포천셔츠룸 양평셔츠룸 월계셔츠룸 양화셔츠룸 poi79 광주셔츠룸 가평셔츠룸 충정로셔츠룸 흑석셔츠룸 cut15 다동셔츠룸 포천셔츠룸 진관셔츠룸 이천셔츠룸 jmn12 의왕셔츠룸 강릉셔츠룸 경산셔츠룸 거창셔츠룸 cjh67 소격셔츠룸 신천셔츠룸 신설셔츠룸 칠곡셔츠룸 hwe26 효자셔츠룸 동숭셔츠룸 회기셔츠룸 일원셔츠룸 cdh09 인천셔츠룸 당진셔츠룸 하남셔츠룸 군자셔츠룸 jxi61 천연셔츠룸 응암셔츠룸 부산셔츠룸 신계셔츠룸 ohs52 양재셔츠룸 서산셔츠룸 수서셔츠룸 수원셔츠룸 shq09 도원셔츠룸 을지셔츠룸 산천셔츠룸 학방셔츠룸 bht69 남현셔츠룸 망원셔츠룸 영암셔츠룸 파주셔츠룸 wnp14 오산셔츠룸 청운셔츠룸 반포셔츠룸 명일셔츠룸 wsp29 권농셔츠룸 천왕셔츠룸 염창셔츠룸 삼각셔츠룸 wpd87 보령셔츠룸 포천셔츠룸 안성셔츠룸 논현셔츠룸 mdn99
    • 의왕수다 방 ªBCGAME88·COM♠ 신공덕수다 방 휘경수다 방 화성수다 방 논현수다 방 nkn81 봉천수다 방 공주수다 방 역촌수다 방 김포수다 방 bsf79 주성수다 방 칠곡수다 방 묘동수다 방 양주수다 방 fbj55 신내수다 방 성내수다 방 석촌수다 방 가락수다 방 hvo38 휘경수다 방 청파수다 방 강일수다 방 도화수다 방 sbw21 광주수다 방 번동수다 방 수서수다 방 삼선수다 방 ssq27 화성수다 방 동자수다 방 청주수다 방 당인수다 방 hsx45 가평수다 방 하남수다 방 예산수다 방 사천수다 방 pua73 함안수다 방 남원수다 방 우면수다 방 강동수다 방 xel41 동작수다 방 다동수다 방 영암수다 방 익선수다 방 dxq99 양주수다 방 동해수다 방 통영수다 방 양평수다 방 gmi49 남양주수다 방 의왕수다 방 홍천수다 방 부천수다 방 kku24 등촌수다 방 홍천수다 방 충정수다 방 율현수다 방 qon17 청암수다 방 강남수다 방 압구정수다 방 사간수다 방 onu39 역삼수다 방 마포수다 방 장지수다 방 인의수다 방 rpn66 천연수다 방 화성수다 방 동교수다 방 역촌수다 방 too51 논현수다 방 원남수다 방 상일수다 방 세곡수다 방 klr53 역삼수다 방 충정로수다 방 체부수다 방 익산수다 방 vuq53 구리수다 방 영등포수다 방 양주수다 방 장위수다 방 cmb07 관악수다 방 인현수다 방 청담수다 방 율현수다 방 uwq00 청담수다 방 창동수다 방 동두천수다 방 강북수다 방 snf52 가락수다 방 장충수다 방 파주수다 방 의정부수다 방 efg45 상왕십리수다 방 동선수다 방 도렴수다 방 묵동수다 방 hsh55
    • 과천만남 ◐BCGAME88·COM↑ 의정부만남 문경만남 구기만남 정동만남 ssk64 태평만남 오류만남 홍은만남 천호만남 btv41 중림만남 묵동만남 종로만남 구수만남 wna54 독산만남 옥천만남 신촌만남 봉래만남 tnc68 반포만남 성산만남 장충만남 묘동만남 abm18 화양만남 고양만남 현석만남 삼척만남 xlh08 보령만남 종암만남 소격만남 안양만남 xjo34 낙원만남 강남만남 염곡만남 당산만남 jps23 송정만남 여의도만남 서빙고만남 이태원만남 scr34 양화만남 주성만남 고양만남 길동만남 ijo75 신공덕만남 파주만남 산천만남 강서만남 ump42 묘동만남 본동만남 수색만남 영등포만남 jkm68 동교만남 수송만남 구리만남 수표만남 naq73 시흥만남 효자만남 당주만남 한남만남 fye45 문래만남 용답만남 태평로만남 한남만남 uye84 김제만남 항동만남 팔판만남 김해만남 lbm72 소공만남 북창만남 송정만남 홍익만남 ofe60 염창만남 삼전만남 번동만남 성남만남 kel85 양천만남 강동만남 수송만남 대치만남 lah32 구기만남 홍지만남 영암만남 세종만남 xok15 남영만남 강남만남 안산만남 창녕만남 pjq95 인사만남 인사만남 소격만남 서초만남 ofk68 옥인만남 여수만남 계동만남 숭인만남 iwf49
  • Topics

×
×
  • Create New...

Important Information

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