Skip to content

Commit

Permalink
fix: Fix registry and attribute errors in tests mocking the server pl…
Browse files Browse the repository at this point in the history
…ayer
  • Loading branch information
Steveplays28 committed Mar 14, 2024
1 parent d990c78 commit d480bfc
Show file tree
Hide file tree
Showing 8 changed files with 108 additions and 1 deletion.
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
package io.github.opencubicchunks.cubicchunks.mixin.test.common;

import com.google.common.collect.ImmutableMap;
import net.minecraft.world.entity.ai.attributes.AttributeSupplier;
import net.minecraft.world.entity.ai.attributes.DefaultAttributes;
import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.injection.At;
import org.spongepowered.asm.mixin.injection.Redirect;

@Mixin(DefaultAttributes.class)
public class MixinDefaultAttributesTest {
@Redirect(method = "<clinit>", at = @At(value = "FIELD", target = "Lnet/minecraft/world/entity/ai/attributes/DefaultAttributes;SUPPLIERS:Ljava/util/Map;", shift = At.Shift.BY, by = -1))
private static ImmutableMap<?, ?> cubic_chunks_3$fixNeoForgeRegistryError(ImmutableMap.Builder<?, ?> instance) {
return ImmutableMap.builder().build();
}

@Redirect(method = "<clinit>", at = @At(value = "INVOKE", target = "Lnet/minecraft/world/entity/LivingEntity;createLivingAttributes()Lnet/minecraft/world/entity/ai/attributes/AttributeSupplier$Builder;"))
private static AttributeSupplier.Builder cubic_chunks_3$fixNeoForgeRegistryError() {
return AttributeSupplier.builder();
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
package io.github.opencubicchunks.cubicchunks.mixin.test.common;

import net.minecraft.core.Holder;
import net.minecraft.world.entity.Entity;
import net.neoforged.neoforge.fluids.FluidType;
import org.mockito.Mockito;
import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.injection.At;
import org.spongepowered.asm.mixin.injection.Redirect;

@Mixin(Entity.class)
public abstract class MixinEntityTest {
@Redirect(method = "<init>", at = @At(value = "FIELD", target = "Lnet/minecraft/world/entity/Entity;forgeFluidTypeOnEyes:Lnet/neoforged/neoforge/fluids/FluidType;", shift = At.Shift.BY, by = -3))
private Holder<FluidType> cubic_chunks_3$fixNeoForgeRegistryError() {
return Mockito.mock();
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
package io.github.opencubicchunks.cubicchunks.mixin.test.common;

import net.minecraft.world.entity.LivingEntity;
import net.minecraft.world.entity.ai.attributes.Attribute;
import net.minecraft.world.entity.ai.attributes.AttributeSupplier;
import org.mockito.Mockito;
import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.injection.At;
import org.spongepowered.asm.mixin.injection.Inject;
import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable;

@Mixin(LivingEntity.class)
public abstract class MixinLivingEntityTest {
@Inject(method = "createLivingAttributes", at = @At(value = "HEAD"), cancellable = true)
private static void cubic_chunks_3$mockLivingAttributesInitialization(CallbackInfoReturnable<AttributeSupplier.Builder> cir) {
cir.setReturnValue(Mockito.mock());
}

@Inject(method = "getAttributeValue(Lnet/minecraft/world/entity/ai/attributes/Attribute;)D", at = @At(value = "HEAD"), cancellable = true)
private void cubic_chunks_3$fixNeoForgeErrors(Attribute pAttribute, CallbackInfoReturnable<Double> cir) {
cir.setReturnValue(1d);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
package io.github.opencubicchunks.cubicchunks.mixin.test.common;

import net.minecraft.world.entity.Mob;
import net.minecraft.world.entity.ai.attributes.AttributeSupplier;
import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.injection.At;
import org.spongepowered.asm.mixin.injection.Inject;
import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable;

@Mixin(Mob.class)
public abstract class MixinMobTest {
@Inject(method = "createMobAttributes", at = @At(value = "HEAD"), cancellable = true)
private static void cubic_chunks_3$fixNeoForgeErrors(CallbackInfoReturnable<AttributeSupplier.Builder> cir) {
cir.setReturnValue(AttributeSupplier.builder());
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
package io.github.opencubicchunks.cubicchunks.mixin.test.common;

import net.minecraft.world.entity.ai.attributes.AttributeSupplier;
import net.minecraft.world.entity.player.Player;
import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.injection.At;
import org.spongepowered.asm.mixin.injection.Inject;
import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable;

@Mixin(Player.class)
public class MixinPlayerTest {
@Inject(method = "createAttributes", at = @At(value = "HEAD"), cancellable = true)
private static void cubic_chunks_3$fixNeoForgeErrors(CallbackInfoReturnable<AttributeSupplier.Builder> cir) {
cir.setReturnValue(AttributeSupplier.builder());
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
@ParametersAreNonnullByDefault
@MethodsReturnNonnullByDefault
package io.github.opencubicchunks.cubicchunks.mixin.test.common;

import javax.annotation.ParametersAreNonnullByDefault;

import io.github.opencubicchunks.cc_core.annotation.MethodsReturnNonnullByDefault;
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
@ParametersAreNonnullByDefault
@MethodsReturnNonnullByDefault
package io.github.opencubicchunks.cubicchunks.mixin.test.common.server.level;

import javax.annotation.ParametersAreNonnullByDefault;

import io.github.opencubicchunks.cc_core.annotation.MethodsReturnNonnullByDefault;
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ private ServerPlayer setupServerPlayer(ServerLevel serverLevel) {
return new ServerPlayer(mock(RETURNS_DEEP_STUBS), serverLevel, mock(RETURNS_DEEP_STUBS), mock(RETURNS_DEEP_STUBS));
}

// TODO: Stub. This test needs a mixin from MixinEntityTest to ignore forgeFluidTypeOnEyes from NeoForge.
// TODO: Stub. This test needs a network connection to work.
@Disabled @Test public void testTeleportToVanilla() throws Exception {
try (CloseableReference<ServerLevel> serverLevelReference = setupServerLevel()) {
ServerPlayer player = setupServerPlayer(serverLevelReference.value());
Expand Down

0 comments on commit d480bfc

Please sign in to comment.