Jump to content

Recommended Posts

Posted

I have read past forum posts addressing this, but I still can't seem to figure it out. I have a block that should create a variant for each EnumDyeColor. (So, 16 altogether.) I have already gotten this same block to work using a "facing" property so that it faces the player when placed, but I can't seem to get the "color" property to work. It generates 16 items without textures in the inventory and without textures when placed. I am pretty sure it's a JSON thing, because of the error which I will post below. Thanks.

Spoiler

Exception loading model for variant test_block#color=6,facing=east for blockstate "test_block"

The console also says "suppressed 59 additional model loading errors."

Here is my JSON file.

Spoiler

{
  "forge_marker": 1,
  "variants": {
    "type": {
      "normal": {
        "model": "my_mod:test_block"
      }
    },

    "facing=north": { "model": "my_mod:test_block", "y": 270 },
    "facing=east": { "model": "my_mod:test_block", "y": 0 },
    "facing=south": { "model": "my_mod:test_block", "y": 90 },
    "facing=west": { "model": "my_mod:test_block", "y": 180 },

    "color": {
      "0": {
        "textures": {
          "top": "blocks/hardened_clay_stained_white"
        }
      },
      "1": {
        "textures": {
          "top": "blocks/hardened_clay_stained_orange"
        }
      },
      "2": {
        "textures": {
          "top": "blocks/hardened_clay_stained_magenta"
        }
      },
      "3": {
        "textures": {
          "top": "blocks/hardened_clay_stained_light_blue"
        }
      },
      "4": {
        "textures": {
          "top": "blocks/hardened_clay_stained_yellow"
        }
      },
      "5": {
        "textures": {
          "top": "blocks/hardened_clay_stained_lime"
        }
      },
      "6": {
        "textures": {
          "top": "blocks/hardened_clay_stained_pink"
        }
      },
      "7": {
        "textures": {
          "top": "blocks/hardened_clay_stained_gray"
        }
      },
      "8": {
        "textures": {
          "top": "blocks/hardened_clay_stained_silver"
        }
      },
      "9": {
        "textures": {
          "top": "blocks/hardened_clay_stained_cyan"
        }
      },
      "10": {
        "textures": {
          "top": "blocks/hardened_clay_stained_purple"
        }
      },
      "11": {
        "textures": {
          "top": "blocks/hardened_clay_stained_blue"
        }
      },
      "12": {
        "textures": {
          "top": "blocks/hardened_clay_stained_brown"
        }
      },
      "13": {
        "textures": {
          "top": "blocks/hardened_clay_stained_green"
        }
      },
      "14": {
        "textures": {
          "top": "blocks/hardened_clay_stained_red"
        }
      },
      "15": {
        "textures": {
          "top": "blocks/hardened_clay_stained_black"
        }
      }
    }
  }
}

And just to clarify, the block model is loading a "test_block" in, just not generating the blockstate variants for the other 16 colors.

  • Replies 64
  • Created
  • Last Reply

Top Posters In This Topic

Posted (edited)

You can't have that many states.  IBlockState is still baked by a 1 nibble (half byte) metadata that can hold only 16 values. 

Edited by Draco18s

Apparently I'm a complete and utter jerk and come to this forum just like to make fun of people, be confrontational, and make your personal life miserable.  If you think this is the case, JUST REPORT ME.  Otherwise you're just going to get reported when you reply to my posts and point it out, because odds are, I was trying to be nice.

 

Exception: If you do not understand Java, I WILL NOT HELP YOU and your thread will get locked.

 

DO NOT PM ME WITH PROBLEMS. No help will be given.

Posted

You can have UnlistedProperties, or create a new block for every color. I recommend the 2nd one

About Me

Spoiler

My Discord - Cadiboo#8887

My WebsiteCadiboo.github.io

My ModsCadiboo.github.io/projects

My TutorialsCadiboo.github.io/tutorials

Versions below 1.14.4 are no longer supported on this forum. Use the latest version to receive support.

When asking support remember to include all relevant log files (logs are found in .minecraft/logs/), code if applicable and screenshots if possible.

Only download mods from trusted sites like CurseForge (minecraft.curseforge.com). A list of bad sites can be found here, with more information available at stopmodreposts.org

