Jump to content
Search In
  • More options...
Find results that contain...
Find results in...

ImNotJahan

Members
  • Posts

    68
  • Joined

  • Last visited

Posts posted by ImNotJahan

  1. I'm implementing the IChestLid interface, and doing everything basically the same as in the vanilla chest and in the iron chests mod, yet still whenever it gets the openness value in the tile entity renderer it's always 0. 

    This is where I get the openness value:

    Spoiler
    float f1 = iCallbackWrapper.apply(TabulatedChest.getLid(tileEntity)).get(partialTicks);

     

    And everywhere I set the value of the lid angle

    Spoiler
    @Override
        public void tick()
        {
            int i = this.worldPosition.getX();
            int j = this.worldPosition.getY();
            int k = this.worldPosition.getZ();
            ++this.ticksSinceSync;
            this.numPlayersUsing = getNumberOfPlayersUsing(this.level, this, this.ticksSinceSync, i, j, k, this.numPlayersUsing);
            this.prevLidAngle = this.lidAngle;
            float f = 0.1F;
    
            if (this.numPlayersUsing > 0 && this.lidAngle == 0.0F)
            {
                this.playSound(SoundEvents.CHEST_OPEN);
            }
    
            if (this.numPlayersUsing == 0 && this.lidAngle > 0.0F || this.numPlayersUsing > 0 && this.lidAngle < 1.0F)
            {
                float f1 = this.lidAngle;
                if (this.numPlayersUsing > 0)
                {
                    this.lidAngle += 0.1F;
                }
                else
                {
                    this.lidAngle -= 0.1F;
                }
    
                if (this.lidAngle > 1.0F)
                {
                    this.lidAngle = 1.0F;
                }
    
                float f2 = 0.5F;
                if (this.lidAngle < 0.5F && f1 >= 0.5F)
                {
                    this.playSound(SoundEvents.CHEST_CLOSE);
                }
    
                if (this.lidAngle < 0.0F)
                {
                    this.lidAngle = 0.0F;
                }
            }
        }

     

    And lastly where I get the value:

    Spoiler
    @Override
      public float getOpenNess(float time)
    {
      return MathHelper.lerp(time, prevLidAngle, lidAngle);
    }
    @OnlyIn(Dist.CLIENT)
        public static TileEntityMerger.ICallback<TabulatedTile, Float2FloatFunction> getLid(final IChestLid lid)
        {
            return new TileEntityMerger.ICallback<TabulatedTile, Float2FloatFunction>()
            {
                @Override
                public Float2FloatFunction acceptDouble(TabulatedTile firstTile, TabulatedTile secondTile)
                {
                    return (p_226921_2_) -> Math.max(firstTile.getOpenNess(p_226921_2_), secondTile.getOpenNess(p_226921_2_));
                }
    
                @Override
                public Float2FloatFunction acceptSingle(TabulatedTile p_225538_1_)
                {
                    return p_225538_1_::getOpenNess;
                }
    
                @Override
                public Float2FloatFunction acceptNone()
                {
                    return lid::getOpenNess;
                }
            };
        }

     

    Any help's appreciated

  2. FMLClientSetupEvent is only called once, and is only called on the client (you'll want to give potion effects on the server), so the event you should use is TickEvent.PlayerTickEvent, then event.player.getHealth() to get the health, and lastly to add a potion effect you can also call .addEffect on the player instance provided by the event

  3. Like what the title says I need the slots in a container to all be removed so I can then add in new ones. I have a method for whenever they should change, and it just runs

    slots.clear();
    
    switch(menuIndex)
            {
                case 0:
                    setupSwordInv(playerInventory);
                    break;
        ... and more of this for a few more lines

    The setupSwordInv functions and others just place the slots, and I know that each function is being ran when it's meant to but all the slots seem to be in the exact same position from what they're set at during the start. I'm guessing there's something I have to do with syncing the container and screen after changing them, but I'm not sure what so any help is appreciated. 

  4. 2 hours ago, diesieben07 said:

    What a strange choice of exception to throw here.

    Some of the code was made at a time I didn't know how to make exceptions so back then I just used ArithmeticExceptions for capabilities. I do got an exception for that now tho so I should probably change it so thanks for pointing that out.

     

    I did fix it and the solution was a large mix of things so I'm not exactly sure what fixed it, but I know a few of the things I needed to do were this:

    1. private static final LazyOptional<IStatus> lazyStatus = LazyOptional.of(Status::new);
        This line in my capability provider was static which was what was causing it to transfer over worlds, making it not static however made it stop saving.
    2. To fix that I had to change the parameters in both my readNBT and writeNBT calls from
      STATUS_CAP, this.instance, Status.capSide, nbt
      to 
      STATUS_CAP, this.lazyStatus.orElseThrow(MissingStatus::new), Status.capSide, nbt

      because instance was a variable I for some reason created, which was never used other than in these functions, that was the default value of the capability

    3. After that I just had to fix up networking a bunch to get everything completely working, and the only problem there is I had no way to discern the packets being sent at the time, but yea fixing that got them all working correctly

  5. I have a capability which gets attached to the player, and yea it stays the same even when you go to another world

    Here are all the events todo with refreshing the capability

    Spoiler
    @SubscribeEvent
        public static void playerLoggedIn(PlayerEvent.PlayerLoggedInEvent event)
        {
            ServerPlayerEntity player = (ServerPlayerEntity) event.getPlayer();
            PacketHandler.INSTANCE.send(PacketDistributor.PLAYER.with(() -> player), new MessageStatus(
                    player.getCapability(StatusProvider.STATUS_CAP, Status.capSide).orElseThrow(ArithmeticException::new)));
        }
    
        @SubscribeEvent
        public static void playerDeath(LivingDeathEvent event)
        {
            if(!event.getEntity().getCommandSenderWorld().isClientSide)
            {
                if (event.getEntity() instanceof PlayerEntity)
                {
                    ServerPlayerEntity player = (ServerPlayerEntity) event.getEntity();
                    PacketHandler.INSTANCE.send(PacketDistributor.PLAYER.with(() -> player), new MessageStatus(
                            player.getCapability(StatusProvider.STATUS_CAP, Status.capSide).orElseThrow(ArithmeticException::new)));
                }
            }
        }

    Here are the packets

    Spoiler
    public class MessageStatus
    {
        public IStatus status;
    
        public static void handle(MessageStatus msg, Supplier<NetworkEvent.Context> ctx)
        {
            ctx.get().enqueueWork(() ->
                    DistExecutor.unsafeRunWhenOn(Dist.CLIENT, () -> () -> ClientPacketHandler.handleStatus(msg, ctx)));
            ctx.get().setPacketHandled(true);
        }
    
        public static MessageStatus decode(PacketBuffer buf)
        {
            IStatus status = new Status();
    
            status.setFamilia(buf.readUtf());
            status.setArray(buf.readVarIntArray());
    
            return new MessageStatus(status);
        }
    
        public static void encode(MessageStatus message, PacketBuffer buf)
        {
            buf.writeUtf(message.status.getFamilia());
            buf.writeVarIntArray(message.status.getArray());
        }
    
        public MessageStatus(IStatus status)
        {
            this.status = status;
        }
    
        public MessageStatus()
        {
            status = new Status();
        }
    }

     

    Spoiler
    public class MessageClientStatus
    {
        public IStatus status;
    
        public static void handle(MessageClientStatus msg, Supplier<NetworkEvent.Context> ctx)
        {
            ctx.get().enqueueWork(() ->
            {
                ServerPlayerEntity sender = ctx.get().getSender();
    
                if(sender == null) return;
    
                IStatus status = sender.getCapability(StatusProvider.STATUS_CAP, Status.capSide)
                        .orElseThrow(ArithmeticException::new);
    
                if(status.getLevel() != msg.status.getLevel()) sender.awardStat(Stats.LEVEL);
    
                status.setArray(msg.status.getArray());
            });
            ctx.get().setPacketHandled(true);
        }
    
        public static MessageClientStatus decode(PacketBuffer buf)
        {
            IStatus status = new Status();
    
            status.setFamilia(buf.readUtf());
            status.setArray(buf.readVarIntArray());
    
            return new MessageClientStatus(status);
        }
    
        public static void encode(MessageClientStatus message, PacketBuffer buf)
        {
            buf.writeUtf(message.status.getFamilia());
            buf.writeVarIntArray(message.status.getArray());
        }
    
        public MessageClientStatus(IStatus status)
        {
            this.status = status;
        }
    
        public MessageClientStatus()
        {
            status = new Status();
        }
    }

     

    And here's the rest of the source code https://github.com/ImNotJahan/danmachi-mod/tree/master/v1.16.5/src/main/java/imnotjahan/mod/danmachi

  6. It'd be a lot easier to test out my mods by using the help of other ones, but whenever I add a mod to the run/mods folder I get a ton of ClassNotFoundException(s). Same thing also used to happen back when I did 1.12.2 modding, so I'm guessing either you just can't with the forge mdk, or that I've got something wrong in my build.gradle/run configurations. 

  7. Actually yea that's a good point, I'll just call super instead, but also I've figured out why it wasn't working

    By looking at SweetBerryBush I figured out that you have to replace the block to change the block state, so I just changed my previous state.setValue to world.setBlock(pos, state.setValue(POWER, Math.min(state.getValue(POWER) + 1, 100)), 2); and it all works now.

  8. I have a custom TNT block which is meant to increase its power by 1 whenever given gunpowder, and I tried to make it put its power in a property instead of just a variable so I'd save, but nothing seems to change despite everything else working correctly. I know the explosion size changes correctly as it worked previously before using properties, and the only thing I've really done since it stopped working was add properties.

    Block class:

    Spoiler
    public class DynamicTnt extends TNTBlock
    {
        public static final IntegerProperty POWER = imnotjahan.mod.dynamictnt.init.Properties.POWER;
    
        public DynamicTnt()
        {
            super(AbstractBlock.Properties.of(Material.EXPLOSIVE));
        }
        
        @Override
        public ActionResultType use(BlockState state, World world, BlockPos pos, PlayerEntity player,
                                    Hand hand, BlockRayTraceResult ray)
        {
            ItemStack itemstack = player.getItemInHand(hand);
            Item item = itemstack.getItem();
            if (item != Items.FLINT_AND_STEEL && item != Items.FIRE_CHARGE) 
            {
                if(item == Items.GUNPOWDER)
                {
                    itemstack.shrink(1);
    
                    int powerP1 = state.getValue(POWER) + 1; // P1 = Plus one
                    state.setValue(POWER, Integer.valueOf(Math.min(powerP1, 100)));
    
                    return ActionResultType.SUCCESS;
                } else return super.use(state, world, pos, player, hand, ray);
            } else // From here it's all minecraft code
            {
                catchFire(state, world, pos, ray.getDirection(), player);
                world.setBlock(pos, Blocks.AIR.defaultBlockState(), 11);
                if (!player.isCreative()) 
                {
                    if (item == Items.FLINT_AND_STEEL) 
                    {
                        itemstack.hurtAndBreak(1, player, (p_220287_1_) -> {
                            p_220287_1_.broadcastBreakEvent(hand);
                        });
                    } else 
                    {
                        itemstack.shrink(1);
                    }
                }
    
                return ActionResultType.sidedSuccess(world.isClientSide);
            }
        }
    
        @Override
        public void catchFire(BlockState state, World world, BlockPos pos, @Nullable net.minecraft.util.Direction face,
                              @Nullable LivingEntity igniter)
        {
            explode(world, pos, igniter, state.getValue(POWER));
        }
    
        private void explode(World world, BlockPos pos, @Nullable LivingEntity entity, int power)
        {
            if (!world.isClientSide)
            {
                DynamicTNTEntity tntEntity = new DynamicTNTEntity(world,
                        (double)pos.getX() + 0.5D, pos.getY(), (double)pos.getZ() + 0.5D, entity, power);
                world.addFreshEntity(tntEntity);
                world.playSound(null, tntEntity.getX(), tntEntity.getY(), tntEntity.getZ(), SoundEvents.TNT_PRIMED,
                        SoundCategory.BLOCKS, 1.0F, 1.0F);
            }
        }
    
        @Override
        protected void createBlockStateDefinition(StateContainer.Builder<Block, BlockState> stateBuilder)
        {
            super.createBlockStateDefinition(stateBuilder);
            stateBuilder.add(POWER);
        }
    }

     

     

    TNT entity class

    Spoiler
    public class DynamicTNTEntity extends TNTEntity
    {
        LivingEntity owner;
        int size = 4;
    
        public DynamicTNTEntity(EntityType<? extends TNTEntity> type, World world)
        {
            super(type, world);
        }
    
        public DynamicTNTEntity(World world, double xo, double yo, double zo, @Nullable LivingEntity owner, int size)
        {
            this(EntityType.TNT, world);
            this.setPos(xo, yo, zo);
            double d0 = world.random.nextDouble() * (double)((float)Math.PI * 2F);
            this.setDeltaMovement(-Math.sin(d0) * 0.02D, (double)0.2F, -Math.cos(d0) * 0.02D);
            this.setFuse(80);
            this.xo = xo;
            this.yo = yo;
            this.zo = zo;
            this.size = size;
            this.owner = owner;
        }
    
        @Override
        protected void explode()
        {
            this.level.explode(this, this.getX(), this.getY(0.0625D), this.getZ(),
                    size, Explosion.Mode.BREAK);
        }
    
        @Nullable
        @Override
        public LivingEntity getOwner()
        {
            return this.owner;
        }
    }

     

     

    Properties class:

    Spoiler
    public class Properties
    {
        public static final IntegerProperty POWER = IntegerProperty.create("tnt_power", 4, 100);
    }

     

     

  9. I've got capabilities and I was just wondering if there's a way to add a statistic with the value of that capability to the stat menu, so I can make my mod more useable with FTB quests and other similar mods which can take in a statistic to trigger an event

×
×
  • Create New...

Important Information

By using this site, you agree to our Privacy Policy.