Skip to content

Commit

Permalink
working
Browse files Browse the repository at this point in the history
  • Loading branch information
loordgek committed Mar 20, 2020
1 parent 8209587 commit 3cd683d
Show file tree
Hide file tree
Showing 7 changed files with 50 additions and 112 deletions.
7 changes: 3 additions & 4 deletions src/main/java/mod/dragonita/fantasymod/Main.java
Expand Up @@ -5,8 +5,7 @@
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;

import mod.dragonita.fantasymod.customthings.PacketHandler;
import mod.dragonita.fantasymod.customthings.PanicMessage;
import network.PacketHandler;
import mod.dragonita.fantasymod.init.ModBlocks;
import mod.dragonita.fantasymod.init.ModDimensions;
import mod.dragonita.fantasymod.init.ModEntityTypes;
Expand Down Expand Up @@ -42,7 +41,7 @@ public final class Main
public static final String MODID = "fantasymod";
public static final Logger LOGGER = LogManager.getLogger(MODID);
public static final ResourceLocation DIMENSION_TYPE = new ResourceLocation(Main.MODID, "rainbow_dimension");
private static int ID = 505156459;
private static int ID;

public Main()
{
Expand Down Expand Up @@ -73,7 +72,7 @@ public Main()

public void setup(final FMLCommonSetupEvent event) {

PacketHandler.INSTANCE.registerMessage(ID++, PanicMessage.class, PanicMessage::encode, PanicMessage::new, PanicMessage::handle);
PacketHandler.init();
DeferredWorkQueue.runLater(new Runnable() {
@Override
public void run() {
Expand Down
Expand Up @@ -5,7 +5,6 @@
import mod.dragonita.fantasymod.entities.UnicornEntity;
import mod.dragonita.fantasymod.util.PCEntityModel;
import mod.dragonita.fantasymod.util.PCRenderModel;
import net.minecraft.entity.ai.goal.PanicGoal;

/**
* ModelUnicornTabula - DragonITA
Expand Down Expand Up @@ -305,7 +304,7 @@ public void setRotationAngles(UnicornEntity entity, float limbSwing, float limbS
swing(FrontRightLeg2, 0.1F, -0.5F*globalDegree, true, 0.4F, 0.0F, limbSwing, limbSwingAmount);
}else */if(entity.prevPosX != entity.getPosX() || entity.prevPosY != entity.getPosY() || entity.prevPosZ != entity.getPosZ()){
if(entity.CompareGoal(PanicGoal.class)) {
if(entity.getDataManager().get(UnicornEntity.PANIC)) {
loadDefaultPose();

//Body
Expand Down

This file was deleted.

This file was deleted.

This file was deleted.

29 changes: 19 additions & 10 deletions src/main/java/mod/dragonita/fantasymod/entities/UnicornEntity.java
Expand Up @@ -7,16 +7,21 @@
import net.minecraft.entity.passive.horse.AbstractHorseEntity;
import net.minecraft.entity.passive.horse.HorseEntity;
import net.minecraft.network.IPacket;
import net.minecraft.network.datasync.DataParameter;
import net.minecraft.network.datasync.DataSerializers;
import net.minecraft.network.datasync.EntityDataManager;
import net.minecraft.world.World;
import net.minecraftforge.fml.common.registry.IEntityAdditionalSpawnData;
import net.minecraftforge.fml.network.FMLPlayMessages;
import net.minecraftforge.fml.network.NetworkHooks;

public class UnicornEntity extends HorseEntity{
public static DataParameter<Boolean> PANIC = EntityDataManager.createKey(UnicornEntity.class, DataSerializers.BOOLEAN);
//private static Logger LOGGER = Main.LOGGER;

public UnicornEntity(final EntityType<? extends UnicornEntity> entityType, final World world) {
super(entityType, world);
dataManager.register(PANIC, false);
}

@Override
Expand All @@ -30,17 +35,21 @@ protected void registerAttributes() {
this.getAttribute(SharedMonsterAttributes.MAX_HEALTH).setBaseValue(baseHealth * 1.5D);
}

/*
* This Function return true if the running Goal was the same as in the parameters
*
* @param The Class of the Goal we want to compare
* @return true if it was the same, else false
* @see The goals
*/
public boolean CompareGoal(Class<PanicGoal> TargetGoal) {
return this.goalSelector.getRunningGoals().anyMatch(goal -> goal.getGoal().getClass() == TargetGoal);

public boolean isPanic() {
return this.goalSelector.getRunningGoals().anyMatch(goal -> goal.getGoal().getClass() == PanicGoal.class);
}


@Override
public void tick() {
super.tick();
if (!world.isRemote) {
if (isPanic() && !dataManager.get(PANIC)) {
dataManager.set(PANIC, true);
} else dataManager.set(PANIC, false);
}
}

/**
* Creates a child new entity from the parent entity.
* Can be used to set additional on the child entity based on the parent.
Expand Down
27 changes: 27 additions & 0 deletions src/main/java/network/PacketHandler.java
@@ -0,0 +1,27 @@
package network;

import mod.dragonita.fantasymod.Main;
import net.minecraft.entity.player.ServerPlayerEntity;
import net.minecraft.util.ResourceLocation;
import net.minecraftforge.fml.network.NetworkDirection;
import net.minecraftforge.fml.network.NetworkRegistry;
import net.minecraftforge.fml.network.simple.SimpleChannel;

public class PacketHandler {
private static final String PROTOCOL_VERSION = "1";
public static final SimpleChannel CHANNEL = NetworkRegistry.newSimpleChannel(new ResourceLocation(Main.MODID, "main"),
() -> PROTOCOL_VERSION,
PROTOCOL_VERSION::equals,
PROTOCOL_VERSION::equals
);
private static int ID;

public static void init(){
//int ID; you can also use a local var because it gets called only 1 time
//CHANNEL.registerMessage(ID++, PanicMessage.class, PanicMessage::encode, PanicMessage::new, PanicMessageHandler::handle);
}

public static <MSG> void sentToClient(MSG msg, ServerPlayerEntity playerEntity){
CHANNEL.sendTo(msg, playerEntity.connection.netManager, NetworkDirection.PLAY_TO_CLIENT);
}
}

1 comment on commit 3cd683d

@FrostDracony
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank for helping me!

Please sign in to comment.