Edit your own signature at www.minecraftforge.net/forum/settings/signature/ (Make sure to check its compatibility with the Dark Theme)

Posted (edited)
6 hours ago, Cadiboo said:

You can have UnlistedProperties, or create a new block for every color. I recommend the 2nd one

 

Unlisted properties aren't used to determine which model to render for a block, they're used by custom block models to determine how they should render. The correct solution here (while keeping a single block) would be to store the extra data in a TileEntity and use regular properties that have their values set in Block#getActualState. Though Mojang is moving away from having a single block for all colours with The Flattening in 1.13, so it may be best to split the colours into separate blocks now (as Cadiboo suggested).

 

I have an example of a block with a colour and a facing here: Block, TileEntity, blockstates file

Edited by Choonster

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.

Posted

Write to NBT - write your data to a NBTTagCompound for serialisation (saving)

Read from NBT - read your data from a NBTTagCompound for deserialisation (loading)

About Me

Spoiler

My Discord - Cadiboo#8887

My WebsiteCadiboo.github.io

My ModsCadiboo.github.io/projects

My TutorialsCadiboo.github.io/tutorials

Versions below 1.14.4 are no longer supported on this forum. Use the latest version to receive support.

When asking support remember to include all relevant log files (logs are found in .minecraft/logs/), code if applicable and screenshots if possible.

Only download mods from trusted sites like CurseForge (minecraft.curseforge.com). A list of bad sites can be found here, with more information available at stopmodreposts.org

Edit your own signature at www.minecraftforge.net/forum/settings/signature/ (Make sure to check its compatibility with the Dark Theme)

Posted
On 12/14/2018 at 12:24 AM, Choonster said:

I have an example of a block with a colour and a facing here

Huh, I looked through that, and my JSON file is formatted the same way, but it gives me an Exception loading model for variant error. I made sure to register the tileentity, but maybe I'm missing something else with the actual model?

Posted

Show your new code? Preferably as a GitHub repository 

About Me

Spoiler

My Discord - Cadiboo#8887

My WebsiteCadiboo.github.io

My ModsCadiboo.github.io/projects

My TutorialsCadiboo.github.io/tutorials

Versions below 1.14.4 are no longer supported on this forum. Use the latest version to receive support.

When asking support remember to include all relevant log files (logs are found in .minecraft/logs/), code if applicable and screenshots if possible.

Only download mods from trusted sites like CurseForge (minecraft.curseforge.com). A list of bad sites can be found here, with more information available at stopmodreposts.org

Edit your own signature at www.minecraftforge.net/forum/settings/signature/ (Make sure to check its compatibility with the Dark Theme)

Posted

Yeah, I've been getting a repository set up. For now, I'll just post the code directly.

Spoiler

public class BlockCounter extends BlockColored {

    public static final IProperty<EnumFacing> FACING = PropertyDirection.create("facing");

    public static final AxisAlignedBB RED_COUNTER_AABB = new AxisAlignedBB(0.0D, 0.0D, 0.0D, 1.0D, 1.0D, 1.0D);

    public BlockCounter(final Material material) {
        super(Material.CLAY);
        setCreativeTab(CreativeTabs.DECORATIONS);
    }

    @Override
    public boolean isOpaqueCube(IBlockState state) {
        return false;
    }

    @Override
    public boolean isFullCube(IBlockState state) {
        return false;
    }

    @Override
    public AxisAlignedBB getBoundingBox(IBlockState state, IBlockAccess source, BlockPos pos) {
        return RED_COUNTER_AABB;
    }

    @Override
    protected BlockStateContainer createBlockState()
    {
        return new BlockStateContainer(this, COLOR, FACING);
    }

    @Override
    public boolean hasTileEntity(final IBlockState state) {
        return true;
    }

    @Nullable
    @Override
    public TileEntity createTileEntity(World world, IBlockState state) {
        return new TileEntityCounter();
    }

    @Nullable
    public TileEntityCounter getTileEntity(final IBlockAccess world, final BlockPos pos) {
        return (TileEntityCounter) world.getTileEntity(pos);
    }

    public EnumFacing getFacing(final IBlockAccess world, final BlockPos pos) {
        final TileEntityCounter tileEntity = getTileEntity(world, pos);
        return tileEntity != null ? tileEntity.getFacing() : EnumFacing.NORTH;
    }

