Guide Book as advancement reward

This commit is contained in:
Aleksey 2021-01-10 00:02:29 +03:00
parent 3b96ee6307
commit 1a4cc735d2
5 changed files with 37 additions and 7 deletions

View file

@ -41,7 +41,6 @@ public class ModelLoaderMixin {
model = JsonUnbakedModel.deserialize(reader);
model.id = id.toString();
info.setReturnValue(model);
info.cancel();
} catch (Exception ex) {
String data[] = id.getPath().split("/");
if (data.length > 1) {
@ -52,7 +51,6 @@ public class ModelLoaderMixin {
Patterned patterned = (Patterned) block.get();
model = this.be_getModel(data, id, patterned);
info.setReturnValue(model);
info.cancel();
}
} else {
Optional<Item> item = Registry.ITEM.getOrEmpty(itemId);
@ -60,7 +58,6 @@ public class ModelLoaderMixin {
Patterned patterned = (Patterned) item.get();
model = this.be_getModel(data, id, patterned);
info.setReturnValue(model);
info.cancel();
}
}
}

View file

@ -43,7 +43,6 @@ public abstract class NamespaceResourceManagerMixin {
Resource stateRes = this.getResource(stateId);
resources.add(stateRes);
info.setReturnValue(resources);
info.cancel();
} catch (Exception ex) {
BetterEnd.LOGGER.catching(ex);
}

View file

@ -8,7 +8,6 @@ import org.spongepowered.asm.mixin.injection.Inject;
import org.spongepowered.asm.mixin.injection.callback.CallbackInfo;
import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable;
import net.fabricmc.fabric.api.entity.event.v1.ServerEntityWorldChangeEvents;
import net.minecraft.entity.Entity;
import net.minecraft.entity.EntityType;
import net.minecraft.server.world.ServerWorld;
@ -16,6 +15,7 @@ import net.minecraft.util.math.BlockPos;
import net.minecraft.util.math.Vec3d;
import net.minecraft.world.TeleportTarget;
import net.minecraft.world.World;
import ru.betterend.interfaces.TeleportingEntity;
@Mixin(Entity.class)
@ -74,7 +74,6 @@ public abstract class EntityMixin implements TeleportingEntity {
destination.resetIdleTimeout();
this.world.getProfiler().pop();
this.beExitPos = null;
ServerEntityWorldChangeEvents.AFTER_ENTITY_CHANGE_WORLD.invoker().afterChangeWorld(Entity.class.cast(this), entity, (ServerWorld) world, (ServerWorld) entity.world);
info.setReturnValue(entity);
info.cancel();
}

View file

@ -0,0 +1,34 @@
package ru.betterend.mixin.common;
import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.Shadow;
import org.spongepowered.asm.mixin.injection.At;
import org.spongepowered.asm.mixin.injection.Inject;
import org.spongepowered.asm.mixin.injection.At.Shift;
import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable;
import net.minecraft.advancement.Advancement;
import net.minecraft.advancement.PlayerAdvancementTracker;
import net.minecraft.item.ItemStack;
import net.minecraft.server.network.ServerPlayerEntity;
import net.minecraft.util.Identifier;
import ru.betterend.BetterEnd;
import ru.betterend.item.GuideBookItem;
@Mixin(PlayerAdvancementTracker.class)
public abstract class PlayerAdvancementTrackerMixin {
@Shadow
private ServerPlayerEntity owner;
@Inject(method = "grantCriterion", at = @At(
value = "INVOKE",
target = "Lnet/minecraft/advancement/AdvancementRewards;apply(Lnet/minecraft/server/network/ServerPlayerEntity;)V",
shift = Shift.AFTER))
public void grantBonuses(Advancement advancement, String criterionName, CallbackInfoReturnable<Boolean> info) {
Identifier advId = new Identifier("minecraft:end/enter_end_gateway");
if (BetterEnd.hasGuideBook() && advId.equals(advancement.getId())) {
this.owner.giveItemStack(new ItemStack(GuideBookItem.GUIDE_BOOK));
}
}
}

View file

@ -4,8 +4,9 @@
"package": "ru.betterend.mixin.common",
"compatibilityLevel": "JAVA_8",
"mixins": [
"ServerPlayNetworkHandlerMixin",
"EnchantmentScreenHandlerMixin",
"PlayerAdvancementTrackerMixin",
"ServerPlayNetworkHandlerMixin",
"CraftingScreenHandlerMixin",
"GenerationSettingsAccessor",
"NoiseChunkGeneratorMixin",