Jump to content

Recommended Posts

Posted

package email
import com.google.common.collect.Lists;
import email.CPLog;
import email.ChargePadType;
import email.ChargePadType.IconSuffix;
import email.ChargePads;
import email.effects.DamageSourcePad;
import email.item.ItemChargePad;
import email.tileentity.TileEntityChargePad;
import email.util.Util;
import cpw.mods.fml.common.registry.GameRegistry;
import cpw.mods.fml.relauncher.Side;
import cpw.mods.fml.relauncher.SideOnly;
import net.minecraft.block.Block;
import net.minecraft.block.BlockContainer;
import net.minecraft.block.material.Material;
import net.minecraft.client.renderer.texture.IIconRegister;
import net.minecraft.creativetab.CreativeTabs;
import net.minecraft.entity.Entity;
import net.minecraft.entity.EntityLivingBase;
import net.minecraft.entity.item.EntityItem;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.item.ItemStack;
import net.minecraft.tileentity.TileEntity;
import net.minecraft.util.AxisAlignedBB;
import net.minecraft.util.IIcon;
import net.minecraft.util.MathHelper;
import net.minecraft.world.Explosion;
import net.minecraft.world.IBlockAccess;
import net.minecraft.world.World;
import net.minecraftforge.common.util.ForgeDirection;

import java.util.*;

public class BlockChargePad extends BlockContainer {
    public BlockChargePad() {
        super(Material.iron);
        this.setBlockTextureName("chargepadsreborn" + ":" + "chargePad");
        this.setStepSound(Block.soundTypeMetal);
        this.setHardness(1.5F);
        setBlockName("chargepadsreborn" + ":" + "chargePad");

        this.setTickRandomly(true);
        this.setBlockBounds(0.0F, 0.0F, 0.0F, 1.0F, 0.25F, 1.0F);
        this.setCreativeTab(CreativeTabs.tabCombat);
        GameRegistry.registerBlock(this, ItemChargePad.class, "chargePad");
    }




    @Override
    public TileEntity createNewTileEntity(World world, int meta) {
        return ChargePadType.makeEntity(meta);
    }

    public void onBlockClicked(World world, int x, int y, int z, EntityPlayer player) {
    }

    public boolean onBlockActivated(World world, int x, int y, int z, EntityPlayer player, int side, float xOffset, float yOffset, float zOffset) {
        if(player.isSneaking()) {
            return false;
        } else if(world.isRemote) {
            return true;
        } else {
            TileEntity te = world.getTileEntity(x, y, z);
            if(te != null && te instanceof TileEntityChargePad) {
                TileEntityChargePad tecp = (TileEntityChargePad)te;
                if((tecp.upgrade_drain || tecp.upgrade_damage) && ForgeDirection.getOrientation(side) != ForgeDirection.DOWN) {
                    return true;
                }

                ChargePads.proxy.openGui(player, tecp);
            }

            return true;
        }
    }

    public boolean isBlockSolidOnSide(World world, int x, int y, int z, ForgeDirection side) {
        return side.equals(ForgeDirection.DOWN);
    }

    public int isProvidingStrongPower(IBlockAccess access, int x, int y, int z, int side) {
        return side == ForgeDirection.DOWN.ordinal()?0:(this.isPadActive(access, x, y, z)?15:0);
    }

    public int isProvidingWeakPower(IBlockAccess access, int x, int y, int z, int side) {
        return this.isProvidingStrongPower(access, x, y, z, side);
    }

    public boolean canProvidePower() {
        return true;
    }

    public boolean canConnectRedstone(IBlockAccess world, int x, int y, int z, int side) {
        return side != -1;
    }

    public void onFallenUpon(World world, int x, int y, int z, Entity entity, float impact) {
        if(!world.isRemote && ChargePads.FALLING_ZAP) {
            int md = ChargePadType.validateMeta(world.getBlockMetadata(x, y, z));
            if(ChargePadType.isImpactDamaging(md, impact)) {
                if(entity instanceof EntityLivingBase) {
                    EntityLivingBase el = (EntityLivingBase)entity;
                    el.attackEntityFrom(DamageSourcePad.electrocute, (float)(3 + 3 * md));
                }

            }
        }
    }

    public boolean canHarvestBlock(EntityPlayer player, int meta) {
        return false;
    }