    public void setFacing(final IBlockAccess world, final BlockPos pos, final EnumFacing facing) {
        final TileEntityCounter tileEntity = getTileEntity(world, pos);
        if (tileEntity != null) {
            tileEntity.setFacing(facing);
        }
    }

    @Override
    public void onBlockPlacedBy(final World worldIn, final BlockPos pos, final IBlockState state, final EntityLivingBase placer, final ItemStack stack) {
        setFacing(worldIn, pos, EnumFacing.getDirectionFromEntityLiving(pos, placer).getOpposite());
    }

    @Override
    public IBlockState getActualState(final IBlockState state, final IBlockAccess worldIn, final BlockPos pos) {
        return state.withProperty(FACING, getFacing(worldIn, pos));
    }

    @Override
    public void getSubBlocks(CreativeTabs item, NonNullList<ItemStack> items) {
        for (int i = 0; i < EnumDyeColor.values().length; i++) {
            items.add(new ItemStack(this, 1, i));
        }
    }

    @Override
    public boolean onBlockActivated(final World worldIn, final BlockPos pos, final IBlockState state, final EntityPlayer playerIn, final EnumHand hand, final EnumFacing side, final float hitX, final float hitY, final float hitZ)
    {
        final ItemStack heldItem = playerIn.getHeldItem(hand);

        if (!heldItem.isEmpty()) {
            final Optional<EnumDyeColor> dyeColour = DyeUtils.colorFromStack(heldItem);
            if (dyeColour.isPresent()) {
                final boolean success = recolorBlock(worldIn, pos, side, dyeColour.get());
                if (success && !playerIn.isCreative()) {
                    heldItem.shrink(1);
                }
                return true;
            }
        }
        return false;
    }
}
Spoiler

public class TileEntityCounter extends TileEntity {

    private EnumFacing facing = EnumFacing.NORTH;

    public EnumFacing getFacing() {
        return facing;
    }

    public void setFacing(final EnumFacing facing) {
        this.facing = facing;
        markDirty();
    }

    @Override
    public void readFromNBT(final NBTTagCompound compound) {
        super.readFromNBT(compound);
        facing = EnumFacing.getFront(compound.getInteger("facing"));
    }

    @Override
    public NBTTagCompound writeToNBT(final NBTTagCompound compound) {
        super.writeToNBT(compound);
        compound.setInteger("facing", facing.getIndex());
        return compound;
    }

    private void notifyBlockUpdate() {
        final IBlockState state = getWorld().getBlockState(getPos());
        getWorld().notifyBlockUpdate(getPos(), state, state, 3);
    }

    @Override
    public void markDirty() {
        super.markDirty();
        notifyBlockUpdate();
    }

    @Override
    public NBTTagCompound getUpdateTag() {
        return writeToNBT(new NBTTagCompound());
    }

    @Nullable
    @Override
    public SPacketUpdateTileEntity getUpdatePacket() {
        return new SPacketUpdateTileEntity(getPos(), 0, getUpdateTag());
    }

    @Override
    public void onDataPacket(final NetworkManager net, final SPacketUpdateTileEntity pkt) {
        readFromNBT(pkt.getNbtCompound());
        notifyBlockUpdate();
    }

    @Override
    public boolean shouldRefresh(final World world, final BlockPos pos, final IBlockState oldState, final IBlockState newSate) {
        return oldState.getBlock() != newSate.getBlock();
    }
}

These are the two java classes for the Block itself, and then the TileEntity.

Posted

Still stuck on this, I thought I figured out but the proper textures for each blockstate were not rendering properly. Just seeing if anyone has any ideas. Thanks.

Posted

I've been having issues with the repo right now. I duplicated some files accidentally, and some of the old files are still in it. Here is the blockstate and model file. The java classes are the ones posted above. Thanks.

Spoiler

