-
Notifications
You must be signed in to change notification settings - Fork 161
Adds respawning handler for agents - MUST UPDATE OLD ENV-SPECS #462
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: dev
Are you sure you want to change the base?
Changes from all commits
6e62961
1d4cb60
2ac0f15
78cf687
04aae20
3d99d74
4cb31dd
a2f2f11
28601ba
9aa2e4d
46522ab
40a821c
386d7ef
bae28af
521b9ab
d021bab
88db31c
b4b583d
8f4fa2d
dfa0551
94cdeb0
1b643b9
81ddb74
426c9ec
cd58b00
ced9603
7fe5da8
ff04c6f
fd69a88
877e38d
3ab329c
409c758
05f3438
d719a73
3d93181
ac0f89d
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Large diffs are not rendered by default.
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,76 @@ | ||
// -------------------------------------------------------------------------------------------------- | ||
// Copyright (c) 2016 Microsoft Corporation | ||
// | ||
// Permission is hereby granted, free of charge, to any person obtaining a copy of this software and | ||
// associated documentation files (the "Software"), to deal in the Software without restriction, | ||
// including without limitation the rights to use, copy, modify, merge, publish, distribute, | ||
// sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is | ||
// furnished to do so, subject to the following conditions: | ||
// | ||
// The above copyright notice and this permission notice shall be included in all copies or | ||
// substantial portions of the Software. | ||
// | ||
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT | ||
// NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND | ||
// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, | ||
// DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, | ||
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. | ||
// -------------------------------------------------------------------------------------------------- | ||
|
||
package com.microsoft.Malmo.MissionHandlers; | ||
|
||
import com.microsoft.Malmo.MissionHandlerInterfaces.IWantToQuit; | ||
import com.microsoft.Malmo.Schemas.AgentQuitFromTimeUp; | ||
import com.microsoft.Malmo.Schemas.MissionInit; | ||
import net.minecraft.client.Minecraft; | ||
import net.minecraft.util.DamageSource; | ||
import net.minecraft.util.text.Style; | ||
import net.minecraft.util.text.TextComponentString; | ||
import net.minecraft.util.text.TextFormatting; | ||
import net.minecraftforge.common.ForgeHooks; | ||
import net.minecraftforge.event.entity.living.LivingDeathEvent; | ||
import net.minecraftforge.fml.common.eventhandler.EventPriority; | ||
import net.minecraftforge.fml.common.eventhandler.SubscribeEvent; | ||
import net.minecraftforge.fml.common.gameevent.TickEvent; | ||
|
||
/** | ||
* IWantToQuit object that returns true when an agent dies. | ||
* Also records the reason for death. | ||
*/ | ||
|
||
public class AgentQuitFromDeathImplementation extends HandlerBase implements IWantToQuit | ||
{ | ||
private String quitCode = ""; | ||
private DamageSource deathSource = null; | ||
|
||
|
||
@Override | ||
public boolean parseParameters(Object params) | ||
{ | ||
return true; | ||
} | ||
|
||
|
||
@SubscribeEvent(priority = EventPriority.LOWEST) | ||
public void onClientTick(LivingDeathEvent event) | ||
{ | ||
// Use the client tick to ensure we regularly update our state (from the client thread) | ||
this.deathSource = event.getSource(); | ||
// TODO this could have a lot more info here about who killed the agent, location, ect. | ||
this.quitCode = this.deathSource.getDamageType(); | ||
} | ||
|
||
@Override | ||
public boolean doIWantToQuit(MissionInit missionInit) { | ||
return Minecraft.getMinecraft().player.isDead; | ||
} | ||
|
||
@Override | ||
public void prepare(MissionInit missionInit) {} | ||
|
||
@Override | ||
public void cleanup() {} | ||
|
||
@Override | ||
public String getOutcome() { return this.quitCode; } | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,66 @@ | ||
// -------------------------------------------------------------------------------------------------- | ||
// Copyright (c) 2016 Microsoft Corporation | ||
// | ||
// Permission is hereby granted, free of charge, to any person obtaining a copy of this software and | ||
// associated documentation files (the "Software"), to deal in the Software without restriction, | ||
// including without limitation the rights to use, copy, modify, merge, publish, distribute, | ||
// sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is | ||
// furnished to do so, subject to the following conditions: | ||
// | ||
// The above copyright notice and this permission notice shall be included in all copies or | ||
// substantial portions of the Software. | ||
// | ||
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT | ||
// NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND | ||
// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, | ||
// DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, | ||
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. | ||
// -------------------------------------------------------------------------------------------------- | ||
|
||
package com.microsoft.Malmo.MissionHandlers; | ||
|
||
import com.microsoft.Malmo.MissionHandlerInterfaces.IWantToQuit; | ||
import com.microsoft.Malmo.Schemas.ServerQuitFromDeath; | ||
import com.microsoft.Malmo.Schemas.MissionInit; | ||
import net.minecraft.client.Minecraft; | ||
import net.minecraft.entity.player.EntityPlayerMP; | ||
|
||
import java.util.Objects; | ||
|
||
/** | ||
* IWantToQuit object that returns true when an agent dies. | ||
* Also records the reason for death. | ||
*/ | ||
|
||
public class ServerQuitFromDeathImplementation extends AgentQuitFromDeathImplementation implements IWantToQuit | ||
{ | ||
private ServerQuitFromDeath params = null; | ||
private Boolean quitWhenAnyDead = true; | ||
|
||
@Override | ||
public boolean parseParameters(Object params) { | ||
if (!(params instanceof ServerQuitFromDeath)) | ||
return false; | ||
|
||
this.params = (ServerQuitFromDeath) params; | ||
this.quitWhenAnyDead = this.params.isQuitWhenAnyDead(); | ||
return true; | ||
} | ||
|
||
|
||
@Override | ||
public boolean doIWantToQuit(MissionInit missionInit) { | ||
for (EntityPlayerMP playerMP : Objects.requireNonNull(Minecraft.getMinecraft().getIntegratedServer()).getPlayerList().playerEntityList) { | ||
if (this.quitWhenAnyDead == playerMP.isDead) | ||
return this.quitWhenAnyDead; | ||
} | ||
return !this.quitWhenAnyDead; | ||
} | ||
|
||
@Override | ||
public void prepare(MissionInit missionInit) {} | ||
|
||
@Override | ||
public void cleanup() {} | ||
|
||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -78,12 +78,12 @@ public abstract class MixinMinecraftGameloop { | |
@Shadow public Snooper usageSnooper; | ||
@Shadow public abstract int getLimitFramerate(); | ||
@Shadow public abstract boolean isFramerateLimitBelowMax(); | ||
@Shadow public boolean inGameHasFocus; | ||
|
||
@Shadow public boolean inGameHasFocus; | ||
@Shadow private int leftClickCounter; | ||
|
||
@Shadow public abstract void displayGuiScreen(GuiScreen guiScreen); | ||
|
||
private int numTicksPassed = 0; | ||
|
||
|
||
|
@@ -268,14 +268,14 @@ private void runGameLoop() throws IOException | |
|
||
this.mcProfiler.endSection(); //root | ||
} | ||
|
||
@Overwrite | ||
public void setIngameFocus() | ||
{ | ||
if (!this.inGameHasFocus) { | ||
this.inGameHasFocus = true; | ||
this.displayGuiScreen((GuiScreen) null); | ||
this.leftClickCounter = 10000; | ||
this.leftClickCounter = 0; | ||
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. If we leave this 10000 the agent has to wait that long before it is able to interact with anything again. Potentially a better fix would be to set this to 0 on respawn, but this should not affect the behavior of agents |
||
} | ||
} | ||
|
||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -1255,6 +1255,17 @@ | |
</xs:complexType> | ||
</xs:element> | ||
|
||
<xs:element name="ServerQuitFromDeath"> | ||
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. maybe 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. Good catch |
||
<xs:annotation> | ||
<xs:documentation> | ||
Specifies a time limit that applies to all agents. | ||
</xs:documentation> | ||
</xs:annotation> | ||
<xs:complexType> | ||
<xs:attribute name="quitWhenAnyDead" type="xs:boolean" use="optional" default="false"/> | ||
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. Note the default behavior here is different then the current default behavior for experiments (they are more simmilar to quitWhenAnyDead=true) |
||
</xs:complexType> | ||
</xs:element> | ||
|
||
<xs:element name="ServerQuitWhenAnyAgentFinishes"> | ||
<xs:annotation> | ||
<xs:documentation> | ||
|
@@ -3109,6 +3120,15 @@ | |
</xs:complexType> | ||
</xs:element> | ||
|
||
<xs:element name="AgentQuitFromDeath"> | ||
<xs:annotation> | ||
<xs:documentation> | ||
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. for agent to quit means to not respawn, correct? 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. Correct - they will stop being in the episode and the number of active agents will decrease unless the server also wants to quit when any agent dies 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. what happens if AgentQuitFromDeath is true, 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. The episode should end when there are 0 agents and the episode has started. I will check |
||
Allows the agent to quit on death. If not specified, agents will respawn per vanilla spawn mechanics. | ||
Sets the quit code of the agent based on how the agent died, e.g. "lava", "cactus", "flyIntoWall" | ||
</xs:documentation> | ||
</xs:annotation> | ||
</xs:element> | ||
|
||
<xs:element name="AgentQuitFromTouchingBlockType"> | ||
<xs:annotation> | ||
<xs:documentation> | ||
|
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.
nitpick - your opening curly brackets seem inconsistent (sometimes they are on a new line, sometimes on the same line as function / class name
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.
OK with either convention, I'll try and normalize. Off-topic should we lint all of the code base? I had a huge diff here because the code became auto-linted