Jump to content

[1.6.4] How to override a super class method when you are calling said method


skullywag

Recommended Posts

Hi all,

 

Couldnt fit what I wanted in the title so apologies about the vagueness.

 

My issue is im trying to make a version of zombies that dont burn in sunlight, so I have extended the EntityZombie Class and overriden the method that does the burning, however in this same method is a call to the super.method which is in EntityZombie and obviously DOES contain the burning code. Now i need the stuff further up the chain in the supers so but would like to basically bypass the EntityZombie method and go straight to EntityMob, am I missing something fundementally simple here or am i going to have create a whole new Entity for this?

Link to comment
Share on other sites

Hi

 

I am told by experts that there is no way in Java to call super.super.method.

 

Which means that if you want to call EntityMob.method directly, you're out of luck.  You will either need to copy the code from EntityMob.method into your own Entity (which might not work if it accesses any private variables or methods), or derive from EntityMob instead.  (Copy the EntityZombie code into your own Entity).

 

-TGG

Link to comment
Share on other sites

Duplicate the zombie.  Name it something else.  Done.

 

You have encountered the failing of the Object Inheritance Pattern.

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.

Link to comment
Share on other sites

Ok i kind of have it working, had to make copy:

 

EntityZombie

RenderEntityZombie

EntityZombieGroupData

EntityZombieINNER1

ZombieEvent

 

This gets me no fire in daylight, brilliant! however, all custom zombies are zombie villagers...*sigh*...nerd world problems....ill have a play for a bit see if i cant backtrace why this is happening and post a new thread if I get nowhere.

 

edit - nope i derped, all is well. I accidentally deleted an IF so it was setting villager to TRUE all the time.....

Link to comment
Share on other sites

Yeah, you have to copy the render stuff too.  Like I said, failing of the Object Inheritance Model.

 

You might be interested in this topic.

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.

Link to comment
Share on other sites

Hi

 

To be honest, I don't think it's a failing of the Object inheritance model, it's a feature.  OO is all about encapsulation and preventing you from having to know the details of how an object is written, and allowing you to make changes to objects without breaking all your existing code.  Inheritance is intended for the situation when your derived class can always be substituted for the base class(es), and it should not be possible to violate this by ignoring what the super class says.  The problem in the case of the Zombie is that the vanilla code has been designed with the two incompatible assumptions that all zombies burn in sunlight, and that only zombies can call to each other for aid.  That's not a failing of the inheritance model, that's a design decision.

 

I do agree that there's a tendency for folks to use inheritance when they should use something else such as interfaces or composition. 

 

-TGG

Link to comment
Share on other sites

I do agree that there's a tendency for folks to use inheritance when they should use something else such as interfaces or composition.

 

Mob behavior should probably be the latter, not the former.

 

