-
Notifications
You must be signed in to change notification settings - Fork 14
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #43 from sleepy-evelyn/1.20
Add common protection api support & small fixes
- Loading branch information
Showing
37 changed files
with
437 additions
and
258 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
1 change: 0 additions & 1 deletion
1
src/main/java/ladysnake/blast/common/entity/BonesburrierEntity.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
1 change: 0 additions & 1 deletion
1
src/main/java/ladysnake/blast/common/entity/GunpowderBlockEntity.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
79 changes: 79 additions & 0 deletions
79
src/main/java/ladysnake/blast/common/entity/ShrapnelBlockEntity.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,79 @@ | ||
package ladysnake.blast.common.entity; | ||
|
||
import ladysnake.blast.common.util.ProtectionsProvider; | ||
import ladysnake.blast.mixin.FallingBlockEntityAccessor; | ||
import net.minecraft.block.BlockState; | ||
import net.minecraft.entity.EntityType; | ||
import net.minecraft.entity.FallingBlockEntity; | ||
import net.minecraft.entity.MovementType; | ||
import net.minecraft.entity.player.PlayerEntity; | ||
import net.minecraft.nbt.NbtCompound; | ||
import net.minecraft.server.world.ServerWorld; | ||
import net.minecraft.state.property.Properties; | ||
import net.minecraft.util.math.BlockPos; | ||
import net.minecraft.util.math.Vec3d; | ||
import net.minecraft.world.World; | ||
import org.jetbrains.annotations.Nullable; | ||
|
||
public class ShrapnelBlockEntity extends FallingBlockEntity { | ||
|
||
@Nullable | ||
private PlayerEntity owner; | ||
|
||
public ShrapnelBlockEntity(EntityType<? extends FallingBlockEntity> entityType, World world) { | ||
super(entityType, world); | ||
} | ||
|
||
private ShrapnelBlockEntity(World world, double x, double y, double z, BlockState block, @Nullable PlayerEntity owner) { | ||
this(EntityType.FALLING_BLOCK, world); | ||
|
||
((FallingBlockEntityAccessor) this).setBlock(block); | ||
this.intersectionChecked = true; | ||
this.setPosition(x, y, z); | ||
this.setVelocity(Vec3d.ZERO); | ||
this.prevX = x; | ||
this.prevY = y; | ||
this.prevZ = z; | ||
this.owner = owner; | ||
this.setFallingBlockPos(this.getBlockPos()); | ||
} | ||
|
||
public static ShrapnelBlockEntity spawnFromBlock(World world, BlockPos pos, BlockState state, @Nullable PlayerEntity owner) { | ||
var explosionThrownBlockEntity = new ShrapnelBlockEntity( | ||
world, (double)pos.getX() + 0.5, pos.getY(), (double)pos.getZ() + 0.5, | ||
state.contains(Properties.WATERLOGGED) ? state.with(Properties.WATERLOGGED, false) : state, owner | ||
); | ||
world.setBlockState(pos, state.getFluidState().getBlockState(), 3); | ||
world.spawnEntity(explosionThrownBlockEntity); | ||
return explosionThrownBlockEntity; | ||
} | ||
|
||
@Nullable | ||
public PlayerEntity getOwner() { return owner; } | ||
|
||
@Override | ||
protected void writeCustomDataToNbt(NbtCompound nbt) { | ||
super.writeCustomDataToNbt(nbt); | ||
if (!getWorld().isClient && owner != null) { | ||
nbt.putUuid("Owner", owner.getUuid()); | ||
} | ||
} | ||
|
||
@Override | ||
protected void readCustomDataFromNbt(NbtCompound nbt) { | ||
super.readCustomDataFromNbt(nbt); | ||
if (nbt.containsUuid("Owner") && getWorld() instanceof ServerWorld serverWorld) { | ||
owner = serverWorld.getServer().getPlayerManager().getPlayer(nbt.getUuid("Owner")); | ||
} | ||
} | ||
|
||
@Override | ||
public void move(MovementType movementType, Vec3d movement) { | ||
super.move(movementType, movement); | ||
if (this.isOnGround() && !getWorld().isClient) { | ||
if(!ProtectionsProvider.canPlaceBlock(getBlockPos(), getWorld(), owner)) { | ||
setDestroyedOnLanding(); | ||
} | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.