net.minecraft.world.GameRules Java Examples

The following examples show how to use net.minecraft.world.GameRules. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: LivingEntityMixin.java    From the-hallow with MIT License 6 votes vote down vote up
@Inject(method = "drop(Lnet/minecraft/entity/damage/DamageSource;)V", at = @At("HEAD"))
public void drop(DamageSource damageSource, CallbackInfo info) {
	LivingEntity livingEntity = (LivingEntity) (Object) this;
	if (damageSource.getSource() instanceof LivingEntity && livingEntity.world.getGameRules().getBoolean(GameRules.DO_MOB_LOOT) && BeheadingEnchantment.hasBeheading((LivingEntity) damageSource.getSource())) {
		if (BeheadingEnchantment.getHead(damageSource)) {
			if (livingEntity.getType() == EntityType.WITHER_SKELETON) {
				livingEntity.dropStack(new ItemStack(Items.WITHER_SKELETON_SKULL));
			} else if (livingEntity.getType() == EntityType.SKELETON) {
				livingEntity.dropStack(new ItemStack(Items.SKELETON_SKULL));
			} else if (livingEntity.getType() == EntityType.ZOMBIE) {
				livingEntity.dropStack(new ItemStack(Items.ZOMBIE_HEAD));
			} else if (livingEntity.getType() == EntityType.CREEPER) {
				livingEntity.dropStack(new ItemStack(Items.CREEPER_HEAD));
			} else if (livingEntity.getType() == EntityType.PLAYER) {
				livingEntity.dropStack(new ItemStack(Items.PLAYER_HEAD));
			}
		}
	}
}
 
Example #2
Source File: EatBreadcrumbsGoal.java    From the-hallow with MIT License 5 votes vote down vote up
@Override
public boolean canStart() {
	if (!this.stepAndDestroyMob.world.getGameRules().getBoolean(GameRules.MOB_GRIEFING)) {
		return false;
	} else if (this.cooldown > 0) {
		--this.cooldown;
		return false;
	} else if (this.hasAvailableTarget()) {
		this.cooldown = 20;
		return true;
	} else {
		this.cooldown = this.getInterval(this.mob);
		return false;
	}
}
 
Example #3
Source File: HallowedInfestedBlock.java    From the-hallow with MIT License 5 votes vote down vote up
@Override
public void onStacksDropped(BlockState state, World world, BlockPos pos, ItemStack stack) {
	if (!world.isClient && world.getGameRules().getBoolean(GameRules.DO_TILE_DROPS) && EnchantmentHelper.getLevel(Enchantments.SILK_TOUCH, stack) == 0) {
		EndermiteEntity endermite = (EndermiteEntity) EntityType.ENDERMITE.create(world);
		endermite.updatePositionAndAngles(pos.getX() + 0.5D, pos.getY(), pos.getZ() + 0.5D, 0.0F, 0.0F);
		world.spawnEntity(endermite);
		endermite.playSpawnEffects();
	}
}
 
Example #4
Source File: LivingEntity_maxCollisionsMixin.java    From fabric-carpet with MIT License 5 votes vote down vote up
@Inject(method = "tickCramming", cancellable = true, at = @At("HEAD"))
private void tickPushingReplacement(CallbackInfo ci)
{
    List<Entity> list_1 = this.world.getEntities((Entity)this, this.getBoundingBox(), EntityPredicates.canBePushedBy(this));
    if (!list_1.isEmpty()) {
        int int_1 = this.world.getGameRules().getInt(GameRules.MAX_ENTITY_CRAMMING);
        int int_2;
        if (int_1 > 0 && list_1.size() > int_1 - 1 && this.random.nextInt(4) == 0) {
            int_2 = 0;

            for(int int_3 = 0; int_3 < list_1.size(); ++int_3) {
                if (!((Entity)list_1.get(int_3)).hasVehicle()) {
                    ++int_2;
                }
            }

            if (int_2 > int_1 - 1) {
                this.damage(DamageSource.CRAMMING, 6.0F);
            }
        }

        int limit = list_1.size();
        if (CarpetSettings.maxEntityCollisions > 0)
            limit = Math.min(limit, CarpetSettings.maxEntityCollisions);

        for(int_2 = 0; int_2 < limit; ++int_2) {
            Entity entity_1 = (Entity)list_1.get(int_2);
            this.pushAway(entity_1);
        }
    }
    ci.cancel();
}
 
Example #5
Source File: WorldMixin_RealTime.java    From Galaxy with GNU Affero General Public License v3.0 5 votes vote down vote up
@Inject(method = "tickTime", at = @At("HEAD"))
private void realTimeImpl$fixTimeOfDayForRealTime(CallbackInfo ci) {
    if (this.properties.getGameRules().getBoolean(GameRules.DO_DAYLIGHT_CYCLE)) {
        // Subtract the one the original tick method is going to add
        long diff = this.realTimeBridge$getRealTimeTicks() - 1;
        // Don't set if we're not changing it as other mods might be listening for changes
        if (diff > 0) {
            this.method_29199(this.properties.getTimeOfDay() + diff);
        }
    }
}
 
Example #6
Source File: CyberwareDataHandler.java    From Cyberware with MIT License 5 votes vote down vote up
@SubscribeEvent
public void worldLoad(WorldEvent.Load event)
{
	GameRules rules = event.getWorld().getGameRules();
	if(!rules.hasRule(KEEP_WARE_GAMERULE))
	{
		rules.addGameRule(KEEP_WARE_GAMERULE, Boolean.toString(CyberwareConfig.DEFAULT_KEEP), ValueType.BOOLEAN_VALUE);
	}
	if(!rules.hasRule(DROP_WARE_GAMERULE))
	{
		rules.addGameRule(DROP_WARE_GAMERULE, Boolean.toString(CyberwareConfig.DEFAULT_DROP), ValueType.BOOLEAN_VALUE);
	}
}
 
Example #7
Source File: EventHandlerWorld.java    From Gadomancy with GNU Lesser General Public License v3.0 5 votes vote down vote up
@SubscribeEvent(priority = EventPriority.NORMAL)
public void on(WorldEvent.Load e) {
    if (!e.world.isRemote && e.world.provider.dimensionId == 0) {
        Gadomancy.loadModData();

        GolemEnumHelper.validateSavedMapping();
        GolemEnumHelper.reorderEnum();

        TCMazeHandler.init();
    }

    GameRules rules = e.world.getGameRules();
    rules.theGameRules.put("mobGriefing", new ValueOverride(this, String.valueOf(rules.getGameRuleBooleanValue("mobGriefing"))));
}