    public boolean removeBlockByPlayer(World world, EntityPlayer player, int x, int y, int z) {
        if(!world.isRemote && !player.capabilities.isCreativeMode) {
            TileEntity te = world.getTileEntity(x, y, z);
            if(te instanceof TileEntityChargePad) {
                TileEntityChargePad tecp = (TileEntityChargePad)te;
                boolean nuke = tecp.isExplosionNuclear();
                if(ChargePads.DISCHARGE_ZAP) {
                    if(nuke) {
                        tecp.explodeMachineAt(world, x, y, z);
                    } else {
                        int meta = ChargePadType.validateMeta(world.getBlockMetadata(x, y, z), true);
                        this.electricalBlast(world, x, y, z, meta);
                        player.attackEntityFrom(DamageSourcePad.electrocute, (float)((meta & 7) * 2));
                    }
                }

                if(!nuke) {
                    tecp.damageInventoryContent();
                }
            }
        }

        return removeBlockByPlayer(world, player, x, y, z);
    }

    public void breakBlock(World world, int x, int y, int z, Block blockId, int metadata) {
        TileEntity te = world.getTileEntity(x, y, z);
        if(te instanceof TileEntityChargePad) {
            TileEntityChargePad tecp = (TileEntityChargePad)te;
            ArrayList drops = Lists.newArrayList();
            if(tecp.getInventoryContent(drops) > 0) {
                Iterator i$ = drops.iterator();

                while(i$.hasNext()) {
                    ItemStack stack = (ItemStack)i$.next();
                    if(stack != null) {
                        double f = 0.7D;
                        double dx = (double)world.rand.nextFloat() * f + (1.0D - f) * 0.5D;
                        double dy = (double)world.rand.nextFloat() * f + (1.0D - f) * 0.5D;
                        double dz = (double)world.rand.nextFloat() * f + (1.0D - f) * 0.5D;
                        EntityItem entityItem = new EntityItem(world, (double)x + dx, (double)y + dy, (double)z + dz, stack);
                        entityItem.delayBeforeCanPickup = 10;
                        world.spawnEntityInWorld(entityItem);
                    }
                }
            }
        }

       super.breakBlock(world, x, y, z, Block.getBlockById(9), metadata);
    }

    public void onBlockDestroyedByExplosion(World world, int x, int y, int z, Explosion exp) {
        world.removeTileEntity(x, y, z);
    }

    public void electricalBlast(World world, int x, int y, int z, int metadata) {
        if(!world.isRemote) {
            TileEntityChargePad tecp = (TileEntityChargePad)world.getTileEntity(x, y, z);
            if(tecp == null) {
                CPLog.warning("TileEntity.%s missing @%d,%d,%d ?!", new Object[]{ChargePadType.values()[metadata & 7].name(), Integer.valueOf(x), Integer.valueOf(y), Integer.valueOf(z)});
            }

            int charge = tecp != null?tecp.getStorageLevel():0;
            int halfhearts = ChargePadType.getDetonationDamage(metadata, charge);
            int maxdist = ChargePadType.getMaxDetonationRange(metadata);
            maxdist = Math.max(halfhearts, maxdist);
            AxisAlignedBB bb = this.getCollisionBoundingBoxFromPool(world, x, y, z).expand((double) maxdist, (double) maxdist, (double) maxdist);
            List ents = world.getEntitiesWithinAABB(EntityLivingBase.class, bb);
            Iterator i$ = ents.iterator();

            while(i$.hasNext()) {
                Object o = i$.next();
                EntityLivingBase el = (EntityLivingBase)o;
                int dist = MathHelper.floor_double(el.getDistance((double) x, (double) y, (double) z));
                el.attackEntityFrom(DamageSourcePad.electrocute, (float) (halfhearts - dist));
            }

        }
    }

    public boolean isPadActive(IBlockAccess iBA, int x, int y, int z) {
        return ChargePadType.isActive(iBA.getBlockMetadata(x, y, z));
    }

    public int tickRate(World world) {
        return 10;
    }

    public void updateTick(World world, int x, int y, int z, Random rand) {
        if(!world.isRemote) {
            if(this.isPadActive(world, x, y, z)) {
                this.setStateOnInteraction(world, x, y, z);
            }

        }
    }

    public void onEntityCollidedWithBlock(World world, int x, int y, int z, Entity entity) {
        if(!world.isRemote) {
            if(!this.isPadActive(world, x, y, z)) {
                this.setStateOnInteraction(world, x, y, z);
            }

        }
    }