{
  "forge_marker": 1,
  "defaults": {
    "model": "testmod:counter"
  },
  "variants": {
    "facing": {
      "down": {
        "x": 90
      },
      "up": {
        "x": 270
      },
      "north": {
        "y": 270
      },
      "south": {
        "y": 90
      },
      "east": {
        "y": 0
      },
      "west": {
        "y": 180
      }
    },
    "color": {
      "white": {
        "textures": {
          "top": "blocks/hardened_clay_stained_white"
        }
      },
      "orange": {
        "textures": {
          "top": "blocks/hardened_clay_stained_orange"
        }
      },
      "magenta": {
        "textures": {
          "top": "blocks/hardened_clay_stained_magenta"
        }
      },
      "light_blue": {
        "textures": {
          "top": "blocks/hardened_clay_stained_light_blue"
        }
      },
      "yellow": {
        "textures": {
          "top": "blocks/hardened_clay_stained_yellow"
        }
      },
      "lime": {
        "textures": {
          "top": "blocks/hardened_clay_stained_lime"
        }
      },
      "pink": {
        "textures": {
          "top": "blocks/hardened_clay_stained_pink"
        }
      },
      "gray": {
        "textures": {
          "top": "blocks/hardened_clay_stained_gray"
        }
      },
      "silver": {
        "textures": {
          "top": "blocks/hardened_clay_stained_silver"
        }
      },
      "cyan": {
        "textures": {
          "top": "blocks/hardened_clay_stained_cyan"
        }
      },
      "purple": {
        "textures": {
          "top": "blocks/hardened_clay_stained_purple"
        }
      },
      "blue": {
        "textures": {
          "top": "blocks/hardened_clay_stained_blue"
        }
      },
      "brown": {
        "textures": {
          "top": "blocks/hardened_clay_stained_brown"
        }
      },
      "green": {
        "textures": {
          "top": "blocks/hardened_clay_stained_green"
        }
      },
      "red": {
        "textures": {
          "top": "blocks/hardened_clay_stained_red"
        }
      },
      "black": {
        "textures": {
          "top": "blocks/hardened_clay_stained_black"
        }
      }
    }
  }
}

Spoiler

{
    "textures": {
        "particle": "blocks/concrete_white",
        "bottom": "blocks/concrete_white",
        "top": "blocks/hardened_clay_stained_red"
    },
    "display": {
        "gui": {
            "rotation": [ 30, 135, 0 ],
            "translation": [ 0, 0, 0 ],
            "scale": [ 0.625, 0.625, 0.625 ]
        },
        "ground": {
            "rotation": [ 0, 0, 0 ],
            "translation": [ 0, 3, 0 ],
            "scale": [ 0.25, 0.25, 0.25 ]
        },
        "fixed": {
            "rotation": [ 0, 0, 0 ],
            "translation": [ 0, 0, 0 ],
            "scale": [ 0.5, 0.5, 0.5 ]
        },
        "thirdperson_righthand": {
            "rotation": [ 75, 45, 0 ],
            "translation": [ 0, 2.5, 0 ],
            "scale": [ 0.375, 0.375, 0.375 ]
        },
        "thirdperson_lefthand": {
            "rotation": [ 75, 225, 0 ],
            "translation": [ 0, 2.5, 0 ],
            "scale": [ 0.375, 0.375, 0.375 ]
        },
        "firstperson_righthand": {
            "rotation": [ 0, 45, 0 ],
            "translation": [ 0, 0, 0 ],
            "scale": [ 0.40, 0.40, 0.40 ]
        },
        "firstperson_lefthand": {
            "rotation": [ 0, 225, 0 ],
            "translation": [ 0, 0, 0 ],
            "scale": [ 0.40, 0.40, 0.40 ]
        }
    },
    "elements": [
        {
            "name": "Cube",
            "from": [ 2.0, 0.0, 0.0 ],
            "to": [ 16.0, 14.0, 16.0 ],
            "faces": {
                "north": { "texture": "#bottom", "uv": [ 0.0, 0.0, 16.0, 14.0 ] },
                "east": { "texture": "#bottom", "uv": [ 1.0, 0.0, 15.0, 14.0 ] },
                "south": { "texture": "#bottom", "uv": [ 0.0, 0.0, 16.0, 14.0 ] },
                "west": { "texture": "#bottom", "uv": [ 1.0, 0.0, 15.0, 14.0 ] },
                "up": { "texture": "#bottom", "uv": [ 0.0, 0.0, 16.0, 14.0 ] },
                "down": { "texture": "#bottom", "uv": [ 0.0, 0.0, 16.0, 14.0 ] }
            }
        },
        {
            "name": "Cube",
            "from": [ 0.0, 14.0, 0.0 ],
            "to": [ 16.0, 16.0, 16.0 ],
            "faces": {
                "north": { "texture": "#top", "uv": [ 0.0, 0.0, 16.0, 2.0 ] },
                "east": { "texture": "#top", "uv": [ 0.0, 0.0, 16.0, 2.0 ] },
                "south": { "texture": "#top", "uv": [ 0.0, 0.0, 16.0, 2.0 ] },
                "west": { "texture": "#top", "uv": [ 0.0, 0.0, 16.0, 2.0 ] },
                "up": { "texture": "#top", "uv": [ 0.0, 0.0, 16.0, 16.0 ] },
                "down": { "texture": "#top", "uv": [ 0.0, 0.0, 16.0, 16.0 ] }
            }
        }
    ]
}

 

