Skip to content

Commit

Permalink
Add the beesSeekRainShelter game rule
Browse files Browse the repository at this point in the history
- Closes #2.
- All game rules are now namespaced with "beeangry-est:"
  • Loading branch information
Juuxel committed Nov 21, 2019
1 parent d321d11 commit f33bb10
Show file tree
Hide file tree
Showing 4 changed files with 22 additions and 2 deletions.
4 changes: 3 additions & 1 deletion src/main/java/juuxel/bee/BeeAngryest.java
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,13 @@
import net.minecraft.util.registry.Registry;

public final class BeeAngryest implements ModInitializer {
public static final String ID = "beeangry-est";

public static final Item BEE = new BeeItem(new Item.Settings().group(ItemGroup.MISC)/*.maxCount(1)*/);
public static final Item SCOOP = new ScoopItem(new Item.Settings().group(ItemGroup.TOOLS).maxDamage(100));

public static Identifier id(String path) {
return new Identifier("beeangry-est", path);
return new Identifier(ID, path);
}

@Override
Expand Down
3 changes: 2 additions & 1 deletion src/main/java/juuxel/bee/BeeGameRules.java
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
public final class BeeGameRules {
public static GameRules.RuleKey<GameRules.BooleanRule> SAVE_SCOOPED_BEE_NBT = register("saveScoopedBeeNbt", true);
public static GameRules.RuleKey<GameRules.BooleanRule> ALWAYS_DROP_SCOOPED_BEES = register("alwaysDropScoopedBees", true);
public static GameRules.RuleKey<GameRules.BooleanRule> BEES_SEEK_RAIN_SHELTER = register("beesSeekRainShelter", true);

private BeeGameRules() {}

Expand All @@ -15,6 +16,6 @@ public static void init() {
}

private static GameRules.RuleKey<GameRules.BooleanRule> register(String name, boolean defaultValue) {
return GameRulesAccessor.callRegister(name, BooleanRuleAccessor.callOf(defaultValue));
return GameRulesAccessor.callRegister(BeeAngryest.ID + ":" + name, BooleanRuleAccessor.callOf(defaultValue));
}
}
16 changes: 16 additions & 0 deletions src/main/java/juuxel/bee/mixin/BeeEntityMixin.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package juuxel.bee.mixin;

import juuxel.bee.BeeGameRules;
import net.minecraft.entity.Entity;
import net.minecraft.entity.EntityType;
import net.minecraft.entity.passive.AnimalEntity;
Expand All @@ -10,6 +11,7 @@
import org.spongepowered.asm.mixin.Unique;
import org.spongepowered.asm.mixin.injection.At;
import org.spongepowered.asm.mixin.injection.Inject;
import org.spongepowered.asm.mixin.injection.Redirect;
import org.spongepowered.asm.mixin.injection.callback.CallbackInfo;
import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable;

Expand All @@ -33,4 +35,18 @@ private void onTryAttack(Entity entity, CallbackInfoReturnable<Boolean> info) {
private void onMobTick(CallbackInfo info) {
world.createExplosion(this, getX(), getY(), getZ(), BEE_EXPLOSION_STRENGTH, Explosion.DestructionType.DESTROY);
}

@Redirect(method = "canEnterHive", at = @At(value = "INVOKE", target = "Lnet/minecraft/world/World;isRaining()Z", ordinal = 0))
private boolean redirectIsRaining(World world) {
return world.isRaining() && world.getGameRules().getBoolean(BeeGameRules.BEES_SEEK_RAIN_SHELTER);
}

@Mixin(targets = "net.minecraft.entity.passive.BeeEntity$PollinateGoal")
static class PollinateGoalMixin {
@SuppressWarnings("InvalidMemberReference")
@Redirect(method = {"canBeeStart", "canBeeContinue"}, at = @At(value = "INVOKE", target = "Lnet/minecraft/world/World;isRaining()Z", ordinal = 0))
private boolean redirectIsRaining(World world) {
return world.isRaining() && world.getGameRules().getBoolean(BeeGameRules.BEES_SEEK_RAIN_SHELTER);
}
}
}
1 change: 1 addition & 0 deletions src/main/resources/mixins.beeangryest.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
"compatibilityLevel": "JAVA_8",
"mixins": [
"BeeEntityMixin",
"BeeEntityMixin$PollinateGoalMixin",
"BooleanRuleAccessor",
"CriterionsAccessor",
"CriterionsMixin",
Expand Down

0 comments on commit f33bb10

Please sign in to comment.