    private void setStateOnInteraction(World world, int x, int y, int z) {
        int meta = ChargePadType.validateMeta(world.getBlockMetadata(x, y, z), true);
        boolean active = (meta &  != 0;
        double margin = 0.125D;
        AxisAlignedBB aabb = AxisAlignedBB.getBoundingBox((double) x + margin, (double) y, (double) z + margin, (double) (x + 1) - margin, (double) y + 0.5D, (double) (z + 1) - margin);
        List entities = world.getEntitiesWithinAABB(EntityPlayer.class, aabb);
        boolean force_disable = false;
        TileEntityChargePad tecp = null;
        if(active) {
            TileEntity hasEntity = world.getTileEntity(x, y, z);
            if(hasEntity != null && hasEntity instanceof TileEntityChargePad) {
                tecp = (TileEntityChargePad)hasEntity;
                if(entities.isEmpty()) {
                    force_disable = tecp.getForceDisable();
                }

                if(tecp.upgrade_fieldexp > 0) {
                    aabb = aabb.expand((double) tecp.upgrade_fieldexp, 0.0D, (double) tecp.upgrade_fieldexp);
                    entities = world.getEntitiesWithinAABB(EntityPlayer.class, aabb);
                }
            }
        }

        boolean hasEntity1 = !entities.isEmpty();
        boolean changed = false;
        if(hasEntity1 && !active) {
            changed = true;
            world.setBlockMetadataWithNotify(x, y, z, meta | 8, 2);
            world.playSoundEffect((double) x + 0.5D, (double) y + 0.25D, (double) z + 0.5D, "random.click", 0.3F, 0.6F);
        }

        if(active && (!hasEntity1 || force_disable)) {
            changed = true;
            if(tecp != null) {
                tecp.setForceDisable(false);
            }

            world.setBlockMetadataWithNotify(x, y, z, meta & 7, 2);
            world.playSoundEffect((double) x + 0.5D, (double) y + 0.25D, (double) z + 0.5D, "random.click", 0.3F, 0.5F);
        }

        if(changed) {


            world.notifyBlockOfNeighborChange(x, y - 1, z, getBlockFromName("chargepadsreborn" + ":" + "chargePad"));
            world.notifyBlockOfNeighborChange(x - 1, y, z, getBlockFromName("chargepadsreborn" + ":" + "chargePad"));
            world.notifyBlockOfNeighborChange(x + 1, y, z, getBlockFromName("chargepadsreborn" + ":" + "chargePad"));
            world.notifyBlockOfNeighborChange(x, y, z - 1, getBlockFromName("chargepadsreborn" + ":" + "chargePad"));
            world.notifyBlockOfNeighborChange(x, y, z + 1, getBlockFromName("chargepadsreborn" + ":" + "chargePad"));
            world.markBlockRangeForRenderUpdate(x, y, z, x, y, z);

        }

        if(hasEntity1) {
          world.scheduleBlockUpdate(x, y, z, getBlockFromName("chargepadsreborn" + ":" + "chargePad"), this.tickRate(world));
        }

    }

    public boolean renderAsNormalBlock() {
        return false;
    }

    public boolean isOpaqueCube() {
        return false;
    }

    @SideOnly(Side.CLIENT)
    public void randomDisplayTick(World world, int blockX, int blockY, int blockZ, Random rand) {
        if(this.isPadActive(world, blockX, blockY, blockZ)) {
            TileEntity te = world.getTileEntity(blockX, blockY, blockZ);
            if(te != null && te instanceof TileEntityChargePad) {
                ((TileEntityChargePad)te).spawnParticles(world, blockX, blockY, blockZ, rand);
            }
        }
    }

    @SideOnly(Side.CLIENT)
    public IIcon getIcon(int side, int metadata) {
        int meta = ChargePadType.validateMeta(metadata, true);
        boolean active = (meta &  != 0;
        if(meta != metadata) {
            CPLog.warning("Invalid meta check: %d/%sactive (ignoring)", new Object[]{Integer.valueOf(metadata), active?"":"in"});
        }

        ChargePadType type = ChargePadType.getType(meta);
        return side == ForgeDirection.DOWN.ordinal()?type.getIcon(IconSuffix.Base):(side == ForgeDirection.UP.ordinal()?type.getIcon(active?IconSuffix.Top1:IconSuffix.Top0):type.getIcon(IconSuffix.Side));
    }

    public int getMobilityFlag() {
        return 1;
    }

   // public int func_71885_a(int metadata, Random random, int par3) {
       //return this.getItem();

    public int damageDropped(int metadata) {
        return metadata & 7;
    }

    public int quantityDropped(Random random) {
        return 1;
    }

    public ArrayList<ItemStack> getBlockDropped(World world, int x, int y, int z, int metadata, int fortune) {
        ArrayList dropped = super.getDrops(world, x, y, z, metadata, fortune);
        TileEntity te = world.getTileEntity(x, y, z);
        if(te instanceof TileEntityChargePad) {
            TileEntityChargePad tecp = (TileEntityChargePad)te;
            tecp.getInventoryContent(dropped);
        }

        return dropped;
    }

    @SideOnly(Side.CLIENT)
    public void getSubBlocks(int blockId, CreativeTabs tabs, List istacks) {
        ChargePadType[] arr$ = ChargePadType.values();
        int len$ = arr$.length;

        for(int i$ = 0; i$ < len$; ++i$) {
            ChargePadType type = arr$[i$];
            istacks.add(new ItemStack(this, 1, type.ordinal()));
        }

    }

    @SideOnly(Side.CLIENT)
    public void registerIcons(IIconRegister ireg) {
        ChargePadType[] arr$ = ChargePadType.values();
        int len$ = arr$.length;

        for (int i$ = 0; i$ < len$; ++i$) {
            ChargePadType type = arr$[i$];
            String prefix = type.name().toLowerCase(Locale.ENGLISH);
            IconSuffix[] arr$1 = IconSuffix.values();
            int len$1 = arr$1.length;

            for (int i$1 = 0; i$1 < len$1; ++i$1) {
                IconSuffix suffix = arr$1[i$1];
                type.setIcon(suffix, ireg.registerIcon(Util.getTextureNameQ(prefix + suffix.name())));
            }
        }

    }
}

 

 

 

This is an old plugin for ic2 that i did not originally make but Im just messing around with it.

my block isn't showing up and I'm not seeing anything wrong in any of my classes This is my Blocks class is there something wrong here I don't see? (I'm new to posting on forums please tell me anything I did wrong)

 

 

Posted

override getRenderType

 

EDIT:

Default for standard blocks is a RenderType of 3. If you take a closer look at BlockContainer you can see that minecraft overrides it with -1, which you need to change if you want a block to render "normal"

Posted

this had no affect

 

some information this is is being updated from 1.6.2 to 1.7.10 and this block is just a slab that's half the Y, also the Blocks and items don't even appear in the game, not in nei nor creative tabs

Posted

Missunderstood your question and dont read your whole code, sorry.

I am not sure about the GameRegistry call with 3 args, since I am always using 2 args. (but im mainly 1.8 modder)

Posted

the 3rd argument is for if you have a different class for the itemBlock, here i will post my itemBlock class to see if theirs something there that's wrong

 

public class ItemChargePad extends ItemBlock {
    public ItemChargePad(Block block) {
        super(block);
        this.setMaxDamage(0);
        this.setHasSubtypes(true);
        this.setMaxStackSize(4);
    }
    @Override
    public int getMetadata(int damage) {
        return ChargePadType.validateMeta(damage, true);
    }