Posted
On 12/16/2018 at 2:45 AM, Siqhter said:

@Override public IBlockState getActualState(final IBlockState state, final IBlockAccess worldIn, final BlockPos pos) { return state.withProperty(FACING, getFacing(worldIn, pos)); }

You are not including the color in your state here.

 

On 12/16/2018 at 12:13 AM, Siqhter said:

However, using the getSubBlocks method, the textures for all other 15 blocks are not registering.

What is your issue? Are item textures not there? Or those of blocks? If it's blocks then see above, otherwise you need to show how you are registering models for your itemblocks.

Posted
1 hour ago, V0idWa1k3r said:

You are not including the color in your state here.

Ok, so would I return COLOR and  FACING? Because right now it gives an error if I pass in COLOR.

Posted
17 minutes ago, Siqhter said:

Ok, so would I return COLOR and  FACING?

Yes.

18 minutes ago, Siqhter said:

Because right now it gives an error if I pass in COLOR.

What is the mysterious "it"? The compiler? The IDE? The game? If it's the first two then you should be able to fix it, since it's just a compile error and those are easily fixable with some java knowledge. If it's the latter then post the error log.

Posted

Sorry, I meant the IDE, as in the red underline. It still compiles. The only error I get is "withProperty()" in IBlockState cannot be applied  to: IProperty<T> COLOR (EnumDyeColor)".

Posted
53 minutes ago, Siqhter said:

It still compiles.

It can't because you have a syntax error that you've posted.

From the looks of the error you are passing wrong arguments to the method. See the method parameters and pass what it wants.

Posted

Well, this is what it says it expects in the error: block.properties.IProperty<T>.  But I don't think I really understand what it actually wants, other than COLOR, or rather what I'd pass in.

Posted

I assume just the method?

Spoiler

