import{vec3 as t}from"../utils.js";import{Hand as e,stickLikeOverrides as r,upgrades as s}from"../render.js";import{getPlayerHeldItem as o}from"../utils/players.js";import{DrawerType as i}from"../base/drawer_type.js";import{ITEM_COUNT_KEY as n}from"../drawers.js";import"../main.js";import"@minecraft/server";class a extends i{constructor(){super(...arguments),this.allowedHands=[e.MAIN_HAND,e.OFF_HAND],this.onUse=(t,e)=>{const r=this.getOrCreateEntity(t),s=o(e),i=this.getHandFromBlock(this.rayCastBlock(e));this.handleUpgradesAndKeys(e,r,t,s)||this.handleItemTypeInDrawer(e,r,s,i,t)},this.tick=r=>{const s=this.getEntityFromBlock(r);this.processHopperInteraction(s,t(0,1,0),0,r,e.MAIN_HAND),this.processHopperInteraction(s,t(0,0,1),2,r,e.MAIN_HAND),this.processHopperInteraction(s,t(0,0,-1),3,r,e.MAIN_HAND),this.processHopperInteraction(s,t(1,0,0),4,r,e.MAIN_HAND),this.processHopperInteraction(s,t(-1,0,0),5,r,e.MAIN_HAND),this.processHopperInteraction(s,t(0,1,0),0,r,e.OFF_HAND),this.processHopperInteraction(s,t(0,0,1),2,r,e.OFF_HAND),this.processHopperInteraction(s,t(0,0,-1),3,r,e.OFF_HAND),this.processHopperInteraction(s,t(1,0,0),4,r,e.OFF_HAND),this.processHopperInteraction(s,t(-1,0,0),5,r,e.OFF_HAND),s&&(this.processHopperTake(s,e.MAIN_HAND),this.processHopperTake(s,e.OFF_HAND))},this.onPlace=(t,e)=>{},this.canBreak=(t,r)=>{const s=this.getEntityFromBlock(r);if(!s)return!0;let o=void 0!==this.getStackInDrawer(s,e.MAIN_HAND)&&0!==this.getDrawerItemCount(s,e.MAIN_HAND);const i=this.getStackInDrawer(s,e.OFF_HAND);return o=o||void 0!==i&&0!==this.getDrawerItemCount(s,e.OFF_HAND),!o},this.onHit=(t,r,s)=>{const o=this.getEntityFromBlock(s);if(!o)return;const i=this.rayCastBlock(t);if(i){const r=i.faceLocation;if(r.y>.46){const r=this.getStackInDrawer(o,e.OFF_HAND);null!=r&&this.requestRemoveFromDrawer(t.isSneaking?r.maxAmount:1,t,r,e.OFF_HAND,o,s)}else if(r.y<=.4){const r=this.getStackInDrawer(o,e.MAIN_HAND);null!=r&&this.requestRemoveFromDrawer(t.isSneaking?r.maxAmount:1,t,r,e.MAIN_HAND,o,s)}}},this.getKeyForHand=t=>t===e.MAIN_HAND?n:n+"_offhand",this.getSlotForHand=t=>t===e.MAIN_HAND?0:1,this.rayCastBlock=t=>t.dimension.getBlockFromRay(t.getHeadLocation(),t.getViewDirection(),{maxDistance:5,includeTags:[this.getBlockTag]}),this.getHandFromBlock=t=>{if(!t)return e.MAIN_HAND;const r=t.faceLocation;return r.y>.46?e.OFF_HAND:r.y<=.4?e.MAIN_HAND:void 0}}getDrawerMaxItemCountWithMuti(t,e){return super.getDrawerMaxItemCountWithMuti(t,e)/2}onStackSet(t,e,o){r.includes(o?.typeId)||s.includes(o?.typeId)}getSettingGUIBody(t){return{translate:"ftb_sd.double_settings",with:["\n",`${this.getDrawerItemCount(t,e.OFF_HAND)} / ${this.getDrawerMaxItemCount(t)}`,"\n",`${this.getDrawerItemCount(t,e.MAIN_HAND)} / ${this.getDrawerMaxItemCount(t)}`]}}}class c extends a{constructor(){super(...arguments),this.getEntityTypeId="ftb_sd:double_drawer",this.getBlockTag="ftb:double_drawer"}}class h extends a{constructor(){super(...arguments),this.getEntityTypeId="ftb_sd:half_double_drawer",this.getBlockTag="ftb:half_double_drawer"}}export{a as AbstractDoubleDrawer,h as HalfDoubleSingleDrawer,c as SingleDoubleDrawer};
