analysis parameters
look atparsing parameters (object parameters)
functions in each classtask manager
. This should give us a good idea of what to do.
The code we will add.After the parameter
The function is as follows. Note that we removed the code that was already insideAfter the parameter
It just calls the superclass method. This is not really what we want. We want to override the superclass method and change the return value.
@Override public Boolean parseParameters(Object params) { if (params == null || !(params instancia de RewardForStructureCopying)) devuelve false; } RewardForStructureCopying rscparams = (RewardForStructureCopying) parametri; BlockPos minPlayerStructurePos = this.blockPosFromPos(rscparams.getPlayerStructureBounds().getMin()); BlockPos maxPlayerStructurePos = this.blockPosFromPos(rscparams.getPlayerStructureBounds().getMax()); BlockPos minGoalStructurePos = this.blockPosFromPos(rscparams.getGoalStructureBounds().getMin()); BlockPos maxGoalStructurePos = this.blockPosFromPos(rscparams.getGoalStructureBounds().getMax()); this.playerStructureAABB = new AxisAlignedBB(minPlayerStructurePos, maxPlayerStructurePos); this.goalStructureAABB = new AxisAlignedBB(minGoalStructurePos, maxGoalStructurePos); if(playerStructureAABB.intersectsWith(goalStructureAABB)) { System.out.print("警告!RewardForStructureCopying 得到玩家结构边界" + " 和目标结构边界相交!" + " 可能会出现未定义的行为!\n"); this.structVolume =volumeOfAABB(playerStructureAABB); if(this.structVolume != volumeOfAABB(goalStructureAABB)) { System.out.print("警告!RewardForStructureCopying 获得了玩家结构边界" + " 和目标结构边界具有不等的体积!" + " 可能会出现未定义的行为!\n" ); this.delta = new Vec3i(goalStructureAABB.minX -playerStructureAABB.minX,goalStructureAABB.minY -playerStructureAABB.minY,goalStructureAABB.minZ -playerStructureAABB.minZ); this.rewardDensity = rscparams.getRewardD ensity(); DrawBlockBasedObjectType blockBasedObjectType = rscparams.getBlockTypeOnCorrectPlacement(); this.blockTypeOnCorrectPlacement = BlockDrawingHelper.applyModifications(MinecraftTypeHelper.ParseBlockType(blockBasedObjectType.getType().value()), blockBasedObjectType.getC olour(), blockBasedObjectType.getFace(), blockBasedObjectType.getVariant()) ; blockBasedObjectType = rscparams.getBlockTypeOnIn CorrectPlacement(); this.blockTypeOnIn CorrectPlacement = BlockDrawingHelper.applyModifications( MinecraftTypeHelper.ParseBlockType(blockBasedObjectType.getType().value()), blockBasedObjectType.getColour(), blockBasedObject Type.getFace(), blockBasedObjectType.getVariant( ) ); this.dimension = rscparams.getDimension();返回真; }
The first thing we do is check ifparameter
The object is either null or is not the schema type we expect, that is, it is not of that type.Prizes for structural copies
. If that's the case, we'll be backInaccurately
Probably telling the caller of this function that the provided Schmea is not what this implementation is designed for.
S druge strane, akoparameter
Objects are actually typesPrizes for structural copies
, we do the honorGoal
, the only class in Java that does not have a superclass from which all other classes inherit,Prizes for structural copies
and set the instance to the named variationrsc parameters
Follow the conventions of other reward managers (rsc stands for reward, structure and replication).
once we have aPrizes for structural copies
For example, we can ask it about the variables we want to store.
First we get fourBlock point of sale
example. This is the first kind of Minecraft we've seen!Block point of sale
Basically, an object that contains information about the location of a block, or in other words, data similar to a three-dimensional tuple or a three-dimensional vector. Pay attention to the use of the method.lock position from position
As follows:
BlockPos privatni blockPosFromPos (@Nonnull Pos pos) { devolver nuevo BlockPos(pos.getX().intValueExact(), pos.getY().intValueExact(), pos.getZ().intValueExact());}
The above method simply returns newBlock point of sale
Example forPlace
JAXB seems to have created an instance (remember ourunnamed network definition
Use the types defined in the schema, ie.Place
.) The resultPlace
includedecimal large
fromPlace
usexs: decimalno
s. This is a good type for performing exact arithmetic; however, to compare two grids of the same volume, we'll be comparing blocks within the grid itself, and we don't really care about decimal or floating-point arithmetic. We can settle for whole numbers. That's how we create a new oneBlock point of sale
gintValueExact()
of threedecimal large
. Finally, pay attention to the use of annotations.@is not empty
This helps the IDE find where it needs to golock position from position
It can be called with a "null" argument and throw an error to the user (even before compile time).
Then we define two boundary blocks aligned with the axis, essentially asunnamed network definition
yes, but usingBlock point of sale
' ratherPlace
'. We use them for simple checks right away: do the player structure and the target structure intersect? If they do, we give up; if they want, we give up. Otherwise, we continue.
Now we continue the search and make sure that both structures have the same structure volume. This uses the following member functions:
AABB privatni float volumen (AxisAlignedBB axisAlignedBB) { return (float)(axisAlignedBB.maxX - axisAlignedBB.minX + 1) * (float)(axisAlignedBB.maxY - axisAlignedBB.minY + 1) * (float)(axisAlignedBB.maxZ - axisAlignedBB . minZ ) + 1);}
Continuing, we finddelta
This is a 3D vector that specifies the vector to be added to a specific block position in the player structure to obtain the block position of the corresponding target structure. We will use this vector when comparing two structures. Moving on, we store the reward density.
It isBlock Diagram Wizard
class iMinecraftTipoAyudante
The courses are definitely something you should consider, they are taughtdrawing decorator
It is also useful when analyzing schema information, e.g.A brick-based object type
arriveblock state
s, an internal representation of BlockStates in Minecraft. So, second to last, we have twoIBlockStates
Matches block states for correct block placement and incorrect block placement cases. Finally, we store the reward dimension for this instance.Prizes for structural copies
will be sent.
If all of the above is successful, we are done with the analysisPrizes for structural copies
scheme and can be returnedreal
.
prepare and clean
Once again, if we look at other task managers, especially reward managers, we have in mindPrepare
method, we eliminateexit code
It exists inModo Malmö
attribute and class registration. Next step, register the course on Minecraft Forgeevent bus
Crucial when we start adding event handlers. Without it, the event handler will not run. Note that there is another bus for adding event handlers, vizFMLCommonHandler.bus()
. To see when you need to register event handlers with this bus, see the full list of Forge event handlers available as a Minecraft Forge resource in the Java and MinecraftForge section. So prepare as follows:
@Overridepublic void pripreme(MissionInit MissionInit) { intentar { if (MalmoMod.getPropertiesForCurrentThread().containsKey("QuitCode")) MalmoMod.getPropertiesForCurrentThread().remove("QuitCode"); } } catch (Excepción e) { System.out.println("获取属性失败。"); MinecraftForge.EVENT_BUS.register(esto);}
Cleaning is very simple, all we need to do is cancel the clock, like this:
@Overridepublic void cleanup() { MinecraftForge.EVENT_BUS.unregister(esto);}
The end result of this section, along with some member variables not shown, is as follows:
public class RewardForStructureConstructionImplementation extends HandlerBase implements IRewardProducer { AxisAlignedBB private playerStructureAABB; private AxisAlignedBB goalStructureAABB; private Vec3i increment; volume of private floating structure; private RewardDensityForBuildAndBreak reward density; private IBlockState blockTypeOnCorrectPlacement; private IBlockState blockType OnIn CorrectPlacement; private int dimension; /** * Attempt to set The given object has been resolved into a parameter set for this controller. * * @param params The parameter block to parse * @return true if the object is meaningful to this controller; false otherwise. */ @Override public boolean parseParameters(Object params) { if (params == null || !(params instance of RewardForStructureCopying)) return false; } RewardForStructureCopying rscparams = (RewardForStructureCopying) params; BlockPos minPlayerStructurePos = this.block PosFromPos(rscparams.getPlayerS boundsStructure().getMin()); BlockPos maxPlayerStructurePos = this.blockPosFromPos(rscparams.getPlayerStructureBounds().getMax()); BlockPos minGoalStructurePos = this.blockPosFromPos(rscparams.getGoalStructureBounds().getMin()); BlockPos maxGoalStructurePos = this.blockPosFromPos ( rscparams.getGoalStructureBounds().getMax()); this.playerStructureAABB = new AxisAlignedBB(minPlayerStructurePos, maxPlayerStructurePos); this.goalStructureAABB = new AxisAlignedBB(minGoalStructurePos, maxGoalStructurePos); assert(!playerStructureAABB.intersects with(GoalStructureAABB)); this one. structVolume = volumeOfAABB(playerStructureAABB); assert(this.structVolume==volumeOfAABB(targetStructureAABB)); this.delta = new Vec3i(targetStructureAABB.minX -playerStructureAABB.minX,targetStructureAABB.minY -playerStructureAABB.minY,targetStructureAABB.minZ -playerStructureAABB.minZ); this.rewardDensity = rscparams.getRewardDensity(); DrawBlockBasedObjectType blockBasedObjectType = rscparams.getBlockTypeOnCorrectPlacement(); this.blockTypeOnCorrectPlacement = BlockDrawingHelper.applyModifications(MinecraftTypeHelper.ParseBlockType(blockBasedObjectType.getType().value()), blockBasedObjectType. get Color() , blockBasedObjectType. getFace(), blockBasedOb jectType.getVariant()); blockBasedObjectType = rscparams.getBlockTypeOnIn CorrectPlacement(); this.blockTypeOnIn CorrectPlacement = BlockDrawingHelper.applyModifications( MinecraftTypeHelper.ParseBlockType(blockBasedObjectType.getType().value()), blockBasedObjectType.get Color(), blockBasedObjectType.getFace(), blockBasedObjectType eg.getVariant()); this.dimension = rscparams.getDimension(); returns true; } private BlockPos blockPosFromPos(@Nonnull Pos pos) { return new BlockPos(pos.getX().intValueExact(), pos.getY().intValueExact(), pos.getZ().intValueExact()); } AABB private float volume(AxisAlignedBB axisAlignedBB) { return (float) (axisAlignedBB.maxX - axisAlignedBB.minX + 1) * (float) (axisAlignedBB.maxY - axisAlignedBB.minY + 1) * (float) (axisAlignedBB.maxZ - axisAlignedBB .minZ + 1); } /** * Get the reward value for the current state of Minecraft. * * @param MissionInit A MissionInit object for the current mission, * which may contain parameters for reward requests. * @return float identifying the current reward signal for the learning agent */ @Override public float getReward(MissionInit MissionInit) { return 0; } /** * Called once before starting a mission, for any necessary initialization. * * @param MissionInit */ @Override public void Preparation(MissionInit MissionInit) { try { if (MalmoMod.getPropertiesForCurrentThread().containsKey("QuitCode")) MalmoMod.getPropertiesForCurrentThread().remove("QuitCode"); } } catch (Exception e) { System.out.println("Error getting property."); MinecraftForge.EVENT_BUS.register(this); } /** * Called once after the task completes, for any necessary cleanup. */ @Override public void cleanup() { MinecraftForge.EVENT_BUS.unregister(this); }}