Skip to content

Commit

Permalink
chore: merge upstream for api cleanup
Browse files Browse the repository at this point in the history
Signed-off-by: Gabriel Harris-Rouquette <[email protected]>
  • Loading branch information
gabizou committed Oct 12, 2024
2 parents 805eb43 + 49fad39 commit 29e4beb
Show file tree
Hide file tree
Showing 8 changed files with 303 additions and 221 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
/*
* This file is part of Sponge, licensed under the MIT License (MIT).
*
* Copyright (c) SpongePowered <https://www.spongepowered.org>
* Copyright (c) contributors
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
* THE SOFTWARE.
*/
package org.spongepowered.common.accessor.world.level.block;

import net.minecraft.resources.ResourceKey;
import net.minecraft.world.level.block.Block;
import net.minecraft.world.level.block.StemBlock;
import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.gen.Accessor;

@Mixin(StemBlock.class)
public interface StemBlockAccessor {

@Accessor("fruit") ResourceKey<Block> accessor$fruit();

@Accessor("attachedStem") ResourceKey<Block> accessor$attachedStem();
}
423 changes: 212 additions & 211 deletions src/accessors/resources/mixins.sponge.accessors.json

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
Expand Up @@ -53,9 +53,14 @@ public AddBlockEventTransaction(final SpongeBlockSnapshot original, final Tracka
this.original = original;
}

@Override
protected boolean actualBlockTransaction() {
return false;
}

@Override
protected SpongeBlockSnapshot getResultingSnapshot() {
return this.getOriginalSnapshot();
throw new UnsupportedOperationException();
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,9 +52,14 @@ public ScheduleUpdateTransaction(final SpongeBlockSnapshot original, final Sched
this.original = original;
}

@Override
protected boolean actualBlockTransaction() {
return false;
}

@Override
protected SpongeBlockSnapshot getResultingSnapshot() {
return this.getOriginalSnapshot();
throw new UnsupportedOperationException();
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,10 +24,21 @@
*/
package org.spongepowered.common.event.tracking.phase.tick;

import net.minecraft.core.Registry;
import net.minecraft.core.registries.Registries;
import net.minecraft.world.level.Level;
import net.minecraft.world.level.block.Block;
import net.minecraft.world.level.block.Blocks;
import net.minecraft.world.level.block.BonemealableBlock;
import net.minecraft.world.level.block.BushBlock;
import net.minecraft.world.level.block.CactusBlock;
import net.minecraft.world.level.block.ChorusFlowerBlock;
import net.minecraft.world.level.block.ChorusPlantBlock;
import net.minecraft.world.level.block.StemBlock;
import net.minecraft.world.level.block.SugarCaneBlock;
import net.minecraft.world.level.block.state.BlockState;
import org.checkerframework.checker.nullness.qual.Nullable;
import org.spongepowered.common.accessor.world.level.block.StemBlockAccessor;
import org.spongepowered.common.event.tracking.PhaseTracker;
import org.spongepowered.common.event.tracking.TrackingUtil;
import org.spongepowered.common.world.BlockChange;
Expand Down Expand Up @@ -56,13 +67,26 @@ public BlockChange associateBlockChangeWithSnapshot(
final BlockState currentState
) {
final Block newBlock = newState.getBlock();
if (phaseContext.tickingBlock instanceof BonemealableBlock) {
if (newBlock == Blocks.AIR) {
return BlockChange.BREAK;
}
if (newBlock instanceof BonemealableBlock || newState.ignitedByLava()) {
if (newBlock == Blocks.AIR) {
return BlockChange.BREAK;
} else if (phaseContext.tickingBlock instanceof BonemealableBlock) {
if (newBlock instanceof BonemealableBlock) {
return BlockChange.GROW;
} else if (phaseContext.tickingBlock instanceof final StemBlock stemBlock) {
final Registry<Block> registry = ((Level) phaseContext.world).registryAccess().registryOrThrow(Registries.BLOCK);
final @Nullable Block fruitBlock = registry.get(((StemBlockAccessor) stemBlock).accessor$fruit());
final @Nullable Block attachedStemBlock = registry.get(((StemBlockAccessor) stemBlock).accessor$attachedStem());
if (newBlock == fruitBlock || newBlock == attachedStemBlock) {
return BlockChange.GROW;
}
}
} else if ((phaseContext.tickingBlock instanceof BushBlock ||
phaseContext.tickingBlock instanceof SugarCaneBlock ||
phaseContext.tickingBlock instanceof CactusBlock) && (Block) phaseContext.tickingBlock == newBlock) {
return BlockChange.GROW;
} else if (phaseContext.tickingBlock instanceof ChorusFlowerBlock &&
(newBlock instanceof ChorusFlowerBlock || newBlock instanceof ChorusPlantBlock)) {
return BlockChange.GROW;
}
return super.associateBlockChangeWithSnapshot(phaseContext, newState, currentState);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@
import org.spongepowered.api.registry.RegistryHolder;
import org.spongepowered.api.registry.RegistryTypes;
import org.spongepowered.api.util.transformation.Transformation;
import org.spongepowered.api.world.BlockChangeFlag;
import org.spongepowered.api.world.BlockChangeFlags;
import org.spongepowered.api.world.biome.Biome;
import org.spongepowered.api.world.schematic.Palette;
Expand Down Expand Up @@ -264,6 +265,13 @@ public ArchetypeVolume transform(final Transformation transformation) {
@Override
public void applyToWorld(
final ServerWorld target, final Vector3i placement, final Supplier<SpawnType> spawnContext
) {
this.applyToWorld(target, placement, spawnContext, BlockChangeFlags.DEFAULT_PLACEMENT);
}

@Override
public void applyToWorld(
final ServerWorld target, final Vector3i placement, final Supplier<SpawnType> spawnContext, final BlockChangeFlag flag
) {
Objects.requireNonNull(target, "Target world cannot be null");
Objects.requireNonNull(placement, "Target position cannot be null");
Expand All @@ -276,7 +284,7 @@ public void applyToWorld(
.apply(VolumeCollectors.of(
target,
VolumePositionTranslators.relativeTo(placement),
VolumeApplicators.applyBlocks(BlockChangeFlags.DEFAULT_PLACEMENT)
VolumeApplicators.applyBlocks(flag)
));

this.biomeStream(this.min(), this.max(), StreamOptions.lazily())
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ public abstract class IngredientMixin_API {
}

public boolean ingredient$test(final ItemStackLike itemStack) {
return this.shadow$test(ItemStackUtil.toNative(itemStack.asMutable()));
return this.shadow$test(ItemStackUtil.fromLikeToNative(itemStack));
}

}

0 comments on commit 29e4beb

Please sign in to comment.