package Ġend er box Ċ Ċ import Ġcom . google . common . collect . Immutable Map Ċ import Ġnet . fabric mc . api . Env Type Ċ import Ġnet . fabric mc . api . Environment Ċ import Ġnet . minecraft . block .* Ċ import Ġnet . minecraft . block . entity . Block Entity Ċ import Ġnet . minecraft . client . Minecraft Client Ċ import Ġnet . minecraft . item . ItemStack Ċ import Ġnet . minecraft . nbt . Compound Tag Ċ import Ġnet . minecraft . nbt . N bt Helper Ċ import Ġnet . minecraft . util . math . Block Pos Ċ import Ġnet . minecraft . world . Block View Ċ Ċ private Ġconst Ġval Ġblock State Key Ġ= Ġ" block State " Ċ private Ġconst Ġval Ġblock Entity Tag Key Ġ= Ġ" block Entity Tag " Ċ Ċ data Ġclass ĠBlock Data ( Ċ ĉ val Ġblock State : ĠBlock State Ġ= ĠBlock State ( Blocks . AIR , ĠImmutableMap . of ()), Ċ ĉ val Ġblock Entity Tag : ĠCompound Tag ? Ġ= Ġnull , Ċ ĉ private Ġvar Ġrender State : ĠRender State Ġ= ĠRender State . Not Loaded Ċ ) Ġ{ Ċ ĉ val Ġblock : ĠBlock Ċĉ ĉ get () Ġ= Ġblock State . block ĊĉĊ ĉ constructor ( tag : ĠCompound Tag ) Ġ: Ġthis ( Ċĉ ĉ N bt Helper . to BlockState ( tag . get Compound ( block State Key )), Ċĉ ĉ if Ġ( tag . contains ( block Entity Tag Key )) Ġtag . get Compound ( block Entity Tag Key ) Ġelse Ġnull Ċ ĉ ) ĊĉĊ ĉ fun Ġto Tag ( tag : ĠCompound Tag Ġ= ĠCompound Tag ()): ĠCompound Tag Ġ{ Ċĉ ĉ tag . put ( block State Key , ĠNbt Helper . from BlockState ( block State )) ĊĉĉĊĉ ĉ tag . remove ( block Entity Tag Key ) Ċĉ ĉ if Ġ( block Entity Tag Ġ!= Ġnull ) Ġ{ Ċĉĉ ĉ tag . put ( block Entity Tag Key , Ġblock Entity Tag ) Ċĉ ĉ } ĊĉĉĊĉ ĉ return Ġtag Ċ ĉ } ĊĉĊ ĉ /** Ġupdates Ġthe Ġcontained Ġtile Ġentity 's Ġposition , Ġif Ġapplicable Ġ Ġ*/ Ċ ĉ fun Ġupdate Position ( position : ĠBlockPos ) Ġ{ Ċĉ ĉ block Entity Tag ?. apply Ġ{ Ċĉĉ ĉ // Ġthis Ġis Ġkind a Ġhack y , Ġbut Ġthere 's Ġno Ġother Ġoption Ċĉĉ ĉ put Int (" x ", Ġposition . x ) Ċĉĉ ĉ put Int (" y ", Ġposition . y ) Ċĉĉ ĉ put Int (" z ", Ġposition . z ) Ċĉ ĉ } Ċ ĉ } ĊĉĊ ĉ @ Environment ( Env Type . CLIENT ) Ċ ĉ fun Ġpicked Block ( block View : ĠBlock View , Ġpos : ĠBlockPos ): ĠItemStack Ġ{ Ċĉ ĉ try Ġ{ Ċĉĉ ĉ // Ġtry Ġto Ġsimulate Ġpicking Ġthe Ġblock Ċĉĉ ĉ return Ġblock . get Pick Stack ( block View , Ġpos , Ġblock State ) Ċĉ ĉ } Ġcatch Ġ(_ : ĠException ) Ġ{ Ċĉĉ ĉ // Ġcould Ġfail Ġe . g . Ġbecause Ġthe Ġpick Ġblock Ġcode Ġexpects Ġa Ġcertain Ġtile Ġentity Ċĉ ĉ } ĊĉĉĊĉ ĉ // Ġconstruct Ġthe Ġdropped Ġitem Ġourselves Ċĉ ĉ return ĠItemStack ( block State . block , Ġ 1 ) Ċ ĉ } ĊĉĊ ĉ /** Ġclient - only ! Ġ*/ Ċ ĉ fun Ġrender ( renderer : Ġ( Block Entity ) Ġ-> ĠUnit , Ġfallback : Ġ( BlockState ) Ġ-> ĠUnit ) Ġ{ Ċĉ ĉ if Ġ( render State Ġ== ĠRender State . Not Loaded ) Ċĉĉ ĉ render State Ġ= Ġmake Render State () ĊĉĉĊĉ ĉ val Ġblock Entity Ġ= Ġ( render State Ġas ? ĠRender State . Loaded )?. block Entity Ċĉ ĉ if Ġ( block Entity Ġ!= Ġnull ) Ġ{ Ċĉĉ ĉ try Ġ{ Ċĉĉĉ ĉ renderer ( block Entity ) Ċĉĉĉ ĉ return Ċĉĉ ĉ } Ġcatch Ġ( e : ĠException ) Ġ{ Ċĉĉĉ ĉ // Ġwe Ġprobably Ġvi olated Ġsome Ġassumptions ; Ġlet 's Ġjust Ġpret end Ġwe Ġnever Ġtried Ġanything . Ċĉĉĉ ĉ render State Ġ= ĠRender State . Render Failed Ċĉĉĉ ĉ fallback ( block State ) Ċĉĉ ĉ } Ċĉ ĉ } Ġelse Ġ{ Ċĉĉ ĉ fallback ( block State ) Ċĉ ĉ } Ċ ĉ } ĊĉĊ ĉ private Ġfun Ġmake Render State (): ĠRender State Ġ{ Ċĉ ĉ if Ġ( block State . render Type Ġ!= ĠBlock Render Type . ENTITY BLOCK _ ANIM ATED ) Ċĉĉ ĉ return ĠRender State . Not Applicable ĊĉĉĊĉ ĉ try Ġ{ Ċĉĉ ĉ val Ġprovider Ġ= Ġblock State . block Ġas ? ĠBlock Entity Provider Ċĉĉĉ ĉ ?: Ġreturn ĠRender State . Load Failed ĊĉĉĉĊĉĉ ĉ val Ġworld Ġ= ĠMinecraft Client . getInstance (). world Ċĉĉ ĉ val Ġblock Entity Ġ= Ġprovider . create Block Entity ( world ) Ċĉĉĉ ĉ ?: Ġreturn ĠRender State . Load Failed ĊĉĉĉĊĉĉ ĉ block Entity . setLocation ( world , ĠBlockPos . ORIGIN ) Ċĉĉ ĉ block Entity . from Tag ( block Entity Tag ) ĊĉĉĉĊĉĉ ĉ ( block Entity Ġas ĠSet table Cached State ). set Cached State ( block State ) ĊĉĉĉĊĉĉ ĉ return ĠRender State . Loaded ( block Entity ) Ċĉ ĉ } Ġcatch Ġ( e : ĠException ) Ġ{ Ċĉĉ ĉ // Ġwe Ġprobably Ġvi olated Ġsome Ġassumptions ; Ġlet 's Ġjust Ġpret end Ġwe Ġnever Ġtried Ġanything . Ċĉĉ ĉ return ĠRender State . Load Failed Ċĉ ĉ } Ċ ĉ } ĊĉĊ ĉ sealed Ġclass ĠRender State Ġ{ Ċĉ ĉ object ĠNot Loaded Ġ: ĠRender State () Ċĉ ĉ object ĠNot Applicable Ġ: ĠRender State () Ċĉ ĉ object ĠLoad Failed Ġ: ĠRender State () Ċĉ ĉ object ĠRender Failed Ġ: ĠRender State () Ċĉ ĉ data Ġclass ĠLoaded ( val Ġblock Entity : ĠBlock Entity ) Ġ: ĠRender State () Ċ ĉ } Ċ } Ċ Ċ interface ĠSet table Cached State Ġ{ Ċ ĉ fun Ġset Cached State ( cached State : ĠBlock State ?) Ċ } Ċ