Skip to content

Commit

Permalink
Fix Warp+Bore lens breaking force relays
Browse files Browse the repository at this point in the history
(fixes #4225)
  • Loading branch information
TheRealWormbo committed Apr 29, 2024
1 parent 7c3d64a commit 9229fc8
Show file tree
Hide file tree
Showing 6 changed files with 117 additions and 13 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -50,9 +50,11 @@ public boolean collideBurst(ManaBurst burst, HitResult rtr, boolean isManaBlock,
BlockState state = world.getBlockState(collidePos);

ItemStack composite = ((LensItem) stack.getItem()).getCompositeLens(stack);
boolean warp = !composite.isEmpty() && composite.is(BotaniaItems.lensWarp);
boolean warpItems = !composite.isEmpty() && composite.is(BotaniaItems.lensWarp);
ItemStack sourceLens = burst.getSourceLens();
boolean canWarp = warpItems || sourceLens.is(BotaniaItems.lensWarp);

if (warp && (state.is(BotaniaBlocks.pistonRelay) || state.is(Blocks.PISTON) || state.is(Blocks.MOVING_PISTON) || state.is(Blocks.PISTON_HEAD))) {
if (canWarp && (state.is(BotaniaBlocks.pistonRelay) || state.is(Blocks.PISTON) || state.is(Blocks.MOVING_PISTON) || state.is(Blocks.PISTON_HEAD))) {
return false;
}

Expand All @@ -78,7 +80,7 @@ && canHarvest(harvestLevel, state)
}

boolean sourceless = source.equals(ManaBurst.NO_SOURCE);
boolean doWarp = warp && !sourceless;
boolean doWarp = warpItems && !sourceless;
Vec3 dropPosition;
if (doWarp && world.getBlockEntity(source) instanceof ManaSpreaderBlockEntity spreader) {
Vec3 sourceVec = Vec3.atCenterOf(source);
Expand Down
13 changes: 13 additions & 0 deletions Xplat/src/main/java/vazkii/botania/test/TestingUtil.java
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
import net.minecraft.gametest.framework.GameTestHelper;
import net.minecraft.world.InteractionHand;
import net.minecraft.world.entity.player.Player;
import net.minecraft.world.item.Item;
import net.minecraft.world.item.ItemStack;
import net.minecraft.world.item.context.UseOnContext;
import net.minecraft.world.level.block.entity.BlockEntity;
Expand All @@ -26,7 +27,9 @@
import org.jetbrains.annotations.Nullable;

import vazkii.botania.common.block.ForceRelayBlock;
import vazkii.botania.common.block.block_entity.BotaniaBlockEntities;
import vazkii.botania.common.item.BotaniaItems;
import vazkii.botania.common.item.lens.LensItem;

import java.util.Objects;
import java.util.function.Supplier;
Expand Down Expand Up @@ -130,4 +133,14 @@ public static BlockPos getBoundForceRelayTarget(GameTestHelper helper, BlockPos
var data = ForceRelayBlock.WorldData.get(helper.getLevel());
return data.mapping.get(helper.absolutePos(relayPos));
}

public static void setUpSpreaderAndCompositeLens(GameTestHelper helper, Item firstLensType, Item secondLensType, BlockPos spreaderPos, BlockPos spreaderTargetPos) {
final var firstLensStack = new ItemStack(firstLensType);
final var secondLensStack = new ItemStack(secondLensType);
final var compositeLens = ((LensItem) firstLensStack.getItem()).setCompositeLens(firstLensStack, secondLensStack);
final var spreaderEntity = assertBlockEntity(helper, spreaderPos, BotaniaBlockEntities.SPREADER);
spreaderEntity.getItemHandler().setItem(0, compositeLens);

bindWithWandOfTheForest(helper, spreaderPos, spreaderTargetPos);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
package vazkii.botania.test.item.lens;

import net.minecraft.core.BlockPos;
import net.minecraft.gametest.framework.GameTest;
import net.minecraft.gametest.framework.GameTestHelper;
import net.minecraft.world.item.Item;
import net.minecraft.world.item.Items;
import net.minecraft.world.level.block.ButtonBlock;
import net.minecraft.world.level.block.state.BlockState;

import vazkii.botania.common.block.BotaniaBlocks;
import vazkii.botania.common.item.BotaniaItems;
import vazkii.botania.test.TestingUtil;

public class BoreWarpLensTest {
private static final String TEMPLATE = "botania:item/lens/bore_warp_relay_interaction";

private static final BlockPos SPREADER_POS = new BlockPos(2, 2, 1);
private static final BlockPos SPREADER_TARGET_POS = new BlockPos(5, 2, 1);
private static final BlockPos BUTTON_POS = new BlockPos(2, 3, 2);
private static final BlockPos RELAY_POS = new BlockPos(4, 2, 1);
private static final BlockPos BOUND_POS = new BlockPos(1, 2, 4);
private static final BlockPos TARGET_BLOCK_POS = new BlockPos(3, 2, 4);
private static final BlockPos UNWARPED_HOPPER_POS = new BlockPos(3, 1, 4);
private static final BlockPos WARPED_HOPPER_POS = new BlockPos(1, 1, 1);

@GameTest(template = TEMPLATE, timeoutTicks = 25)
public void testWarpBoreLens(GameTestHelper helper) {
setUpLensesAndBindings(helper, BotaniaItems.lensWarp, BotaniaItems.lensMine);

helper.startSequence()
.thenExecuteAfter(1, () -> helper.pressButton(BUTTON_POS))
.thenWaitUntil(() -> helper.assertBlockProperty(BUTTON_POS, ButtonBlock.POWERED, false))
.thenExecute(() -> {
helper.assertBlock(RELAY_POS, block -> block == BotaniaBlocks.pistonRelay, "Force relay was broken");
helper.assertBlockState(TARGET_BLOCK_POS, BlockState::isAir, () -> "Target block was not broken");
helper.assertContainerContains(UNWARPED_HOPPER_POS, Items.POLISHED_ANDESITE);
helper.assertContainerEmpty(WARPED_HOPPER_POS);
})
.thenSucceed();
}

@GameTest(template = TEMPLATE, timeoutTicks = 25)
public void testBoreWarpLens(GameTestHelper helper) {
setUpLensesAndBindings(helper, BotaniaItems.lensMine, BotaniaItems.lensWarp);

helper.startSequence()
.thenExecuteAfter(1, () -> helper.pressButton(BUTTON_POS))
.thenWaitUntil(() -> helper.assertBlockProperty(BUTTON_POS, ButtonBlock.POWERED, false))
.thenExecute(() -> {
helper.assertBlock(RELAY_POS, block -> block == BotaniaBlocks.pistonRelay, "Force relay was broken");
helper.assertBlockState(TARGET_BLOCK_POS, BlockState::isAir, () -> "Target block was not broken");
helper.assertContainerEmpty(UNWARPED_HOPPER_POS);
helper.assertContainerContains(WARPED_HOPPER_POS, Items.POLISHED_ANDESITE);
})
.thenSucceed();
}

private static void setUpLensesAndBindings(GameTestHelper helper, Item firstLensType, Item secondLensType) {
TestingUtil.setUpSpreaderAndCompositeLens(helper, firstLensType, secondLensType, SPREADER_POS, SPREADER_TARGET_POS);
TestingUtil.bindForceRelayTarget(helper, RELAY_POS, BOUND_POS);
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -4,15 +4,12 @@
import net.minecraft.gametest.framework.GameTest;
import net.minecraft.gametest.framework.GameTestHelper;
import net.minecraft.world.item.Item;
import net.minecraft.world.item.ItemStack;
import net.minecraft.world.level.block.Blocks;
import net.minecraft.world.level.block.ButtonBlock;
import net.minecraft.world.level.block.state.BlockState;

import vazkii.botania.common.block.BotaniaBlocks;
import vazkii.botania.common.block.block_entity.BotaniaBlockEntities;
import vazkii.botania.common.item.BotaniaItems;
import vazkii.botania.common.item.lens.LensItem;
import vazkii.botania.test.TestingUtil;

public class WarpForceTest {
Expand Down Expand Up @@ -96,13 +93,7 @@ public void testForceWarpLens(GameTestHelper helper) {
}

private static void setUpLensesAndBindings(GameTestHelper helper, Item firstLensType, Item secondLensType) {
final var warpLensStack = new ItemStack(firstLensType);
final var forceLensStack = new ItemStack(secondLensType);
final var compositeLens = ((LensItem) warpLensStack.getItem()).setCompositeLens(warpLensStack, forceLensStack);
final var spreaderEntity = TestingUtil.assertBlockEntity(helper, SPREADER_POS, BotaniaBlockEntities.SPREADER);
spreaderEntity.getItemHandler().setItem(0, compositeLens);

TestingUtil.bindWithWandOfTheForest(helper, SPREADER_POS, SPREADER_TARGET_POS);
TestingUtil.setUpSpreaderAndCompositeLens(helper, firstLensType, secondLensType, SPREADER_POS, SPREADER_TARGET_POS);
TestingUtil.bindForceRelayTarget(helper, RELAY_POS, BOUND_POS);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
{
DataVersion: 3465,
size: [6, 4, 6],
data: [
{pos: [1, 0, 1], state: "minecraft:hopper{enabled:true,facing:north}"},
{pos: [3, 0, 4], state: "minecraft:hopper{enabled:true,facing:north}"},
{pos: [2, 1, 1], state: "botania:redstone_spreader{has_scaffolding:false,waterlogged:false}"},
{pos: [2, 1, 2], state: "botania:creative_pool{color:none,waterlogged:false}"},
{pos: [2, 1, 3], state: "minecraft:air"},
{pos: [2, 1, 4], state: "minecraft:air"},
{pos: [2, 1, 5], state: "minecraft:air"},
{pos: [3, 1, 0], state: "minecraft:air"},
{pos: [3, 1, 1], state: "minecraft:air"},
{pos: [3, 1, 2], state: "minecraft:air"},
{pos: [3, 1, 3], state: "minecraft:air"},
{pos: [3, 1, 4], state: "minecraft:polished_andesite"},
{pos: [4, 1, 1], state: "botania:piston_relay"},
{pos: [5, 1, 1], state: "botania:mana_void"},
{pos: [5, 1, 4], state: "botania:mana_void"},
{pos: [2, 2, 1], state: "minecraft:polished_andesite"},
{pos: [2, 2, 2], state: "minecraft:polished_blackstone_button{face:wall,facing:south,powered:false}"}
],
entities: [],
palette: [
"minecraft:polished_andesite",
"botania:piston_relay",
"botania:mana_void",
"minecraft:polished_blackstone_button{face:wall,facing:south,powered:false}",
"minecraft:hopper{enabled:true,facing:north}",
"botania:redstone_spreader{has_scaffolding:false,waterlogged:false}",
"botania:creative_pool{color:none,waterlogged:false}"
]
}
1 change: 1 addition & 0 deletions web/changelog.md
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ and start a new "Upcoming" section.
* Fix: Fake player detection for the gaia fight has been improved, so you no longer get extra loot for e.g. a nearby running RFTools builder
* Fix: The Cirrus and Nimbus amulets got math lessons and should be able to properly count the number of mid-air jumps now
* Fix: Botania advancement tab and root advancement title
* Fix: Warp+Bore bursts can now teleport via a force relay without breaking it
* Language updates:
* ko_kr completed (Tareun3406)
* uk_ua added (fasero1)
Expand Down

0 comments on commit 9229fc8

Please sign in to comment.