    @Override
    @SideOnly(Side.CLIENT)
    public EnumRarity getRarity(ItemStack istack) {
        return ChargePadType.isRare(istack.getItemDamage() & 7)?EnumRarity.uncommon:EnumRarity.common;
    }
    @Override
    @SideOnly(Side.CLIENT)
    public String getUnlocalizedName(ItemStack istack) {
        return "item.chargePad." + ChargePadType.values()[ChargePadType.validateMeta(istack.getItemDamage())].name();
    }
}

Posted

lets say its not rendering correctly would it still show up a broken textured item in nei/creativetab?

 

im just wondering because we can narrow the problem to just those 2 classes if this is not true.

Posted

lets say its not rendering correctly would it still show up a broken textured item in nei/creativetab?

 

im just wondering because we can narrow the problem to just those 2 classes if this is not true.

You appear to be registering the block to the GameRegistry inside the constructor for the block. One question I'd like to ask is in your main class are you creating a new instance of the block? If not then the call to the registry is never being executed.

Posted

lets say its not rendering correctly would it still show up a broken textured item in nei/creativetab?

 

im just wondering because we can narrow the problem to just those 2 classes if this is not true.

You appear to be registering the block to the GameRegistry inside the constructor for the block. One question I'd like to ask is in your main class are you creating a new instance of the block? If not then the call to the registry is never being executed.

This did it thanks :D

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

    • Okay, but does the modpack works with 1.12 or just with 1.12.2, because I need the Forge client specifically for Minecraft 1.12, not 1.12.2
    • 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?
  • Topics

×
×
  • Create New...

Important Information

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