use of org.spongepowered.asm.mixin.injection.Redirect in project SpongeCommon by SpongePowered.
the class MixinBlockStateContainer method setFixedBlockState.
/**
* @author barteks2x
*
* Attempts to fix invalid block metadata instead of completely throwing away the block.
* When block state lookup returns null - gets block by ID and attempts to use the default state.
*/
@Redirect(method = "setDataFromNBT", at = @At(value = "INVOKE", target = "Lnet/minecraft/world/chunk/BlockStateContainer;set(ILnet/minecraft/block/state/IBlockState;)V"))
private void setFixedBlockState(BlockStateContainer this_, int i, IBlockState state, byte[] id, NibbleArray meta, @Nullable NibbleArray add) {
IBlockState newState;
if (state != null) {
newState = state;
} else {
int x = i & 15;
int y = i >> 8 & 15;
int z = i >> 4 & 15;
int idAdd = add == null ? 0 : add.get(x, y, z);
int blockId = idAdd << 8 | (id[i] & 255);
Block block = Block.REGISTRY.getObjectById(blockId);
if (block != null) {
newState = block.getDefaultState();
} else {
newState = null;
}
}
this.set(i, newState);
}
use of org.spongepowered.asm.mixin.injection.Redirect in project SpongeCommon by SpongePowered.
the class MixinWorldGenDungeons method onSetEntityName.
@Redirect(method = "generate", at = @At(value = "INVOKE", target = "Lnet/minecraft/tileentity/MobSpawnerBaseLogic;setEntityId(Lnet/minecraft/util/ResourceLocation;)V"))
public void onSetEntityName(MobSpawnerBaseLogic logic, ResourceLocation mobName) {
if (this.data != null) {
// Use custom spawner data
SpawnerUtils.applyData(logic, this.data);
return;
}
if (this.choices != null) {
// Use custom choices
WeightedTable<EntityArchetype> choices = this.getChoices().get();
EntityArchetype entity = choices.get(logic.getSpawnerWorld().rand).stream().findFirst().orElse(null);
if (entity == null) {
// No choices to choose from? Use default instead.
return;
}
SpawnerUtils.setNextEntity(logic, new WeightedSerializableObject<>(entity, 1));
return;
}
// Just use the given mobName
logic.setEntityId(mobName);
}
use of org.spongepowered.asm.mixin.injection.Redirect in project SpongeCommon by SpongePowered.
the class MixinPlayerAdvancements method onUnregisterListenersGetProgress.
@Redirect(method = "registerListeners(Lnet/minecraft/advancements/Advancement;)V", at = @At(value = "INVOKE", ordinal = 0, target = "Lnet/minecraft/advancements/CriterionProgress;isObtained()Z"))
private boolean onUnregisterListenersGetProgress(CriterionProgress progress) {
final AdvancementCriterion criterion = ((org.spongepowered.api.advancement.criteria.CriterionProgress) progress).getCriterion();
final IMixinCriterion mixinCriterion = (IMixinCriterion) criterion;
// Only remove the trigger once the goal is reached
if (mixinCriterion.getScoreCriterion() != null) {
return ((IMixinCriterionProgress) progress).getAdvancementProgress().get(mixinCriterion.getScoreCriterion()).get().achieved();
}
return progress.isObtained();
}
use of org.spongepowered.asm.mixin.injection.Redirect in project SpongeCommon by SpongePowered.
the class MixinSaveHandler method spongeReadPlayerData.
/**
* Redirects the reader such that since the player file existed already, we can safely assume
* we can grab the file attributes and check if the first join time exists in the sponge compound,
* if it does not, then we add it to the sponge data part of the compound.
*
* @param inputStream The input stream to direct to compressed stream tools
* @return The compound that may be modified
* @throws IOException
*/
@Redirect(method = READ_PLAYER_DATA, at = @At(value = "INVOKE", target = COMPRESSED_READ_FILE))
private NBTTagCompound spongeReadPlayerData(InputStream inputStream) throws IOException {
Instant creation = this.file == null ? Instant.now() : Files.readAttributes(this.file, BasicFileAttributes.class).creationTime().toInstant();
NBTTagCompound compound = CompressedStreamTools.readCompressed(inputStream);
Instant lastPlayed = Instant.now();
// first try to migrate bukkit join data stuff
if (compound.hasKey(NbtDataUtil.BUKKIT, NbtDataUtil.TAG_COMPOUND)) {
final NBTTagCompound bukkitCompound = compound.getCompoundTag(NbtDataUtil.BUKKIT);
creation = Instant.ofEpochMilli(bukkitCompound.getLong(NbtDataUtil.BUKKIT_FIRST_PLAYED));
lastPlayed = Instant.ofEpochMilli(bukkitCompound.getLong(NbtDataUtil.BUKKIT_LAST_PLAYED));
}
UUID playerId = null;
if (compound.hasUniqueId(NbtDataUtil.UUID)) {
playerId = compound.getUniqueId(NbtDataUtil.UUID);
}
if (playerId != null) {
Optional<Instant> savedFirst = SpongePlayerDataHandler.getFirstJoined(playerId);
if (savedFirst.isPresent()) {
creation = savedFirst.get();
}
Optional<Instant> savedJoined = SpongePlayerDataHandler.getLastPlayed(playerId);
if (savedJoined.isPresent()) {
lastPlayed = savedJoined.get();
}
SpongePlayerDataHandler.setPlayerInfo(playerId, creation, lastPlayed);
}
this.file = null;
return compound;
}
use of org.spongepowered.asm.mixin.injection.Redirect in project SpongeCommon by SpongePowered.
the class MixinCommandScoreboard method onGetUUIDLeave.
@Redirect(method = "leaveTeam", at = @At(value = "INVOKE", target = ITERATOR_NEXT, ordinal = 0, remap = false))
private Object onGetUUIDLeave(Iterator<Entity> iterator) {
Entity entity = iterator.next();
this.onGetUUID(entity);
return entity;
}
Aggregations