@Override
public IBlockState getActualState(final IBlockState state, final IBlockAccess worldIn, final BlockPos pos) {
    return state.withProperty(COLOR, FACING, getFacing(worldIn, pos));
}

 

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

    • Version 1.19 - Forge 41.0.63 I want to create a wolf entity that I can ride, so far it seems to be working, but the problem is that when I get on the wolf, I can’t control it. I then discovered that the issue is that the server doesn’t detect that I’m riding the wolf, so I’m struggling with synchronization. However, it seems to not be working properly. As I understand it, the server receives the packet but doesn’t register it correctly. I’m a bit new to Java, and I’ll try to provide all the relevant code and prints *The comments and prints are translated by chatgpt since they were originally in Spanish* Thank you very much in advance No player is mounted, or the passenger is not a player. No player is mounted, or the passenger is not a player. No player is mounted, or the passenger is not a player. No player is mounted, or the passenger is not a player. No player is mounted, or the passenger is not a player. MountableWolfEntity package com.vals.valscraft.entity; import com.vals.valscraft.network.MountSyncPacket; import com.vals.valscraft.network.NetworkHandler; import net.minecraft.client.Minecraft; import net.minecraft.network.syncher.EntityDataAccessor; import net.minecraft.network.syncher.EntityDataSerializers; import net.minecraft.network.syncher.SynchedEntityData; import net.minecraft.server.MinecraftServer; import net.minecraft.server.level.ServerPlayer; import net.minecraft.world.entity.EntityType; import net.minecraft.world.entity.Mob; import net.minecraft.world.entity.ai.attributes.AttributeSupplier; import net.minecraft.world.entity.ai.attributes.Attributes; import net.minecraft.world.entity.animal.Wolf; import net.minecraft.world.entity.player.Player; import net.minecraft.world.entity.Entity; import net.minecraft.world.InteractionHand; import net.minecraft.world.InteractionResult; import net.minecraft.world.item.ItemStack; import net.minecraft.world.item.Items; import net.minecraft.world.level.Level; import net.minecraft.world.phys.Vec3; import net.minecraftforge.event.TickEvent; import net.minecraftforge.eventbus.api.SubscribeEvent; import net.minecraftforge.network.PacketDistributor; public class MountableWolfEntity extends Wolf { private boolean hasSaddle; private static final EntityDataAccessor<Byte> DATA_ID_FLAGS = SynchedEntityData.defineId(MountableWolfEntity.class, EntityDataSerializers.BYTE); public MountableWolfEntity(EntityType<? extends Wolf> type, Level level) { super(type, level); this.hasSaddle = false; } @Override protected void defineSynchedData() { super.defineSynchedData(); this.entityData.define(DATA_ID_FLAGS, (byte)0); } public static AttributeSupplier.Builder createAttributes() { return Wolf.createAttributes() .add(Attributes.MAX_HEALTH, 20.0) .add(Attributes.MOVEMENT_SPEED, 0.3); } @Override public InteractionResult mobInteract(Player player, InteractionHand hand) { ItemStack itemstack = player.getItemInHand(hand); if (itemstack.getItem() == Items.SADDLE && !this.hasSaddle()) { if (!player.isCreative()) { itemstack.shrink(1); } this.setSaddle(true); return InteractionResult.SUCCESS; } else if (!level.isClientSide && this.hasSaddle()) { player.startRiding(this); MountSyncPacket packet = new MountSyncPacket(true); // 'true' means the player is mounted NetworkHandler.CHANNEL.sendToServer(packet); // Ensure the server handles the packet return InteractionResult.SUCCESS; } return InteractionResult.PASS; } @Override public void travel(Vec3 travelVector) { if (this.isVehicle() && this.getControllingPassenger() instanceof Player) { System.out.println("The wolf has a passenger."); System.out.println("The passenger is a player."); Player player = (Player) this.getControllingPassenger(); // Ensure the player is the controller this.setYRot(player.getYRot()); this.yRotO = this.getYRot(); this.setXRot(player.getXRot() * 0.5F); this.setRot(this.getYRot(), this.getXRot()); this.yBodyRot = this.getYRot(); this.yHeadRot = this.yBodyRot; float forward = player.zza; float strafe = player.xxa; if (forward <= 0.0F) { forward *= 0.25F; } this.flyingSpeed = this.getSpeed() * 0.1F; this.setSpeed((float) this.getAttributeValue(Attributes.MOVEMENT_SPEED) * 1.5F); this.setDeltaMovement(new Vec3(strafe, travelVector.y, forward).scale(this.getSpeed())); this.calculateEntityAnimation(this, false); } else { // The wolf does not have a passenger or the passenger is not a player System.out.println("No player is mounted, or the passenger is not a player."); super.travel(travelVector); } } public boolean hasSaddle() { return this.hasSaddle; } public void setSaddle(boolean hasSaddle) { this.hasSaddle = hasSaddle; } @Override protected void dropEquipment() { super.dropEquipment(); if (this.hasSaddle()) { this.spawnAtLocation(Items.SADDLE); this.setSaddle(false); } } @SubscribeEvent public static void onServerTick(TickEvent.ServerTickEvent event) { if (event.phase == TickEvent.Phase.START) { MinecraftServer server = net.minecraftforge.server.ServerLifecycleHooks.getCurrentServer(); if (server != null) { for (ServerPlayer player : server.getPlayerList().getPlayers()) { if (player.isPassenger() && player.getVehicle() instanceof MountableWolfEntity) { MountableWolfEntity wolf = (MountableWolfEntity) player.getVehicle(); System.out.println("Tick: " + player.getName().getString() + " is correctly mounted on " + wolf); } } } } } private boolean lastMountedState = false; @Override public void tick() { super.tick(); if (!this.level.isClientSide) { // Only on the server boolean isMounted = this.isVehicle() && this.getControllingPassenger() instanceof Player; // Only print if the state changed if (isMounted != lastMountedState) { if (isMounted) { Player player = (Player) this.getControllingPassenger(); // Verify the passenger is a player System.out.println("Server: Player " + player.getName().getString() + " is now mounted."); } else { System.out.println("Server: The wolf no longer has a passenger."); } lastMountedState = isMounted; } } } @Override public void addPassenger(Entity passenger) { super.addPassenger(passenger); if (passenger instanceof Player) { Player player = (Player) passenger; if (!this.level.isClientSide && player instanceof ServerPlayer) { // Send the packet to the server to indicate the player is mounted NetworkHandler.CHANNEL.send(PacketDistributor.PLAYER.with(() -> (ServerPlayer) player), new MountSyncPacket(true)); } } } @Override public void removePassenger(Entity passenger) { super.removePassenger(passenger); if (passenger instanceof Player) { Player player = (Player) passenger; if (!this.level.isClientSide && player instanceof ServerPlayer) { // Send the packet to the server to indicate the player is no longer mounted NetworkHandler.CHANNEL.send(PacketDistributor.PLAYER.with(() -> (ServerPlayer) player), new MountSyncPacket(false)); } } } @Override public boolean isControlledByLocalInstance() { Entity entity = this.getControllingPassenger(); return entity instanceof Player; } @Override public void positionRider(Entity passenger) { if (this.hasPassenger(passenger)) { double xOffset = Math.cos(Math.toRadians(this.getYRot() + 90)) * 0.4; double zOffset = Math.sin(Math.toRadians(this.getYRot() + 90)) * 0.4; passenger.setPos(this.getX() + xOffset, this.getY() + this.getPassengersRidingOffset() + passenger.getMyRidingOffset(), this.getZ() + zOffset); } } } MountSyncPacket package com.vals.valscraft.network; import com.vals.valscraft.entity.MountableWolfEntity; import net.minecraft.network.FriendlyByteBuf; import net.minecraft.server.level.ServerLevel; import net.minecraft.server.level.ServerPlayer; import net.minecraft.world.entity.Entity; import net.minecraft.world.entity.player.Player; import net.minecraftforge.network.NetworkEvent; import java.util.function.Supplier; public class MountSyncPacket { private final boolean isMounted; public MountSyncPacket(boolean isMounted) { this.isMounted = isMounted; } public void encode(FriendlyByteBuf buffer) { buffer.writeBoolean(isMounted); } public static MountSyncPacket decode(FriendlyByteBuf buffer) { return new MountSyncPacket(buffer.readBoolean()); } public void handle(NetworkEvent.Context context) { context.enqueueWork(() -> { ServerPlayer player = context.getSender(); // Get the player from the context if (player != null) { // Verifies if the player has dismounted if (!isMounted) { Entity vehicle = player.getVehicle(); if (vehicle instanceof MountableWolfEntity wolf) { // Logic to remove the player as a passenger wolf.removePassenger(player); System.out.println("Server: Player " + player.getName().getString() + " is no longer mounted."); } } } }); context.setPacketHandled(true); // Marks the packet as handled } } networkHandler package com.vals.valscraft.network; import com.vals.valscraft.valscraft; import net.minecraft.resources.ResourceLocation; import net.minecraftforge.network.NetworkRegistry; import net.minecraftforge.network.simple.SimpleChannel; import net.minecraftforge.network.NetworkEvent; import java.util.function.Supplier; public class NetworkHandler { private static final String PROTOCOL_VERSION = "1"; public static final SimpleChannel CHANNEL = NetworkRegistry.newSimpleChannel( new ResourceLocation(valscraft.MODID, "main"), () -> PROTOCOL_VERSION, PROTOCOL_VERSION::equals, PROTOCOL_VERSION::equals ); public static void init() { int packetId = 0; // Register the mount synchronization packet CHANNEL.registerMessage( packetId++, MountSyncPacket.class, MountSyncPacket::encode, MountSyncPacket::decode, (msg, context) -> msg.handle(context.get()) // Get the context with context.get() ); } }  
    • Do you use features of inventory profiles next (ipnext) or is there a change without it?
    • Remove rubidium - you are already using embeddium, which is a fork of rubidium
  • Topics

×
×
  • Create New...

Important Information

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