Jump to content

[1.8.9] Conflicting positions for SP and MP


Tschipp

Recommended Posts

Hi

I'm trying to make a wand tool, similar to worldedit. I am saving the material of the wand into NBT but not pos1 and pos2, as I want the player to be able to use multiple wands that share positions, but not materials.

Now I just run into the problem that when using the wand on a server, all players share the same pos1 and pos2, causing major problems.

How do I make the positions individual for each player, but not for each wand? Should I edit the player's nbt? Here is the code that I have so far: (I know it's a mess, please bare with me ::))

package tschipp.creativePlus.items;

import java.util.List;

import tschipp.creativePlus.CreativePlus;
import net.minecraft.block.Block;
import net.minecraft.block.state.BlockState;
import net.minecraft.block.state.IBlockState;
import net.minecraft.client.Minecraft;
import net.minecraft.client.resources.Language;
import net.minecraft.creativetab.CreativeTabs;
import net.minecraft.entity.Entity;
import net.minecraft.entity.EntityLivingBase;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.init.Blocks;
import net.minecraft.item.Item;
import net.minecraft.item.ItemStack;
import net.minecraft.nbt.NBTTagCompound;
import net.minecraft.util.BlockPos;
import net.minecraft.util.ChatComponentText;
import net.minecraft.util.EnumFacing;
import net.minecraft.util.StatCollector;
import net.minecraft.util.Vec3;
import net.minecraft.world.World;
import net.minecraftforge.fml.relauncher.Side;
import net.minecraftforge.fml.relauncher.SideOnly;

public class Wand extends Item{


                public Vec3 pos1;
                public Vec3 pos2;
                public Vec3 difference;
                public Vec3 posToPlaceBlock;

                public IBlockState mat;

                public Wand() {
                               this.setMaxStackSize(1);
                               
                }

                @Override
                @SideOnly(Side.CLIENT)
                public void getSubItems(Item item, CreativeTabs tab, List<ItemStack> subItems)
                {
                               NBTTagCompound tag = new NBTTagCompound();
                               tag.setString("material", "minecraft:stone");
                               tag.setInteger("damage", 0);
                               ItemStack stack = new ItemStack(item, 1, 0);
                               stack.setTagCompound(tag);

                               subItems.add(stack);
                }

                public boolean onItemUse(ItemStack stack, EntityPlayer player, World worldIn, BlockPos pos, EnumFacing side, float hitX, float hitY, float hitZ)
                {

                               World world = player.worldObj;
                               if(pos.getX() < 0) {
                                               pos2 = new Vec3(pos.getX()-0.5, pos.getY(), pos.getZ());
                               }
                               if(pos.getX() > 0) {
                                               pos2 = new Vec3(pos.getX()+0.5, pos.getY(), pos.getZ());
                               }
                               if(pos.getZ() < 0) {
                                               pos2 = new Vec3(pos.getX(), pos.getY(), pos.getZ()-0.5);
                               }
                               if(pos.getX() > 0) {
                                               pos2 = new Vec3(pos.getX()-0.5, pos.getY(), pos.getZ()+0.5);
                               }
                               if(pos.getX() < 0 && pos.getZ() < 0) {
                                               pos2 = new Vec3(pos.getX()-0.5, pos.getY(), pos.getZ()-0.5);
                               }
                               if(pos.getX() > 0 && pos.getZ() > 0) {
                                               pos2 = new Vec3(pos.getX()+0.5, pos.getY(), pos.getZ()+0.5);
                               }
                               if(pos.getX() < 0 && pos.getZ() > 0) {
                                               pos2 = new Vec3(pos.getX()-0.5, pos.getY(), pos.getZ()+0.5);
                               }
                               if(pos.getX() > 0 && pos.getZ() < 0) {
                                               pos2 = new Vec3(pos.getX()+0.5, pos.getY(), pos.getZ()-0.5);
                               }
                               if(!world.isRemote) {
                                               player.addChatComponentMessage(new ChatComponentText("§dSet Pos2 at X: " + (int)pos2.xCoord + ", Y: " + (int)pos2.yCoord + ", Z: " + (int)pos2.zCoord));
                               }
                               world.markBlockForUpdate(pos);
                               return false;
                }


