Skip to content

Commit 0ff7d86

Browse files
committed
send resources
1 parent d487a0d commit 0ff7d86

File tree

8 files changed

+231
-11
lines changed

8 files changed

+231
-11
lines changed

TODO.txt

+2-1
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,8 @@ HEROES (in order of priority)
1919
- equipment
2020

2121

22-
April fools mob ;)
22+
[❌] April fools mob ;)
23+
- Add plus jump power when targeting a ghast
2324

2425
Bugfixes
2526
--------

src/main/java/com/solegendary/reignofnether/CommonModEvents.java

+2-2
Original file line numberDiff line numberDiff line change
@@ -108,6 +108,7 @@ public static void registerRenderers(EntityRenderersEvent.RegisterRenderers evt)
108108
evt.registerEntityRenderer(EntityRegistrar.LLAMA_UNIT.get(), LlamaUnitRenderer::new);
109109

110110
evt.registerEntityRenderer(EntityRegistrar.PHANTOM_SUMMON.get(), PhantomRenderer::new);
111+
evt.registerEntityRenderer(EntityRegistrar.KILLER_RABBIT_UNIT.get(), RabbitRenderer::new);
111112
}
112113

113114
@SubscribeEvent
@@ -153,7 +154,7 @@ public static void registerAttributes(EntityAttributeCreationEvent evt) {
153154
evt.put(EntityRegistrar.ROYAL_GUARD_UNIT.get(), RoyalGuardUnit.createAttributes().build());
154155
evt.put(EntityRegistrar.NECROMANCER_UNIT.get(), NecromancerUnit.createAttributes().build());
155156
evt.put(EntityRegistrar.PIGLIN_MERCHANT_UNIT.get(), PiglinMerchantUnit.createAttributes().build());
156-
157+
evt.put(EntityRegistrar.KILLER_RABBIT_UNIT.get(), KillerRabbitUnit.createAttributes().build());
157158
}
158159

159160
@SubscribeEvent
@@ -217,7 +218,6 @@ public static void creativeTabSetup(BuildCreativeModeTabContentsEvent event) {
217218
event.accept(ItemRegistrar.ROYAL_GUARD_UNIT_SPAWN_EGG);
218219
event.accept(ItemRegistrar.NECROMANCER_UNIT_SPAWN_EGG);
219220
event.accept(ItemRegistrar.PIGLIN_MERCHANT_UNIT_SPAWN_EGG);
220-
221221
}
222222
}
223223
}

src/main/java/com/solegendary/reignofnether/cursor/CursorClientEvents.java

+4-4
Original file line numberDiff line numberDiff line change
@@ -188,8 +188,8 @@ public static void onDrawScreen(ScreenEvent.Render evt) {
188188
cursorWorldPos.z
189189
);
190190
cursorWorldPos = MiscUtil.screenPosToWorldPos(MC, evt.getMouseX(), evt.getMouseY());
191-
cursorWorldPos.y -= 1.3f;
192-
cursorWorldPos.z -= 2.0f;
191+
//cursorWorldPos.y -= 1.3f;
192+
//cursorWorldPos.z -= 2.0f;
193193

