Fix coupling data not being sent to clients

This commit is contained in:
simibubi 2020-11-27 20:37:10 +01:00
parent a49aad24c2
commit cbe23a6aba
2 changed files with 17 additions and 0 deletions

View file

@ -36,6 +36,7 @@ import net.minecraftforge.common.capabilities.ICapabilitySerializable;
import net.minecraftforge.common.util.LazyOptional; import net.minecraftforge.common.util.LazyOptional;
import net.minecraftforge.common.util.NonNullConsumer; import net.minecraftforge.common.util.NonNullConsumer;
import net.minecraftforge.event.AttachCapabilitiesEvent; import net.minecraftforge.event.AttachCapabilitiesEvent;
import net.minecraftforge.event.entity.player.PlayerEvent;
import net.minecraftforge.event.world.ChunkEvent; import net.minecraftforge.event.world.ChunkEvent;
public class CapabilityMinecartController implements ICapabilitySerializable<CompoundNBT> { public class CapabilityMinecartController implements ICapabilitySerializable<CompoundNBT> {
@ -200,6 +201,7 @@ public class CapabilityMinecartController implements ICapabilitySerializable<Com
Entity entity = event.getObject(); Entity entity = event.getObject();
if (!(entity instanceof AbstractMinecartEntity)) if (!(entity instanceof AbstractMinecartEntity))
return; return;
CapabilityMinecartController capability = new CapabilityMinecartController((AbstractMinecartEntity) entity); CapabilityMinecartController capability = new CapabilityMinecartController((AbstractMinecartEntity) entity);
ResourceLocation id = Create.asResource("minecart_controller"); ResourceLocation id = Create.asResource("minecart_controller");
event.addCapability(id, capability); event.addCapability(id, capability);
@ -211,6 +213,14 @@ public class CapabilityMinecartController implements ICapabilitySerializable<Com
.add((AbstractMinecartEntity) entity); .add((AbstractMinecartEntity) entity);
} }
public static void startTracking(PlayerEvent.StartTracking event) {
Entity entity = event.getTarget();
if (!(entity instanceof AbstractMinecartEntity))
return;
entity.getCapability(MINECART_CONTROLLER_CAPABILITY)
.ifPresent(MinecartController::sendData);
}
public static void register() { public static void register() {
CapabilityManager.INSTANCE.register(MinecartController.class, new Capability.IStorage<MinecartController>() { CapabilityManager.INSTANCE.register(MinecartController.class, new Capability.IStorage<MinecartController>() {

View file

@ -9,6 +9,7 @@ import com.simibubi.create.content.contraptions.fluids.recipe.PotionMixingRecipe
import com.simibubi.create.content.contraptions.wrench.WrenchItem; import com.simibubi.create.content.contraptions.wrench.WrenchItem;
import com.simibubi.create.content.schematics.ServerSchematicLoader; import com.simibubi.create.content.schematics.ServerSchematicLoader;
import com.simibubi.create.foundation.command.AllCommands; import com.simibubi.create.foundation.command.AllCommands;
import com.simibubi.create.foundation.utility.Debug;
import com.simibubi.create.foundation.utility.ServerSpeedProvider; import com.simibubi.create.foundation.utility.ServerSpeedProvider;
import com.simibubi.create.foundation.utility.WorldAttached; import com.simibubi.create.foundation.utility.WorldAttached;
import com.simibubi.create.foundation.utility.recipe.RecipeFinder; import com.simibubi.create.foundation.utility.recipe.RecipeFinder;
@ -25,6 +26,7 @@ import net.minecraftforge.event.TickEvent.WorldTickEvent;
import net.minecraftforge.event.entity.EntityJoinWorldEvent; import net.minecraftforge.event.entity.EntityJoinWorldEvent;
import net.minecraftforge.event.entity.living.LivingEvent.LivingUpdateEvent; import net.minecraftforge.event.entity.living.LivingEvent.LivingUpdateEvent;
import net.minecraftforge.event.entity.player.AttackEntityEvent; import net.minecraftforge.event.entity.player.AttackEntityEvent;
import net.minecraftforge.event.entity.player.PlayerEvent;
import net.minecraftforge.event.world.ChunkEvent; import net.minecraftforge.event.world.ChunkEvent;
import net.minecraftforge.event.world.WorldEvent; import net.minecraftforge.event.world.WorldEvent;
import net.minecraftforge.eventbus.api.SubscribeEvent; import net.minecraftforge.eventbus.api.SubscribeEvent;
@ -122,4 +124,9 @@ public class CommonEvents {
CapabilityMinecartController.attach(event); CapabilityMinecartController.attach(event);
} }
@SubscribeEvent
public static void startTracking(PlayerEvent.StartTracking event) {
CapabilityMinecartController.startTracking(event);
}
} }