                public ItemStack onItemRightClick(ItemStack stack, World worldIn, EntityPlayer playerIn)
                {

                               if(pos1 != null && pos2 != null && playerIn.isSneaking()) {

                                               difference = pos1.subtractReverse(pos2).normalize();
                                               posToPlaceBlock = pos1;
                                               World world = Minecraft.getMinecraft().getIntegratedServer().getEntityWorld();
                                               if(compare()) {
                                                               pos1 = null;
                                                               if(!world.isRemote) {
                                                                               world.setBlockState(new BlockPos((int)pos1.xCoord, (int)pos1.yCoord, (int)pos1.zCoord), Block.getBlockFromName(stack.getTagCompound().getString("material")).getStateFromMeta(stack.getTagCompound().getInteger("damage")), 2);
                                                               }
                                                               pos2 = null;
                                               } else {
                                                               while (!compare())
                                                               {

                                                                               posToPlaceBlock = posToPlaceBlock.add(difference);
                                                                               if(!world.isRemote) {
                                                                                              world.setBlockState(new BlockPos((int)posToPlaceBlock.xCoord, (int)posToPlaceBlock.yCoord, (int)posToPlaceBlock.zCoord),  Block.getBlockFromName(stack.getTagCompound().getString("material")).getStateFromMeta(stack.getTagCompound().getInteger("damage")), 2);
                                                                               }

                                                               }
                                               }


                               }
                               return stack;
                }

                public boolean compare() {

                               if(Math.abs(pos1.xCoord) <= Math.abs(pos2.xCoord) && Math.abs(pos1.zCoord) <= Math.abs(pos2.zCoord)) {
                                               return Math.abs(posToPlaceBlock.xCoord) >= Math.abs(pos2.xCoord) && Math.abs(posToPlaceBlock.zCoord) >= Math.abs(pos2.zCoord);
                               }
                               else if(Math.abs(pos1.xCoord) >= Math.abs(pos2.xCoord) && Math.abs(pos1.zCoord) >= Math.abs(pos2.zCoord)) {
                                               return Math.abs(posToPlaceBlock.xCoord) <= Math.abs(pos2.xCoord) && Math.abs(posToPlaceBlock.zCoord) <= Math.abs(pos2.zCoord);
                               }
                               else if(Math.abs(pos1.xCoord) <= Math.abs(pos2.xCoord) && Math.abs(pos1.zCoord) >= Math.abs(pos2.zCoord)) {
                                               return Math.abs(posToPlaceBlock.xCoord) >= Math.abs(pos2.xCoord) && Math.abs(posToPlaceBlock.zCoord) <= Math.abs(pos2.zCoord);
                               }
                               else if(Math.abs(pos1.xCoord) >= Math.abs(pos2.xCoord) && Math.abs(pos1.zCoord) <= Math.abs(pos2.zCoord)) {
                                               return Math.abs(posToPlaceBlock.xCoord) <= Math.abs(pos2.xCoord) && Math.abs(posToPlaceBlock.zCoord) >= Math.abs(pos2.zCoord);
                               }
                               else {
                                               return true;
                               }
                }



                public boolean onBlockStartBreak(ItemStack itemstack, BlockPos pos, EntityPlayer player)
                {

                               World world = player.worldObj;

                               if(player.isSneaking()) {

                                               mat = world.getBlockState(pos);
                                               NBTTagCompound tag = new NBTTagCompound();
                                               tag.setString("material", mat.getBlock().getRegistryName());
                                               tag.setInteger("damage", mat.getBlock().getMetaFromState(mat));
                                               itemstack.setTagCompound(tag);
                                               if(!world.isRemote) {
                                                               player.addChatComponentMessage(new ChatComponentText("§dMaterial set to: " + StatCollector.translateToLocal(StatCollector.translateToLocal(Block.getBlockFromName(itemstack.getTagCompound().getString("material")).getLocalizedName()))));
                                               }
                                               world.markBlockForUpdate(pos);
                               }
                               else {
                                               if(pos.getX() < 0) {
                                                               pos1 = new Vec3(pos.getX()-0.5, pos.getY(), pos.getZ());
                                               }
                                               if(pos.getX() > 0) {
                                                               pos1 = new Vec3(pos.getX()+0.5, pos.getY(), pos.getZ());
                                               }
                                               if(pos.getZ() < 0) {
                                                               pos1 = new Vec3(pos.getX(), pos.getY(), pos.getZ()-0.5);
                                               }
                                               if(pos.getX() > 0) {
                                                               pos1 = new Vec3(pos.getX()-0.5, pos.getY(), pos.getZ()+0.5);
                                               }
                                               if(pos.getX() < 0 && pos.getZ() < 0) {
                                                               pos1 = new Vec3(pos.getX()-0.5, pos.getY(), pos.getZ()-0.5);
                                               }
                                               if(pos.getX() > 0 && pos.getZ() > 0) {
                                                               pos1 = new Vec3(pos.getX()+0.5, pos.getY(), pos.getZ()+0.5);
                                               }
                                               if(pos.getX() < 0 && pos.getZ() > 0) {
                                                               pos1 = new Vec3(pos.getX()-0.5, pos.getY(), pos.getZ()+0.5);
                                               }
                                               if(pos.getX() > 0 && pos.getZ() < 0) {
                                                               pos1 = new Vec3(pos.getX()+0.5, pos.getY(), pos.getZ()-0.5);
                                               }
                                               if(!world.isRemote) {
                                                               player.addChatComponentMessage(new ChatComponentText("§dSet Pos1 at X: " + (int)pos1.xCoord + ", Y: " + (int)pos1.yCoord + ", Z: " + (int)pos1.zCoord));
                                               }
                                               world.markBlockForUpdate(pos);

                               }

                               return true;
                }

