Skip to content
Open
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
13 changes: 10 additions & 3 deletions src/main/java/xyz/nucleoid/bedwars/custom/BridgeEggEntity.java
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,8 @@ public class BridgeEggEntity extends EggEntity {

private final BlockState trailBlock;

public BridgeEggEntity(World world, LivingEntity thrower, BlockState trailBlock) {
super(world, thrower, new ItemStack(Items.EGG));
public BridgeEggEntity(World world, LivingEntity thrower, ItemStack stack, BlockState trailBlock) {
super(world, thrower, stack);
this.trailBlock = trailBlock;
}

Expand Down Expand Up @@ -56,11 +56,18 @@ private void tryPlaceAt(BlockPos pos) {
protected void onCollision(HitResult hitResult) {
// ignore self-collisions
if (hitResult.getType() == HitResult.Type.BLOCK) {
if (this.getWorld().getBlockState(((BlockHitResult) hitResult).getBlockPos()) == this.trailBlock) {
var pos = ((BlockHitResult) hitResult).getBlockPos();
var state = this.getWorld().getBlockState(pos);

if (isTrailBlock(state, pos)) {
return;
}
}

super.onCollision(hitResult);
}

public boolean isTrailBlock(BlockState state, BlockPos pos) {
return state == this.trailBlock;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -172,8 +172,7 @@ private ActionResult onUseBridgeEgg(ServerPlayerEntity player, ItemStack stack)
BlockState state = ColoredBlocks.wool(team.config().blockDyeColor()).getDefaultState();

// Spawn egg
BridgeEggEntity eggEntity = new BridgeEggEntity(this.world, player, state);
eggEntity.setItem(stack);
BridgeEggEntity eggEntity = new BridgeEggEntity(this.world, player, stack, state);
eggEntity.setVelocity(player, player.getPitch(), player.getYaw(), 0.0F, 1.5F, 1.0F);

this.world.spawnEntity(eggEntity);
Expand Down
25 changes: 25 additions & 0 deletions src/main/java/xyz/nucleoid/bedwars/mixin/AbstractBlockMixin.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
package xyz.nucleoid.bedwars.mixin;

import net.minecraft.block.AbstractBlock;
import net.minecraft.block.BlockState;
import net.minecraft.block.EntityShapeContext;
import net.minecraft.block.ShapeContext;
import net.minecraft.util.math.BlockPos;
import net.minecraft.util.shape.VoxelShape;
import net.minecraft.util.shape.VoxelShapes;
import net.minecraft.world.BlockView;
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;
import xyz.nucleoid.bedwars.custom.BridgeEggEntity;

@Mixin(AbstractBlock.class)
public class AbstractBlockMixin {
@Inject(method = "getCollisionShape", at = @At("HEAD"), cancellable = true)
public void preventBridgeEggTrailBlockCollision(BlockState state, BlockView world, BlockPos pos, ShapeContext context, CallbackInfoReturnable<VoxelShape> ci) {
if (context instanceof EntityShapeContext entityContext && entityContext.getEntity() instanceof BridgeEggEntity egg && egg.isTrailBlock(state, pos)) {
ci.setReturnValue(VoxelShapes.empty());
}
}
}
1 change: 1 addition & 0 deletions src/main/resources/bw.mixins.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
"package": "xyz.nucleoid.bedwars.mixin",
"compatibilityLevel": "JAVA_17",
"mixins": [
"AbstractBlockMixin",
"BedBlockMixin",
"ExplosionBehaviorMixin",
"LeavesBlockMixin",
Expand Down