generated from KessokuTeaTime/Example-Mod
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
6 changed files
with
280 additions
and
36 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
111 changes: 111 additions & 0 deletions
111
src/main/java/net/krlite/knowledges/impl/representable/KnowledgesBlockRepresentable.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,111 @@ | ||
package net.krlite.knowledges.impl.representable; | ||
|
||
import net.krlite.knowledges.api.representable.BlockRepresentable; | ||
import net.minecraft.block.Block; | ||
import net.minecraft.block.BlockState; | ||
import net.minecraft.block.Blocks; | ||
import net.minecraft.block.entity.BlockEntity; | ||
import net.minecraft.entity.player.PlayerEntity; | ||
import net.minecraft.nbt.NbtCompound; | ||
import net.minecraft.util.hit.BlockHitResult; | ||
import net.minecraft.util.math.BlockPos; | ||
import net.minecraft.util.math.Direction; | ||
import net.minecraft.world.World; | ||
|
||
import java.util.function.Supplier; | ||
|
||
public class KnowledgesBlockRepresentable extends KnowledgesRepresentable<BlockHitResult> implements BlockRepresentable { | ||
private final BlockState blockState; | ||
private final Supplier<BlockEntity> blockEntitySupplier; | ||
|
||
public KnowledgesBlockRepresentable(Builder builder) { | ||
super(builder); | ||
this.blockState = builder.blockState; | ||
this.blockEntitySupplier = builder.blockEntitySupplier; | ||
} | ||
|
||
@Override | ||
public Block block() { | ||
return blockState.getBlock(); | ||
} | ||
|
||
@Override | ||
public BlockState blockState() { | ||
return blockState; | ||
} | ||
|
||
@Override | ||
public BlockEntity blockEntity() { | ||
return blockEntitySupplier.get(); | ||
} | ||
|
||
@Override | ||
public BlockPos blockPos() { | ||
return hitResult().getBlockPos(); | ||
} | ||
|
||
@Override | ||
public Direction side() { | ||
return hitResult().getSide(); | ||
} | ||
|
||
public static final class Builder extends KnowledgesRepresentable.Builder<BlockHitResult> implements BlockRepresentable.Builder { | ||
private BlockState blockState = Blocks.AIR.getDefaultState(); | ||
private Supplier<BlockEntity> blockEntitySupplier; | ||
|
||
@Override | ||
public Builder hitResult(BlockHitResult hitResult) { | ||
this.hitResult = hitResult; | ||
return this; | ||
} | ||
|
||
@Override | ||
public Builder world(World world) { | ||
this.world = world; | ||
return this; | ||
} | ||
|
||
@Override | ||
public Builder player(PlayerEntity player) { | ||
this.player = player; | ||
return this; | ||
} | ||
|
||
@Override | ||
public Builder data(NbtCompound data) { | ||
this.data = data; | ||
return this; | ||
} | ||
|
||
@Override | ||
public Builder hasServer(boolean hasServer) { | ||
this.hasServer = hasServer; | ||
return this; | ||
} | ||
|
||
@Override | ||
public Builder blockState(BlockState blockState) { | ||
this.blockState = blockState; | ||
return this; | ||
} | ||
|
||
@Override | ||
public Builder blockEntitySupplier(Supplier<BlockEntity> blockEntitySupplier) { | ||
this.blockEntitySupplier = blockEntitySupplier; | ||
return this; | ||
} | ||
|
||
@Override | ||
public KnowledgesBlockRepresentable build() { | ||
return new KnowledgesBlockRepresentable(this); | ||
} | ||
|
||
public static Builder create() { | ||
return new Builder(); | ||
} | ||
|
||
public static Builder from(BlockRepresentable representable) { | ||
return (Builder) BlockRepresentable.Builder.append(create(), representable); | ||
} | ||
} | ||
} |
77 changes: 77 additions & 0 deletions
77
src/main/java/net/krlite/knowledges/impl/representable/KnowledgesEntityRepresentable.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,77 @@ | ||
package net.krlite.knowledges.impl.representable; | ||
|
||
import net.krlite.knowledges.api.representable.EntityRepresentable; | ||
import net.minecraft.entity.Entity; | ||
import net.minecraft.entity.player.PlayerEntity; | ||
import net.minecraft.nbt.NbtCompound; | ||
import net.minecraft.util.hit.EntityHitResult; | ||
import net.minecraft.world.World; | ||
|
||
import java.util.function.Supplier; | ||
|
||
public class KnowledgesEntityRepresentable extends KnowledgesRepresentable<EntityHitResult> implements EntityRepresentable { | ||
private final Supplier<Entity> entitySupplier; | ||
|
||
public KnowledgesEntityRepresentable(Builder builder) { | ||
super(builder); | ||
this.entitySupplier = builder.entitySupplier; | ||
} | ||
|
||
@Override | ||
public Entity entity() { | ||
return entitySupplier.get(); | ||
} | ||
|
||
public static class Builder extends KnowledgesRepresentable.Builder<EntityHitResult> implements EntityRepresentable.Builder { | ||
private Supplier<Entity> entitySupplier; | ||
|
||
@Override | ||
public Builder entitySupplier(Supplier<Entity> entitySupplier) { | ||
this.entitySupplier = entitySupplier; | ||
return this; | ||
} | ||
|
||
@Override | ||
public Builder hitResult(EntityHitResult hitResult) { | ||
this.hitResult = hitResult; | ||
return this; | ||
} | ||
|
||
@Override | ||
public Builder world(World world) { | ||
this.world = world; | ||
return this; | ||
} | ||
|
||
@Override | ||
public Builder player(PlayerEntity player) { | ||
this.player = player; | ||
return this; | ||
} | ||
|
||
@Override | ||
public Builder data(NbtCompound data) { | ||
this.data = data; | ||
return this; | ||
} | ||
|
||
@Override | ||
public Builder hasServer(boolean hasServer) { | ||
this.hasServer = hasServer; | ||
return this; | ||
} | ||
|
||
@Override | ||
public EntityRepresentable build() { | ||
return new KnowledgesEntityRepresentable(this); | ||
} | ||
|
||
public static Builder create() { | ||
return new Builder(); | ||
} | ||
|
||
public static Builder from(EntityRepresentable representable) { | ||
return (Builder) EntityRepresentable.Builder.append(create(), representable); | ||
} | ||
} | ||
} |
62 changes: 62 additions & 0 deletions
62
src/main/java/net/krlite/knowledges/impl/representable/KnowledgesRepresentable.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,62 @@ | ||
package net.krlite.knowledges.impl.representable; | ||
|
||
import net.krlite.knowledges.api.representable.Representable; | ||
import net.minecraft.entity.player.PlayerEntity; | ||
import net.minecraft.nbt.NbtCompound; | ||
import net.minecraft.util.hit.HitResult; | ||
import net.minecraft.world.World; | ||
|
||
import java.util.function.Supplier; | ||
|
||
public abstract class KnowledgesRepresentable<H extends HitResult> implements Representable<H> { | ||
private final Supplier<H> hitResultSupplier; | ||
private final World world; | ||
private final PlayerEntity player; | ||
private final NbtCompound data; | ||
private final boolean hasServer; | ||
|
||
protected KnowledgesRepresentable(Supplier<H> hitResultSupplier, World world, PlayerEntity player, NbtCompound data, boolean hasServer) { | ||
this.hitResultSupplier = hitResultSupplier; | ||
this.world = world; | ||
this.player = player; | ||
this.data = data; | ||
this.hasServer = hasServer; | ||
} | ||
|
||
protected <B extends Builder<H>> KnowledgesRepresentable(B builder) { | ||
this(() -> builder.hitResult, builder.world, builder.player, builder.data, builder.hasServer); | ||
} | ||
|
||
@Override | ||
public H hitResult() { | ||
return hitResultSupplier.get(); | ||
} | ||
|
||
@Override | ||
public World world() { | ||
return world; | ||
} | ||
|
||
@Override | ||
public PlayerEntity player() { | ||
return player; | ||
} | ||
|
||
@Override | ||
public NbtCompound data() { | ||
return data; | ||
} | ||
|
||
@Override | ||
public boolean hasServer() { | ||
return hasServer; | ||
} | ||
|
||
public static class Builder<H extends HitResult> { | ||
protected H hitResult; | ||
protected World world; | ||
protected PlayerEntity player; | ||
protected NbtCompound data; | ||
protected boolean hasServer; | ||
} | ||
} |