                @Override
                @SideOnly(Side.CLIENT)
                public void addInformation(ItemStack stack, EntityPlayer playerIn, List<String> tooltip, boolean advanced)
                {
                               tooltip.add("Draws a straight line from two points");
                               tooltip.add("Material: "+ StatCollector.translateToLocal(Block.getBlockFromName(stack.getTagCompound().getString("material")).getLocalizedName()) + ", Meta: " + stack.getTagCompound().getInteger("damage"));

                }


}

Link to comment
Share on other sites

Sorry for not providing this in my last post.

http://mcforge.readthedocs.io/en/latest/datastorage/capabilities/

VANILLA MINECRAFT CLASSES ARE THE BEST RESOURCES WHEN MODDING

I will be posting 1.15.2 modding tutorials on this channel. If you want to be notified of it do the normal YouTube stuff like subscribing, ect.

Forge and vanilla BlockState generator.

Link to comment
Share on other sites

You can't use the

Minecraft

class in common code, it's client-only. You're already provided the

World

as an argument of your

Item#onItemRightClick

and

Item#onItemUse

overrides, use this instead of trying to get it from the integrated server.

 

Item

s are singletons, you can't store per-item data in fields of your

Item

class. You need to store this data in the

ItemStack

using metadata, NBT or capabilities as appropriate.

 

Always annotate override methods with

@Override

so you get a compilation error if they don't actually override a super method.

 

Why are you using

Vec3

s to store block positions? Just use

BlockPos

.

 

 

You can find the official documentation for the capability system here.

 

Forge itself has several capability examples, look at the usages of

CapabilityManager.register

in your IDE. There's also a test mod here.

 

I have some examples here: API, implementation

