Jump to content

Recommended Posts

Posted (edited)

hai there

 

im trying to make a item thats the only way to harvest bananas from the banana bunch but when u brake the banana bunch it brakes the block not return to age 0 (ive used parms harvest craft code for refrance)

so tryed to make the item do the same thing as right click harvest only on right clicking its doing nothing :(  anybody got a idea on to y the block brakes insted or turning back to age 0 OR y the banana picker is doing nothing on right click?

 

https://github.com/monkeybee11/monkeysmod/blob/master/src/main/java/com/monkeybee11/monkeysmod/item/ItemBananaPicker.java  banana pickers code 

 

https://github.com/monkeybee11/monkeysmod/blob/master/src/main/java/com/monkeybee11/monkeysmod/block/BlockBananaBunch.java banana bunch code 

Edited by monkeybee
forgot no 1 uses a lefthanded mouse ¬.¬
Posted
56 minutes ago, monkeybee said:

on left clicking its doing nothing

Quote

PlayerInteractEvent.RightClickBlock event

I wonder why indeed... 

This is not what you use events for. Events are when you need to hook into existing behaviour, not when you need to create a completely new one. Just override Block#onBlockActivated, check if the item in the player's hand is your item and do what you need to do.

 

if (!(state.getValue(AGE) != 3)) {

		}

What is the purpose of this code? The condition will never be true and even if it was it does nothing.

 

56 minutes ago, monkeybee said:

y the block brakes insted or turning back to age 0

Well so far you've done absolutely nothing to change the default breaking behaviour, thus it breaks as all other blocks.

 

Posted (edited)
29 minutes ago, V0idWa1k3r said:

I wonder why indeed... 

This is not what you use events for. Events are when you need to hook into existing behaviour, not when you need to create a completely new one. Just override Block#onBlockActivated, check if the item in the player's hand is your item and do what you need to do.

 


if (!(state.getValue(AGE) != 3)) {

		}

What is the purpose of this code? The condition will never be true and even if it was it does nothing.

 

Well so far you've done absolutely nothing to change the default breaking behaviour, thus it breaks as all other blocks.

 

MY BAD!!!! ive used a hard wired left handed mouse since ive used a pc so the buttions are swaped for me >.<
on right click then sry :P

im not 100% sure what the code dose was using parms code as a very close refraces bc befor had tryed to code it my self with only vanilla cocoa as refrance and it didt turn out well so something in parms mite have 3 ages insted of 2?

Edited by monkeybee
Posted
11 minutes ago, monkeybee said:

im not 100% sure what the code dose was using parms code as a very close refraces bc befor had tryed to code it

Well you should then inspect your code and actually understand what it is doing. Programming without a clear understanding of what the code does is like trying to assemble a rocket without a manual or assembly markers.

 

What behaviour do you actually want? Afaik when you break a fruit in pam's it breaks like a normal block and doesn't revert to age 0. Pam's fruits are harvested by right-clicking.

Posted
1 minute ago, V0idWa1k3r said:

Well you should then inspect your code and actually understand what it is doing. Programming without a clear understanding of what the code does is like trying to assemble a rocket without a manual or assembly markers.

 

What behaviour do you actually want? Afaik when you break a fruit in pam's it breaks like a normal block and doesn't revert to age 0. Pam's fruits are harvested by right-clicking.

im lurning JAVA as im going along do better learning something by doing then sitting there watching/reading/taking lessens 

 

ive not used parms harvest craft since 1.5mc back then when the fruit was fully grown u punched it and it woud return to the 1st growth state (age 0) and drop its fruit

if u tryed to brake the fruit befor it was fully grown u woud still get a fruit BUT the "block" woud get destroyed

im trying to get something like that but 
1 it can only be harvested by the banana picker item
2 if u try to harvest it with anything else it will just not brake the block and send a message to the players chat (me know thats not even in my code im just trying to get part 1 working 1st) 

Posted

Override Block#removedByPlayer, it fires when the block is broken by the player. Check whether the player is holding your picker item and if they aren't send your message and return false, otherwise invoke the base implementation(return super.removedByPlayer). That is if you want it harvested by breaking the block.

 

If you want to harvest the block with a right click then do what I've said earlier:

50 minutes ago, V0idWa1k3r said:

Just override Block#onBlockActivated, check if the item in the player's hand is your item and do what you need to do.

And by "do what you need to do" in this case I mean drop the item and set the block to air.

Posted
2 hours ago, V0idWa1k3r said:

The condition will never be true

Yes it will, it's just ridiculous.

@monkeybee Just say value == 3

 

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.

Posted (edited)
14 minutes ago, Animefan8888 said:

Yes it will, it's just ridiculous.

@monkeybee Just say value == 3

 

        if (!(state.getValue(AGE) !==3)) {


Syntax error on token "=", delete this token 
 

if ureplace the ! with a 1 it says the same error but on token "1"

Edited by monkeybee
Posted
10 hours ago, monkeybee said:

im lurning JAVA as im going along do better learning something by doing then sitting there watching/reading/taking lessens 

Learning java through modding Minecraft is really painful, I suggest getting a basic understanding of java or at least OOP (Object Oriented Programming) in general first

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
8 hours ago, Cadiboo said:

Learning java through modding Minecraft is really painful, I suggest getting a basic understanding of java or at least OOP (Object Oriented Programming) in general first

the thing is as me said me learn stuff better by doing then learning minecraft is really the only thing vie got to "play about with" thats java ? 
the other stuff ive messed about with "coding" is
dont starve togeather modding (lua)
computercraft (lua)

nintendo labo (but thats more logic gate stuff so.....)

having a quick google on what OOP is .....guess nintendo labo coud be classed as that if not....mcreator did use that program befor giving up on how limmited it is to ppl who dont understand java and moving on to eclips

 

but HEY at leace ive got to the point of being able to add item blocks and custom 3d json models on my own now so baby steps XD

Posted
56 minutes ago, monkeybee said:

but HEY at leace ive got to the point of being able to add item blocks and custom 3d json models on my own now so baby steps XD

Baby steps are the right way to go. However, instead of starting off with modding minecraft you could have started off with something like a calculator or a very simple game that will teach you the basics of Java itself instead of trying to make a modification to an already existing application via an external API.

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.

Posted

ok so the thing me want to happen still aint happerning ive removed all the cote from banana picker so its just a plain item and added 

 

	public boolean onBlockActivated(NonNullList<ItemStack> drops, IBlockAccess world, EntityPlayer playerIn, BlockPos pos, IBlockState state,int fortune) {
		ItemStack itm = playerIn.getHeldItemMainhand();
		if(!itm.equals(TutorialItems.BANANA_PICKER) == true)
			return true;
			drops.add(new ItemStack(TutorialItems.BASIC_ITEM, 6));
			
			if(!itm.equals(TutorialItems.BANANA_PICKER) == false); {
				playerIn.sendMessage(new TextComponentString("cant reach that from here if only there was a banana picker"));
			return false;
			}
		
	}

to banana bunch and // out the code for itemdrop but.....it dose nothing ?

right click is doing nothing

and braking the block is making the stem drop now ima confused monkey

https://github.com/monkeybee11/monkeysmod/blob/master/src/main/java/com/monkeybee11/monkeysmod/block/BlockBananaBunch.java

Posted
2 hours ago, monkeybee said:

if(!itm.equals(TutorialItems.BANANA_PICKER) == true)

An ItemStack will never be equal to an item. Also that is not how you make a condition.

 

2 hours ago, monkeybee said:

drops.add(new ItemStack(TutorialItems.BASIC_ITEM, 6));

What is this mysterious drops object and how does it work?

 

2 hours ago, monkeybee said:

if(!itm.equals(TutorialItems.BANANA_PICKER) == false); { playerIn.sendMessage(new TextComponentString("cant reach that from here if only there was a banana picker")); return false; }

Again, this is a horrific way of making conditions. There is so much unnecessary stuff in it. Also you terminated whatever the condition was supposed to control with a ; meaning that the code in your brackets will get executed regardless.

Posted
1 hour ago, V0idWa1k3r said:

An ItemStack will never be equal to an item. Also that is not how you make a condition.

 

What is this mysterious drops object and how does it work?

 

Again, this is a horrific way of making conditions. There is so much unnecessary stuff in it. Also you terminated whatever the condition was supposed to control with a ; meaning that the code in your brackets will get executed regardless.

1 ah ok

 

2....dont know makes the itemdrop?

 

3 ive got nothing to say just trying my best :s

Posted

You should have a basic grasp of java before making a mod.

On 10/11/2018 at 1:39 AM, Animefan8888 said:

Baby steps are the right way to go. However, instead of starting off with modding minecraft you could have started off with something like a calculator or a very simple game that will teach you the basics of Java itself instead of trying to make a modification to an already existing application via an external API.

 

onBlockActivated(params...) {

  if(age==fully grown) {

    if (stack.getItem() == ModItems.BANANA_PICKER) {

      drops.add(new ItemStack(ModItems.BANANA));

    } else {

      //tell player they need to use a banana picker

    }

  }

}

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
14 hours ago, Cadiboo said:

You should have a basic grasp of java before making a mod.

now the confusing part of telling me this

ppl say that after u start but the  u have dw20 vaskii amadeus laxmanos?(think notsure) on the minecraft modded pannel at minecraft earth who say modding minecraft is a good place to start so im like.....who the heck do u baleave :s

Posted
18 minutes ago, monkeybee said:

now the confusing part of telling me this

ppl say that after u start but the  u have dw20 vaskii amadeus laxmanos?(think notsure) on the minecraft modded pannel at minecraft earth who say modding minecraft is a good place to start so im like.....who the heck do u baleave :s

Do you understand the basic concepts of Object Oriented Programming? Do you understand basic java? Minecrafts code is badly and confusingly written and forge is complicated. You should have a good basic understanding of both before starting Modding. I’ve been programming for a few years and decided to learn java through modding and it was pretty (very) hard to just jump in and learn the basics, not to mention all the special stuff and intricacies of modding. It’s possible, but you need to be receptive and read a bunch of documentation and take baby steps. 

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
1 hour ago, monkeybee said:

say modding minecraft is a good place to start

Nobody is saying that modding is a good place to start if you know nothing about programming or the language. It really isn't. Modding expects you to know quite a lot about how java functions. Minecraft isn't a good place to learn how to code in java. It's too complicated for it's own good and in a lot of cases is plain bad as in it teaches you bad practices. It is a fine place to start if you have the basics nailed down. Or at least know other programming languages which feature OOP.

Posted
1 hour ago, V0idWa1k3r said:

Nobody is saying that modding is a good place to start if you know nothing about programming or the language. It really isn't. Modding expects you to know quite a lot about how java functions. Minecraft isn't a good place to learn how to code in java. It's too complicated for it's own good and in a lot of cases is plain bad as in it teaches you bad practices. It is a fine place to start if you have the basics nailed down. Or at least know other programming languages which feature OOP.

dont want this to go off topic im just posting my sorce of ppl saying modding mc is a good place to start
and sry it wasent laxmanos it was king lemmin

 



 

Spoiler

 

but like me said dont want it to go of topic now ive posted the sorce of my info S:

 

 

image.png

Posted (edited)

Just because it worked for one person does not mean that it's:

a) a good idea

b) going to work for you

 

(Thinking otherwise is called Survivorship Bias)

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.

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.