Skip to content

Commit 007d930

Browse files
committed
Recent batch of converted kotlin block code.
1 parent 603b17c commit 007d930

21 files changed

Lines changed: 1150 additions & 891 deletions

File tree

common/src/main/java/generations/gg/generations/core/generationscore/common/world/entity/GenerationsBoatEntity.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -39,9 +39,9 @@ protected void readAdditionalSaveData(CompoundTag compound) {
3939
}
4040

4141
@Override
42-
protected void defineSynchedData() {
43-
super.defineSynchedData();
44-
this.entityData.define(DATA_ID_TYPE, Type.GHOST.ordinal());
42+
protected void defineSynchedData(SynchedEntityData.Builder builder) {
43+
super.defineSynchedData(builder);
44+
builder.define(DATA_ID_TYPE, Type.GHOST.ordinal());
4545
}
4646

4747
@Override

common/src/main/java/generations/gg/generations/core/generationscore/common/world/entity/GenerationsChestBoatEntity.java

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,10 @@
11
package generations.gg.generations.core.generationscore.common.world.entity;
22

33
import generations.gg.generations.core.generationscore.common.world.item.GenerationsItems;
4+
import net.minecraft.core.HolderLookup;
45
import net.minecraft.core.NonNullList;
56
import net.minecraft.nbt.CompoundTag;
7+
import net.minecraft.resources.ResourceKey;
68
import net.minecraft.resources.ResourceLocation;
79
import net.minecraft.world.Containers;
810
import net.minecraft.world.InteractionHand;
@@ -22,14 +24,15 @@
2224
import net.minecraft.world.item.ItemStack;
2325
import net.minecraft.world.level.Level;
2426
import net.minecraft.world.level.gameevent.GameEvent;
27+
import net.minecraft.world.level.storage.loot.LootTable;
2528
import org.jetbrains.annotations.NotNull;
2629
import org.jetbrains.annotations.Nullable;
2730

2831
public class GenerationsChestBoatEntity extends GenerationsBoatEntity implements HasCustomInventoryScreen, ContainerEntity {
2932
private static final int CONTAINER_SIZE = 27;
3033
private NonNullList<ItemStack> itemStacks;
3134
@Nullable
32-
private ResourceLocation lootTable;
35+
private ResourceKey<LootTable> lootTable;
3336
private long lootTableSeed;
3437

3538
public GenerationsChestBoatEntity(EntityType<? extends GenerationsChestBoatEntity> entityType, Level level) {
@@ -55,12 +58,12 @@ protected int getMaxPassengers() {
5558

5659
protected void addAdditionalSaveData(CompoundTag compoundTag) {
5760
super.addAdditionalSaveData(compoundTag);
58-
this.addChestVehicleSaveData(compoundTag);
61+
this.addChestVehicleSaveData(compoundTag, this.registryAccess());
5962
}
6063

6164
protected void readAdditionalSaveData(CompoundTag compoundTag) {
6265
super.readAdditionalSaveData(compoundTag);
63-
this.readChestVehicleSaveData(compoundTag);
66+
this.readChestVehicleSaveData(compoundTag, this.registryAccess());
6467
}
6568

6669
public void destroy(DamageSource damageSource) {
@@ -147,13 +150,13 @@ public void unpackLootTable(@Nullable Player player) {
147150
this.unpackChestVehicleLootTable(player);
148151
}
149152

150-
@Nullable
151-
public ResourceLocation getLootTable() {
153+
public ResourceKey<LootTable> getLootTable() {
152154
return this.lootTable;
153155
}
154156

155-
public void setLootTable(@Nullable ResourceLocation resourceLocation) {
156-
this.lootTable = resourceLocation;
157+
@Override
158+
public void setLootTable(@Nullable ResourceKey<LootTable> lootTable) {
159+
this.lootTable = lootTable;
157160
}
158161

159162
public long getLootTableSeed() {

common/src/main/java/generations/gg/generations/core/generationscore/common/world/entity/block/SittableEntity.java

Lines changed: 18 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,12 @@
77
import net.minecraft.nbt.CompoundTag;
88
import net.minecraft.network.protocol.Packet;
99
import net.minecraft.network.protocol.game.ClientGamePacketListener;
10+
import net.minecraft.network.syncher.SynchedEntityData;
11+
import net.minecraft.server.level.ServerEntity;
1012
import net.minecraft.server.level.ServerLevel;
1113
import net.minecraft.util.Mth;
1214
import net.minecraft.world.InteractionResult;
15+
import net.minecraft.world.ItemInteractionResult;
1316
import net.minecraft.world.entity.Entity;
1417
import net.minecraft.world.entity.EntityType;
1518
import net.minecraft.world.entity.LivingEntity;
@@ -29,6 +32,11 @@ public SittableEntity(EntityType<? extends Entity> type, Level level) {
2932
this.noPhysics = true;
3033
}
3134

35+
@Override
36+
protected void defineSynchedData(SynchedEntityData.Builder builder) {
37+
38+
}
39+
3240
private SittableEntity(Level level, BlockPos pos, double offset, float yaw) {
3341
this(GenerationsEntities.SEAT.get(), level);
3442
this.setPos(pos.getX() + 0.5, pos.getY() + offset, pos.getZ() + 0.5);
@@ -69,16 +77,17 @@ public void tick() {
6977
// }
7078
// }
7179

72-
@Override
73-
protected void defineSynchedData() {}
74-
7580
@Override
7681
protected void readAdditionalSaveData(@NotNull CompoundTag compound) {}
7782

7883
@Override
7984
protected void addAdditionalSaveData(@NotNull CompoundTag compound) {}
8085

8186
@Override
87+
public Vec3 getPassengerRidingPosition(Entity entity) {
88+
return super.getPassengerRidingPosition(entity).add(0.0, getPassengersRidingOffset(), 0.0);
89+
}
90+
8291
public double getPassengersRidingOffset()
8392
{
8493
return 0.0;
@@ -91,27 +100,27 @@ protected boolean canRide(@NotNull Entity entity)
91100
}
92101

93102
// Call to mount the player to a newly created SittableEntity
94-
public static InteractionResult mount(Level level, BlockPos pos, double yOffset, Player player, float direction) {
103+
public static ItemInteractionResult mount(Level level, BlockPos pos, double yOffset, Player player, float direction) {
95104
if(level instanceof ServerLevel serverLevel) {
96105
List<SittableEntity> seats = level.getEntitiesOfClass(SittableEntity.class, new AABB(pos.getX(), pos.getY(), pos.getZ(), pos.getX() + 1.0, pos.getY() + 1.0, pos.getZ() + 1.0));
97106
if(seats.isEmpty()) {
98107
SittableEntity seat = new SittableEntity(level, pos, yOffset, direction);
99108
if(level.addFreshEntity(seat)) {
100109
player.startRiding(seat);
101-
return InteractionResult.SUCCESS;
110+
return ItemInteractionResult.SUCCESS;
102111
} else {
103-
return InteractionResult.FAIL;
112+
return ItemInteractionResult.FAIL;
104113
}
105114
}
106115
}
107116

108-
return InteractionResult.PASS;
117+
return ItemInteractionResult.PASS_TO_DEFAULT_BLOCK_INTERACTION;
109118
}
110119

111120

112121
@Override
113-
public @NotNull Packet<ClientGamePacketListener> getAddEntityPacket() {
114-
return NetworkManager.createAddEntityPacket(this);
122+
public Packet<ClientGamePacketListener> getAddEntityPacket(ServerEntity entity) {
123+
return NetworkManager.createAddEntityPacket(this, entity);
115124
}
116125

117126
// Tick the key and check if the block is removed or if there are no more passengers
Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,13 @@
11
package generations.gg.generations.core.generationscore.common.world.level.block;
22

3-
import dev.architectury.registry.registries.RegistrySupplier;
4-
import generations.gg.generations.core.generationscore.common.world.level.block.entities.ModelProvidingBlockEntity;
5-
import generations.gg.generations.core.generationscore.common.world.level.block.utilityblocks.DyeableBlock;
3+
import net.minecraft.core.Holder;
64
import net.minecraft.world.item.DyeColor;
75
import net.minecraft.world.level.block.Block;
86

97
import java.util.Map;
10-
import java.util.function.Supplier;
118

12-
public record DyedGroup<V extends DyeableBlock<T, V>, T extends ModelProvidingBlockEntity>(Map<DyeColor, RegistrySupplier<V>> block) {
9+
public record DyedGroup(Map<DyeColor, Holder<Block>> block) {
1310
public Block[] toArray() {
14-
return block().values().stream().map(Supplier::get).map(a -> (Block) a).toArray(Block[]::new);
11+
return block().values().stream().map(Holder::value).map(a -> (Block) a).toArray(Block[]::new);
1512
}
1613
}

0 commit comments

Comments
 (0)