I was able to, however, implement some version of composition on top of the Item system.  My last count (which was an estimation anyway) was 67 million combinations allowable.

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.

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.



  • Recently Browsing

    • No registered users viewing this page.
  • Posts

    • I have: Minecraft.getInstance().player.sendChatMessage(command); but im getting an error saying: Cannot resolve method 'sendChatMessage' in 'LocalPlayer':49 Now, I know what this error means, but I have no clue how to fix it. I am knew to java and forge modding. I was thinking maybe it was an import issue? here are all my imports:   import net.minecraft.client.Minecraft; import net.minecraftforge.common.MinecraftForge; import net.minecraftforge.event.entity.player.PlayerEvent; import net.minecraftforge.eventbus.api.SubscribeEvent; import net.minecraftforge.fml.common.Mod; import net.minecraftforge.client.event.ClientChatEvent; import org.apache.logging.log4j.LogManager; import org.apache.logging.log4j.Logger; import java.util.Timer; import java.util.TimerTask;     Does anybody know the solution?
    • ROTER88 : Waspada Situs Scam dengan Withdraw Tidak Dibayar Di era digital saat ini, banyak orang yang mencari keberuntungan melalui situs perjudian online. Namun, dibalik gemerlap janji-janji manis kemenangan, ada bahaya yang mengintai. Salah satu situs yang patut diwaspadai adalah ROTER88. Situs ini mendapat reputasi buruk karena banyak laporan dari pengguna yang mengklaim bahwa mereka tidak bisa menarik dana kemenangan mereka. Dalam artikel ini, kita akan membahas mengapa ROTER88 dianggap sebagai situs scam dan bagaimana Anda bisa melindungi diri dari penipuan serupa. Pengalaman Pengguna: Penarikan Tidak Dibayar Beberapa pengguna telah melaporkan pengalaman buruk mereka dengan ROTER88. Mereka mengaku bahwa setelah memenangkan sejumlah uang dan mencoba menariknya, proses penarikan mereka ditolak tanpa alasan yang jelas. Bahkan, beberapa pengguna melaporkan bahwa akun mereka tiba-tiba diblokir setelah mencoba melakukan penarikan, sehingga mereka kehilangan akses ke dana mereka sama sekali.
    • Hello! Im trying to get biome on player's position, if the player is in desert biome the variable "temperature" should increase but it doesn't. am i missing something? package net.mcreator.drowningbelow.procedures; import net.minecraftforge.fml.common.Mod; import net.minecraftforge.eventbus.api.SubscribeEvent; import net.minecraftforge.eventbus.api.Event; import net.minecraftforge.event.TickEvent; import net.minecraft.world.entity.player.Player; import net.minecraft.world.entity.Entity; import net.minecraft.network.chat.Component; import net.minecraft.resources.ResourceLocation; import net.mcreator.drowningbelow.network.DrowningbelowModVariables; import javax.annotation.Nullable; import net.minecraft.world.level.LevelAccessor; import net.minecraft.core.BlockPos; import net.minecraft.world.level.Level; import net.minecraft.client.Minecraft; import net.minecraftforge.fml.loading.moddiscovery.MinecraftLocator; import net.minecraft.server.MinecraftServer; import net.minecraft.world.level.biome.Biome; import java.io.Console; @Mod.EventBusSubscriber public class TemperaturaProcedure { private static final int TICKS_INTERVAL = 60; // 60 ticks = 3 segundos private static int tickCounter = 0; private static final int TICK_BIOME_INTERVAL = 60; private static int tickBiomeCounter = 0; @SubscribeEvent public static void onPlayerTick(TickEvent.PlayerTickEvent event) { if (event.phase == TickEvent.Phase.END) { tickCounter++; tickBiomeCounter++; if (tickCounter >= TICKS_INTERVAL) { tickCounter = 0; checkAndUpdateTemperature(event.player); } if (tickBiomeCounter >= TICK_BIOME_INTERVAL) { tickBiomeCounter = 0; execute(event, event.player.level(), event.player); } displayTemperature(event.player); } } private static void checkAndUpdateTemperature(Entity entity) { if (entity == null) return; if (entity.isInWaterRainOrBubble()) { double newTemperature = (entity.getCapability(DrowningbelowModVariables.PLAYER_VARIABLES_CAPABILITY, null) .orElse(new DrowningbelowModVariables.PlayerVariables())).Temperatura - 2; entity.getCapability(DrowningbelowModVariables.PLAYER_VARIABLES_CAPABILITY, null).ifPresent(capability -> { capability.Temperatura = newTemperature; capability.syncPlayerVariables(entity); }); } } private static void displayTemperature(Entity entity) { if (entity == null) return; if (entity instanceof Player _player && !_player.level().isClientSide()) { double temperatura = (entity.getCapability(DrowningbelowModVariables.PLAYER_VARIABLES_CAPABILITY, null) .orElse(new DrowningbelowModVariables.PlayerVariables())).Temperatura; _player.displayClientMessage(Component.literal("\u00A76\u00A7l\u2600\u00A7e\u00A7l Temperatura \u00A76\u00A7l\u2600 \u00A7e\u00A7l" + temperatura + "\u00B0"), true); } } private static void execute(@Nullable Event event, LevelAccessor world, Entity entity) { System.out.println("Esto si se mando 2"); if (world.getBiome(BlockPos.containing(entity.getX(), entity.getY(), entity.getX())).is(new ResourceLocation("desert"))) { System.out.println("Esto si se mando 3"); double _setval = (entity.getCapability(DrowningbelowModVariables.PLAYER_VARIABLES_CAPABILITY, null).orElse(new DrowningbelowModVariables.PlayerVariables())).Temperatura + 2; entity.getCapability(DrowningbelowModVariables.PLAYER_VARIABLES_CAPABILITY, null).ifPresent(capability -> { capability.Temperatura = _setval; capability.syncPlayerVariables(entity); }); System.out.println("Esto si se mando 4"); } } }  
    • Also, before he disconnects this appears on the log:  [18:07:30] [Render thread/WARN]: Failed to get file path of mod fastpaintings: / 2648[18:07:30] [Render thread/WARN]: Failed to get file path of mod moonlight: / 2649[18:07:30] [Render thread/WARN]: Failed to get file path of mod dummmmmmy: / 2650[18:07:30] [Render thread/WARN]: Failed to get file path of mod amendments: / 2651[18:07:30] [Render thread/WARN]: Failed to get file path of mod supplementaries: / Does this have anything to do with the error?
  • Topics

×
×
  • Create New...

Important Information

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