mirror of
https://github.com/GTNewHorizons/Botania.git
synced 2026-11-17 19:05:16 +00:00
Advancement: That's Why I Baked Bread
Context: Issue 2403, and https://www.nicovideo.jp/watch/sm33746095
This commit is contained in:
1 parent
b3ac525569
commit
6346da980e
6 files changed
+160
-4
No files matched your search
@@ -38,6 +38,7 @@ import vazkii.botania.api.item.IExoflameHeatable;
|
||||
import vazkii.botania.api.item.IFloatingFlower;
|
||||
import vazkii.botania.client.core.proxy.ClientProxy;
|
||||
import vazkii.botania.common.advancements.AlfPortalTrigger;
|
||||
import vazkii.botania.common.advancements.AlfPortalBreadTrigger;
|
||||
import vazkii.botania.common.advancements.CorporeaRequestTrigger;
|
||||
import vazkii.botania.common.advancements.LokiPlaceTrigger;
|
||||
import vazkii.botania.common.advancements.ManaGunTrigger;
|
||||
@@ -215,6 +216,7 @@ public class Botania {
|
||||
CriteriaTriggers.register(UseItemSuccessTrigger.INSTANCE);
|
||||
CriteriaTriggers.register(ManaGunTrigger.INSTANCE);
|
||||
CriteriaTriggers.register(LokiPlaceTrigger.INSTANCE);
|
||||
CriteriaTriggers.register(AlfPortalBreadTrigger.INSTANCE);
|
||||
|
||||
CraftingHelper.register(FluxfieldCondition.SERIALIZER);
|
||||
|
||||
|
||||
@@ -0,0 +1,112 @@
|
||||
package vazkii.botania.common.advancements;
|
||||
|
||||
import com.google.gson.JsonDeserializationContext;
|
||||
import com.google.gson.JsonObject;
|
||||
import net.minecraft.advancements.ICriterionInstance;
|
||||
import net.minecraft.advancements.ICriterionTrigger;
|
||||
import net.minecraft.advancements.PlayerAdvancements;
|
||||
import net.minecraft.advancements.criterion.LocationPredicate;
|
||||
import net.minecraft.entity.player.ServerPlayerEntity;
|
||||
import net.minecraft.util.ResourceLocation;
|
||||
import net.minecraft.util.math.BlockPos;
|
||||
import net.minecraft.world.server.ServerWorld;
|
||||
import vazkii.botania.common.lib.LibMisc;
|
||||
|
||||
import javax.annotation.Nonnull;
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
import java.util.HashSet;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
|
||||
public class AlfPortalBreadTrigger implements ICriterionTrigger<AlfPortalBreadTrigger.Instance> {
|
||||
public static final ResourceLocation ID = new ResourceLocation(LibMisc.MOD_ID, "alf_portal_bread");
|
||||
public static final AlfPortalBreadTrigger INSTANCE = new AlfPortalBreadTrigger();
|
||||
private final Map<PlayerAdvancements, AlfPortalBreadTrigger.PlayerTracker> playerTrackers = new HashMap<>();
|
||||
|
||||
private AlfPortalBreadTrigger() {}
|
||||
|
||||
@Nonnull
|
||||
@Override
|
||||
public ResourceLocation getId() {
|
||||
return ID;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void addListener(@Nonnull PlayerAdvancements player, @Nonnull ICriterionTrigger.Listener<AlfPortalBreadTrigger.Instance> listener) {
|
||||
this.playerTrackers.computeIfAbsent(player, AlfPortalBreadTrigger.PlayerTracker::new).listeners.add(listener);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void removeListener(@Nonnull PlayerAdvancements player, @Nonnull ICriterionTrigger.Listener<AlfPortalBreadTrigger.Instance> listener) {
|
||||
AlfPortalBreadTrigger.PlayerTracker tracker = this.playerTrackers.get(player);
|
||||
|
||||
if(tracker != null) {
|
||||
tracker.listeners.remove(listener);
|
||||
|
||||
if(tracker.listeners.isEmpty()) {
|
||||
this.playerTrackers.remove(player);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void removeAllListeners(@Nonnull PlayerAdvancements player) {
|
||||
playerTrackers.remove(player);
|
||||
}
|
||||
|
||||
@Nonnull
|
||||
@Override
|
||||
public AlfPortalBreadTrigger.Instance deserializeInstance(@Nonnull JsonObject json, @Nonnull JsonDeserializationContext context) {
|
||||
return new AlfPortalBreadTrigger.Instance(LocationPredicate.deserialize(json.get("portal_location")));
|
||||
}
|
||||
|
||||
static class PlayerTracker {
|
||||
private final PlayerAdvancements playerAdvancements;
|
||||
final Set<Listener<AlfPortalBreadTrigger.Instance>> listeners = new HashSet<>();
|
||||
|
||||
PlayerTracker(PlayerAdvancements playerAdvancementsIn) {
|
||||
this.playerAdvancements = playerAdvancementsIn;
|
||||
}
|
||||
|
||||
public void trigger(ServerWorld world, BlockPos portal) {
|
||||
List<Listener<AlfPortalBreadTrigger.Instance>> list = new ArrayList<>();
|
||||
|
||||
for(ICriterionTrigger.Listener<AlfPortalBreadTrigger.Instance> listener : this.listeners) {
|
||||
if(listener.getCriterionInstance().test(world, portal)) {
|
||||
list.add(listener);
|
||||
}
|
||||
}
|
||||
|
||||
for(ICriterionTrigger.Listener<AlfPortalBreadTrigger.Instance> listener : list) {
|
||||
listener.grantCriterion(this.playerAdvancements);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public void trigger(ServerPlayerEntity player, BlockPos portal) {
|
||||
AlfPortalBreadTrigger.PlayerTracker tracker = playerTrackers.get(player.getAdvancements());
|
||||
if(tracker != null) {
|
||||
tracker.trigger(player.getServerWorld(), portal);
|
||||
}
|
||||
}
|
||||
|
||||
static class Instance implements ICriterionInstance {
|
||||
private final LocationPredicate portal;
|
||||
|
||||
Instance(LocationPredicate portal) {
|
||||
this.portal = portal;
|
||||
}
|
||||
|
||||
@Nonnull
|
||||
@Override
|
||||
public ResourceLocation getId() {
|
||||
return ID;
|
||||
}
|
||||
|
||||
boolean test(ServerWorld world, BlockPos portal) {
|
||||
return this.portal.test(world, portal.getX(), portal.getY(), portal.getZ());
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -12,6 +12,8 @@ package vazkii.botania.common.block.tile;
|
||||
|
||||
import net.minecraft.block.BlockState;
|
||||
import net.minecraft.entity.item.ItemEntity;
|
||||
import net.minecraft.entity.player.PlayerEntity;
|
||||
import net.minecraft.entity.player.ServerPlayerEntity;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.item.Items;
|
||||
import net.minecraft.nbt.CompoundNBT;
|
||||
@@ -32,6 +34,7 @@ import vazkii.botania.api.recipe.RecipeElvenTrade;
|
||||
import vazkii.botania.api.state.BotaniaStateProps;
|
||||
import vazkii.botania.api.state.enums.AlfPortalState;
|
||||
import vazkii.botania.client.fx.WispParticleData;
|
||||
import vazkii.botania.common.advancements.AlfPortalBreadTrigger;
|
||||
import vazkii.botania.common.block.ModBlocks;
|
||||
import vazkii.botania.common.block.mana.BlockPool;
|
||||
import vazkii.botania.common.block.tile.mana.TilePool;
|
||||
@@ -43,9 +46,11 @@ import vazkii.patchouli.api.IMultiblock;
|
||||
import vazkii.patchouli.api.PatchouliAPI;
|
||||
|
||||
import javax.annotation.Nonnull;
|
||||
import javax.annotation.Nullable;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.Optional;
|
||||
import java.util.UUID;
|
||||
|
||||
public class TileAlfPortal extends TileMod implements ITickableTileEntity {
|
||||
|
||||
@@ -77,6 +82,8 @@ public class TileAlfPortal extends TileMod implements ITickableTileEntity {
|
||||
private int ticksSinceLastItem = 0;
|
||||
private boolean closeNow = false;
|
||||
private boolean explode = false;
|
||||
@Nullable
|
||||
private UUID breadPlayer = null;
|
||||
|
||||
public TileAlfPortal() {
|
||||
super(TYPE);
|
||||
@@ -124,7 +131,7 @@ public class TileAlfPortal extends TileMod implements ITickableTileEntity {
|
||||
|
||||
if (consume) {
|
||||
item.remove();
|
||||
if (validateItemUsage(stack))
|
||||
if (validateItemUsage(item))
|
||||
addItem(stack);
|
||||
ticksSinceLastItem = 0;
|
||||
}
|
||||
@@ -149,17 +156,29 @@ public class TileAlfPortal extends TileMod implements ITickableTileEntity {
|
||||
world.createExplosion(null, pos.getX() + .5, pos.getY() + 2.0, pos.getZ() + .5,
|
||||
3f, Explosion.Mode.DESTROY);
|
||||
explode = false;
|
||||
|
||||
if (!world.isRemote && breadPlayer != null) {
|
||||
PlayerEntity entity = world.getPlayerByUuid(breadPlayer);
|
||||
if (entity instanceof ServerPlayerEntity) {
|
||||
AlfPortalBreadTrigger.INSTANCE.trigger((ServerPlayerEntity) entity, getPos());
|
||||
}
|
||||
}
|
||||
breadPlayer = null;
|
||||
}
|
||||
}
|
||||
|
||||
private boolean validateItemUsage(ItemStack inputStack) {
|
||||
private boolean validateItemUsage(ItemEntity entity) {
|
||||
ItemStack inputStack = entity.getItem();
|
||||
for(RecipeElvenTrade recipe : BotaniaAPI.elvenTradeRecipes.values()) {
|
||||
if(recipe.containsItem(inputStack)) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
if(inputStack.getItem() == Items.BREAD) //Don't teleport bread. (See also: #2403)
|
||||
if(inputStack.getItem() == Items.BREAD) {
|
||||
//Don't teleport bread. (See also: #2403)
|
||||
explode = true;
|
||||
breadPlayer = entity.getThrowerId();
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user