Skip to content

Commit

Permalink
Merge pull request #814 from mrsterner/1.18.x/main
Browse files Browse the repository at this point in the history
Important fix for latest create
  • Loading branch information
ThePlasticPotato authored Apr 16, 2024
2 parents 88d9088 + 62ca22c commit 2d1e1cd
Show file tree
Hide file tree
Showing 6 changed files with 79 additions and 12 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,6 @@
"mod_compat.create.block.MixinRedstoneContactBlock",
"mod_compat.create.block.MixinStickerBlock",
"mod_compat.create.blockentity.IMixinMechanicalBearingTileEntity",
"mod_compat.create.blockentity.MixinChuteBlockEntity",
"mod_compat.create.blockentity.MixinCrushingWheelControllerTileEntity",
"mod_compat.create.blockentity.MixinEjectorTileEntity",
"mod_compat.create.blockentity.MixinEncasedFanTileEntity",
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package org.valkyrienskies.mod.mixin.mod_compat.create.blockentity;
package org.valkyrienskies.mod.fabric.mixin.compat.create;

import com.llamalad7.mixinextras.sugar.Local;
import com.simibubi.create.content.logistics.chute.ChuteBlockEntity;
import net.minecraft.core.BlockPos;
import net.minecraft.world.entity.item.ItemEntity;
Expand All @@ -13,20 +14,21 @@
import org.spongepowered.asm.mixin.injection.At.Shift;
import org.spongepowered.asm.mixin.injection.Inject;
import org.spongepowered.asm.mixin.injection.callback.CallbackInfo;
import org.spongepowered.asm.mixin.injection.callback.LocalCapture;
import org.valkyrienskies.core.api.ships.ServerShip;
import org.valkyrienskies.mod.common.VSGameUtilsKt;
import org.valkyrienskies.mod.mixin.mod_compat.create.accessors.ChuteBlockEntityAccessor;

