This repository has been archived by the owner on Apr 28, 2020. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 52
Patch entity networking #37
Open
UpcraftLP
wants to merge
10
commits into
DimensionalDevelopment:master
Choose a base branch
from
UpcraftLP:patch-entity-networking
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
10 commits
Select commit
Hold shift + click to select a range
64b6797
sorted mixins file
UpcraftLP e976be3
added maven names
UpcraftLP 355f08b
fix testmod sourceset
UpcraftLP 96db3d2
added logger getter
UpcraftLP b28fbb5
bootstrap init
UpcraftLP a1c657a
more reflection utils
UpcraftLP 1fb957d
added custom entity spawn packets
UpcraftLP 973b25e
add test item for spawn packets
UpcraftLP 25e254c
add test case for overriding vanilla tracking behaviour
UpcraftLP d27a574
fix tracking entities that extend vanilla entities
UpcraftLP File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -30,9 +30,18 @@ targetCompatibility = 1.8 | |
|
||
repositories { | ||
mavenCentral() | ||
maven { url 'https://libraries.minecraft.net/' } | ||
maven { url 'https://www.dimdev.org/maven/' } | ||
maven { url = 'https://repo.spongepowered.org/maven/' } | ||
maven { | ||
name = "Minecraft" | ||
url = "https://libraries.minecraft.net/" | ||
} | ||
maven { | ||
name = "Dimensional Development" | ||
url = "https://www.dimdev.org/maven/" | ||
} | ||
maven { | ||
name = "Sponge" | ||
url = "https://repo.spongepowered.org/maven/" | ||
} | ||
} | ||
|
||
dependencies { | ||
|
@@ -59,9 +68,9 @@ mixin { | |
} | ||
|
||
sourceSets { | ||
main | ||
debug { | ||
compileClasspath += main.compileClasspath | ||
compileClasspath += main.compileClasspath + main.output | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. ? |
||
runtimeClasspath += main.runtimeClasspath | ||
} | ||
} | ||
|
||
|
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
31 changes: 31 additions & 0 deletions
31
src/debug/java/org/dimdev/testmod/entity/EntityGrenade.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,31 @@ | ||
package org.dimdev.testmod.entity; | ||
|
||
import net.minecraft.entity.EntityLivingBase; | ||
import net.minecraft.entity.projectile.EntityThrowable; | ||
import net.minecraft.util.math.RayTraceResult; | ||
import net.minecraft.world.World; | ||
import org.dimdev.testmod.TestMod; | ||
|
||
public class EntityGrenade extends EntityThrowable { | ||
|
||
public EntityGrenade(World world) { | ||
super(TestMod.ENTITY_TYPE_GRENADE, world); | ||
} | ||
|
||
public EntityGrenade(World world, EntityLivingBase shooter) { | ||
super(TestMod.ENTITY_TYPE_GRENADE, shooter, world); | ||
} | ||
|
||
public EntityGrenade(World world, double x, double y, double z) { | ||
super(TestMod.ENTITY_TYPE_GRENADE, x, y, z, world); | ||
} | ||
|
||
@Override | ||
protected void onImpact(RayTraceResult result) { | ||
if(this.world.isRemote()) { | ||
this.world.createExplosion(this, this.posX, this.posY, this.posZ, 12.0F, false); | ||
} | ||
this.setDead(); | ||
} | ||
|
||
} |
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,38 @@ | ||
package org.dimdev.testmod.item; | ||
|
||
import net.minecraft.entity.player.EntityPlayer; | ||
import net.minecraft.init.SoundEvents; | ||
import net.minecraft.item.Item; | ||
import net.minecraft.item.ItemStack; | ||
import net.minecraft.stats.StatList; | ||
import net.minecraft.util.ActionResult; | ||
import net.minecraft.util.EnumActionResult; | ||
import net.minecraft.util.EnumHand; | ||
import net.minecraft.util.SoundCategory; | ||
import net.minecraft.world.World; | ||
import org.dimdev.testmod.entity.EntityGrenade; | ||
|
||
public class ItemGrenade extends Item { | ||
|
||
public ItemGrenade(Builder builder) { | ||
super(builder); | ||
} | ||
|
||
@Override | ||
public ActionResult<ItemStack> onItemRightClick(World world, EntityPlayer player, EnumHand hand) { | ||
ItemStack stack = player.getHeldItem(hand); | ||
if (!player.capabilities.isCreativeMode) { | ||
stack.shrink(1); | ||
} | ||
|
||
world.playSound(null, player.posX, player.posY, player.posZ, SoundEvents.ENTITY_SNOWBALL_THROW, SoundCategory.NEUTRAL, 0.5F, 0.4F / (itemRand.nextFloat() * 0.4F + 0.8F)); | ||
if (!world.isRemote) { | ||
EntityGrenade grenade = new EntityGrenade(world, player); | ||
grenade.shoot(player, player.rotationPitch, player.rotationYaw, 0.0F, 1.5F, 1.0F); | ||
world.spawnEntity(grenade); | ||
} | ||
|
||
player.addStat(StatList.ITEM_USED.get(this)); | ||
return new ActionResult<>(EnumActionResult.SUCCESS, stack); | ||
} | ||
} |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
{ | ||
"parent": "block/tnt" | ||
} |
3 changes: 3 additions & 0 deletions
3
src/debug/resources/assets/testmod/models/item/packet_tester.json
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,3 @@ | ||
{ | ||
"parent": "item/bone" | ||
} |
16 changes: 16 additions & 0 deletions
16
src/main/java/org/dimdev/rift/entity/EntityTrackerRegistry.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,16 @@ | ||
package org.dimdev.rift.entity; | ||
|
||
import net.minecraft.entity.EntityType; | ||
import org.dimdev.rift.listener.EntityTrackerAdder; | ||
import org.dimdev.riftloader.RiftLoader; | ||
|
||
import java.util.HashMap; | ||
import java.util.Map; | ||
|
||
public class EntityTrackerRegistry { | ||
public static final Map<EntityType, EntityTrackerAdder.EntityTrackerInfo> TRACKER_INFO = new HashMap<>(); | ||
|
||
public static void buildTrackerInfo() { | ||
RiftLoader.instance.getListeners(EntityTrackerAdder.class).forEach(trackerAdder -> trackerAdder.addEntityTrackerInfo(TRACKER_INFO)); | ||
} | ||
} |
13 changes: 13 additions & 0 deletions
13
src/main/java/org/dimdev/rift/entity/IEntityExtraSpawnData.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,13 @@ | ||
package org.dimdev.rift.entity; | ||
|
||
import net.minecraft.network.PacketBuffer; | ||
|
||
/** | ||
* used to de/serialize custom data on entity spawn | ||
*/ | ||
public interface IEntityExtraSpawnData { | ||
|
||
void read(PacketBuffer buffer) throws Exception; | ||
|
||
void write(PacketBuffer buffer) throws Exception; | ||
} |
37 changes: 37 additions & 0 deletions
37
src/main/java/org/dimdev/rift/listener/EntityTrackerAdder.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,37 @@ | ||
package org.dimdev.rift.listener; | ||
|
||
import net.minecraft.entity.Entity; | ||
import net.minecraft.entity.EntityType; | ||
|
||
import java.util.Map; | ||
|
||
@Deprecated //TODO make this a static register() call that is to be called when adding the type! | ||
public interface EntityTrackerAdder { | ||
|
||
void addEntityTrackerInfo(Map<EntityType, EntityTrackerAdder.EntityTrackerInfo> entityTrackers); | ||
|
||
class EntityTrackerInfo<T extends Entity> { | ||
|
||
private final int trackingRange; | ||
private final int updateFrequency; | ||
private final boolean sendVelocityUpdates; | ||
|
||
public EntityTrackerInfo(int trackingRange, int updateFrequency, boolean sendVelocityUpdates) { | ||
this.trackingRange = trackingRange; | ||
this.updateFrequency = updateFrequency; | ||
this.sendVelocityUpdates = sendVelocityUpdates; | ||
} | ||
|
||
public int getTrackingRange() { | ||
return trackingRange; | ||
} | ||
|
||
public int getUpdateFrequency() { | ||
return updateFrequency; | ||
} | ||
|
||
public boolean shouldSendVelocityUpdates() { | ||
return sendVelocityUpdates; | ||
} | ||
} | ||
} |
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,5 +1,6 @@ | ||
package org.dimdev.rift.listener; | ||
|
||
@Deprecated | ||
public interface EntityTypeAdder { | ||
void registerEntityTypes(); | ||
} |
24 changes: 24 additions & 0 deletions
24
src/main/java/org/dimdev/rift/mixin/hook/MixinEntityTracker.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,24 @@ | ||
package org.dimdev.rift.mixin.hook; | ||
|
||
import net.minecraft.entity.Entity; | ||
import net.minecraft.entity.EntityTracker; | ||
import org.dimdev.rift.entity.EntityTrackerRegistry; | ||
import org.dimdev.rift.listener.EntityTrackerAdder; | ||
import org.spongepowered.asm.mixin.Mixin; | ||
import org.spongepowered.asm.mixin.injection.At; | ||
import org.spongepowered.asm.mixin.injection.Inject; | ||
import org.spongepowered.asm.mixin.injection.callback.CallbackInfo; | ||
|
||
@Mixin(EntityTracker.class) | ||
public class MixinEntityTracker { | ||
|
||
@SuppressWarnings("ConstantConditions") | ||
@Inject(method = "track", at = @At("HEAD"), cancellable = true) | ||
public void trackEntity(Entity entityIn, CallbackInfo ci) { | ||
if(EntityTrackerRegistry.TRACKER_INFO.containsKey(entityIn.getType())) { | ||
EntityTrackerAdder.EntityTrackerInfo info = EntityTrackerRegistry.TRACKER_INFO.get(entityIn.getType()); | ||
((EntityTracker) (Object) this).track(entityIn, info.getTrackingRange(), info.getUpdateFrequency(), info.shouldSendVelocityUpdates()); | ||
ci.cancel(); | ||
} | ||
} | ||
} |
35 changes: 35 additions & 0 deletions
35
src/main/java/org/dimdev/rift/mixin/hook/MixinEntityTrackerEntry.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,35 @@ | ||
package org.dimdev.rift.mixin.hook; | ||
|
||
import net.minecraft.entity.Entity; | ||
import net.minecraft.entity.EntityTrackerEntry; | ||
import net.minecraft.entity.EntityType; | ||
import net.minecraft.network.EnumPacketDirection; | ||
import net.minecraft.network.Packet; | ||
import net.minecraft.util.ResourceLocation; | ||
import org.dimdev.rift.network.message.MessageSpawnEntity; | ||
import org.spongepowered.asm.mixin.Final; | ||
import org.spongepowered.asm.mixin.Mixin; | ||
import org.spongepowered.asm.mixin.Shadow; | ||
import org.spongepowered.asm.mixin.injection.At; | ||
import org.spongepowered.asm.mixin.injection.Inject; | ||
import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable; | ||
|
||
@Mixin(EntityTrackerEntry.class) | ||
public class MixinEntityTrackerEntry { | ||
|
||
@Shadow | ||
@Final | ||
private Entity trackedEntity; | ||
|
||
@Inject(method = "createSpawnPacket", at = @At("INVOKE"), cancellable = true) | ||
private void createCustomSpawnPacket(CallbackInfoReturnable<Packet<?>> info) { | ||
if(!this.trackedEntity.isDead) { | ||
EntityType type = this.trackedEntity.getType(); | ||
ResourceLocation typeName = EntityType.getId(type); | ||
if(!typeName.getNamespace().equals("minecraft")) { | ||
info.setReturnValue(new MessageSpawnEntity(this.trackedEntity).toPacket(EnumPacketDirection.CLIENTBOUND)); | ||
} | ||
} | ||
} | ||
|
||
} |
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
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Redundant formatting change