
auriny
Members-
Posts
53 -
Joined
-
Last visited
Everything posted by auriny
-
thanks, that worked, but how can i increase count of particles? with this code only one particle appears...
-
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; }
-
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
-
how....
-
sorry, but i'm still don't understand how to get player that owning my capability
-
oh
-
noArg?
-
and how to send this packet only for players that owning that cap?
-
but all of the players owning this capability
-
i can't, i just don’t understand where to put it
-
ok, im trying
-
mmh how to use it? sorry im so stupid
-
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()); } }
-
like this? NetworkingRegistry.INSTANCE.send(PacketDistributor.ALL.noArg(), new PacketEtherBar(this));
-
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(); } }
-
hah, and this value is out of sync with the test item when i use it. ether is regens, but if i try to use an item and if i completely deplete all the ether, it will still be equal to what i put + time for regen should i send all capability code?
-
if i change ether value with debugger it will regen, but bar doesn't change
-
well, this didn't work
-
like... this? i has that event before you said, it was used for ether regeneration @Mod.EventBusSubscriber(modid = CoSRPG.MOD_ID, bus = Mod.EventBusSubscriber.Bus.FORGE) public class TickEvent { public static int tick; @SubscribeEvent public void tickServer(TickEvent.ServerTickEvent evt) { if(evt.phase == TickEvent.Phase.END) { tick ++; if(tick > 100000) tick = 0; } } @SubscribeEvent public static void playerTick(TickEvent.PlayerTickEvent event){ if(event.phase == TickEvent.Phase.START){ Ether ether = event.player.getCapability(EtherCapability.CAPABILITY_ETHER, null).orElse(Ether.createADefaultInstance()); ether.regen(event.player); } } @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()); } }
-
oh, thanks, please wait
-
seems like no, i can show all caps code, but how to do it?
-
hmm no, ether is always equals 200, but this code working perfectly and if i make a certain number of right clicks, the whole ether will end and in both cases its returning 200 public ActionResult<ItemStack> onItemRightClick(World world, PlayerEntity player, Hand hand) { Ether ether = player.getCapability(EtherCapability.CAPABILITY_ETHER, null).orElse(Ether.createADefaultInstance()); ItemStack itemstack = player.getHeldItem(hand); if (!world.isRemote() && ether.getEther() >= 25) { // <- here is breakpoint world.playSound(null, player.getPosX(), player.getPosY(), player.getPosZ(), SoundEvents.BLOCK_LAVA_EXTINGUISH, SoundCategory.PLAYERS, 1, 1); ether.consume(player, 25); player.getCooldownTracker().setCooldown(this, 20); return ActionResult.resultFail(itemstack); } return ActionResult.resultSuccess(itemstack); } ether = {Ether@18499} tickDelay = 4 max = 200.0 ether = 200.0
-
the problematic part of the code in getPercentage, i think, but what's wrong in it - idk
-
i changed my code and blit started rendering two bars, and all of those bars was full (i have two sprites: full and empty, and sprites was full) and these bars still doesn't changed
-
yes yes, to make sure of this on 100%, i even changed the height of the second blit and i had two bars on the same level, not counting the height. that's right