Railcraft

Railcraft

34M Downloads

Animal detector incorrectly detects Mooshrooms as Cows

McSharidan opened this issue ยท 4 comments

commented

Railcraft Version: 9.6.1.0
Minecraft Version: 1.7.10

Scenario: Using Animal Detectors to sort out stock vanilla animals: pigs, chickens, cows, mooshrooms and sheep. Random animals are picked up from a pen then transported to the sorting area which has 5 individual pens. Each of these 5 pens has it's own Animal Detector with a Disembarking Track on top of the detector. Each Animal Detector is set to only emit a redstone signal, if the correct animal is in the cart. One pen for Pigs (AD set to: Pig only). One pen for chickens (AD set to: Chicken only). One pen for cows (AD set to: Cow only). One pen for Mooshrooms (AD set to: Mooshroom only). One pen for sheep (AD set to: Sheep only). Running this scenario results in all cows and mooshrooms ending up in the Cow pen, leaving the Mooshroom pen empty.

commented

Fixed by 65af632

commented

This issue is caused by the way minecraft extends EntityCow in the EntityMooshroom class. https://github.com/CovertJaguar/Railcraft/blob/master/src/main/java/mods/railcraft/common/blocks/detector/types/DetectorAnimal.java#L53-684

} else if (cart.riddenByEntity instanceof EntityCow) {
    if (cow) {
        return FULL_POWER;
    }
} else if (cart.riddenByEntity instanceof EntityMooshroom) {
    if (mooshroom) {
        return FULL_POWER;
    }
}

As shown by the excerpt, because the cow detection is before the code for mooshroom detection, the mooshroom is triggered by the cow detection.
There's 2 ways the problem could be fixed, A: Put Mooshroom detection before Cow. Or B: Instead of instanceof, .getClass() could be used to eliminate extended class detection (but that may be intended).

CJ will make the final decision, but flipping the cow and mooshroom may be the best fix.

TLDR: instanceof detected the EntityMooshroom's extends EntityCow leading to premature detection
CJ Feel free to change this however you want (you don't need my permission), but each way kind of has its ups and downs. Realistically, this should be changed to select any entity in the game (like the villager detector)
Pull request #640

commented

Thank you for digging into this cruck1000. I don't have any personal experience modding minecraft, but I do get your fine explanation. Given how Mooshrooms are based off the Cow class, the easy fix would indeed be to move the check for Mooshrooms above the check for Cows. Like you said, ultimately it's up to Covert to decide how to implement a fix.
It's great seeing detailed explanations and good references, rather than just being thrown the usual "you're a noob" comments. Thank you cruck1000, for taking the time to write out this fine explanation - /respect.

commented

I like to provide a possible fix and an explaination for the person wondering :) Thanks