Advertisement
SforzandoCF

mods

Sep 24th, 2024 (edited)
36
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 16.85 KB | None | 0 0
  1. package com.sforzando.worldsteel.common.init;
  2.  
  3. public class WorldsteelItems {
  4.     public static final Item GLOWING_BOTTLE = register("glowing_bottle", new Item(new Item.Settings().maxCount(1).food(new FoodComponent.Builder().nutrition(2).saturationModifier(0F).statusEffect(new StatusEffectInstance(StatusEffects.GLOWING), 0.7F).alwaysEdible().snack().build())));
  5.     public static final Item DISTILLED_SOULS = register("distilled_souls", new Item(new Item.Settings().maxCount(1).food(new FoodComponent.Builder().nutrition(2).saturationModifier(0F).statusEffect(new StatusEffectInstance(StatusEffects.WITHER), 0.7F).alwaysEdible().snack().build())));
  6.     public static final Item SOUL_STEEL_SCRAPS = register("soul_steel_scraps", new Item(new Item.Settings().maxCount(16)));
  7.     public static final Item SOUL_STEEL_INGOT = register("soul_steel_ingot", new Item(new Item.Settings().rarity(Rarity.UNCOMMON)));
  8.     public static final Item SOUL_STEEL_SWORD = register("soul_steel_sword", new SwordItem(WorldsteelToolTiers.SOUL_STEEL, new Item.Settings().rarity(Rarity.UNCOMMON)));
  9.     public static final Item SOUL_STEEL_SHOVEL = register("soul_steel_shovel", new ShovelItem(WorldsteelToolTiers.SOUL_STEEL, new Item.Settings().rarity(Rarity.UNCOMMON)));
  10.     public static final Item SOUL_STEEL_PICKAXE = register("soul_steel_pickaxe", new PickaxeItem(WorldsteelToolTiers.SOUL_STEEL, new Item.Settings().rarity(Rarity.UNCOMMON)));
  11.     public static final Item SOUL_STEEL_AXE = register("soul_steel_axe", new AxeItem(WorldsteelToolTiers.SOUL_STEEL, new Item.Settings().rarity(Rarity.UNCOMMON)));
  12.     public static final Item SOUL_STEEL_HOE = register("soul_steel_hoe", new HoeItem(WorldsteelToolTiers.SOUL_STEEL, new Item.Settings().rarity(Rarity.UNCOMMON)));
  13.     public static final Item SOUL_STEEL_HELMET = register("soul_steel_helmet", new ArmorItem(RegistryEntry.<ArmorMaterial>of(WorldsteelArmorMaterials.SOUL_STEEL), ArmorItem.Type.HELMET, new Item.Settings().rarity(Rarity.UNCOMMON)));
  14.     public static final Item SOUL_STEEL_CHESTPLATE = register("soul_steel_chestplate", new ArmorItem(RegistryEntry.<ArmorMaterial>of(WorldsteelArmorMaterials.SOUL_STEEL), ArmorItem.Type.CHESTPLATE, new Item.Settings().rarity(Rarity.UNCOMMON)));
  15.     public static final Item SOUL_STEEL_LEGGINGS = register("soul_steel_leggings", new ArmorItem(RegistryEntry.<ArmorMaterial>of(WorldsteelArmorMaterials.SOUL_STEEL), ArmorItem.Type.LEGGINGS, new Item.Settings().rarity(Rarity.UNCOMMON)));
  16.     public static final Item SOUL_STEEL_BOOTS = register("soul_steel_boots", new ArmorItem(RegistryEntry.<ArmorMaterial>of(WorldsteelArmorMaterials.SOUL_STEEL), ArmorItem.Type.BOOTS, new Item.Settings().rarity(Rarity.UNCOMMON)));
  17.     public static final Item SOUL_STEEL_BLOCK = register("soul_steel_block", new BlockItem(WorldsteelBlocks.SOUL_STEEL_BLOCK, new Item.Settings().rarity(Rarity.UNCOMMON)));
  18.     public static final Item SOUL_STEEL_GRATE = register("soul_steel_grate", new BlockItem(WorldsteelBlocks.SOUL_STEEL_GRATE, new Item.Settings().rarity(Rarity.UNCOMMON)));
  19.     public static final Item SOUL_TRAP = register("soul_trap", new BlockItem(WorldsteelBlocks.SOUL_TRAP, new Item.Settings().rarity(Rarity.UNCOMMON)));
  20.    
  21.     public static final Item PEARL_CRYSTAL = register("pearl_crystal", new Item(new Item.Settings()));
  22.     public static final Item PEARL_CRYSTAL_ORE = register("pearl_crystal_ore", new BlockItem(WorldsteelBlocks.PEARL_CRYSTAL_ORE, new Item.Settings()));
  23.     public static final Item PEARL_CRYSTAL_BLOCK = register("pearl_crystal_block", new BlockItem(WorldsteelBlocks.PEARL_CRYSTAL_BLOCK, new Item.Settings()));
  24.     public static final Item GROUND_AMETHYST = register("ground_amethyst", new Item(new Item.Settings()));
  25.     public static final Item WORLDSTEEL_CORE = register("worldsteel_core", new Item(new Item.Settings()));
  26.     public static final Item WORLDSTEEL_SCRAPS = register("worldsteel_scraps", new Item(new Item.Settings().maxCount(16)));
  27.     public static final Item WORLDSTEEL_INGOT = register("worldsteel_ingot", new Item(new Item.Settings().rarity(Rarity.RARE)));
  28.     public static final Item WORLDSTEEL_SWORD = register("worldsteel_sword", new SwordItem(WorldsteelToolTiers.WORLDSTEEL, new Item.Settings().rarity(Rarity.RARE)));
  29.     public static final Item WORLDSTEEL_SHOVEL = register("worldsteel_shovel", new ShovelItem(WorldsteelToolTiers.WORLDSTEEL, new Item.Settings().rarity(Rarity.RARE)));
  30.     public static final Item WORLDSTEEL_PICKAXE = register("worldsteel_pickaxe", new PickaxeItem(WorldsteelToolTiers.WORLDSTEEL, new Item.Settings().rarity(Rarity.RARE)));
  31.     public static final Item WORLDSTEEL_AXE = register("worldsteel_axe", new AxeItem(WorldsteelToolTiers.WORLDSTEEL, new Item.Settings().rarity(Rarity.RARE)));
  32.     public static final Item WORLDSTEEL_HOE = register("worldsteel_hoe", new HoeItem(WorldsteelToolTiers.WORLDSTEEL, new Item.Settings().rarity(Rarity.RARE)));
  33.     public static final Item WORLDSTEEL_HELMET = register("worldsteel_helmet", new ArmorItem(RegistryEntry.<ArmorMaterial>of(WorldsteelArmorMaterials.WORLDSTEEL), ArmorItem.Type.HELMET, new Item.Settings().rarity(Rarity.RARE)));
  34.     public static final Item WORLDSTEEL_CHESTPLATE = register("worldsteel_chestplate", new ArmorItem(RegistryEntry.<ArmorMaterial>of(WorldsteelArmorMaterials.WORLDSTEEL), ArmorItem.Type.CHESTPLATE, new Item.Settings().rarity(Rarity.RARE)));
  35.     public static final Item WORLDSTEEL_LEGGINGS = register("worldsteel_leggings", new ArmorItem(RegistryEntry.<ArmorMaterial>of(WorldsteelArmorMaterials.WORLDSTEEL), ArmorItem.Type.LEGGINGS, new Item.Settings().rarity(Rarity.RARE)));
  36.     public static final Item WORLDSTEEL_BOOTS = register("worldsteel_boots", new ArmorItem(RegistryEntry.<ArmorMaterial>of(WorldsteelArmorMaterials.WORLDSTEEL), ArmorItem.Type.BOOTS, new Item.Settings().rarity(Rarity.RARE)));
  37.     public static final Item WORLDSTEEL_BLOCK = register("worldsteel_block", new BlockItem(WorldsteelBlocks.WORLDSTEEL_BLOCK, new Item.Settings().rarity(Rarity.RARE)));
  38.     public static final Item WORLDSTEEL_RIFT = register("worldsteel_rift", new WorldsteelRiftItem(new Item.Settings().maxCount(1).rarity(Rarity.EPIC)));
  39.    
  40.     public static final Item SWEET_STARDUST = register("sweet_stardust", new Item(new Item.Settings().food(new FoodComponent.Builder().nutrition(3).saturationModifier(0.5F).snack().build())));
  41.     public static final Item SWEET_STARDUST_PIE = register("sweet_stardust_pie", new Item(new Item.Settings().food(new FoodComponent.Builder().nutrition(9).saturationModifier(0.8F).build())));
  42.     public static final Item SWEET_STARDUST_CAKE = register("sweet_stardust_cake", new BlockItem(WorldsteelBlocks.SWEET_STARDUST_CAKE, new Item.Settings()));
  43.     public static final Item SWEET_STARFIRE = register("sweet_starfire", new Item(new Item.Settings().food(new FoodComponent.Builder().nutrition(3).saturationModifier(0.5F).snack().build())));
  44.     public static final Item SWEET_STARFIRE_PIE = register("sweet_starfire_pie", new Item(new Item.Settings().food(new FoodComponent.Builder().nutrition(9).saturationModifier(0.8F).build())));
  45.     public static final Item SWEET_STARFIRE_CAKE = register("sweet_starfire_cake", new BlockItem(WorldsteelBlocks.SWEET_STARDUST_CAKE, new Item.Settings()));
  46.    
  47.     private static Item register (String path, Item i) {
  48.         Registry.register(Registries.ITEM, i, Identifier.of("worldsteel", path));
  49.     }
  50. }
  51.  
  52. package com.sforzando.worldsteel.common.item;
  53.  
  54. public class WorldsteelRiftItem extends Item {
  55.     public WorldsteelRiftItem (Item.Settings settings) {
  56.         super (settings);
  57.     }
  58.    
  59.     public void onItemEntityDestroyed (ItemEntity item) {
  60.         item.getWorld().playSound(item, item.getBlockPos(), SoundEvents.ITEM_TOTEM_USE, SoundCategory.BLOCKS, 1F, 1F);
  61.         item.getWorld().playSound(item, item.getBlockPos(), SoundEvents.ENTITY_WITHER_SPAWN, SoundCategory.BLOCKS, 1F, 1F);
  62.         for (Entity e : item.getWorld().getEntities(item.getOwner(), new Box(item.getBlockPos()).expand(25, 25, 25), (te) -> {
  63.             return te instanceof MobEntity && ((MobEntity)te).getTarget() == item.getOwner();
  64.         }))
  65.              e.kill();
  66.     }
  67.    
  68.     public TypedActionResult<ItemStack> use (World world, PlayerEntity player, Hand hand) {
  69.         if (world.isClientSide()) MinecraftClient.getInstance().gameRenderer.showFloatingItem(player.getStackInHand(hand));
  70.         world.playSound(player, player.getBlockPos(), SoundEvents.ITEM_TOTEM_USE, SoundCategory.PLAYERS, 1F, 1F);
  71.         world.playSound(player, player.getBlockPos(), SoundEvents.ENTITY_WITHER_SPAWN, SoundCategory.PLAYERS, 1F, 1F);
  72.         for (Entity e : world.getEntities(player, new Box(player.getBlockPos()).expand(25, 25, 25), (te) -> {
  73.             return te instanceof MobEntity && ((MobEntity)te).getTarget() == player;
  74.         }))
  75.              e.kill();
  76.         player.setStackInHand(player.getStackInHand(hand).shrink(1), hand);
  77.         return new TypedActionResult(InteractionResult.sidedSuccess(true), player.getStackInHand(hand));
  78.     }
  79.    
  80.     public boolean hasGlint (ItemStack s) {
  81.         return true;
  82.     }
  83. }
  84.  
  85. package com.sforzando.worldsteel.common.init;
  86.  
  87. public class WorldsteelBlocks {
  88.     public static final Block SOUL_STEEL_BLOCK = register("soul_steel_block", new Block(AbstractBlock.Settings.of().mapColor(DyeColor.GRAY).sound(SoundType.METAL).strength(6F, 40F).requiresTool()));
  89.     public static final Block SOUL_STEEL_GRATE = register("soul_steel_grate", new PaneBlock(AbstractBlock.Settings.of().mapColor(MapColor.CLEAR).sound(BlockSoundGroup.METAL).strength(4F, 10F).dynamicBounds().requiresTool()));
  90.     public static final Block SOUL_TRAP = register("soul_trap", new SoulTrapBlock(AbstractBlock.Settings.of().mapColor(MapColor.GRAY).sound(BlockSoundGroup.METAL).strength(4F, 10F).dynamicBounds().requiresTool().luminance((getOrFalse(s, FILLED) && getOrFalse(s, ACTIVE)) ? 4 : 0)));
  91.     public static final Block PEARL_CRYSTAL_ORE = register("pearl_crystal_ore", new Block(AbstractBlock.Settings.of().mapColor(MapColor.PALE_YELLOW).sound(BlockSoundGroup.STONE).strength(4.5F, 9F).dynamicBounds().requiresTool()));
  92.     public static final Block PEARL_CRYSTAL_BLOCK = register("pearl_crystal_block", new PearlCrystalBlock(AbstractBlock.Settings.of().mapColor(MapColor.DARK_AQUA).sound(BlockSoundGroup.AMETHYST).strength(4.5F, 9F).dynamicBounds().requiresTool()));
  93.     public static final Block WORLDSTEEL_BLOCK = register("worldsteel_block", new Block(AbstractBlock.Settings.of().mapColor(DyeColor.DARK_AQUA).sound(SoundType.NETHERITE).strength(14F, 1300F).requiresTool()));
  94.     public static final Block SWEET_STARDUST_CAKE = register("sweet_stardust_cake", new CandlelessCakeBlock(AbstractBlock.copy(Blocks.CAKE)));
  95.     public static final Block SWEET_STARFIRE_CAKE = register("sweet_starfire_cake", new CandlelessCakeBlock(AbstractBlock.copy(Blocks.CAKE)));
  96.    
  97.     private static Block register (String path, Item i) {
  98.         Registry.register(Registries.BLOCK, i, Identifier.of("worldsteel", path));
  99.     }
  100. }
  101.  
  102. package com.sforzando.worldsteel.common.block;
  103.  
  104. public class SoulTrapBlock extends BlockWithEntity {
  105.     public static final BooleanProperty FILLED = Properties.OCCUPIED;
  106.     public static final BooleanProperty ACTIVE = Properties.ENABLED;
  107.    
  108.     public SoulTrapBlock (AbstractBlock.Settings settings) {
  109.         super(settings);
  110.         this.appendProperties(new StateManager.Builder<Block, BlockState>(this).add(FILLED, ACTIVE));
  111.     }
  112.    
  113.     protected MapCodec<SoulTrapBlock> getCodec () {
  114.         return simpleCodec(SoulTrapBlock:new);
  115.     }
  116.    
  117.     public BlockEntity newBlockEntity (BlockPos pos, BlockState state) {
  118.         return new SoulTrapBlockEntity(pos, state);
  119.     }
  120.    
  121.     public <T extends SoulTrapBlock> BlockEntityTicker<T> getTicker (World world, BlockState state, BlockEntityType<T> type) {
  122.         return (w, p, s, e) -> { entity.tick(); };
  123.     }
  124.    
  125.     public boolean canPlaceAt (BlockState state, WorldView view, BlockPos pos) {
  126.         return super.canPlaceAt(state, view, pos) && survives(view, pos);
  127.     }
  128.    
  129.     public void randomTick (BlockState state, ServerWorld world, BlockPos pos, Random random) {
  130.         super.randomTick(state, world, pos, random);
  131.         if (!survives(state, world, pos))
  132.             world.breakBlock(pos, false);
  133.     }
  134.    
  135.     protected void neighborUpdate (BlockState state, World world, BlockPos pos, Block sourceBlock, BlockPos sourcePos, boolean notify)
  136.     {
  137.         super.neighborUpdate(state, world, pos, sourceBlock, sourcePos, notify);
  138.         if (!survives(world, pos)) world.breakBlock(pos, false);
  139.    
  140.     protected InteractionResult onUse (BlockState state, World world, BlockPos pos, PlayerEntity player, BlockHitResult hit) {
  141.         if (!getOrFalse(state, FILLED)) return InteractionResult.PASS;
  142.         player.giveItemStack(new ItemStack(getOrFalse(state, COMPLETE) ? WorldsteelItems.DISTILLED_SOULS : WorldsteelItems.GLOWING_BOTTLE));
  143.         world.setBlockState(pos, state.with(SoulTrapBlock.FILLED, Boolean.valueOf(false)));
  144.         if (world.getBlockEntity(pos) instanceof SoulTrapBlockEntity stbe && world.isClientSide())
  145.             stbe.clientStop();
  146.     }
  147.    
  148.     protected ItemInteractionResult onUseWithItem (ItemStack stack, BlockState state, World world, BlockPos pos, PlayerEntity player, Hand hand, BlockHitResult hit) {
  149.         if (stack.isEmpty() || stack.getItem() != WorldsteelItems.GLOWING_BOTTLE || !getOrFalse(state, FILLED)) return ItemInteractionResult.PASS_TO_DEFAULT_BLOCK_INTERACTION;
  150.         player.setItemInHand(stack.shrink(1), hand);
  151.         world.setBlockState(pos, state.with(SoulTrapBlock.FILLED, Boolean.valueOf(true)));
  152.         if (world.getBlockEntity(pos) instanceof SoulTrapBlockEntity stbe && world.isClientSide())
  153.             stbe.clientStart();
  154.     }
  155.    
  156.     public void survives (WorldView world, BlockPos pos) {
  157.         return world.getBlockState(pos.down()).isIn(BlockTags.SOUL_SPEED_BLOCKS);
  158.     }
  159. }
  160.  
  161. public class SoulTrapBlockEntity {
  162.     private SoulTrapClientData client;
  163.     private int progress;
  164.    
  165.     public SoulTrapBlockEntity (BlockPos pos, BlockState state) {
  166.         super (WorldsteelBlockEntities.SOUL_TRAP, pos, state);
  167.         this.client = new SoulTrapClientData(SoulTrapBlock.getOrFalse(state, SoulTrapBlock.FILLED), SoulTrapBlock.getOrFalse(SoulTrapBlock.ACTIVE) ? WorldsteelItems.GLOWING_BOTTLE : WorldsteelItems.DISTILLED_SOULS);
  168.     }
  169.    
  170.     public void tick () {
  171.         if (!this.hasLevel()) return;
  172.         if (this.getLevel().isClientSide()) this.client.tick();
  173.         if (SoulTrapBlock.getOrFalse(this.getBlockState(), SoulTrapBlock.ACTIVE))
  174.             this.progress++;
  175.         if (this.progress >= 24000) {
  176.             this.getLevel().setBlockState(SoulTrapBlock.trySet(this.getBlockState(), SoulTrapBlock.ACTIVE, false));
  177.             if (this.getLevel().isClientSide()) this.client.setItem(WorldsteelItems.GLOWING_BOTTLE);
  178.         }
  179.     }
  180.    
  181.     public void clientStart () {
  182.         if (this.hasLevel() && this.getLevel().isClientSide()) this.client.setRenderable(true);
  183.     }
  184.    
  185.     public void clientStop () {
  186.         if (this.hasLevel() && this.getLevel().isClientSide()) this.client.setRenderable(false);
  187.     }
  188. }
  189.  
  190. package com.sforzando.worldsteel.client;
  191.  
  192. public class SoulTrapClientData {
  193.     private Item item;
  194.     private boolean renderable;
  195.    
  196.     private int rotation = 0;
  197.     private int oRotation = 0;
  198.    
  199.     public SoulTrapClientData (Item i, boolean b) {
  200.         this.item = i;
  201.         this.renderable = b;
  202.     }
  203.    
  204.     public void tick () {
  205.         this.oRotation = rotation;
  206.         this.rotation += 10;
  207.     }
  208.    
  209.     public void setRenderable (boolean b) {
  210.         this.renderable = b;
  211.     }
  212.    
  213.     public boolean isRenderable () {
  214.         return this.renderable;
  215.     }
  216.    
  217.     public void setItem (Item i) {
  218.         this.item = i;
  219.     }
  220.    
  221.     public Item getItem () {
  222.         return this.item;
  223.     }
  224.    
  225.     public int getRotation () {
  226.         return this.rotation;
  227.     }
  228.    
  229.     public int getORotation () {
  230.         return this.oRotation;
  231.     }
  232. }
  233.  
  234. public class SoulTrapRenderer implements BlockEntityRenderer<SoulTrapBlockEntity> {
  235.     private BlockEntityRendererFactory.Context context;
  236.    
  237.     public SoulTrapRenderer (BlockEntityRendererFactory.Context ctx) {
  238.         this.context = ctx;
  239.     }
  240.    
  241.     public void render (SoulTrapBlockEntity entity, float tickDelta, MatrixStack matrices, VertexConsumerProvider vertexConsumers, int light, int overlay) {
  242.         if (!entity.getClientData().isRenderable()) return;
  243.         matrices.push();
  244.         matrices.translate(0.5F, 0.4F, 0.5F);
  245.         matrices.multiply(RotationAxis.POSITIVE_Y.rotationDegrees(MathHelper.lerpAngleDegrees(tickDelta, context.getRotation(), context.getORotation())));
  246.         this.context.getItemRenderer().renderItem(new ItemStack(entity.getClientData().getItem()), ModelTransformationMode.GROUND, light, overlay, matrices, vertexConsumers, entity.getWorld(), 0);
  247.         matrices.pop();
  248.     }
  249. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement