Skip to content

Commit

Permalink
Fix NPE when placing a machine in-world automatically (#800)
Browse files Browse the repository at this point in the history
  • Loading branch information
Technici4n authored Jul 24, 2024
1 parent ac1ba8e commit 00a87fc
Show file tree
Hide file tree
Showing 4 changed files with 8 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -199,7 +199,7 @@ public void openMenu(Player player) {
protected abstract MachineModelClientData getModelData();

@MustBeInvokedByOverriders
public void onPlaced(LivingEntity placer, ItemStack itemStack) {
public void onPlaced(@Nullable LivingEntity placer, ItemStack itemStack) {
orientation.onPlaced(placer, itemStack);
placedBy.onPlaced(placer);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@
import net.minecraft.world.entity.LivingEntity;
import net.minecraft.world.entity.player.Player;
import net.minecraft.world.item.ItemStack;
import org.jetbrains.annotations.Nullable;

public class OrientationComponent implements IComponent {
public Direction facingDirection = Direction.NORTH;
Expand Down Expand Up @@ -92,8 +93,9 @@ public boolean useWrench(Player player, InteractionHand hand, Direction face) {
return false;
}

public void onPlaced(LivingEntity placer, ItemStack itemStack) {
Direction dir = placer.getDirection();
public void onPlaced(@Nullable LivingEntity placer, ItemStack itemStack) {
// The placer can be null using some mods' automatic placement: pick NORTH arbitrarily.
Direction dir = placer != null ? placer.getDirection() : Direction.NORTH;
facingDirection = dir.getOpposite();
if (params.hasOutput) {
outputDirection = dir;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ public void readNbt(CompoundTag tag) {
}
}

public void onPlaced(LivingEntity placer) {
public void onPlaced(@Nullable LivingEntity placer) {
if (placer instanceof Player) {
placerId = placer.getUUID();
} else {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@
import net.minecraft.nbt.CompoundTag;
import net.minecraft.world.entity.LivingEntity;
import net.minecraft.world.item.ItemStack;
import org.jetbrains.annotations.Nullable;

public abstract class HatchBlockEntity extends MachineBlockEntity implements Tickable {
public HatchBlockEntity(BEP bep, MachineGuiParameters guiParams, OrientationComponent.Params orientationParams) {
Expand Down Expand Up @@ -108,7 +109,7 @@ protected MachineModelClientData getModelData() {
}

@Override
public void onPlaced(LivingEntity placer, ItemStack itemStack) {
public void onPlaced(@Nullable LivingEntity placer, ItemStack itemStack) {
super.onPlaced(placer, itemStack);
if (orientation.params.hasOutput) {
orientation.outputDirection = orientation.outputDirection.getOpposite();
Expand Down

0 comments on commit 00a87fc

Please sign in to comment.