Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
import com.simibubi.create.content.contraptions.behaviour.MovementContext;
import dev.ryanhcode.sable.ActiveSableCompanion;
import dev.ryanhcode.sable.Sable;
import dev.ryanhcode.sable.neoforge.mixinhelper.compatibility.create.behavior_compatibility.harvester_block_entity.DummyMovementContext;
import net.minecraft.core.BlockPos;
import org.spongepowered.asm.mixin.Mixin;

Expand All @@ -15,14 +16,15 @@ public class HarvesterMovementBehaviourMixin {
@SuppressWarnings("ResultOfMethodCallIgnored")
@WrapMethod(method = "visitNewPosition")
public void sable$checkAllPositions(final MovementContext context, final BlockPos pos, final Operation<Void> original) {
if (context != null) {
final ActiveSableCompanion helper = Sable.HELPER;
helper.runIncludingSubLevels(context.world, pos.getCenter(), true, helper.getContaining(context.contraption.entity), (sublevel, blockPos) -> {
original.call(context, blockPos);
return null;
});
} else {
original.call(null, pos);
if (context instanceof DummyMovementContext) {
original.call(context, pos);
return;
}

final ActiveSableCompanion helper = Sable.HELPER;
helper.runIncludingSubLevels(context.world, pos.getCenter(), true, helper.getContaining(context.contraption.entity), (sublevel, blockPos) -> {
original.call(context, blockPos);
return null;
});
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -7,18 +7,16 @@
import dev.ryanhcode.sable.api.block.BlockEntitySubLevelActor;
import dev.ryanhcode.sable.companion.math.JOMLConversion;
import dev.ryanhcode.sable.neoforge.mixinhelper.compatibility.create.harvester.HarvesterLerpedSpeed;
import dev.ryanhcode.sable.neoforge.mixinhelper.compatibility.create.harvester.HarvesterMovementBehaviourExtension;
import dev.ryanhcode.sable.neoforge.mixinhelper.compatibility.create.harvester.HarvesterTicker;
import dev.ryanhcode.sable.sublevel.ServerSubLevel;
import net.createmod.catnip.animation.LerpedFloat;
import net.minecraft.core.BlockPos;
import net.minecraft.core.Position;
import net.minecraft.world.level.block.entity.BlockEntityType;
import net.minecraft.world.level.block.state.BlockState;
import net.minecraft.world.phys.Vec3;
import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.Unique;

import static dev.ryanhcode.sable.neoforge.mixinhelper.compatibility.create.harvester.HarvesterTicker.blockEntityBehaviour;

@Mixin(HarvesterBlockEntity.class)
public abstract class HarvesterBlockEntityMixin extends CachedRenderBBBlockEntity implements HarvesterLerpedSpeed, BlockEntitySubLevelActor {

Expand Down Expand Up @@ -46,30 +44,23 @@ public HarvesterBlockEntityMixin(final BlockEntityType<?> type, final BlockPos p
@Override
public void sable$tick(final ServerSubLevel subLevel) {
final ActiveSableCompanion helper = Sable.HELPER;
final Vec3 center = this.getBlockPos().getCenter();
BlockPos gatheredPos = helper.runIncludingSubLevels(this.getLevel(), center, false, helper.getContaining(this), (sublevel, pos) -> {
if (blockEntityBehaviour.isValidCrop(this.getLevel(), pos, this.getLevel().getBlockState(pos))) {
final Position center = this.getBlockPos().getCenter();
BlockPos gatheredPos = helper.runIncludingSubLevels(this.level, center, false, helper.getContaining(this), (sublevel, pos) -> {
if (HarvesterTicker.blockEntityBehaviour.isValidCrop(this.level, pos, this.level.getBlockState(pos))) {
return pos;
} else {
return null;
}

return null;
});

if (gatheredPos == null) {
gatheredPos = BlockPos.containing(helper.projectOutOfSubLevel(this.getLevel(), center));
gatheredPos = BlockPos.containing(helper.projectOutOfSubLevel(this.level, center));
}

if (!this.sable$previousPos.equals(gatheredPos)) {
this.sable$previousPos = gatheredPos;

final HarvesterMovementBehaviourExtension duck = (HarvesterMovementBehaviourExtension) blockEntityBehaviour;
duck.sable$setManualLevel(this.getLevel());
duck.sable$setSelfPos(this.getBlockPos());

blockEntityBehaviour.visitNewPosition(null, this.sable$previousPos);

duck.sable$setManualLevel(null);
duck.sable$setSelfPos(null);
HarvesterTicker.dummyMovementContext.update(this.level, this.getBlockPos(), this.getBlockState(), null);
HarvesterTicker.blockEntityBehaviour.visitNewPosition(HarvesterTicker.dummyMovementContext, this.sable$previousPos);
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,64 +4,19 @@
import com.llamalad7.mixinextras.injector.wrapoperation.WrapOperation;
import com.simibubi.create.content.contraptions.actors.harvester.HarvesterMovementBehaviour;
import com.simibubi.create.content.contraptions.behaviour.MovementContext;
import dev.ryanhcode.sable.neoforge.mixinhelper.compatibility.create.harvester.HarvesterMovementBehaviourExtension;
import dev.ryanhcode.sable.neoforge.mixinhelper.compatibility.create.behavior_compatibility.harvester_block_entity.DummyMovementContext;
import dev.ryanhcode.sable.neoforge.mixinhelper.compatibility.create.harvester.HarvesterTicker;
import net.minecraft.core.BlockPos;
import net.minecraft.world.item.ItemStack;
import net.minecraft.world.level.Level;
import org.objectweb.asm.Opcodes;
import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.Unique;
import org.spongepowered.asm.mixin.injection.At;
import org.spongepowered.asm.mixin.injection.Redirect;

import java.lang.ref.Reference;
import java.lang.ref.WeakReference;

@Mixin(HarvesterMovementBehaviour.class)
public class HarvesterBlockEntityUsageMixin implements HarvesterMovementBehaviourExtension {

@Unique
private Reference<Level> sable$manualLevel;

@Unique
private BlockPos sable$selfPos = null;

@Override
public BlockPos sable$getSelfPos() {
return this.sable$selfPos;
}

@Override
public void sable$setSelfPos(final BlockPos sable$selfPos) {
this.sable$selfPos = sable$selfPos;
}

@Override
public Level sable$getManualLevel() {
return this.sable$manualLevel.get();
}

@Override
public void sable$setManualLevel(final Level level) {
this.sable$manualLevel = new WeakReference<>(level);
}

@Redirect(method = "visitNewPosition", at = @At(value = "FIELD", target = "Lcom/simibubi/create/content/contraptions/behaviour/MovementContext;world:Lnet/minecraft/world/level/Level;", opcode = Opcodes.GETFIELD))
public Level sable$replaceWorld(final MovementContext instance) {
if (instance == null) { // we're only going to be passing in null from our mixin, so this is valid
return this.sable$getManualLevel();
} else {
return instance.world;
}
}
public class HarvesterBlockEntityUsageMixin {

@WrapOperation(method = "lambda$visitNewPosition$0", at = @At(value = "INVOKE", target = "Lcom/simibubi/create/content/contraptions/actors/harvester/HarvesterMovementBehaviour;collectOrDropItem(Lcom/simibubi/create/content/contraptions/behaviour/MovementContext;Lnet/minecraft/world/item/ItemStack;)V"))
public void sable$replaceDropItem(final HarvesterMovementBehaviour instance, final MovementContext movementContext, final ItemStack itemStack, final Operation<Void> original) {
if (movementContext == null) {
if (this.sable$getManualLevel() != null && this.sable$getSelfPos() != null) {
HarvesterTicker.dropItem(this.sable$getManualLevel(), itemStack, this.sable$getSelfPos());
}
if (movementContext instanceof DummyMovementContext) {
HarvesterTicker.dropItem(movementContext.world, itemStack, movementContext.localPos);
} else {
original.call(instance, movementContext, itemStack);
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
package dev.ryanhcode.sable.neoforge.mixinhelper.compatibility.create.behavior_compatibility.harvester_block_entity;

import com.simibubi.create.content.contraptions.behaviour.MovementContext;
import net.minecraft.core.BlockPos;
import net.minecraft.nbt.CompoundTag;
import net.minecraft.world.level.Level;
import net.minecraft.world.level.block.Blocks;
import net.minecraft.world.level.block.state.BlockState;
import net.minecraft.world.level.levelgen.structure.templatesystem.StructureTemplate;
import org.jetbrains.annotations.Nullable;

public class DummyMovementContext extends MovementContext {

public DummyMovementContext() {
super(null, new StructureTemplate.StructureBlockInfo(BlockPos.ZERO, Blocks.AIR.defaultBlockState(), null), null);
}

public void update(final Level level, final BlockPos pos, final BlockState state, @Nullable final CompoundTag blockEntityData) {
this.world = level;
this.state = state;
this.localPos = pos;
this.blockEntityData = blockEntityData;
}
}

This file was deleted.

Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package dev.ryanhcode.sable.neoforge.mixinhelper.compatibility.create.harvester;

import com.simibubi.create.content.contraptions.actors.harvester.HarvesterMovementBehaviour;
import dev.ryanhcode.sable.neoforge.mixinhelper.compatibility.create.behavior_compatibility.harvester_block_entity.DummyMovementContext;
import net.minecraft.core.BlockPos;
import net.minecraft.world.entity.item.ItemEntity;
import net.minecraft.world.item.ItemStack;
Expand All @@ -13,6 +14,7 @@
public class HarvesterTicker<T extends BlockEntity & HarvesterLerpedSpeed> implements BlockEntityTicker<T> {

public static final HarvesterMovementBehaviour blockEntityBehaviour = new HarvesterMovementBehaviour();
public static final DummyMovementContext dummyMovementContext = new DummyMovementContext();

@Override
public void tick(final Level level, final BlockPos arg2, final BlockState arg3, final T be) {
Expand Down
Loading