Defining Simple Functions - Malmö Project Blog (2023)

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 parameterThe function is as follows. Note that we removed the code that was already insideAfter the parameterIt 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 ifparameterThe 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 backInaccuratelyProbably telling the caller of this function that the provided Schmea is not what this implementation is designed for.

S druge strane, akoparameterObjects 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 copiesand set the instance to the named variationrsc parametersFollow the conventions of other reward managers (rsc stands for reward, structure and replication).

once we have aPrizes for structural copiesFor example, we can ask it about the variables we want to store.

First we get fourBlock point of saleexample. This is the first kind of Minecraft we've seen!Block point of saleBasically, 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 positionAs 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 saleExample forPlaceJAXB seems to have created an instance (remember ourunnamed network definitionUse the types defined in the schema, ie.Place.) The resultPlaceincludedecimal largefromPlaceusexs: decimalnos. 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 salegintValueExact()of threedecimal large. Finally, pay attention to the use of annotations.@is not emptyThis helps the IDE find where it needs to golock position from positionIt 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 definitionyes, 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 finddeltaThis 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 Wizardclass iMinecraftTipoAyudanteThe courses are definitely something you should consider, they are taughtdrawing decoratorIt is also useful when analyzing schema information, e.g.A brick-based object typearriveblock states, an internal representation of BlockStates in Minecraft. So, second to last, we have twoIBlockStatesMatches block states for correct block placement and incorrect block placement cases. Finally, we store the reward dimension for this instance.Prizes for structural copieswill be sent.

If all of the above is successful, we are done with the analysisPrizes for structural copiesscheme and can be returnedreal.

prepare and clean

Once again, if we look at other task managers, especially reward managers, we have in mindPreparemethod, we eliminateexit codeIt exists inModo Malmöattribute and class registration. Next step, register the course on Minecraft Forgeevent busCrucial 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); }}

References

Top Articles
Latest Posts
Article information

Author: Horacio Brakus JD

Last Updated: 11/23/2023

Views: 5869

Rating: 4 / 5 (51 voted)

Reviews: 82% of readers found this page helpful

Author information

Name: Horacio Brakus JD

Birthday: 1999-08-21

Address: Apt. 524 43384 Minnie Prairie, South Edda, MA 62804

Phone: +5931039998219

Job: Sales Strategist

Hobby: Sculling, Kitesurfing, Orienteering, Painting, Computer programming, Creative writing, Scuba diving

Introduction: My name is Horacio Brakus JD, I am a lively, splendid, jolly, vivacious, vast, cheerful, agreeable person who loves writing and wants to share my knowledge and understanding with you.