Jump to content
View in the app

A better way to browse. Learn more.

Forge Forums

A full-screen app on your home screen with push notifications, badges and more.

To install this app on iOS and iPadOS
  1. Tap the Share icon in Safari
  2. Scroll the menu and tap Add to Home Screen.
  3. Tap Add in the top-right corner.
To install this app on Android
  1. Tap the 3-dot menu (⋮) in the top-right corner of the browser.
  2. Tap Add to Home screen or Install app.
  3. Confirm by tapping Install.

egod

Members
  • Joined

  • Last visited

Everything posted by egod

  1. Solved this problem, but it's not so friendly. public class ModWorldGen { private static final CountRangeConfig copper_cfg = new CountRangeConfig(20,0,0,255); private static final int copper_veinsize = 9; public static void setupOre(){ ForgeRegistries.BIOMES.getValues().stream() .filter(biome -> biome.getCategory() != Biome.Category.THEEND) .filter(biome -> biome.getCategory() != Biome.Category.NETHER) .forEach(biome -> { biome.addFeature( GenerationStage.Decoration.UNDERGROUND_DECORATION, Feature.ORE.func_225566_b_( new OreFeatureConfig( OreFeatureConfig.FillerBlockType.NATURAL_STONE, BlockHolder.lingkiore.getDefaultState(), copper_veinsize ) ) .func_227228_a_(Placement.COUNT_RANGE.func_227446_a_(copper_cfg)) ); }); } } these func_225566_b_ func_227228_a_ func_227446_a_ are somehow difficult to understand (at least for recent days)
  2. I have a custom OreBlock public class OreLingKi extends OreBlock { public OreLingKi() { super(Properties.create(Material.ROCK) .lightValue(1).harvestLevel(1).hardnessAndResistance(3.0f, 100.0f)); setRegistryName(Main.MODID,"lingkiore"); } } I want to how to generate it so that I can see in world? I used to do this by implements IWorldGenerator but in 1.15.1 that not work. Thanks for help?
  3. It works! Thank you! I modify PlayerEntity player = Minecraft.getInstance().player; to ClientPlayerEntity player = Minecraft.getInstance().player; and everything done!
  4. tanks for your reply, actually this works well when "Single Player" mode, but when I try to start a server and a client, the server would crash. here is my packet handle void handle(Supplier<NetworkEvent.Context> context) { NetworkEvent.Context ctx = context.get(); ctx.enqueueWork(() -> { if (ctx.getDirection().getReceptionSide().isClient() && ctx.getDirection().getOriginationSide().isServer()) { PlayerEntity player = Minecraft.getInstance().player; player.getCapability(XiuXianStateProvider.XiuXianStateCap, null) .ifPresent(state -> { Capability.IStorage<IXiuXianState> storage = XiuXianStateProvider.XiuXianStateCap.getStorage(); storage.readNBT(XiuXianStateProvider.XiuXianStateCap, state, null, data); }); } }); ctx.setPacketHandled(true); } and here is how I register it ublic class NetworkLoader { private static int id=1; private final static ResourceLocation res = new ResourceLocation(Main.MODID); public static final SimpleChannel channel = NetworkRegistry.ChannelBuilder.named(res) .clientAcceptedVersions(s-> Objects.equals(s,"1")) .serverAcceptedVersions(s -> Objects.equals(s,"1")) .networkProtocolVersion(()->"1") .simpleChannel(); public static void registerMessages(){ channel.messageBuilder(XiuXianStateSyncMessage.class,id++) .decoder(XiuXianStateSyncMessage::new) .encoder(XiuXianStateSyncMessage::encode) .consumer(XiuXianStateSyncMessage::handle) .add(); } } and the server crash-report net.minecraftforge.fml.LoadingFailedException: Loading errors encountered: [ LingKi World (lingkiworld) encountered an error during the common_setup event phase §7Attempted to load class net/minecraft/client/entity/player/ClientPlayerEntity for invalid dist DEDICATED_SERVER ] at net.minecraftforge.fml.ModLoader.dispatchAndHandleError(ModLoader.java:201) ~[?:?] {re:classloading} at net.minecraftforge.fml.ModLoader.loadMods(ModLoader.java:154) ~[?:?] {re:classloading} at net.minecraftforge.fml.server.ServerModLoader.begin(ServerModLoader.java:46) ~[?:?] {re:classloading} at net.minecraft.server.dedicated.DedicatedServer.init(DedicatedServer.java:124) ~[?:?] {re:classloading,pl:accesstransformer:B} at net.minecraft.server.MinecraftServer.run(MinecraftServer.java:634) [?:?] {re:classloading,pl:accesstransformer:B,pl:runtimedistcleaner:A} at java.lang.Thread.run(Thread.java:748) [?:1.8.0_221] {}
  5. do you mean that when I want to sync data, I can post a Event above rather than a Packet?
  6. and here is how I try to sync @SubscribeEvent public void onPlayerTracking(PlayerEvent.StartTracking event){ if(!(event.getTarget() instanceof PlayerEntity)) return; PlayerEntity player = (PlayerEntity) event.getTarget(); ServerPlayerEntity target = (ServerPlayerEntity) event.getPlayer(); if (!player.world.isRemote()) { player.getCapability(CapabilityLoader.XiuXianState, null) .ifPresent(state -> { CompoundNBT nbt = new CompoundNBT(); Capability<IXiuXianState> cap = XiuXianStateProvider.XiuXianStateCap; Capability.IStorage<IXiuXianState> storage = cap.getStorage(); nbt.put(cap.getName(), storage.writeNBT(cap, state, null)); XiuXianStateSyncMessage message = new XiuXianStateSyncMessage(nbt); NetworkLoader.channel.send(PacketDistributor.PLAYER.with(() ->target ), message); }); } }
  7. I have create a new capability for PlayerEntity and I want to know how can I sync the data from server to client ? my Interface IXiuXianState.java package egod.mc.lingkiworld.capabilities; public interface IXiuXianState { public Realm getRealm(); public void setRealm(Realm newRealm); public float getXiuWei(); public void setXiuWei(float newValue); public void addXiuWei(float delta); public float getMagic(); public void setMagic(float value); public void healMagic(); public void costMagic(float value); public float getMaxMagic(); public void setMaxMagic(float value); public void copyForRespawn(IXiuXianState deadPlayer); } implementation of the interface XiuXianStateClass.java package egod.mc.lingkiworld.capabilities; import net.minecraft.entity.player.PlayerEntity; public class XiuXianStateClass implements IXiuXianState { private Realm realm; private float xiuWei; private float magic; private float maxMagic; public XiuXianStateClass(){ realm = Realm.FANREN; xiuWei = 0f; magic = 0f; maxMagic = 0f; } @Override public Realm getRealm() { return realm; } @Override public void setRealm(Realm newRealm) { this.realm = newRealm; } @Override public float getXiuWei() { return xiuWei; } @Override public void setXiuWei(float newValue) { this.xiuWei = newValue; } @Override public void addXiuWei(float delta) { this.xiuWei += delta; this.magic += delta; this.maxMagic += delta; } @Override public float getMagic() { return magic; } @Override public void setMagic(float value) { this.magic = value; } @Override public void healMagic() { magic += maxMagic/20f; } @Override public void costMagic(float value) { magic -= value; } @Override public float getMaxMagic() { return maxMagic; } @Override public void setMaxMagic(float value) { this.maxMagic = value; } public static IXiuXianState getFromPlayer(PlayerEntity player){ return player .getCapability(XiuXianStateProvider.XiuXianStateCap,null) .orElseThrow(()->new IllegalArgumentException("LazyOptional must be not empty!")); } @Override public void copyForRespawn(IXiuXianState deadPlayer){ this.setRealm(deadPlayer.getRealm()); this.setXiuWei(deadPlayer.getXiuWei()); this.setMagic(deadPlayer.getMaxMagic()); this.setMaxMagic(deadPlayer.getMaxMagic()); } } Storage for that XiuXianStateProvider.java package egod.mc.lingkiworld.capabilities; import net.minecraft.nbt.CompoundNBT; import net.minecraft.nbt.INBT; import net.minecraft.util.Direction; import net.minecraftforge.common.capabilities.Capability; import javax.annotation.Nullable; public class XiuXianStateStorage implements Capability.IStorage<IXiuXianState> { @Nullable @Override public INBT writeNBT(Capability<IXiuXianState> capability, IXiuXianState instance, Direction side) { CompoundNBT tag =new CompoundNBT(); tag.putString("realm", instance.getRealm().name); tag.putFloat("xiuWei", instance.getXiuWei()); tag.putFloat("magic", instance.getMagic()); tag.putFloat("maxMagic", instance.getMaxMagic()); return tag; } @Override public void readNBT(Capability<IXiuXianState> capability, IXiuXianState instance, Direction side, INBT nbt) { CompoundNBT tag = (CompoundNBT)nbt; instance.setRealm(Realm.fromName(tag.getString("realm"))); instance.setXiuWei(tag.getFloat("xiuWei")); instance.setMagic(tag.getFloat("magic")); instance.setMaxMagic(tag.getFloat("maxMagic")); } } Provider for that XiuXianStateProvider.java package egod.mc.lingkiworld.capabilities; import net.minecraft.nbt.CompoundNBT; import net.minecraft.util.Direction; import net.minecraftforge.common.capabilities.Capability; import net.minecraftforge.common.capabilities.CapabilityInject; import net.minecraftforge.common.capabilities.ICapabilitySerializable; import net.minecraftforge.common.util.LazyOptional; import javax.annotation.Nonnull; import javax.annotation.Nullable; public class XiuXianStateProvider implements ICapabilitySerializable<CompoundNBT> { @CapabilityInject(IXiuXianState.class) public static final Capability<IXiuXianState> XiuXianStateCap=null; private LazyOptional<IXiuXianState> instance = LazyOptional.of(XiuXianStateClass::new); @Nonnull @Override public <T> LazyOptional<T> getCapability(@Nonnull Capability<T> cap, @Nullable Direction side) { if(cap != XiuXianStateCap){ return LazyOptional.empty(); } return this.instance.cast(); } @Override public CompoundNBT serializeNBT() { return (CompoundNBT)XiuXianStateCap.getStorage() .writeNBT(XiuXianStateCap, instance .orElseThrow(()->new IllegalArgumentException("LazyOptional must not be empty!")), null); } @Override public void deserializeNBT(CompoundNBT nbt) { XiuXianStateCap.getStorage() .readNBT(XiuXianStateCap, instance .orElseThrow(()->new IllegalArgumentException("LazyOptional must not be empty!")), null, nbt); } } And here is my package XiuXianStateSyncMessage.java , but it does not work. package egod.mc.lingkiworld.network; import egod.mc.lingkiworld.capabilities.CapabilityLoader; import egod.mc.lingkiworld.capabilities.IXiuXianState; import net.minecraft.client.Minecraft; import net.minecraft.entity.player.PlayerEntity; import net.minecraft.nbt.CompoundNBT; import net.minecraft.network.PacketBuffer; import net.minecraftforge.common.capabilities.Capability; import net.minecraftforge.fml.network.NetworkEvent; import java.util.function.Supplier; public class XiuXianStateSyncMessage { private CompoundNBT data; XiuXianStateSyncMessage(PacketBuffer buf) { this.data = buf.readCompoundTag(); } public XiuXianStateSyncMessage(CompoundNBT nbt) { this.data = nbt; } void encode(PacketBuffer buf) { buf.writeCompoundTag(data); } void handle(Supplier<NetworkEvent.Context> context) { NetworkEvent.Context ctx = context.get(); ctx.enqueueWork(() -> { if (ctx.getDirection().getReceptionSide().isClient() && ctx.getDirection().getOriginationSide().isServer()) { PlayerEntity player = Minecraft.getInstance().player; player.getCapability(CapabilityLoader.XiuXianState, null) .ifPresent(state -> { Capability.IStorage<IXiuXianState> storage = CapabilityLoader.XiuXianState.getStorage(); storage.readNBT(CapabilityLoader.XiuXianState, state, null, data); }); } }); ctx.setPacketHandled(true); } } This is really long, but thanks if you can help me!

Important Information

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

Configure browser push notifications

Chrome (Android)
  1. Tap the lock icon next to the address bar.
  2. Tap Permissions → Notifications.
  3. Adjust your preference.
Chrome (Desktop)
  1. Click the padlock icon in the address bar.
  2. Select Site settings.
  3. Find Notifications and adjust your preference.