-
Notifications
You must be signed in to change notification settings - Fork 8
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
add polar bear shearing age component
- Loading branch information
1 parent
90c8329
commit b0790a9
Showing
5 changed files
with
63 additions
and
59 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
38 changes: 36 additions & 2 deletions
38
src/main/java/com/github/thedeathlycow/frostiful/entity/component/PolarBearComponents.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 |
---|---|---|
@@ -1,27 +1,61 @@ | ||
package com.github.thedeathlycow.frostiful.entity.component; | ||
|
||
import com.github.thedeathlycow.frostiful.entity.FShearable; | ||
import com.github.thedeathlycow.frostiful.registry.FComponents; | ||
import dev.onyxstudios.cca.api.v3.component.Component; | ||
import dev.onyxstudios.cca.api.v3.component.sync.AutoSyncedComponent; | ||
import net.minecraft.entity.passive.PolarBearEntity; | ||
import net.minecraft.nbt.NbtCompound; | ||
import net.minecraft.nbt.NbtElement; | ||
import net.minecraft.network.PacketByteBuf; | ||
import net.minecraft.server.network.ServerPlayerEntity; | ||
|
||
public class PolarBearComponents implements Component, AutoSyncedComponent { | ||
|
||
private int lastShearedAge = 0; | ||
private static final String LAST_SHEARED_AGE_KEY = "last_sheared_age"; | ||
|
||
private int lastShearedAge = -1; | ||
|
||
private final PolarBearEntity provider; | ||
private final FShearable shearable; | ||
|
||
public PolarBearComponents(PolarBearEntity provider) { | ||
this.provider = provider; | ||
this.shearable = (FShearable) provider; | ||
} | ||
|
||
@Override | ||
public void readFromNbt(NbtCompound tag) { | ||
public void writeSyncPacket(PacketByteBuf buf, ServerPlayerEntity recipient) { | ||
buf.writeVarInt(this.lastShearedAge); | ||
} | ||
|
||
@Override | ||
public void applySyncPacket(PacketByteBuf buf) { | ||
this.lastShearedAge = buf.readVarInt(); | ||
} | ||
|
||
@Override | ||
public void readFromNbt(NbtCompound tag) { | ||
if (tag.contains(LAST_SHEARED_AGE_KEY, NbtElement.INT_TYPE)) { | ||
this.lastShearedAge = tag.getInt(LAST_SHEARED_AGE_KEY); | ||
} | ||
} | ||
|
||
@Override | ||
public void writeToNbt(NbtCompound tag) { | ||
if (shearable.frostiful$wasSheared()) { | ||
tag.putInt(LAST_SHEARED_AGE_KEY, lastShearedAge); | ||
} | ||
} | ||
|
||
public int getLastShearedAge() { | ||
return lastShearedAge; | ||
} | ||
|
||
public void setLastShearedAge(int lastShearedAge) { | ||
if (this.lastShearedAge != lastShearedAge) { | ||
this.lastShearedAge = lastShearedAge; | ||
FComponents.POLAR_BEAR_COMPONENTS.sync(this.provider); | ||
} | ||
} | ||
} |
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