Please don't PM me to ask for help. Asking your question in a public thread preserves it for people who are having the same problem in the future.

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Unfortunately, your content contains terms that we do not allow. Please edit your content to remove the highlighted words below.
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Announcements



  • Recently Browsing

    • No registered users viewing this page.
  • Posts

    • For crash 1, set max-tick-time to -1 in your server.properties Crash 2 shows a conflict or incompatibility between LuckPerms and the mod boh-0.0.6.1-forge-1.20.1_2.jar
    • Add the crash-report or latest.log (logs-folder) with sites like https://mclo.gs/ and paste the link to it here  
    • so my minecraft crashes when opening my world, i played without any troubles for about 5 days and today it started tweaking.. pls help me
    • Hi guys! I am having some issues with the server crashing over and over and I was hoping to get some guidance.  Thanks in advance! Crash 1: java.lang.Error: ServerHangWatchdog detected that a single server tick took 60.00 seconds (should be max 0.05)     at net.minecraft.server.dedicated.ServerWatchdog.run(ServerWatchdog.java:43) ~[server-1.20.1-20230612.114412-srg.jar%23217!/:?] {re:classloading}     at java.lang.Thread.run(Thread.java:840) ~[?:?] { Crash 2: java.lang.IllegalStateException: Capability missing for eeb7f026-34b4-42f5-9164-e7736461df83     at me.lucko.luckperms.forge.capabilities.UserCapabilityImpl.lambda$get$0(UserCapabilityImpl.java:66) ~[?:?] {re:classloading,re:classloading,re:classloading}     at net.minecraftforge.common.util.LazyOptional.orElseThrow(LazyOptional.java:261) ~[forge-1.20.1-47.3.10-universal.jar%23222!/:?] {re:mixin,re:classloading}     at me.lucko.luckperms.forge.capabilities.UserCapabilityImpl.get(UserCapabilityImpl.java:66) ~[?:?] {re:classloading,re:classloading,re:classloading}     at me.lucko.luckperms.forge.util.BrigadierInjector$InjectedPermissionRequirement.test(BrigadierInjector.java:143) ~[?:?] {}     at me.lucko.luckperms.forge.util.BrigadierInjector$InjectedPermissionRequirement.test(BrigadierInjector.java:129) ~[?:?] {}     at com.mojang.brigadier.tree.CommandNode.canUse(CommandNode.java:65) ~[brigadier-1.1.8.jar%2376!/:?] {}     at com.mojang.brigadier.CommandDispatcher.parseNodes(CommandDispatcher.java:359) ~[brigadier-1.1.8.jar%2376!/:?] {}     at com.mojang.brigadier.CommandDispatcher.parse(CommandDispatcher.java:349) ~[brigadier-1.1.8.jar%2376!/:?] {}     at com.mojang.brigadier.CommandDispatcher.parse(CommandDispatcher.java:317) ~[brigadier-1.1.8.jar%2376!/:?] {}     at net.minecraft.commands.Commands.m_230957_(Commands.java:237) ~[server-1.20.1-20230612.114412-srg.jar%23217!/:?] {re:classloading}     at net.mcreator.boh.procedures.TeleportbenProcedure.lambda$execute$2(TeleportbenProcedure.java:65) ~[boh-0.0.6.1-forge-1.20.1_2.jar%23165!/:?] {re:classloading}     at net.mcreator.boh.BohMod.lambda$tick$2(BohMod.java:96) ~[boh-0.0.6.1-forge-1.20.1_2.jar%23165!/:?] {re:classloading}     at java.util.ArrayList.forEach(ArrayList.java:1511) ~[?:?] {re:mixin}     at net.mcreator.boh.BohMod.tick(BohMod.java:96) ~[boh-0.0.6.1-forge-1.20.1_2.jar%23165!/:?] {re:classloading}     at net.mcreator.boh.__BohMod_tick_ServerTickEvent.invoke(.dynamic) ~[boh-0.0.6.1-forge-1.20.1_2.jar%23165!/:?] {re:classloading,pl:eventbus:B}     at net.minecraftforge.eventbus.ASMEventHandler.invoke(ASMEventHandler.java:73) ~[eventbus-6.0.5.jar%2352!/:?] {}     at net.minecraftforge.eventbus.EventBus.post(EventBus.java:315) ~[eventbus-6.0.5.jar%2352!/:?] {}     at net.minecraftforge.eventbus.EventBus.post(EventBus.java:296) ~[eventbus-6.0.5.jar%2352!/:?] {}     at net.minecraftforge.event.ForgeEventFactory.onPostServerTick(ForgeEventFactory.java:950) ~[forge-1.20.1-47.3.10-universal.jar%23222!/:?] {re:classloading}     at net.minecraft.server.MinecraftServer.m_5705_(MinecraftServer.java:835) ~[server-1.20.1-20230612.114412-srg.jar%23217!/:?] {re:mixin,pl:accesstransformer:B,xf:fml:xaerominimap:xaero_minecraftserver,re:classloading,pl:accesstransformer:B,xf:fml:xaerominimap:xaero_minecraftserver,pl:mixin:A}     at net.minecraft.server.MinecraftServer.m_130011_(MinecraftServer.java:661) ~[server-1.20.1-20230612.114412-srg.jar%23217!/:?] {re:mixin,pl:accesstransformer:B,xf:fml:xaerominimap:xaero_minecraftserver,re:classloading,pl:accesstransformer:B,xf:fml:xaerominimap:xaero_minecraftserver,pl:mixin:A}     at net.minecraft.server.MinecraftServer.m_206580_(MinecraftServer.java:251) ~[server-1.20.1-20230612.114412-srg.jar%23217!/:?] {re:mixin,pl:accesstransformer:B,xf:fml:xaerominimap:xaero_minecraftserver,re:classloading,pl:accesstransformer:B,xf:fml:xaerominimap:xaero_minecraftserver,pl:mixin:A}     at java.lang.Thread.run(Thread.java:840) ~[?:?] {}
    • Hello there! I am trying to make custom dimensions for a modpack I am making in an older minecraft version, 1.16.5. I like that version and it has a few other mods that have not been updated that I would still like to use. Anyway, I am having a terrible time with getting my dimension to work and have tried using code from other peoples projects to at least figure out what I'm supposed to be doing but it has not been as helpful as I would have liked. If anyone could help that would be greatly appreciated! Here is my github with all the code as I am using it: https://github.com/BladeColdsteel/InvigoratedDimensionsMod I have also included the last log, https://pastebin.com/zX9vsDSq, I had when I tried to load up a world, let me know if there is anything else I should send though, thank you!
  • Topics

×
×
  • Create New...

Important Information

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