194194
// calc near and far cursorWorldPos to get a cursor line vector
195195
Vector3d lookVector = MiscUtil.getPlayerLookVector(MC);
@@ -242,8 +242,8 @@ else if (ResourceSources.GATHERABLE_PLANTS.contains(MC.level.getBlockState(prese
242242

243243
Vector3d cursorWorldPosAdj = new Vector3d(
244244
cursorWorldPos.x,
245-
cursorWorldPos.y + 1.3f,
246-
cursorWorldPos.z + 2.0f
245+
cursorWorldPos.y,// + 1.3f,
246+
cursorWorldPos.z// + 2.0f
247247
);
248248
Vector3d cursorWorldPosNearAdj = MyMath.addVector3d(cursorWorldPosAdj, lookVector, -200);
249249

src/main/java/com/solegendary/reignofnether/player/PlayerServerEvents.java

+9-2
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@
3030
import com.solegendary.reignofnether.unit.interfaces.Unit;
3131
import com.solegendary.reignofnether.unit.interfaces.WorkerUnit;
3232
import com.solegendary.reignofnether.unit.packets.UnitSyncClientboundPacket;
33+
import com.solegendary.reignofnether.unit.units.neutral.KillerRabbitUnit;
3334
import com.solegendary.reignofnether.util.Faction;
3435
import com.solegendary.reignofnether.util.MiscUtil;
3536
import net.minecraft.core.BlockPos;
@@ -99,6 +100,7 @@ public class PlayerServerEvents {
99100
// foodforthought - ignore soft population caps
100101
// thereisnospoon - allow changing survival wave by clicking the wave indicator and using debug commands
101102
// slipslopslap - monster units are unaffected by sunlight
103+
// thebeastofcaerbannog - spawns the Killer Rabbit
102104
public static final List<String> singleWordCheats = List.of(
103105
"warpten",
104106
"operationcwal",
@@ -504,6 +506,11 @@ public static void onPlayerChat(ServerChatEvent evt) {
504506
String[] words = msg.split(" ");
505507
String playerName = evt.getPlayer().getName().getString();
506508

509+
if (words.length == 1 && words[0].equalsIgnoreCase("thebeastofcaerbannog")) {
510+
UnitServerEvents.spawnMob(EntityRegistrar.getEntityType("Killer Rabbit"), serverLevel, evt.getPlayer().getOnPos(), playerName);
511+
sendMessageToAllPlayers("server.reignofnether.used_cheat",false, playerName, words[0]);
512+
}
513+
507514
if (words.length == 2) {
508515
try {
509516
if (words[0].equalsIgnoreCase("greedisgood")) {
@@ -515,7 +522,7 @@ public static void onPlayerChat(ServerChatEvent evt) {
515522
amount
516523
));
517524
evt.setCanceled(true);
518-
sendMessageToAllPlayers("server.reignofnether.used_cheat",
525+
sendMessageToAllPlayers("server.reignofnether.used_cheat_amount",
519526
false,
520527
playerName,
521528
words[0],
@@ -539,7 +546,7 @@ public static void onPlayerChat(ServerChatEvent evt) {
539546
case "ore" -> ResourcesServerEvents.addSubtractResources(new Resources(playerName, 0, 0, amount));
540547
}
541548
evt.setCanceled(true);
542-
sendMessageToAllPlayers("server.reignofnether.used_cheat",
549+
sendMessageToAllPlayers("server.reignofnether.used_cheat_amount",
543550
false,
544551
playerName,
545552
words[0] + " " + words[1],

src/main/java/com/solegendary/reignofnether/registrars/EntityRegistrar.java

+7
Original file line numberDiff line numberDiff line change
@@ -277,6 +277,12 @@ public class EntityRegistrar {
277277
.clientTrackingRange(UNIT_CLIENT_TRACKING_RANGE)
278278
.build(new ResourceLocation(ReignOfNether.MOD_ID, "hero_experience_orb").toString()));
279279

280+
public static final RegistryObject<EntityType<KillerRabbitUnit>> KILLER_RABBIT_UNIT = ENTITIES.register("killer_rabbit_unit",
281+
() -> EntityType.Builder.of(KillerRabbitUnit::new, MobCategory.MISC)
282+
.sized(EntityType.RABBIT.getWidth(), EntityType.RABBIT.getHeight())
283+
.clientTrackingRange(UNIT_CLIENT_TRACKING_RANGE)
284+
.build(new ResourceLocation(ReignOfNether.MOD_ID, "killer_rabbit_unit").toString()));
285+
280286
public static void init() {
281287
ENTITIES.register(FMLJavaModLoadingContext.get().getModEventBus());
282288
}
@@ -320,6 +326,7 @@ public static EntityType<? extends Mob> getEntityType(String unitName) {
320326
case PandaProd.itemName -> EntityRegistrar.PANDA_UNIT.get();
321327
case WolfProd.itemName -> EntityRegistrar.WOLF_UNIT.get();
322328
case LlamaProd.itemName -> EntityRegistrar.LLAMA_UNIT.get();
329+
case "Killer Rabbit" -> EntityRegistrar.KILLER_RABBIT_UNIT.get();
323330
default -> null;
324331
};
325332
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,204 @@
1+
package com.solegendary.reignofnether.unit.units.neutral;
2+
3+
import com.solegendary.reignofnether.ability.Ability;
4+
import com.solegendary.reignofnether.hud.AbilityButton;
5+
import com.solegendary.reignofnether.resources.ResourceCost;
6+
import com.solegendary.reignofnether.resources.ResourceCosts;
7+
import com.solegendary.reignofnether.unit.Checkpoint;
8+
import com.solegendary.reignofnether.unit.goals.*;
9+
import com.solegendary.reignofnether.unit.interfaces.AttackerUnit;
10+
import com.solegendary.reignofnether.unit.interfaces.Unit;
11+
import com.solegendary.reignofnether.util.Faction;
12+
import net.minecraft.core.BlockPos;
13+
import net.minecraft.nbt.CompoundTag;
14+
import net.minecraft.network.syncher.EntityDataAccessor;
15+
import net.minecraft.network.syncher.EntityDataSerializers;
16+
import net.minecraft.network.syncher.SynchedEntityData;
17+
import net.minecraft.sounds.SoundEvents;
18+
import net.minecraft.world.DifficultyInstance;
19+
import net.minecraft.world.entity.*;
20+
import net.minecraft.world.entity.ai.attributes.AttributeSupplier;
21+
import net.minecraft.world.entity.ai.attributes.Attributes;
22+
import net.minecraft.world.entity.ai.goal.FloatGoal;
23+
import net.minecraft.world.entity.ai.goal.Goal;
24+
import net.minecraft.world.entity.animal.PolarBear;
25+
import net.minecraft.world.entity.animal.Rabbit;
26+
import net.minecraft.world.entity.item.ItemEntity;
27+
import net.minecraft.world.entity.monster.Monster;
28+
import net.minecraft.world.item.ItemStack;
29+
import net.minecraft.world.level.Level;
30+
import net.minecraft.world.level.ServerLevelAccessor;
31+
import net.minecraft.world.level.block.state.BlockState;
32+
33+
import javax.annotation.Nullable;
34+
import java.util.ArrayList;
35+
import java.util.List;
36+
37+
// intentionally OP killer rabbit - spawn with cheat 'thebeastofcaerbannog'
38+
39+
public class KillerRabbitUnit extends Rabbit implements Unit, AttackerUnit {
40+
// region
41+
private BlockPos anchorPos = new BlockPos(0,0,0);
42+
public void setAnchor(BlockPos bp) { anchorPos = bp; }
43+
public BlockPos getAnchor() { return anchorPos; }
44+
45+
private final ArrayList<Checkpoint> checkpoints = new ArrayList<>();
46+
public ArrayList<Checkpoint> getCheckpoints() { return checkpoints; };
47+
48+
public GarrisonGoal getGarrisonGoal() { return null; }
49+
public boolean canGarrison() { return getGarrisonGoal() != null; }
50+
51+
UsePortalGoal usePortalGoal;
52+
public UsePortalGoal getUsePortalGoal() { return usePortalGoal; }
53+
public boolean canUsePortal() { return getUsePortalGoal() != null; }
54+
55+
public Faction getFaction() {return Faction.NONE;}
56+
public List<AbilityButton> getAbilityButtons() {return abilityButtons;};
57+
public List<Ability> getAbilities() {return abilities;}
58+
public List<ItemStack> getItems() {return items;};
59+
public MoveToTargetBlockGoal getMoveGoal() {return moveGoal;}
60+
public SelectedTargetGoal<? extends LivingEntity> getTargetGoal() {return targetGoal;}
61+
public ReturnResourcesGoal getReturnResourcesGoal() {return returnResourcesGoal;}
62+
public int getMaxResources() {return maxResources;}
63+
64+
private MoveToTargetBlockGoal moveGoal;
65+
private SelectedTargetGoal<? extends LivingEntity> targetGoal;
66+
private ReturnResourcesGoal returnResourcesGoal;
67+
private AbstractMeleeAttackUnitGoal attackGoal;
68+
private MeleeAttackBuildingGoal attackBuildingGoal;
69+
70+
public LivingEntity getFollowTarget() { return followTarget; }
71+
public boolean getHoldPosition() { return holdPosition; }
72+
public void setHoldPosition(boolean holdPosition) { this.holdPosition = holdPosition; }
73+
74+
// if true causes moveGoal and attackGoal to work together to allow attack moving
75+
// moves to a block but will chase/attack nearby monsters in range up to a certain distance away
76+
private LivingEntity followTarget = null; // if nonnull, continuously moves to the target
77+
private boolean holdPosition = false;
78+
private BlockPos attackMoveTarget = null;
79+
80+
// which player owns this unit? this format ensures its synched to client without having to use packets
81+
public String getOwnerName() { return this.entityData.get(ownerDataAccessor); }
82+
public void setOwnerName(String name) { this.entityData.set(ownerDataAccessor, name); }
83+
public static final EntityDataAccessor<String> ownerDataAccessor =
84+
SynchedEntityData.defineId(KillerRabbitUnit.class, EntityDataSerializers.STRING);
85+
86+
@Override
87+
protected void defineSynchedData() {
88+
super.defineSynchedData();
89+
this.entityData.define(ownerDataAccessor, "");
90+
}
91+
92+
// combat stats
93+
public float getMovementSpeed() {return movementSpeed;}
94+
public float getUnitMaxHealth() {return maxHealth;}
95+
public float getUnitArmorValue() {return armorValue;}
96+
@Nullable
97+
public ResourceCost getCost() {return ResourceCosts.GRIZZLY_BEAR;}
98+
public boolean getWillRetaliate() {return willRetaliate;}
99+
public int getAttackCooldown() {return (int) (20 / attacksPerSecond);}
100+
public float getAttacksPerSecond() {return attacksPerSecond;}
101+
public float getAggroRange() {return aggroRange;}
102+
public boolean getAggressiveWhenIdle() {return aggressiveWhenIdle && !isVehicle();}
103+
public float getAttackRange() {return attackRange;}
104+
public float getUnitAttackDamage() {return attackDamage;}
105+
public BlockPos getAttackMoveTarget() { return attackMoveTarget; }
106+
public boolean canAttackBuildings() {return getAttackBuildingGoal() != null;}
107+
public Goal getAttackGoal() { return attackGoal; }
108+
public Goal getAttackBuildingGoal() { return attackBuildingGoal; }
109+
public void setAttackMoveTarget(@Nullable BlockPos bp) { this.attackMoveTarget = bp; }
110+
public void setFollowTarget(@Nullable LivingEntity target) { this.followTarget = target; }
111+
112+
// endregion
113+
114+
final static public float attackDamage = 100.0f;
115+
final static public float attacksPerSecond = 0.35f;
116+
final static public float attackRange = 2; // only used by ranged units or melee building attackers
117+
final static public float aggroRange = 10;
118+
final static public boolean willRetaliate = true; // will attack when hurt by an enemy
119+
final static public boolean aggressiveWhenIdle = true;
120+
121+
final static public float maxHealth = 1000.0f;
122+
final static public float armorValue = 0.0f;
123+
final static public float movementSpeed = 0.35f;
124+
public int maxResources = 100;
125+
126+
private final List<AbilityButton> abilityButtons = new ArrayList<>();
127+
private final List<Ability> abilities = new ArrayList<>();
128+
private final List<ItemStack> items = new ArrayList<>();
129+
130+
public KillerRabbitUnit(EntityType<? extends Rabbit> entityType, Level level) {
131+
super(entityType, level);
132+
}
133+
134+
@Override
135+
public boolean removeWhenFarAway(double d) { return false; }
136+
137+
public static AttributeSupplier.Builder createAttributes() {
138+
return Monster.createMonsterAttributes()
139+
.add(Attributes.ATTACK_DAMAGE, KillerRabbitUnit.attackDamage)
140+
.add(Attributes.MOVEMENT_SPEED, KillerRabbitUnit.movementSpeed)
141+
.add(Attributes.MAX_HEALTH, KillerRabbitUnit.maxHealth)
142+
.add(Attributes.FOLLOW_RANGE, Unit.getFollowRange())
143+
.add(Attributes.ARMOR, KillerRabbitUnit.armorValue);
144+
}
145+
146+
@Override
147+
protected float getJumpPower() {
148+
return super.getJumpPower() * 2;
149+
}
150+
151+
@Override
152+
public Variant getVariant() {
153+
return Variant.EVIL;
154+
}
155+
156+
@Override // immune to fall damage
157+
protected void checkFallDamage(double pY, boolean pOnGround, BlockState pState, BlockPos pPos) { }
158+
159+
@Override
160+
public boolean doHurtTarget(Entity pEntity) {
161+
this.playSound(SoundEvents.RABBIT_ATTACK, 1.0F, (this.random.nextFloat() - this.random.nextFloat()) * 0.2F + 1.0F);
162+
return pEntity.hurt(this.damageSources().mobAttack(this), attackDamage);
163+
}
164+
165+
@Override // prevent vanilla logic for picking up items
166+
protected void pickUpItem(ItemEntity pItemEntity) { }
167+
@Override
168+
public LivingEntity getTarget() {
169+
return this.targetGoal.getTarget();
170+
}
171+
172+
public void tick() {
173+
this.setCanPickUpLoot(false);
174+
super.tick();
175+
Unit.tick(this);
176+
AttackerUnit.tick(this);
177+
}
178+
179+
public void initialiseGoals() {
180+
this.usePortalGoal = new UsePortalGoal(this);
181+
this.moveGoal = new MoveToTargetBlockGoal(this, false, 0);
182+
this.targetGoal = new SelectedTargetGoal<>(this, true, true);
183+
this.attackGoal = new MeleeAttackUnitGoal(this, false);
184+
this.attackBuildingGoal = new MeleeAttackBuildingGoal(this);
185+
}
186+
187+
@Override
188+
protected void registerGoals() {
189+
initialiseGoals();
190+
this.goalSelector.addGoal(2, usePortalGoal);
191+
this.goalSelector.addGoal(1, new FloatGoal(this));
192+
this.goalSelector.addGoal(2, attackGoal);
193+
this.goalSelector.addGoal(2, attackBuildingGoal);
194+
this.targetSelector.addGoal(2, targetGoal);
195+
this.goalSelector.addGoal(3, moveGoal);
196+
this.goalSelector.addGoal(4, new RandomLookAroundUnitGoal(this));
197+
}
198+
199+
@Override
200+
@Nullable
201+
public SpawnGroupData finalizeSpawn(ServerLevelAccessor pLevel, DifficultyInstance pDifficulty, MobSpawnType pReason, @Nullable SpawnGroupData pSpawnData, @Nullable CompoundTag pDataTag) {
202+
return pSpawnData;
203+
}
204+
}

src/main/java/com/solegendary/reignofnether/util/MiscUtil.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -185,7 +185,7 @@ public static Vector3d screenPosToWorldPos(Minecraft MC, int mouseX, int mouseY)
185185
// for some reason position is off by some y coord so just move it down manually
186186
return new Vector3d(
187187
MC.player.xo - XZRotated.x,
188-
MC.player.yo + y + 1.5f,
188+
MC.player.yo + y,
189189
MC.player.zo - XZRotated.y
190190
);
191191
}

src/main/resources/assets/reignofnether/lang/en_us.json

+2-1
Original file line numberDiff line numberDiff line change
@@ -626,7 +626,8 @@
626626
"server.reignofnether.started_sandbox": "%s has started their game (SANDBOX)",
627627
"server.reignofnether.total_players": "There are now %d total RTS player(s)",
628628
"server.reignofnether.bot_added": "%s (bot) has been added to the game!",
629-
"server.reignofnether.used_cheat": "%s used cheat: %s %s",
629+
"server.reignofnether.used_cheat_amount": "%s used cheat: %s %s",
630+
"server.reignofnether.used_cheat": "%s used cheat: %s",
630631
"server.reignofnether.enabled_cheat": "%s enabled cheat %s",
631632
"server.reignofnether.disabled_cheat": "%s disabled cheat %s",
632633
"server.reignofnether.all_cheats": "%s enabled all cheats",

0 commit comments

Comments
 (0)