Jump to content

auriny

Members
  • Posts

    53
  • Joined

  • Last visited

Recent Profile Visitors

The recent visitors block is disabled and is not being shown to other users.

auriny's Achievements

Stone Miner

Stone Miner (3/8)

0

Reputation

  1. thanks, that worked, but how can i increase count of particles? with this code only one particle appears...
  2. heya everyone! i'm trying to make block that changes by clicking rmb on this, and it works, but there're no particles. how to fix this? @SuppressWarnings("deprecation") @Override public ActionResultType onBlockActivated(BlockState state, World worldIn, BlockPos pos, PlayerEntity player, Hand hand, BlockRayTraceResult hit) { if (player.getHeldItem(hand).getItem() == CoSRPGItems.DevilCompound.get()) { if (!worldIn.isRemote()) { BlockPos blockPos = new BlockPos(pos.getX(), pos.getY(), pos.getZ()); if (!player.isCreative()) player.getHeldItem(hand).shrink(1); worldIn.playSound(null, player.getPosX(), player.getPosY(), player.getPosZ(), SoundEvents.BLOCK_STONE_PLACE, SoundCategory.BLOCKS, 1, 1); worldIn.addParticle(new BlockParticleData(ParticleTypes.BLOCK, CoSRPGBlocks.CORUNDITE_ORE.get().getDefaultState()).setPos(pos), //this code not working pos.getX(), pos.getY(), pos.getZ(), //this code not working 0.0D, 0.0D, 0.0D); //this code not working worldIn.setBlockState(blockPos, CoSRPGBlocks.CORUNDITE_ORE.get().getDefaultState()); } return ActionResultType.SUCCESS; } return ActionResultType.PASS; }
  3. the problem is that im russian, and most likely it sounds different in my language, so i don't understand what you are talking about. sorry i will try google now, ofc
  4. sorry, but i'm still don't understand how to get player that owning my capability
  5. and how to send this packet only for players that owning that cap?
  6. but all of the players owning this capability
  7. i can't, i just don’t understand where to put it
  8. mmh how to use it? sorry im so stupid
  9. npe public class PacketEtherBar { private int delay; private float ether; private float max; public PacketEtherBar(ByteBuf buf) { max = buf.readFloat(); ether = buf.readFloat(); delay = buf.readInt(); } public void toBytes(ByteBuf buf) { buf.writeFloat(max); buf.writeFloat(ether); buf.writeInt(delay); } public PacketEtherBar(Ether ether) { if (ether == null) return; delay = ether.getRegenDelay(); this.ether = ether.getEther(); max = ether.getMaxEther(); } public void handle(Supplier<NetworkEvent.Context> ctx) { ctx.get().enqueueWork(() -> { Ether ether = Objects.requireNonNull(ctx.get().getSender()).getCapability(EtherCapability.CAPABILITY_ETHER, null).orElse(Ether.createADefaultInstance()); ether.setMaxEther(max); ether.setRegenDelay(delay); ether.set(this.ether); }); ctx.get().setPacketHandled(true); } @SubscribeEvent public void onPlayerRespawn(PlayerEvent.PlayerRespawnEvent event) { Ether ether = event.getPlayer().getCapability(EtherCapability.CAPABILITY_ETHER, null).orElse(Ether.createADefaultInstance()); ether.fill(event.getPlayer(), ether.getEther()); } @SubscribeEvent public void onChangeDimension(PlayerEvent.PlayerChangedDimensionEvent event) { Ether ether = event.getPlayer().getCapability(EtherCapability.CAPABILITY_ETHER, null).orElse(Ether.createADefaultInstance()); ether.fill(event.getPlayer(), ether.getMaxEther()-ether.getEther()); } @SubscribeEvent public void onLoggedIn(PlayerEvent.PlayerLoggedInEvent event) { Ether ether = event.getPlayer().getCapability(EtherCapability.CAPABILITY_ETHER, null).orElse(Ether.createADefaultInstance()); ether.fill(event.getPlayer(), ether.getEther()); } }
  10. like this? NetworkingRegistry.INSTANCE.send(PacketDistributor.ALL.noArg(), new PacketEtherBar(this));
  11. ok thx this code is located in PacketEther class, that registries in NetworkRegistry class private static int packetId = 0; public static SimpleChannel INSTANCE = NetworkRegistry.newSimpleChannel(new ResourceLocation(CoSRPG.MOD_ID, "main"), () -> "1.0", s -> true, s -> true); private static int nextID() { return packetId++; } public static void init() { INSTANCE.registerMessage(nextID(), PacketEtherBar.class, PacketEtherBar::toBytes, PacketEtherBar::new, PacketEtherBar::handle); } public class Ether { private int tickDelay = 4; private float max = 100; private float ether; public Ether() { this(200); } public Ether(float chargeLevel) { ether = chargeLevel; } public float getEther() { return ether; } public void consume(PlayerEntity player, float points) { set(getEther() - points); sendPacket(player); } public void fill(PlayerEntity player, float points) { float a = getEther(); set(a + points); if (a != getEther()) sendPacket(player); } public void regen(PlayerEntity player) { if (player.world.getGameTime() % tickDelay == 0) fill(player, 1); } public void set(float points) { ether = MathHelper.clamp(points, 0, getMaxEther()); } public float getMaxEther() { return max; } public void setMaxEther(float max) { this.max = max; } public int getRegenDelay() { return tickDelay; } public void setRegenDelay(int delay) { tickDelay = delay; } private void sendPacket(PlayerEntity player) { if (!(player instanceof FakePlayer) && player instanceof ServerPlayerEntity) NetworkingRegistry.INSTANCE.sendToServer(new PacketEtherBar(this)); } public static class EtherStorage implements Capability.IStorage<Ether> { // implementation of Capability @Override public INBT writeNBT(Capability<Ether> capability, Ether instance, Direction side) { return FloatNBT.valueOf(instance.ether); } @Override public void readNBT(Capability<Ether> capability, Ether instance, Direction side, INBT nbt) { float ether = 0; if (nbt.getType() == FloatNBT.TYPE) { ether = ((FloatNBT) nbt).getFloat(); } instance.set(ether); } } public static Ether createADefaultInstance() { return new Ether(); } }
×
×
  • Create New...

Important Information

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