@Mixin(ChuteBlockEntity.class)
@Mixin(value = ChuteBlockEntity.class, remap = false)
public class MixinChuteBlockEntity {
@Inject(method = "findEntities", at = @At(value = "INVOKE", target = "Lnet/minecraft/world/phys/AABB;<init>(Lnet/minecraft/world/phys/Vec3;Lnet/minecraft/world/phys/Vec3;)V", shift = Shift.AFTER), locals = LocalCapture.CAPTURE_FAILHARD, cancellable = true, remap = false)
private void preFindEntities(float itemSpeed, CallbackInfo ci, Vec3 center) {
if (((ChuteBlockEntity) (Object) this).getLevel() != null) {

final ChuteBlockEntity be = (ChuteBlockEntity) (Object) this;
@Inject(method = "findEntities", at = @At(value = "INVOKE", target = "Lnet/minecraft/world/phys/AABB;<init>(Lnet/minecraft/world/phys/Vec3;Lnet/minecraft/world/phys/Vec3;)V", shift = Shift.AFTER), cancellable = true)
private void preFindEntities(float itemSpeed, CallbackInfo ci, @Local Vec3 center) {
ChuteBlockEntity be = ChuteBlockEntity.class.cast(this);

if (be.getLevel() != null) {

final ChuteBlockEntityAccessor bea = (ChuteBlockEntityAccessor) be;
Level level = ((ChuteBlockEntity) (Object) this).getLevel();
Level level = be.getLevel();

BlockPos pos = be.getBlockPos();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
"compat.cc_restitched.MixinWirelessNetwork",
"compat.create.MixinBlockBreakingKineticTileEntity",
"compat.create.MixinBlocks",
"compat.create.MixinChuteBlockEntity",
"compat.create.MixinControlledContraptionEntity",
"compat.create.client.MixinTrackBlockOutline",
"compat.sodium.MixinRenderSectionManager",
Expand Down
3 changes: 2 additions & 1 deletion forge/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,8 @@ configurations {
}

dependencies {
include(forgeRuntimeLibrary(annotationProcessor(implementation("com.github.LlamaLad7:MixinExtras:0.1.1"))))
compileOnly(annotationProcessor("io.github.llamalad7:mixinextras-common:0.3.5"))
implementation(include("io.github.llamalad7:mixinextras-forge:0.3.5"))


forge "net.minecraftforge:forge:${rootProject.forge_version}"
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
package org.valkyrienskies.mod.forge.mixin.compat.create;

import com.llamalad7.mixinextras.sugar.Local;
import com.simibubi.create.content.logistics.chute.ChuteBlockEntity;
import net.minecraft.core.BlockPos;
import net.minecraft.world.entity.item.ItemEntity;
import net.minecraft.world.item.ItemStack;
import net.minecraft.world.level.Level;
import net.minecraft.world.phys.AABB;
import net.minecraft.world.phys.Vec3;
import org.joml.Vector3d;
import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.injection.At;
import org.spongepowered.asm.mixin.injection.At.Shift;
import org.spongepowered.asm.mixin.injection.Inject;
import org.spongepowered.asm.mixin.injection.callback.CallbackInfo;
import org.valkyrienskies.core.api.ships.ServerShip;
import org.valkyrienskies.mod.common.VSGameUtilsKt;
import org.valkyrienskies.mod.mixin.mod_compat.create.accessors.ChuteBlockEntityAccessor;

@Mixin(value = ChuteBlockEntity.class, remap = false)
public class MixinChuteBlockEntity {

@Inject(method = "findEntities", at = @At(value = "INVOKE", target = "Lnet/minecraft/world/phys/AABB;<init>(Lnet/minecraft/world/phys/Vec3;Lnet/minecraft/world/phys/Vec3;)V", shift = Shift.AFTER), cancellable = true)
private void preFindEntities(float itemSpeed, CallbackInfo ci, @Local Vec3 center) {
ChuteBlockEntity be = ChuteBlockEntity.class.cast(this);

if (be.getLevel() != null) {

final ChuteBlockEntityAccessor bea = (ChuteBlockEntityAccessor) be;
Level level = be.getLevel();

BlockPos pos = be.getBlockPos();

AABB searchArea = new AABB(center.add(0, -bea.getBottomPullDistance() - 0.5, 0), center.add(0, -0.5, 0)).inflate(.45f);

if (VSGameUtilsKt.getShipObjectManagingPos(level, pos) instanceof ServerShip ship) {
Vector3d searchAreaMin = new Vector3d(searchArea.minX, searchArea.minY, searchArea.minZ);
Vector3d searchAreaMax = new Vector3d(searchArea.maxX, searchArea.maxY, searchArea.maxZ);

Vector3d searchAreaReturnMin = new Vector3d();
Vector3d searchAreaReturnMax = new Vector3d();

ship.getTransform().getShipToWorld().transformAab(searchAreaMin, searchAreaMax, searchAreaReturnMin, searchAreaReturnMax);

searchArea = new AABB(searchAreaReturnMin.x, searchAreaReturnMin.y, searchAreaReturnMin.z, searchAreaReturnMax.x, searchAreaReturnMax.y, searchAreaReturnMax.z);

for (ItemEntity itemEntity : level.getEntitiesOfClass(ItemEntity.class, searchArea)) {
if (!itemEntity.isAlive())
continue;
ItemStack entityItem = itemEntity.getItem();
if (!bea.callCanAcceptItem(entityItem))
continue;
be.setItem(entityItem.copy(), (float) (itemEntity.getBoundingBox()
.getCenter().y - be.getBlockPos().getY()));
itemEntity.discard();
break;
}
ci.cancel();
}
}
}
}
5 changes: 3 additions & 2 deletions forge/src/main/resources/valkyrienskies-forge.mixins.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,13 +10,14 @@
"compat.cc_tweaked.MixinWirelessNetwork",
"compat.create.MixinBlockBreakingKineticTileEntity",
"compat.create.MixinBlocks",
"compat.create.MixinChuteBlockEntity",
"compat.create.MixinControlledContraptionEntity",
"compat.immersivengineering.MixinBlockEntityInventory",
"compat.mekanism.MixinRadiationManager",
"compat.modular_routers.MixinContainerModularRouter",
"compat.tfc.MixinTFCChunkGenerator",
"compat.thermalexpansion.MixinTileCoFH",
"compat.tis3d.MixinInfraredPacketEntity",
"compat.modular_routers.MixinContainerModularRouter",
"compat.mekanism.MixinRadiationManager",
"feature.forge_interact.MixinIForgePlayer",
"world.level.block.FireMixin"
],
Expand Down

0 comments on commit 2d1e1cd

Please sign in to comment.