Jump to content

[NoOneButNo]

Members
  • Posts

    89
  • Joined

  • Last visited

  • Days Won

    1

Posts posted by [NoOneButNo]

  1. Subscribe to PlayerTickEvent (or LivingUpdateEvent if you want to include entities aside from player) and check there if your enchantment is present using EnchantmentHelper#getEnchantmentLevel. There you can use LivingEntity#addPotionEffect to apply the speed potion.

  2. 1.) Subscribing to an event requires only one parameter. Two or more won't work.

    2.) PlayerTickEvent or LivingUpdateEvent is your best option. You need to track the travelled blocks of the player and then do the random chance.

    (On the side note: I don't like using speed status effect, I'd rather use an attribute modifier to achieve the same thing. This makes it stackable to other movement speed giving items/abilities/whatever)

    3.) Check if you properly registered the events. Sometimes this is the usual problem after a long hour session of coding.

    4.) Profit.

  3. Here's an example of how you override things:

     

    @ObjectHolder("minecraft:quick_charge")
    public static final Enchantment QUICK_CHARGE = null;
    
    
    @SubscribeEvent 
    public void onRegistry(RegistryEvent.Register<Enchantment> reg){
    
      //note: The class that you are using should be the one you made for the Enchantment Quickcharge. Enchantment class is an abstract class.
      reg.getRegistry().register(new Enchantment().setRegistryName(new ResourceLocation("minecraft", "quick_charge")));
    }

     

    Same thing applies for entity types, etc.

  4. public class RotatedPillarBlock extends Block {
       public static final EnumProperty<Direction.Axis> AXIS = BlockStateProperties.AXIS;
    
       public RotatedPillarBlock(Block.Properties properties) {
          super(properties);
          this.setDefaultState(this.getDefaultState().with(AXIS, Direction.Axis.Y));
       }
    
       /**
        * Returns the blockstate with the given rotation from the passed blockstate. If inapplicable, returns the passed
        * blockstate.
        * @deprecated call via {@link IBlockState#withRotation(Rotation)} whenever possible. Implementing/overriding is
        * fine.
        */
       public BlockState rotate(BlockState state, Rotation rot) {
          switch(rot) {
          case COUNTERCLOCKWISE_90:
          case CLOCKWISE_90:
             switch((Direction.Axis)state.get(AXIS)) {
             case X:
                return state.with(AXIS, Direction.Axis.Z);
             case Z:
                return state.with(AXIS, Direction.Axis.X);
             default:
                return state;
             }
          default:
             return state;
          }
       }
    
       protected void fillStateContainer(StateContainer.Builder<Block, BlockState> builder) {
          builder.add(AXIS);
       }
    
       public BlockState getStateForPlacement(BlockItemUseContext context) {
          return this.getDefaultState().with(AXIS, context.getFace().getAxis());
       }
    }

     

    This is an example of  a vanilla block that implements it. Take your time and read it meanwhile Im gonna go get some sleep.

×
×
  • Create New...

Important Information

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