Advertisement
Guest User

Untitled

a guest
Feb 19th, 2023
52
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 20.30 KB | None | 0 0
  1. public class WarpPipeBlockEntity extends BlockEntity implements MenuProvider {
  2.  
  3. public static int dest0Posx,dest0Posy,dest0Posz;
  4. public static int dest1Posx,dest1Posy,dest1Posz;
  5. public static int dest2Posx,dest2Posy,dest2Posz;
  6. public static int dest3Posx,dest3Posy,dest3Posz;
  7. public static int dest4Posx,dest4Posy,dest4Posz;
  8. public static int dest5Posx,dest5Posy,dest5Posz;
  9. public static int dest6Posx,dest6Posy,dest6Posz;
  10. public static int dest7Posx,dest7Posy,dest7Posz;
  11.  
  12. public static String dest0name="",dest1name="",dest2name="",dest3name="",dest4name="",dest5name="",dest6name="",dest7name="";
  13.  
  14. public static boolean dest0exists = false;
  15. public static boolean dest1exists = false;
  16. public static boolean dest2exists = false;
  17. public static boolean dest3exists = false;
  18. public static boolean dest4exists = false;
  19. public static boolean dest5exists = false;
  20. public static boolean dest6exists = false;
  21. public static boolean dest7exists = false;
  22.  
  23. public static String dest0dim="",dest1dim="",dest2dim="",dest3dim="",dest4dim="",dest5dim="",dest6dim="",dest7dim="";
  24.  
  25. private static boolean worksThroughDimensions = false;
  26. public static String dimName = "";
  27. public static int selectedWheelPart = -1;
  28.  
  29. public final ItemStackHandler itemHandler = new ItemStackHandler(Constants.TELEPORTER_TOTALSLOTS) {
  30. @Override
  31. protected void onContentsChanged(int slot) {
  32. setChanged();
  33. };
  34. };
  35.  
  36. public WarpPipeBlockEntity(BlockPos pos, BlockState state) {
  37. super(ModBlockEntities.WARPPIPE_BLOCKENTITY.get(), pos, state);
  38. }
  39.  
  40.  
  41. public void setPosX(int pos, int dest) {
  42. if(dest == 0) {
  43. dest0Posx = pos;
  44. } else if(dest == 1) {
  45. dest1Posx = pos;
  46. } else if(dest == 2) {
  47. dest2Posx = pos;
  48. } else if(dest == 3) {
  49. dest3Posx = pos;
  50. } else if(dest == 4) {
  51. dest4Posx = pos;
  52. } else if(dest == 5) {
  53. dest5Posx = pos;
  54. } else if(dest == 6) {
  55. dest6Posx = pos;
  56. } else if(dest == 7) {
  57. dest7Posx = pos;
  58. }
  59. }
  60. public void setPosY(int pos, int dest) {
  61. if(dest == 0) {
  62. dest0Posy = pos;
  63. } else if(dest == 1) {
  64. dest1Posy = pos;
  65. } else if(dest == 2) {
  66. dest2Posy = pos;
  67. } else if(dest == 3) {
  68. dest3Posy = pos;
  69. } else if(dest == 4) {
  70. dest4Posy = pos;
  71. } else if(dest == 5) {
  72. dest5Posy = pos;
  73. } else if(dest == 6) {
  74. dest6Posy = pos;
  75. } else if(dest == 7) {
  76. dest7Posy = pos;
  77. }
  78. }
  79. public void setPosZ(int pos, int dest) {
  80. if(dest == 0) {
  81. dest0Posz = pos;
  82. } else if(dest == 1) {
  83. dest1Posz = pos;
  84. } else if(dest == 2) {
  85. dest2Posz = pos;
  86. } else if(dest == 3) {
  87. dest3Posz = pos;
  88. } else if(dest == 4) {
  89. dest4Posz = pos;
  90. } else if(dest == 5) {
  91. dest5Posz = pos;
  92. } else if(dest == 6) {
  93. dest6Posz = pos;
  94. } else if(dest == 7) {
  95. dest7Posz = pos;
  96. }
  97. }
  98. public void setDestName(int dest, String name) {
  99. if(dest == 0) {
  100. dest0name = name;
  101. } else if(dest == 1) {
  102. dest1name = name;
  103. } else if(dest == 2) {
  104. dest2name = name;
  105. } else if(dest == 3) {
  106. dest3name = name;
  107. } else if(dest == 4) {
  108. dest4name = name;
  109. } else if(dest == 5) {
  110. dest5name = name;
  111. } else if(dest == 6) {
  112. dest6name = name;
  113. } else if(dest == 7) {
  114. dest7name = name;
  115. }
  116. }
  117. public void setDestDimension(int dest, String dim) {
  118. if(dest == 0) {
  119. dest0dim = dim;
  120. } else if(dest == 1) {
  121. dest1dim = dim;
  122. } else if(dest == 2) {
  123. dest2dim = dim;
  124. } else if(dest == 3) {
  125. dest3dim = dim;
  126. } else if(dest == 4) {
  127. dest4dim = dim;
  128. } else if(dest == 5) {
  129. dest5dim = dim;
  130. } else if(dest == 6) {
  131. dest6dim = dim;
  132. } else if(dest == 7) {
  133. dest7dim = dim;
  134. }
  135. }
  136. public void setDestExists(int dest, boolean exists) {
  137. if(dest == 0) {
  138. dest0exists = exists;
  139. } else if(dest == 1) {
  140. dest1exists = exists;
  141. } else if(dest == 2) {
  142. dest2exists = exists;
  143. } else if(dest == 3) {
  144. dest3exists = exists;
  145. } else if(dest == 4) {
  146. dest4exists = exists;
  147. } else if(dest == 5) {
  148. dest5exists = exists;
  149. } else if(dest == 6) {
  150. dest6exists = exists;
  151. } else if(dest == 7) {
  152. dest7exists = exists;
  153. }
  154. }
  155. public void setSelectedWheelPart(int part) {
  156. selectedWheelPart = part;
  157. }
  158.  
  159.  
  160.  
  161.  
  162.  
  163.  
  164. public boolean getDimensionWork() {
  165. return this.worksThroughDimensions;
  166. }
  167. public String getDimName() {
  168. return this.dimName;
  169. }
  170. public static void setDimensionName(String dimensionName) {
  171. dimName = dimensionName;
  172. }
  173.  
  174. private LazyOptional<IItemHandler> lazyItemHandler = LazyOptional.empty();
  175.  
  176. @Override
  177. public AbstractContainerMenu createMenu(int id, Inventory inv, Player player) {
  178. ModMessages.sendToClients(new PacketSyncTeleporterPosToClient(
  179. dest0dim,
  180. dest1dim,
  181. dest2dim,
  182. dest3dim,
  183. dest4dim,
  184. dest5dim,
  185. dest6dim,
  186. dest7dim,
  187. dest0exists,
  188. dest1exists,
  189. dest2exists,
  190. dest3exists,
  191. dest4exists,
  192. dest5exists,
  193. dest6exists,
  194. dest7exists,
  195. dest0name,
  196. dest1name,
  197. dest2name,
  198. dest3name,
  199. dest4name,
  200. dest5name,
  201. dest6name,
  202. dest7name,
  203. selectedWheelPart,
  204. dest0Posx,dest0Posy,dest0Posz,
  205. dest1Posx,dest1Posy,dest1Posz,
  206. dest2Posx,dest2Posy,dest2Posz,
  207. dest3Posx,dest3Posy,dest3Posz,
  208. dest4Posx,dest4Posy,dest4Posz,
  209. dest5Posx,dest5Posy,dest5Posz,
  210. dest6Posx,dest6Posy,dest6Posz,
  211. dest7Posx,dest7Posy,dest7Posz,
  212. dimName,worldPosition));
  213. return new TeleporterMenu(id, inv, this);
  214. }
  215.  
  216. @Override
  217. public Component getDisplayName() {
  218. return new TextComponent("");
  219. }
  220.  
  221. @Nonnull
  222. @Override
  223. public <T> LazyOptional<T> getCapability(@Nonnull Capability<T> cap, @javax.annotation.Nullable Direction side) {
  224. if (cap == CapabilityItemHandler.ITEM_HANDLER_CAPABILITY) {
  225. return lazyItemHandler.cast();
  226. }
  227. return super.getCapability(cap, side);
  228. }
  229.  
  230. @Override
  231. public void onLoad() {
  232. super.onLoad();
  233. lazyItemHandler = LazyOptional.of(() -> itemHandler);
  234. ModMessages.sendToClients(new PacketSyncTeleporterPosToClient(
  235. dest0dim,
  236. dest1dim,
  237. dest2dim,
  238. dest3dim,
  239. dest4dim,
  240. dest5dim,
  241. dest6dim,
  242. dest7dim,
  243. dest0exists,
  244. dest1exists,
  245. dest2exists,
  246. dest3exists,
  247. dest4exists,
  248. dest5exists,
  249. dest6exists,
  250. dest7exists,
  251. dest0name,
  252. dest1name,
  253. dest2name,
  254. dest3name,
  255. dest4name,
  256. dest5name,
  257. dest6name,
  258. dest7name,
  259. selectedWheelPart,
  260. dest0Posx,dest0Posy,dest0Posz,
  261. dest1Posx,dest1Posy,dest1Posz,
  262. dest2Posx,dest2Posy,dest2Posz,
  263. dest3Posx,dest3Posy,dest3Posz,
  264. dest4Posx,dest4Posy,dest4Posz,
  265. dest5Posx,dest5Posy,dest5Posz,
  266. dest6Posx,dest6Posy,dest6Posz,
  267. dest7Posx,dest7Posy,dest7Posz,
  268. dimName,worldPosition));
  269. }
  270.  
  271. @Override
  272. public void invalidateCaps() {
  273. super.invalidateCaps();
  274. lazyItemHandler.invalidate();
  275. }
  276.  
  277. @Override
  278. protected void saveAdditional(@NotNull CompoundTag tag) {
  279. super.saveAdditional(tag);
  280. tag.put("inventory", itemHandler.serializeNBT());
  281. tag.putInt("selected", selectedWheelPart);
  282.  
  283. tag.putString("dest0name", dest0name);
  284. tag.putString("dest1name", dest1name);
  285. tag.putString("dest2name", dest2name);
  286. tag.putString("dest3name", dest3name);
  287. tag.putString("dest4name", dest4name);
  288. tag.putString("dest5name", dest5name);
  289. tag.putString("dest6name", dest6name);
  290. tag.putString("dest7name", dest7name);
  291.  
  292. tag.putString("dest0dim", dest0dim);
  293. tag.putString("dest1dim", dest1dim);
  294. tag.putString("dest2dim", dest2dim);
  295. tag.putString("dest3dim", dest3dim);
  296. tag.putString("dest4dim", dest4dim);
  297. tag.putString("dest5dim", dest5dim);
  298. tag.putString("dest6dim", dest6dim);
  299. tag.putString("dest7dim", dest7dim);
  300.  
  301. tag.putBoolean("dest0exists", dest0exists);
  302. tag.putBoolean("dest1exists", dest1exists);
  303. tag.putBoolean("dest2exists", dest2exists);
  304. tag.putBoolean("dest3exists", dest3exists);
  305. tag.putBoolean("dest4exists", dest4exists);
  306. tag.putBoolean("dest5exists", dest5exists);
  307. tag.putBoolean("dest6exists", dest6exists);
  308. tag.putBoolean("dest7exists", dest7exists);
  309.  
  310. tag.putBoolean("worksThroughDimensions", worksThroughDimensions);
  311.  
  312. tag.putInt("dest0posx", dest0Posx);tag.putInt("dest0posy", dest0Posy);tag.putInt("dest0posz", dest0Posz);
  313. tag.putInt("dest1posx", dest1Posx);tag.putInt("dest1posy", dest1Posy);tag.putInt("dest1posz", dest1Posz);
  314. tag.putInt("dest2posx", dest2Posx);tag.putInt("dest2posy", dest2Posy);tag.putInt("dest2posz", dest2Posz);
  315. tag.putInt("dest3posx", dest3Posx);tag.putInt("dest3posy", dest3Posy);tag.putInt("dest3posz", dest3Posz);
  316. tag.putInt("dest4posx", dest4Posx);tag.putInt("dest4posy", dest4Posy);tag.putInt("dest4posz", dest4Posz);
  317. tag.putInt("dest5posx", dest5Posx);tag.putInt("dest5posy", dest5Posy);tag.putInt("dest5posz", dest5Posz);
  318. tag.putInt("dest6posx", dest6Posx);tag.putInt("dest6posy", dest6Posy);tag.putInt("dest6posz", dest6Posz);
  319. tag.putInt("dest7posx", dest7Posx);tag.putInt("dest7posy", dest7Posy);tag.putInt("dest7posz", dest7Posz);
  320. }
  321. @Override
  322. public void load(CompoundTag tag) {
  323. super.load(tag);
  324. itemHandler.deserializeNBT(tag.getCompound("inventory"));
  325. dimName = tag.getString("dim");
  326. worksThroughDimensions = tag.getBoolean("worksThroughDimensions");
  327. selectedWheelPart = tag.getInt("selected");
  328.  
  329. dest0name = tag.getString("dest0name");
  330. dest1name = tag.getString("dest1name");
  331. dest2name = tag.getString("dest2name");
  332. dest3name = tag.getString("dest3name");
  333. dest4name = tag.getString("dest4name");
  334. dest5name = tag.getString("dest5name");
  335. dest6name = tag.getString("dest6name");
  336. dest7name = tag.getString("dest7name");
  337.  
  338. dest0dim = tag.getString("dest0dim");
  339. dest1dim = tag.getString("dest1dim");
  340. dest2dim = tag.getString("dest2dim");
  341. dest3dim = tag.getString("dest3dim");
  342. dest4dim = tag.getString("dest4dim");
  343. dest5dim = tag.getString("dest5dim");
  344. dest6dim = tag.getString("dest6dim");
  345. dest7dim = tag.getString("dest7dim");
  346.  
  347. dest0exists = tag.getBoolean("dest0exists");
  348. dest1exists = tag.getBoolean("dest1exists");
  349. dest2exists = tag.getBoolean("dest2exists");
  350. dest3exists = tag.getBoolean("dest3exists");
  351. dest4exists = tag.getBoolean("dest4exists");
  352. dest5exists = tag.getBoolean("dest5exists");
  353. dest6exists = tag.getBoolean("dest6exists");
  354. dest7exists = tag.getBoolean("dest7exists");
  355.  
  356. dest0Posx=tag.getInt("dest0posx");dest0Posy = tag.getInt("dest0posy");dest0Posz = tag.getInt("dest0posz");
  357. dest1Posx=tag.getInt("dest1posx");dest1Posy = tag.getInt("dest1posy");dest1Posz = tag.getInt("dest1posz");
  358. dest2Posx=tag.getInt("dest2posx");dest2Posy = tag.getInt("dest2posy");dest2Posz = tag.getInt("dest2posz");
  359. dest3Posx=tag.getInt("dest3posx");dest3Posy = tag.getInt("dest3posy");dest3Posz = tag.getInt("dest3posz");
  360. dest4Posx=tag.getInt("dest4posx");dest4Posy = tag.getInt("dest4posy");dest4Posz = tag.getInt("dest4posz");
  361. dest5Posx=tag.getInt("dest5posx");dest5Posy = tag.getInt("dest5posy");dest5Posz = tag.getInt("dest5posz");
  362. dest7Posx=tag.getInt("dest6posx");dest6Posy = tag.getInt("dest6posy");dest6Posz = tag.getInt("dest6posz");
  363. dest7Posx=tag.getInt("dest7posx");dest7Posy = tag.getInt("dest7posy");dest7Posz = tag.getInt("dest7posz");
  364. }
  365.  
  366. public void drops() {
  367. SimpleContainer inventory = new SimpleContainer(itemHandler.getSlots());
  368. for (int i = 0; i < itemHandler.getSlots(); i++) {
  369. inventory.setItem(i, itemHandler.getStackInSlot(i));
  370. }
  371. Containers.dropContents(this.level, this.worldPosition, inventory);
  372. }
  373.  
  374. public void setItemToSlot(int slot, ItemStack stack) {
  375. stack.setCount(1);
  376. this.itemHandler.setStackInSlot(slot, stack);
  377. }
  378. public ItemStack getItemFromSlot(int slot) { return this.itemHandler.getStackInSlot(slot); }
  379. public boolean hasItemInSlot(ItemStack item, int slot) {
  380. return this.itemHandler.getStackInSlot(slot).sameItem(item);
  381. }
  382.  
  383. public static void tick(Level level, BlockPos pPos, BlockState pState, WarpPipeBlockEntity blockEntity) {
  384. if(!level.isClientSide) {
  385. ChunkPos chunkPos = new ChunkPos(pPos);
  386. ResourceKey<Level> currentDimension = level.dimension();
  387. ServerLevel serverLevel = (ServerLevel)level.getServer().getLevel(currentDimension);
  388. ForgeChunkManager.forceChunk(serverLevel, Constants.MOD_ID, pPos, chunkPos.x,chunkPos.z,true,true);
  389. }
  390.  
  391. try {
  392. ItemStack stack = blockEntity.itemHandler.getStackInSlot(0);
  393. CompoundTag tag = stack.getTag();
  394.  
  395. if(selectedWheelPart == 0 || selectedWheelPart == 1 ||selectedWheelPart == 2 || selectedWheelPart == 3 ||selectedWheelPart == 4 || selectedWheelPart == 5 ||selectedWheelPart == 6 || selectedWheelPart == 7) {
  396. level.getEntitiesOfClass(Player.class, new AABB(pPos.getX(), pPos.getY(), pPos.getZ(), pPos.getX() + 1, pPos.getY() + 1, pPos.getZ() + 1)).forEach(entity -> {
  397. if(!(entity instanceof Player)) return;
  398. if(!entity.isShiftKeyDown() || !entity.isCrouching()) return;
  399. if(blockEntity != null && blockEntity instanceof WarpPipeBlockEntity) {
  400.  
  401. entity.playSound(SoundEvents.ENDERMAN_TELEPORT, 1, 1);
  402. if(!level.isClientSide) {
  403. //String dim = TotisPlayerUtils.getDimension(stack);
  404. /*ResourceKey<Level> currentDim = level.dimension();
  405. ServerLevel serverWorld = ((ServerLevel)level).getServer().getLevel(currentDim);*/
  406. ServerPlayer player = (ServerPlayer)entity;
  407.  
  408. if(selectedWheelPart == 0) {
  409. ResourceKey<Level> storedKey = ResourceKey.create(Registry.DIMENSION_REGISTRY, new ResourceLocation(dest0dim));
  410. ServerLevel storedWorld = ((ServerLevel)level).getServer().getLevel(storedKey);
  411. player.teleportTo(storedWorld, dest0Posx+0.5,dest0Posy+1,dest0Posz+0.5, player.getRespawnAngle(), player.getRespawnAngle());
  412. } else if(selectedWheelPart == 1) {
  413. ResourceKey<Level> storedKey = ResourceKey.create(Registry.DIMENSION_REGISTRY, new ResourceLocation(dest1dim));
  414. ServerLevel storedWorld = ((ServerLevel)level).getServer().getLevel(storedKey);
  415. player.teleportTo(storedWorld, dest1Posx+0.5,dest1Posy+1,dest1Posz+0.5, player.getRespawnAngle(), player.getRespawnAngle());
  416. }else if(selectedWheelPart == 2) {
  417. ResourceKey<Level> storedKey = ResourceKey.create(Registry.DIMENSION_REGISTRY, new ResourceLocation(dest2dim));
  418. ServerLevel storedWorld = ((ServerLevel)level).getServer().getLevel(storedKey);
  419. player.teleportTo(storedWorld, dest2Posx+0.5,dest2Posy+1,dest2Posz+0.5, player.getRespawnAngle(), player.getRespawnAngle());
  420. }else if(selectedWheelPart == 3) {
  421. ResourceKey<Level> storedKey = ResourceKey.create(Registry.DIMENSION_REGISTRY, new ResourceLocation(dest3dim));
  422. ServerLevel storedWorld = ((ServerLevel)level).getServer().getLevel(storedKey);
  423. player.teleportTo(storedWorld, dest3Posx+0.5,dest3Posy+1,dest3Posz+0.5, player.getRespawnAngle(), player.getRespawnAngle());
  424. }else if(selectedWheelPart == 4) {
  425. ResourceKey<Level> storedKey = ResourceKey.create(Registry.DIMENSION_REGISTRY, new ResourceLocation(dest4dim));
  426. ServerLevel storedWorld = ((ServerLevel)level).getServer().getLevel(storedKey);
  427. player.teleportTo(storedWorld, dest4Posx+0.5,dest4Posy+1,dest4Posz+0.5, player.getRespawnAngle(), player.getRespawnAngle());
  428. }else if(selectedWheelPart == 5) {
  429. ResourceKey<Level> storedKey = ResourceKey.create(Registry.DIMENSION_REGISTRY, new ResourceLocation(dest5dim));
  430. ServerLevel storedWorld = ((ServerLevel)level).getServer().getLevel(storedKey);
  431. player.teleportTo(storedWorld, dest5Posx+0.5,dest5Posy+1,dest5Posz+0.5, player.getRespawnAngle(), player.getRespawnAngle());
  432. }else if(selectedWheelPart == 6) {
  433. ResourceKey<Level> storedKey = ResourceKey.create(Registry.DIMENSION_REGISTRY, new ResourceLocation(dest6dim));
  434. ServerLevel storedWorld = ((ServerLevel)level).getServer().getLevel(storedKey);
  435. player.teleportTo(storedWorld, dest6Posx+0.5,dest6Posy+1,dest6Posz+0.5, player.getRespawnAngle(), player.getRespawnAngle());
  436. }else if(selectedWheelPart == 7) {
  437. ResourceKey<Level> storedKey = ResourceKey.create(Registry.DIMENSION_REGISTRY, new ResourceLocation(dest7dim));
  438. ServerLevel storedWorld = ((ServerLevel)level).getServer().getLevel(storedKey);
  439. player.teleportTo(storedWorld, dest7Posx+0.5,dest7Posy+1,dest7Posz+0.5, player.getRespawnAngle(), player.getRespawnAngle());
  440. } else {
  441. player.sendMessage(new TextComponent("No destination selected"), player.getUUID());
  442. }
  443. }
  444. for(int i = 0; i < 3; i++) entity.playSound(SoundEvents.ENDERMAN_TELEPORT, 1, 1);
  445. }
  446. });
  447. }
  448. } catch(Exception e) {}
  449. }
  450.  
  451.  
  452. /*Synchronization to the client*/
  453. @Nullable
  454. @Override
  455. public Packet<ClientGamePacketListener> getUpdatePacket() {
  456. return ClientboundBlockEntityDataPacket.create(this);
  457. }
  458. @Override
  459. public CompoundTag getUpdateTag() {
  460. CompoundTag tag = saveWithoutMetadata();
  461. load(tag);
  462. return tag;
  463. }
  464. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement