-
Notifications
You must be signed in to change notification settings - Fork 37
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 #441 from Gu-ZT/releases/1.20.1
注册并实现含生物琥珀块,怨恨琥珀块
- Loading branch information
Showing
57 changed files
with
1,355 additions
and
155 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
27 changes: 27 additions & 0 deletions
27
common/src/main/java/dev/dubhe/anvilcraft/block/MobAmberBlock.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,27 @@ | ||
package dev.dubhe.anvilcraft.block; | ||
|
||
import dev.dubhe.anvilcraft.init.ModBlockEntities; | ||
import net.minecraft.core.BlockPos; | ||
import net.minecraft.world.level.block.BaseEntityBlock; | ||
import net.minecraft.world.level.block.RenderShape; | ||
import net.minecraft.world.level.block.entity.BlockEntity; | ||
import net.minecraft.world.level.block.state.BlockState; | ||
import org.jetbrains.annotations.NotNull; | ||
import org.jetbrains.annotations.Nullable; | ||
|
||
public class MobAmberBlock extends BaseEntityBlock { | ||
public MobAmberBlock(Properties properties) { | ||
super(properties); | ||
} | ||
|
||
@Nullable | ||
@Override | ||
public BlockEntity newBlockEntity(@NotNull BlockPos pos, @NotNull BlockState state) { | ||
return ModBlockEntities.MOB_AMBER_BLOCK.create(pos, state); | ||
} | ||
|
||
@Override | ||
public @NotNull RenderShape getRenderShape(@NotNull BlockState state) { | ||
return RenderShape.MODEL; | ||
} | ||
} |
20 changes: 20 additions & 0 deletions
20
common/src/main/java/dev/dubhe/anvilcraft/block/ResentfulAmberBlock.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,20 @@ | ||
package dev.dubhe.anvilcraft.block; | ||
|
||
import dev.dubhe.anvilcraft.init.ModBlockEntities; | ||
import net.minecraft.core.BlockPos; | ||
import net.minecraft.world.level.block.entity.BlockEntity; | ||
import net.minecraft.world.level.block.state.BlockState; | ||
import org.jetbrains.annotations.NotNull; | ||
import org.jetbrains.annotations.Nullable; | ||
|
||
public class ResentfulAmberBlock extends MobAmberBlock { | ||
public ResentfulAmberBlock(Properties properties) { | ||
super(properties); | ||
} | ||
|
||
@Nullable | ||
@Override | ||
public BlockEntity newBlockEntity(@NotNull BlockPos pos, @NotNull BlockState state) { | ||
return ModBlockEntities.RESENTFUL_AMBER_BLOCK.create(pos, state); | ||
} | ||
} |
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
96 changes: 96 additions & 0 deletions
96
common/src/main/java/dev/dubhe/anvilcraft/block/entity/HasMobBlockEntity.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,96 @@ | ||
package dev.dubhe.anvilcraft.block.entity; | ||
|
||
import net.minecraft.core.BlockPos; | ||
import net.minecraft.nbt.CompoundTag; | ||
import net.minecraft.network.protocol.Packet; | ||
import net.minecraft.network.protocol.game.ClientGamePacketListener; | ||
import net.minecraft.network.protocol.game.ClientboundBlockEntityDataPacket; | ||
import net.minecraft.world.entity.Entity; | ||
import net.minecraft.world.entity.EntityType; | ||
import net.minecraft.world.level.Level; | ||
import net.minecraft.world.level.block.entity.BlockEntity; | ||
import net.minecraft.world.level.block.entity.BlockEntityType; | ||
import net.minecraft.world.level.block.state.BlockState; | ||
import org.jetbrains.annotations.NotNull; | ||
import org.jetbrains.annotations.Nullable; | ||
|
||
import java.util.Optional; | ||
|
||
public abstract class HasMobBlockEntity extends BlockEntity { | ||
private CompoundTag entity = null; | ||
private Entity displayEntity = null; | ||
|
||
protected HasMobBlockEntity(BlockEntityType<?> type, BlockPos pos, BlockState blockState) { | ||
super(type, pos, blockState); | ||
} | ||
|
||
/** | ||
* 设置实体 | ||
*/ | ||
public void setEntity(Entity entity) { | ||
if (entity == null) return; | ||
if (this.entity == null) this.entity = new CompoundTag(); | ||
entity.save(this.entity); | ||
this.entity.remove(Entity.UUID_TAG); | ||
} | ||
|
||
/** | ||
* 设置实体 | ||
*/ | ||
public void setEntity(CompoundTag entity) { | ||
if (entity == null) return; | ||
this.entity = entity; | ||
this.entity.remove(Entity.UUID_TAG); | ||
} | ||
|
||
@Override | ||
protected void saveAdditional(@NotNull CompoundTag tag) { | ||
super.saveAdditional(tag); | ||
if (this.entity != null) { | ||
tag.put("entity", this.entity); | ||
} | ||
} | ||
|
||
@Override | ||
public void load(@NotNull CompoundTag tag) { | ||
if (tag.contains("entity")) { | ||
this.entity = tag.getCompound("entity"); | ||
if (this.level != null) { | ||
this.getEntity(this.level); | ||
} | ||
} | ||
super.load(tag); | ||
} | ||
|
||
@Override | ||
public @NotNull CompoundTag getUpdateTag() { | ||
return this.saveWithoutMetadata(); | ||
} | ||
|
||
@Nullable | ||
@Override | ||
public Packet<ClientGamePacketListener> getUpdatePacket() { | ||
return ClientboundBlockEntityDataPacket.create(this); | ||
} | ||
|
||
/** | ||
* @return 实体 | ||
*/ | ||
@Nullable | ||
public Entity getOrCreateDisplayEntity(Level level) { | ||
if (this.displayEntity == null && this.entity != null) { | ||
this.getEntity(level); | ||
} | ||
return this.displayEntity; | ||
} | ||
|
||
private void getEntity(Level level) { | ||
Optional<EntityType<?>> optional = EntityType.by(this.entity); | ||
if (optional.isEmpty()) return; | ||
EntityType<?> type = optional.get(); | ||
Entity entity = type.create(level); | ||
if (entity == null) return; | ||
entity.load(this.entity); | ||
this.displayEntity = entity; | ||
} | ||
} |
18 changes: 18 additions & 0 deletions
18
common/src/main/java/dev/dubhe/anvilcraft/block/entity/MobAmberBlockEntity.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,18 @@ | ||
package dev.dubhe.anvilcraft.block.entity; | ||
|
||
import net.minecraft.core.BlockPos; | ||
import net.minecraft.world.level.block.entity.BlockEntityType; | ||
import net.minecraft.world.level.block.state.BlockState; | ||
import org.jetbrains.annotations.NotNull; | ||
|
||
public class MobAmberBlockEntity extends HasMobBlockEntity { | ||
protected MobAmberBlockEntity(BlockEntityType<?> type, BlockPos pos, BlockState blockState) { | ||
super(type, pos, blockState); | ||
} | ||
|
||
public static @NotNull MobAmberBlockEntity createBlockEntity( | ||
BlockEntityType<?> type, BlockPos pos, BlockState blockState | ||
) { | ||
return new MobAmberBlockEntity(type, pos, blockState); | ||
} | ||
} |
18 changes: 18 additions & 0 deletions
18
common/src/main/java/dev/dubhe/anvilcraft/block/entity/ResentfulAmberBlock.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,18 @@ | ||
package dev.dubhe.anvilcraft.block.entity; | ||
|
||
import net.minecraft.core.BlockPos; | ||
import net.minecraft.world.level.block.entity.BlockEntityType; | ||
import net.minecraft.world.level.block.state.BlockState; | ||
import org.jetbrains.annotations.NotNull; | ||
|
||
public class ResentfulAmberBlock extends MobAmberBlockEntity { | ||
private ResentfulAmberBlock(BlockEntityType<?> type, BlockPos pos, BlockState blockState) { | ||
super(type, pos, blockState); | ||
} | ||
|
||
public static @NotNull ResentfulAmberBlock createBlockEntity( | ||
BlockEntityType<?> type, BlockPos pos, BlockState blockState | ||
) { | ||
return new ResentfulAmberBlock(type, pos, blockState); | ||
} | ||
} |
Oops, something went wrong.