Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix #10 and #12 #14

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

SnowyStarfall
Copy link

Fixes crash from spawning naturally. Fixes crash from spawning via dispenser

SoldierDollEntity.java

 public ITeam getTeam() {
        // Prevent null reference crashes by defaulting to clay team
        if(team == null) {
            return CLAY_TEAM.get();
        }

        return team;
    }

DollDispenserBehavior.java

...

// Get and set team properly when spawning from dispenser
var team = doll.getTeam(stack);
if (e instanceof SoldierDollEntity soldier)
{
        soldier.setTeam(team);
}

world.playSound(null, pos, SoundEvents.BLOCK_GRAVEL_BREAK, SoundCategory.BLOCKS, 1.0F, 1.0F);
world.emitGameEvent(GameEvent.ENTITY_PLACE, spawnPos, GameEvent.Emitter.of(e));
// Decrement stack properly
stack.decrement(1);

...

SpawnDollItem.java

...

// Code was here
// itemStack.decrement(1);
// world.emitGameEvent(context.getPlayer(), GameEvent.ENTITY_PLACE, blockPos);
// world.playSound(context.getPlayer(), blockPos, SoundEvents.BLOCK_GRAVEL_BREAK, SoundCategory.BLOCKS, 1.f, 1.f);

var team = doll.getTeam(stack);
if (entity instanceof SoldierDollEntity soldier) {
        soldier.setTeam(team);
}

// Moved to here to prevent using potentially empty stack to determine team
itemStack.decrement(1);
world.emitGameEvent(context.getPlayer(), GameEvent.ENTITY_PLACE, blockPos);
world.playSound(context.getPlayer(), blockPos, SoundEvents.BLOCK_GRAVEL_BREAK, SoundCategory.BLOCKS, 1.f, 1.f);
                
...

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant